Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 768 769 [770] 771 772 ... 795

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 818192 times)

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11535 on: November 18, 2019, 02:28:48 pm »

Things like Wine on Linux would almost certainly be a casualty.  At least with Wine virtualization can help since it's easier than ever to just install a Windows VM, but you still have to pay for the copy of Windows and all of that.

Does anyone have a succinct description of the original lawsuit?  I'm curious what was even at stake here.
Logged
Through pain, I find wisdom.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #11536 on: November 18, 2019, 04:17:17 pm »

That depends who gets the most say inside Microsoft. Microsoft has been spending the last few years apologizing to the linux computer and focusing on Open Source and one of the things that the new CEO prioritised was given the developers at Microsoft a bigger say in decisions with regards to their technology.

That they run Azure mostly on Linux may be related or may be a side-effect of giving developers more decision-making power at Microsoft and using that power to force corporate to see the better sides.

Either way, just like how Mono gets an official thumbs up from them nowadays it's not too unlikely they'd give Wine a thumbs up as well. But that they'd even be in a position to do that is a problem still, since ideally they wouldn't have that choice in the first place.

Microsoft have done enough that whilst one can't forget, it's enough for me to forgive.

EDIT: I originally meant "Linux Community", not Linux Computer but...honestly, either work xD
« Last Edit: November 19, 2019, 06:27:40 am by MorleyDev »
Logged

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11537 on: November 22, 2019, 09:05:16 am »

Howdy folks, I'm back on my bullshit once again as the kids say--programming a game once more.

My issue is that I am trying to get and render text input and while it is TECHNICALLY working, it takes maybe 5-15 presses of each key to get it to log. I don't think it's input LAG so to speak as the built up key presses do not accumulate over time, they simply don't register at all. The segments of code we're looking at here can be found generically under the text rendering class and put into practice within the game loop under gamestate #2.

Any suggestions would be appreciated. 
Class for clarity:
Code: [Select]
#text rendering and manipulation
class TextR():
   
    def __init__(self, text, x, y):
        self.text = text
        self.x = x
        self.y = y
       
    def render(self):
        rendered_text = menufont.render(self.text, False, (70, 54, 35))
        gameDisplay.blit(rendered_text, (self.x - rendered_text.get_size()[0]/2, self.y - rendered_text.get_size()[1]/2))
       
    def text_input(self):
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_BACKSPACE:
                    self.text = self.text[:-1]
                elif event.key == pygame.K_RETURN:
                    self.text = ""   
                else:
                    self.text += pygame.key.name(event.key)
Portion of game loop
Code: [Select]
#game loop
while not crashed:

    #quit
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True

        print(event)
   
    #main menu
    if gamestate == 0:
        #menu elements display
        gameDisplay.blit(menuback, (0, 0))
        gameDisplay.blit(menutextsurf, (590, 325))
       
        menuambi.set_volume(0.1)
        menuambi.play()
       
        newgamebutton = Button("newgamebutton", "newgamebutton2", "newgamebutton", 800, 450, 0, False, False)
        loadgamebutton = Button("loadgamebutton", "loadgamebutton", "loadgamebutton3", 800, 575, 1, False, False)
        optionsbutton = Button("optionsbutton", "optionsbutton", "optionsbutton3", 800, 700, 1, False, False)
       
        #new game
        if (newgamebutton.mc == True) and (newgamebutton.ms == True):
            gamestate = 2
            #reset sounds
            pygame.mixer.pause()   
       
        #load game
   
    #options
    if gamestate == 1:
        aaa
       
    #character creation   
    if gamestate == 2:
        #reset screen
        gameDisplay.fill(0)                 
        #text
        whatsyourname.render()
        #text + input
        nameinput.text_input()
        nameinput.render()

Code: [Select]
import pygame, os

pygame.init()
pygame.mixer.init()

gameDisplay = pygame.display.set_mode((1600,900))
pygame.display.set_caption('Artificer')

clock = pygame.time.Clock()

#/
#/
#/
#/
#/

#classes
#button
class Button():
   
    def __init__(self, file1, file2, file3, x, y, lock, mouse_hover, mouse_click):
        #default image
        self.file1 = pygame.image.load(os.path.expanduser("~\Desktop\Artificer\\" + file1 + ".png"))
        #depressed image
        self.file2 = pygame.image.load(os.path.expanduser("~\Desktop\Artificer\\" + file2 + ".png"))
        #locked/greyed out image
        self.file3 = pygame.image.load(os.path.expanduser("~\Desktop\Artificer\\" + file3 + ".png"))
        #blit coordinates
        self.x = x
        self.y = y
        #greyed out lock
        self.lock = lock
       
        self.ms = mouse_hover
        self.mc = mouse_click
       
        #blit default
        gameDisplay.blit(self.file1, (x - self.file1.get_size()[0]/2, y - self.file1.get_size()[1]/2))
       
        #blit greyed out
        if self.lock == 1:
            gameDisplay.blit(self.file3, (x - self.file3.get_size()[0]/2, y - self.file3.get_size()[1]/2))
       
        #blit pressed/depressed
        elif (pygame.mouse.get_pos()[0] < x + self.file1.get_size()[0]/2
              and pygame.mouse.get_pos()[1] <  y + self.file1.get_size()[1]/2
              and pygame.mouse.get_pos()[0] > x - self.file1.get_size()[0]/2
              and pygame.mouse.get_pos()[1] > y - self.file1.get_size()[1]/2
              ):
            gameDisplay.blit(self.file2, (x - self.file2.get_size()[0]/2, y - self.file2.get_size() [1]/2))
            self.ms = True
           
            if pygame.mouse.get_pressed()[0] == True:
                self.mc = True

#text rendering and manipulation
class TextR():
   
    def __init__(self, text, x, y):
        self.text = text
        self.x = x
        self.y = y
       
    def render(self):
        rendered_text = menufont.render(self.text, False, (70, 54, 35))
        gameDisplay.blit(rendered_text, (self.x - rendered_text.get_size()[0]/2, self.y - rendered_text.get_size()[1]/2))
       
    def text_input(self):
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_BACKSPACE:
                    self.text = self.text[:-1]
                elif event.key == pygame.K_RETURN:
                    self.text = ""   
                else:
                    self.text += pygame.key.name(event.key)
               
#/
#/
#/
#/
#/

#hardcoded menu stuff
menuback = pygame.image.load(os.path.expanduser("~\Desktop\Artificer\menuplaceholder.png"))
menufont = pygame.font.Font(os.path.expanduser("~\Desktop\Artificer\\bitmgothic.ttf"), 48)
menutextsurf = menufont.render('A R T I F I C E R', False, (70, 54, 35))

menuambi = pygame.mixer.Sound(os.path.expanduser("~\Desktop\Artificer\menuambienceplaceholder.ogg"))

#hardcoded character creation stuff
whatsyourname = TextR("What is your name?", 800, 450)
nameinput = TextR("", 800, 575)

#game loop stuff and game state variable
gamestate = 0
crashed = False
                       
#/                       
#/                       
#/   
#/                       
#/                       
                       
#game loop
while not crashed:

    #quit
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True

        print(event)
   
    #main menu
    if gamestate == 0:
        #menu elements display
        gameDisplay.blit(menuback, (0, 0))
        gameDisplay.blit(menutextsurf, (590, 325))
       
        menuambi.set_volume(0.1)
        menuambi.play()
       
        newgamebutton = Button("newgamebutton", "newgamebutton2", "newgamebutton", 800, 450, 0, False, False)
        loadgamebutton = Button("loadgamebutton", "loadgamebutton", "loadgamebutton3", 800, 575, 1, False, False)
        optionsbutton = Button("optionsbutton", "optionsbutton", "optionsbutton3", 800, 700, 1, False, False)
       
        #new game
        if (newgamebutton.mc == True) and (newgamebutton.ms == True):
            gamestate = 2
            #reset sounds
            pygame.mixer.pause()   
       
        #load game
   
    #options
    if gamestate == 1:
        aaa
       
    #character creation   
    if gamestate == 2:
        #reset screen
        gameDisplay.fill(0)                 
        #text
        whatsyourname.render()
        #text + input
        nameinput.text_input()
        nameinput.render()
       
    #world map
    if gamestate == 3:
        aaa
       
    #local map
    if gamestate == 4:
        aaa
       
    #combat   
    if gamestate == 5:
        aaa
       
    #loot
    if gamestate == 6:
        aaa
       
    #cutsceens 
    if gamestate == 7:
        aaa
       
    #conversations 
    if gamestate == 8:
        aaa
       
    #inventory/equipment
    if gamestate == 9:
        aaa
       
    #characer sheet/level up
    if gamestate == 10:
        aaa
       
    #crafting***
    if gamestate == 11:
        aaa
       
    #skills and spellbook
    if gamestate == 12:
        aaa
       
    #journal/quests
    if gamestate == 13:
        aaa
       
       
       
       
   
    #refresh & fps
    pygame.display.update()
    clock.tick(60)
   
pygame.quit()
quit()
« Last Edit: November 22, 2019, 12:25:51 pm by Urist McScoopbeard »
Logged
This conversation is getting disturbing fast, disturbingly erotic.

WealthyRadish

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11538 on: November 22, 2019, 01:40:00 pm »

My first guess is you're calling pygame.event.get() in multiple places, which this seems to say will clear all the events in the queue. Like in the first part of the loop where you check for the QUIT event, I think you're deleting all the input events every tick before they're likely to be read.

---


In other news, I was writing some C++ earlier today, and found myself trying to cram a "goto" into a lambda function I had defined inside of a struct method, and you know what, I don't even feel bad about it.
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11539 on: November 22, 2019, 01:40:35 pm »

Ninjaed, but yes, I suspect this code block is eating the key press events:

Code: [Select]
for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True

        print(event)
Logged
Through pain, I find wisdom.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11540 on: November 22, 2019, 01:46:45 pm »

Calling pygame.event.get multiple times isn't necessarily a problem.

Like, you could see if there's a quit event:

Code: [Select]
for event in pygame.event.get(eventtype=pygame.QUIT)

And then wherever you do your key checking, you could continue iterating over all remaining events to ensure you don't start filling up your queues.

Disclaimer: This is an educated guess after reading the docs. If it doesn't work... blame pygame? ‾\_(ツ)_/‾
Logged

Urist McScoopbeard

  • Bay Watcher
  • Damnit Scoopz!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11541 on: November 22, 2019, 02:07:36 pm »

Thanks peeps, it seems that the the quit code block was in fact eating the event queue. After changing it around to function more akin to Mephisto's suggestion, the text input is fast as ever--and the game still quits just fine!

My humble appreciation to all of you!
Logged
This conversation is getting disturbing fast, disturbingly erotic.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11542 on: November 22, 2019, 08:01:51 pm »

My general advice would be to wrap input up in its own class or system, have it generate your own user-rolled "system commands". Then you don't need to know which button was pressed / whether an icon was pressed, just that the input module output a "closeApp" or a "backMenu" command and so forth. This also makes things much easier if you ever want to put in control customization or port to a device without a keyboard or with a different input scheme.

A nice holy grail is where as much of your program as possible doesn't even *know* which libraries are being used. Modules only have need-to-know access to the libraries needed to do their job. Having access to the same libraries scattered around is faster in the short term but makes your program very highly coupled with the implementation they've given you, so can be a big pain later on.
« Last Edit: November 22, 2019, 08:06:07 pm by Reelya »
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11543 on: December 01, 2019, 03:49:04 pm »

I'm of two minds about Twine. On one hand, I appreciate how it's helped me finally get over my fear/ignorance of Javascript, HTML and CSS. On the other hand, the offline editor has some very strange ideas about when and how to save your story. I'll try to test a passage only to find that it's cut off the ends of my tags, or only saved part of the text. Of course, there is no manual save feature--it's all up to the program.

The online editor is better about this, but that has its own problem in that it's impossible to use local images in the online editor. You either have to find your own image hosting, or download the story and insert relative links in the offline editor (most sites allow you to upload Twine stories as a zip containing all images and audio.)

I think for my next Twine project I'll use Twee2. I like the idea of the graphical interface, it just comes with too many caveats to continue using after this project.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11544 on: December 02, 2019, 12:00:10 am »

That already sounds pretty painful.  What exactly were you doing that requires you to call C code from Python?  It almost sounds like you're invoking an external binary that was written in C, but are you actually linking to a C library or something?
Logged
Through pain, I find wisdom.

McTraveller

  • Bay Watcher
  • This text isn't very personal.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11545 on: December 02, 2019, 07:08:14 am »

there are sufficient statistical calculations required that C will not suffice
This just means you don't want to write the statistical routines yourself, correct?  I can't think of how C is not capable of statistics, but I can see how it is not convenient.
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11546 on: December 02, 2019, 11:12:38 am »

So, I suppose the main question then is why you're required to write the program in Python.  This is for a class?  It's not going to affect your grade if your Python program is calling into C code, is it?  Presumably not everything has to be written in Python, since this is pretty much like using a Python library, but if the project is about writing the code to do the NLP and statistics then I could see how a teacher or TA might get fussy if they asked for a Python program and most of the juicy parts are written in C.

Anyway, figuring out how to call C functions from Python should be an interesting exercise and something I've never done.  I've been tempted to try a few times since Python is dog slow, but in the few cases where I decided I needed that it was for personal projects and I ended up rewriting them in C++ entirely.
Logged
Through pain, I find wisdom.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11547 on: December 02, 2019, 03:46:35 pm »

Was just curious if your program had to be mostly or entirely Python for grading reasons or something.  I'm sure that's a reasonable approach, since writing the NLP or neural network code in C would be a massive pain.  I'm sure libraries exist but are probably almost as much of a pain to use, and Python has nice libraries for it already.



Anyway, on a more personal note, I've been struggling to decide what to do for a personal game project.  I've been wanting to make something like an isometric twin stick shooter game for a while now, and even got a long way into it (about 2 years of semi consistent work) with Unreal 4 before I realized what I was doing was infeasible for one guy.  That was a full 3D game, and in that time period I managed to get most of one level done, with about a quarter of the characters modeled, rigged, textured and animated.  All at clearly less than professional quality.  The asset creation was just too time consuming.  I had literally over 200 models for that first level, some of which could be reused in later levels, but most levels would need many new assets.  Characters were a massive time sink, despite attempts to reuse parts of other character models.  Admittedly, I probably shot myself in the foot multiple times from a lack of experience in Blender, but I really didn't want to restart to fix some of the problems.

So, I wanted to try again with a simpler art style, preferably 2D pixel art since it's at least theoretically a lot faster to do environments and static assets.  That, unfortunately, brought about several major questions I still don't know how to resolve.

2D means I'd have to use something other than Unreal.  Unreal technically has 2D support, but it might as well not.  Unity is the go to option for 2D, but Godot looks pretty nice and was much easier to get into and experiment with.  It's fairly barebones though, which leads to workflow problems no matter which direction I want to go with the next question, which is that I don't know exactly what style I want.

2D isometric is a technically tricky thing.  Most people now suggest just using 3D to fake it, and I understand why.  There are a lot of complications with draw order and sorting, which is thankfully handled by the game engines, but it still leads to issues like particles clipping through walls.  Physics implementations are complicated, and I don't know how well Godot handles it out of the box for this.  Asset creation is also notably more complex than a simple, flat overhead view like the old Zelda or RPG maker games.

A simple overhead view like those games is an option, and something I'm strongly considering for its simplicity.  It doesn't look as interesting as isometric, though I suppose there are plenty of games like this that still look good.  Physics is potentially an even bigger issue here, since one thing I really wanted was for the player character to be able to fly, and for there to be multi floor buildings.  I honestly have no idea how to implement that convincingly, at least with Godot.  I could potentially put each "floor" on its own draw layer and swap out collision masks and layers as the player moves up and down, but it feels like this is bound to have an endless number of edge cases, not to mention it would probably be very hard to convey altitude of the player or obstacles.  Projectiles would probably have to be able to hit things regardless of altitude, since it's otherwise impossible to tell how high up they are.

I was researching how to fake 2D isometric using 3D with a fixed perspective and orthographic projection in Godot, and while it looks like it will technically work and solves the physics problems, the workflow is terrible.  Godot supports a "gridmap" system that lets you lay out 3D tiles like a tilemap, but it's pretty rudimentary.  For a tilemap to work, I'd have to create separate materials for every tile, or separate quads with mapped UVs corresponding to a texture atlas.  There's also no easy way to do level or tilemap design with it, since I can imagine trying to draw flat textures that get rendered in isometric would complicate things terribly.  I don't think Unreal has anything like it though, so I'd have to roll my own thing there anyway.

So, I'm not sure what to do now.  I'm pretty sure my only realistic options are to go with a flat overhead view in Godot, possibly removing the ability to fly, or go with a greatly simplified 3D art style and returning to Unreal.  I have been playing a lot of retro N64 and PS1 games lately, and it occurs to me that I'm not aware of any modern retro style games that try to mimic that graphical style.  Most everyone seems to go for pixel art if they want a retro look.  Maybe that's for a good reason...
Logged
Through pain, I find wisdom.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11548 on: December 02, 2019, 07:13:54 pm »

Many older games are really some sort of hybrid. Take Starcraft or Diablo as examples. The levels are drawn as isometric tiles but they're really just 2D levels. So you get the effect of fake-3D backgrounds but you're doing all your actual movement and game code on what is just really a flat plane. You just make some sections look like cliffs but they're really just walls.

If Godot really is that hard to use for this purpose then Unity is probably worth a look, but ask around for tips to get started. A 2D game faked in Unreal actually sounds like a huge pain. Right tool for the right job.
« Last Edit: December 02, 2019, 07:21:21 pm by Reelya »
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11549 on: December 02, 2019, 07:15:39 pm »

Unless you have tall buildings like X-Com or Final Fantasy Tactics, you can probably get away with using a character's y coordinate to determine the clipping order, too. I.e. a wall closer to the bottom of the screen will be drawn over everything that's closer to the top.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.
Pages: 1 ... 768 769 [770] 771 772 ... 795