2015-03-02 15:17:23

Hello,
So i've been messing with python. Again. Wx python appears to be an awesome toolkit, though wxglade and pythoncard don't really work...but anyway. Are there any audiogame examples...or any examples altogether for games in pyglet? I don't really learn from documentation much, as I like to modify the examples and learn from them.
PS: Camlorn, if you're reading this, would you mind following me at @darbaga on twitter? I don't tweet much (read: at all.), but it would be nice to know I could ask for help if I get stumped. I shouldn't really be making topics for every question under the sun that I don't know the answer to, haha.
P.P.S: I looked over some pyglet examples, but they appear to be focusing more on the sprites and animasion than the logic.

This is not a signature.

2015-03-02 16:48:44

You'll want to start with the Pyglet examples because they'll show you how Pyglet itself works.  The logic is not something I can comment on because that's kind of specific to whatever you're doing.  You might try something like tic-tac-toe between two human players on the same machine, as this will give you a good handle on how Pyglet wants you to do things.
Unfortunately, the only other person I know who is using Pyglet in "real" stuff is Frastlin.  I'm not sure if Frastlin has done anything, but the only "example" I have is the beginnings of a full-blown Shades of Doom-style FPS that also contains something that I hope will end up being close to the Audiogame Unity.  And it uses Libaudioverse, so it won't run without you having Libaudioverse.  Consequently, well, it'd not help much.
If you haven't seen my other thread about Pyglet, go there now. You need these two lines.
While Pyglet is harder than BGT, it's worth noting that a marginally complex game will probably recreate everything in Pyglet's event handling modules.  I know because I did; that code is actually still up on GitHub, but I don't suggest anyone use it because Pyglet's is better.
I think I can guess what the stumbling block is, at least if you're coming from BGT.  Suddenly, time.sleep or any other "wait x seconds" function is not allowed.  I can't say anything that really makes transitioning from the style of programming where you can explicitly wait and nothing is happening to this one, but if you've been watching the development room for a while you're probably aware that "you need to transition your game to use tick methods" comes up over and over.  One of the core ideas here is to decrement counters and use an if(counter <=0) if statement for waiting, and another is to have a variable that remembers what state the enemy is in.  The latter is called a finite state machine.
As for menus and stuff, read up on Pyglet's event handling.  You can have multiple "screens", or at least that's what I call them, and the topmost gets all the key presses and events first.  This lets you have fully blocking menus like a pause or inventory screen but, more interestingly especially for online stuff, it lets you have menus that take over a couple keys on the keyboard but still let you walk around and fight.
For my current project, I'm using a custom Pyglet event to drive ticking.  This lets the topmost thing on the event stack block ticking if it wants, simply by handling the event.  The Pyglet manual is really good on this subject, so I'd  go there.
And finally, there's a Python package called blinker.  You may or may not want it right now, but keep it in mind and maybe read about it.  Some people like what it provides for things like games, myself included.  Some games and ways of arranging your logic can benefit a lot, others will benefit not at all.

My Blog
Twitter: @ajhicks1992

2015-03-03 02:58:40

Hi Camlorn.
After I saw this topic I looked up pyglet for future use and there doesn't seem to be a version for python 2.7. The highest version they seem to have is for python 2.6 unless I missed it somehow on the website. Pyglet does sound very interesting so I would love to use it later on.

Guitarman.
What has been created in the laws of nature holds true in the laws of magic as well. Where there is light, there is darkness,  and where there is life, there is also death.
Aerodyne: first of the wizard order

2015-03-03 04:16:49

Pyglet is working fine on 2.7.  Pip install pyglet, that is all.

My Blog
Twitter: @ajhicks1992

2015-03-03 04:23:59

There it is but what on earth is a whl file? I decided to get the zip file instead since windows didn't recognize the other one.

Guitarman.
What has been created in the laws of nature holds true in the laws of magic as well. Where there is light, there is darkness,  and where there is life, there is also death.
Aerodyne: first of the wizard order

2015-03-03 04:40:47 (edited by camlorn 2015-03-03 04:41:37)

Erm. You want pip instal pyglet at a terminal.
If you don't have pip and you're using Python 2.7.9, I believe you want python -m ensurepip at a terminal.  But I haven't upgraded because that's kinda painful.
Edit: Wheels are a thing pip processes.  Once you have pip, you may run pip install mywheel.whl, if I remember the command correctly.  But, 99% of the time, if a wheel for foo is available, pip install foo will also automatically get it for you.

My Blog
Twitter: @ajhicks1992

2015-03-03 05:02:43

Oh okay got it now for some reason I was expecting an executable file.

Guitarman.
What has been created in the laws of nature holds true in the laws of magic as well. Where there is light, there is darkness,  and where there is life, there is also death.
Aerodyne: first of the wizard order

2015-03-05 13:12:12

Hello,
I did some stuff with piglet, but didn't like their documentation or the way they handle scripts. I didn't get past the first part.
I am in the process of writing a python library
pyaudiogame
that is much more simple to use than piglet (but so far, without the graphics) and all the examples (there are a lot) just deal with getting speech and sounds.
I would love someone who knows python a little to take a look and start using it.
I am still writing documentation (That is a lot of work!) and writing examples, but I would love it if someone else could tell me what they would like.
Currently there is:
grid support for maps and objects
menu support
speech support for just about all screen readers
a lovely way to save your game
Basic sound support

all the stuff like window creation and whatnot is already taken care of for you. You just need to overwrite pyaudiogame.App.logic.
It's super clear (I hope) and there is a template in the download I always use.
You can subscribe to the new email list from the website (if it doesn't work, check back in 10-15 minutes, it's super new and I'm still working the bugs out)
and ask me questions there.

2015-03-05 21:16:15

What do you mean by scripts?  The only thing Pyglet is really good at for an Audiogame is event handling, whether that be input or timing or whatever.  You're going to eventually need everything Pyglet is offering you in that respect, regardless of what you code your game in.  So if you dump that part of it, you'll end up just recoding it yourself later.

My Blog
Twitter: @ajhicks1992

2015-03-05 23:35:37

The App
section of pyglet is too confusing. The docks are horrible and if I wish to know how to do something, I have not yet figured out how to find what I am looking for.

But pyaudiogame is much, much, much higher level than pyglet. It has, for example, a UI secton with a grid where you plug in the coords for your walls, make sounds and you have something like Entombed or a side-scroller in less than 50 lines of code.

If that is too much, it is really a thin wrapper around pygame, so you can just import pygame and draw or use the clock functions directly within your logic loop.

But something that is the bane of many young programmers is the lack of relevant documentation or tutorials with your selected platform.
So I am writing something for someone that says:
I have an idea for a game. I don't know any programming, what do I do?
Pyaudiogame gets them writing audio games as fast as possible.
If they then wish to apply their python knowledge to more tutorials, or something else out side of pyaudiogame, they totally can.
But at this point, I am not totally dependent on pygame, so if you replace app.py, event.py and mixer.py, you could use pyglet, Kivy or what ever.

I also have made it super easy (and I hope to make it even easier) for people to include something like libaudioverse into their projects.
I have done a little with the mixer module, but it is pretty much the same as pygame's module currently.

But my idea is if more people start programming games, we will get more games put out and if we have more games put out, there is bound to be some really good games...

And always the hope of an open-source project is that more people who use it, the better it becomes.

So pyaudiogame is not like pyglet in that it wraps around a C library, but it wraps around a wrapper around a C library. I am also writing as many examples and making the API as clear as I possibly can be.
I just need feedback at this early stage from not-so newbie folks just in case something they say will change the basic features of pyaudiogame.
I already, for example, have gotten suggestions to run a function directly from a menu choice, rather than returning a string so you can figure out what to do. (You can do both once I update the next push).
But so far I have not gotten any feedback on the basic infrastructure, so that is what I would like people to take a look at.

I already use pyaudiogame in my other projects if I need to save something to a pickle file, I just load everything into pygame.storage and then call
storage.save("My_save.sav")
and it pickles it.
Then
stuff = storage.load("My_save.sav")
returns the variables I loaded into storage as a dict as well as putting the variables back into storage, exactly as they were before I left.

2015-03-06 00:15:08

The app section of the pyglet documentation looks fine to me; you just call app.run and you're done with it.  The thing you might be interested in is pyglet.window, and such.  But I've never even come close to having a need for anything but pyglet.app.run, and it doesn't look like there's much in that module anyway.  I take it you have read the Pyglet programming guide?  because that's probably the place to go for documentation needs.
And I' not criticizing.  You just seemed to be saying that you're throwing out things that Pyglet already has done for you, namely the event framework.  The problem is that you almost can't live without it, and you can't quite hide it either.  Simple games can live without, but you need event layering for intermediate stuff.
And I know because audiogame_engine basically completely recoded the Pyglet event framework.

My Blog
Twitter: @ajhicks1992

2015-03-06 12:07:02

I'm not 100% sure what you mean by event layering. Do you mean widget trees?
Where you populate a list with events and if one returns True on a key press the iteration through the event list stops and that event is processed?

I personally use something a little different, because I haven't been convinced of the awesomeness of a widget tree. I think they are somewhat restrictive and are kind of complex. I don't think I understand them totally which is probably why I don't use them.

Currently I am just having people deal with the event handler pygame has with the super easy dict of actions being returned each loop. You don't need to understand anything but if statements to get a basic game running.

I then have different screens that each have their own functions.
So for example:
if screen == "start":
start(key)
elif screen == "start2":
start2(key)
elif screen == "choose" and key == "return":
choose()

You can make it into a dict too, but you get the picture.
I think this is much easier to understand than registering events. I'm also not quite sure what advantage the widget tree has over this, other than you don't need to have a list of screens and their functions, you just have functions that change the widgets in the event list.

2015-03-06 16:51:50

So I an on a mission now to understand this type of event handling.
I see in audiogame_engine's readme:
"""
The above may seem complicated to those who use the approach of putting all game logic in one file, stacking if statements 5 and 6 levels deep.  In the end, it is actually better: you can reason about only one, small part of the game at a time.  This reduces the size and complexity of code, without question.  Furthermore, this package keeps time running att a constant speed as much as it can, so the game will try to "catch up" if it falls behind.
"""

OK, so what are you doing?
You have your main loop with keyboard input and mouse.
In this loop you have a screen stack with different screen objects.
Within one screen object you have your logic like:
if key == "space":
    speak("Hello world")

You then have an option to stop the processing, or let the processing move on to the next item in the stack.


If you wished to change the screen object, you pop it from the screen stack.


So if I am in my inventory, the stack would look something like:
[move_screen, inventory_screen]

When I press escape to get out of my inventory, a pop happens like:
screen_stack.pop()
so all I am left with is
[move_screen]


Is this correct?

That does not seem that hard to do and for moving through large menus would be pretty nice, especially if the menus only could close one at a time.
But what about if you have something like:
[move_screen, inventory_screen, item_screen, use_screen]
when you choose an item on the use_screen the whole menu block closes, so you have only
[move_screen]
I guess the screens could have a variable they all could change that they all have access to like:
storage.close = True
then within each menu screen it will check first thing:
if storage.close:
    screen_stack.pop()

popping itself from the stack.
(the menu screens are inventory_screen, item_screen and use_screen)
Is this how this works?

2015-03-06 18:24:45

yes.  Though I have never heard them called widget trees.  If you are thinking WX event handling, that's similar but not the same.  In audiogame_engine, the topmost screen always gets the event first; if it doesn't handle it or wants to pass it through, the next screen down gets it and etc. until one of them stops it, or there are none left.
In most frameworks for this kind of thing, you only get a stack.  A screen or the equivalent will do whatever it needs to to get the world ready for the next one, say stopping all  sounds, and then push it on top.  When the new one is done, it pops itself back off and has either modified the world or called a function somewhere to indicate your choice.  Or whatever, really.
if you need to pop multiple screens off, that needs to be coded in the screens themselves.  I.e. if escape is supposed to get rid of all the menus, then each menu needs to detect the closure of whatever submenu screens it has open in that manner somehow.  It is probably easier to make a generic menu/submenu screen that you populate with stuff, say menu items and callbacks for if they're selected.  I'm not sure if you're saying that audiogame_engine doesn't let you pop multiple screens at once and you want to or something completely different.
Pyglet does basically this, but better.  in Pyglet, you don't have to inherit from a magical base class that magically does stuff and you can define new events, say incoming network message.  The Pyglet programming guide does a pretty good job explaining the how, but the why is basically not there.
What you end up with is something that's a little more complicated individually, in that you have to type some boilerplate framework code around it.  But it's better than the one taken together: you won't have 20 if statements that do different things depending on some sort of state variable and a function that goes on for a very long time dealing with it.
As for when you really, really need it though?
Items that add one-off keystrokes.  Just push some event handlers that intercept keystrokes that item is interested in.  A flute, for example.  That you play with the number keys.  There are other ways of doing this, but the general system here is sufficient to do it.
Modaless menus and dialogs.  A modal dialog is something like a pause screen or inventory screen in an offline, single-player game: while you are in it, nothing else happens.  A modaless menu, supposing that I am spelling that term right, is the opposite.  So, say, a spellcasting menu that doesn't stop gameplay and takes over a couple keys somewhere.  Or a combat system like Final Fantasy XII where you select all your attacks and stuff but can walk around the whole time.  Or basically every menu ever in an online game.
You can do games without it.  It's just something you're eventually going to end up using.  Other types of apps like WX use it; it's pretty common to have a setup like this.  The point is mostly separating logic for reasoning purposes.

My Blog
Twitter: @ajhicks1992

2015-03-06 23:54:07

OK, I believe I get it now. That is not hard to do at all and I see how pyglet runs its event handler. I am looking back at pyglet and I remember why I didn't go far into pyglet. In order to play sounds, one needs AVbin, something I can't get to work on my computer.
I don't think one should need to install a 3rd party dependency if they download and wish to play a game. Of coarse, one can always make an installer, but that is a lot of extra work for everyone.
I do like the mouse handler on pyglet, the lock on window and the two parameters for telling how far the mouse moved right and left for 3d games. I don't think it is done in pygame like that.
Here is a simple event handler with pyaudiogame. Does it look right? my_app.logic is the game loop and actions is a dict of keyboard and mouse actions.


#trys to make a screen stack
import pyaudiogame
my_app = pyaudiogame.App("Screen Stacks")
spk = pyaudiogame.speak


stack = []
screens = {}


class Screen(object):
    """The basic template for a stack screen"""
    def __init__(self):
        #This says don't go to the next item in the stack
        self.through = False

    def stuff(self, actions):
        """Is basicly a logic loop and is meant to be over-ridden"""
        pass


menu1 = Screen()
def stuff(actions):
    if actions['key'] == "up":
        spk("You hit up")
    elif actions['key'] == "down":
        spk("You hit down")
    elif actions['key'] == "backspace":
        stack.pop()
    elif actions['key'] == "a":
        spk("Adding a few new buttons")
        stack.append(screens["clear_screen"])
menu1.stuff = stuff
screens['menu1'] = menu1


clear_screen = Screen()
def stuff(actions):
    key = actions['key']
    if key == "f":
        spk("Fly away!")
    elif key == "h":
        spk("High like the sky")
    elif key == "c":
        spk("closing")
        stack.pop()
clear_screen.stuff = stuff
clear_screen.through = True
screens['clear_screen'] = clear_screen


start = Screen()
def stuff(actions):
    if actions['key'] == "space":
        spk("Hello world")
    elif actions['key'] == "return":
        stack.append(screens['menu1'])
start.stuff = stuff
stack.append(start)


def logic(actions):
    for s in reversed(stack):
        s.stuff(actions)
        if not s.through:
            break


my_app.logic = logic
my_app.run()

2015-03-07 02:37:41 (edited by camlorn 2015-03-07 02:39:21)

Yeah. I think so.  You seem to get the gist anyway.
But:
First, you can use Pyglet for everything and Pygame for sound, I believe.  I'm pretty sure that Pygame doesn't specifically take over the main thread like Pyglet does, and coding this stuff yourself is a waste of time if you can help it.  I'm also pretty sure that Pygame isn't going to go much further with loading audio types; ogg only, as I recall.
Second, just copy avbin.dll to the directory with python in it.  Alternatively, copy avbin.dll to the directory with your stuff in it, but you'll need to launch from a terminal with the current directory set there.  Or use this bit of hackery that works only on Windows:

import ctypes
avbin= ctypes.cdll.LoadLibrary(path_to_avbin)

And then make your engine find an avbin.dll that's distributed with it and run those lines before the first Pyglet import.
Dhruv (sorry about spelling) just figured this out and can probably tell you what you have to do more specifically.  I have Libaudioverse, as always.
Edit:
you should probably also encourage subclassing and not actually lay out the actual code like that.  Also, split up the functions, say tick and key_down and key_up, for example.  I'm not sure if this is a rough prototype or how you intend to actually lay it out, but that's awful imho if that's how you're actually going to do it for all games.  Shows good mastery of first-class functions, though.

My Blog
Twitter: @ajhicks1992

2015-03-07 11:34:13

LOL I through that together in 20 minutes and wanted to be very explicit.
I think probably using decorators is the best idea for doing this actually. But getting a newbie to understand decorators would be horribly difficult.
I like giving a dict to the programmers with all the actions that happened that iteration of the loop. so actions['key'] is the keydown and actions['keyUp'] is the key_up event.
What I will probably do is offer a class the person can import that they make logic equal to that will do the check and then they just sub-class or decorate the screens.
Pygame supports ogg and wav for sound objects and wav, mp3 and ogg (I don't know about any others) for streaming.
I've never had any problem with making all my files .ogg, .ogg is small, sounds great and audacity can convert sounds to ogg if you wish.
I sent an email to the pyglet list to see where I can get the DLL and the other binaries for Linux and Mac as well. Pyaudiogame is trying to be platform independent as much as possible, so I need to distribute everything in the download.
I am also looking at Kivy for being the back-end, as it has support for IPhone and Android as well, but to say Kivy is inaccessible is putting it lightly. It is so complex to do anything but use the custom widgets that I don't think it is worth it. I don't know how good the sound support is either.
I am also considering WXPython, because it has native widgets that one can use the screen reader with. This is super nice and something I would like pyaudiogame to have the ability to do. But I don't really like the way WXPython handles the main loop or the fact it has no sound support.
Someone needs to write a cross-platform python UIA wrapper! (The folks at Kivy are looking at accessibility, but because there is no cross-platform UIA wrapper, (UIA Automation for windows, pyatspi for Linux and coco for mac), there is not much they can do but add accessibility only on mobile platforms).
So I am kind of keeping pyaudiogame as back-end independent as possible so if one of the other options becomes attractive enough, I can move to it with very little hassle.
With windows 10 coming out, I think more and more people will be getting touchscreens, so I really would like Kivy, but it is their darn widgets they teach Kivy with that are holding me back. I can't do much but just hope what they say is happening really is happening.
They also have this really weird scripting language that I have no idea why they use, but they have their only example in it rather than in python, so that doesn't help.
So with Kivy it is the widgets and the documentation that is holding me back from their awesome 5 platform engine,
pyglet it is their strange sound dependencies
and WXPython it is their sound support in general.

Of coarse I would like people to use libaudioverse, but it is not done yet and you're not making it MIT, so I can't use it in the basic distribution of pyaudiogame. sad

2015-03-07 16:26:04

Everything that's actually worth using does the WXPython main loop.  It's called the event loop, and you'll probably end up just duplicating it yourself.  Twisted, Pyglet, lots of stuff.  The fact that Pygame doesn't has always baffled me as getting that right is actually not as simple as it looks.  You can get a basic one working, but you can't get it doing all the power saving stuff and with precise timing and all that like they do so easily.  WX doesn't have a choice though.  Their main loop is so complicated (and has to be) that you'd never really be able to duplicate it.
As for cross-platform accessibility, you can't.  It can't be done.  This has to be done on a per-platform basis.  There is no choice.  I wouldn't hold your breath on Kivy, and Kivy is, as you said, decidedly not simple.  I'm going to probably have to go over there now.
As for Libaudioverse?  Well, yeah, I do want to make money.  But I still maintain: Pygame for sound, something else for, well, everything else.  Or just use the avbin hack.
Do note: you can almost certainly get the Pyglet and WX event loops going in the same app.  I'm about to try this; it doesn't look overly hard.  The Pyglet guide tells you how to make your own Pyglet event loop function, and the WX event loop does have support to call stuff every so often.  This lets you have the game-oriented Pyglet event handling for game stuff and the WX widget-oriented event handling for the WX stuff.
Don't use decorators.  Make people subclass your screens.  This is simple, programming language agnostic, and pretty standard.  Also, yes, you do want to break it into functions.  Your idea of actions as things that happen every tick is kind of off: a key may be pressed at any time, for example.  Whether the engine makes it part of the tick is beside the point; it shouldn't be conceptually exposed that way.  Make a base class, give it empty event handlers: on_key_down, on_key_up, on_mouse_move, on_tick.  Those should be sufficient and should take different arguments depending on what they're for.  The action fo jumping should happen through setting the is_jumping flag or the jump_next_tick flag, not through having tick read controls directly.  The latter does not allow for control remapping or platform-neutral anything, really.
You probably won't win me to your engine, but you probably aren't expecting to.  My personal effort is already at the point where I'm putting in generic object editors which allow one to, well, edit objects.  It's decidedly not basic, but it's looking like it's going to end up being more powerful than I expected going in, which is actually really nice if true.  I suppose that part of this is that I don't care so much about making it super friendly to new programmers, I care about making it powerful enough you could write online games and Shades of Doom clones with it pretty easily.  This does mean adding complexity at the beginning; there's no really good trade-off here, and I'm far enough along that it's not worth cutting out complexity if that means cutting out capabilities or making the code ultimately harder to deal with for gains at the beginning.

My Blog
Twitter: @ajhicks1992

2015-03-07 17:56:18

I think having 2 systems is a little much in one game, but I may consider doing WXPython and something else.
Having native edit boxes and menus would be very very very awesome.


I am not 100% sure what you mean by having an empty bass class with empty functions.
Are you saying have a keyconfig.ini with something like:
jump:space
Then make jump a class that will get all space events?
So when space is pressed, the keydown will be sent to jump if the screen with jump is up and within the jump class there is the keydown method with the stuff you do when it happens.
Then within each screen class there will be a list of objects and each of those event objects will have their own entry in the keyconfig class like jump. If their key is pressed, then that event will fire.
Is this what you are saying? Basically have a keyconfig.ini for every program?
I guess a keyconfig could have something like:
menu_up:up
menu_down:down
walk_forward:up
walk_back:down
I could see this becoming potentially long though.
Am I understanding you?
Have you considered splitting libaudioverse into a basic audio engine like what pygame has, that way people could easily use the light version in what ever they wished, but if they wanted any more like pitch change or what ever else you offer, they can download the full version and that would be under the commercial license.
That way people could start conceptualizing sounds in the way pyaudiogame does without needing to buy it first.
That would also coincidentally solve my little pyglet problem...

2015-03-07 18:23:45

No, you're not.

class BaseScreen(object):
 def on_key_down(self, key, modifiers):
  pass

 def on_key_up(self, key, modifiers):
  pass

 def on_mouse_move(self, x, y):
  pass

 def on_tick(self, dt):
  pass

And then make everyone subclass that.  Or use Pyglet.  There is nothing wrong with two systems in the same game if they play nice.  There's nothing wrong with 5 if they play nice.  if it has code you now don't have to write in it, add it.
You can make subclasses that bind functions to keys based off a dict.  You can make subclasses that maintain a map of what's currently down and what's not.  But that's the basic one you should start with.  The point is that your engine can pass all events to any screen without caring because the one at the bottom of the inheritance hierarchy has methods for them that do nothing.
There is no basic Libaudioverse.  There is no point to split it.  it's already basically as simple as it can get.  Anything simpler needs to be built on top of it, which means I'm giving you the full library.  My plan for this summer is to look into the legal aspects of selling it.  Your only chance of seeing a BSD version is if this falls through or turns out to be too complicated for me to manage without infrastructure I don't have.

My Blog
Twitter: @ajhicks1992

2015-03-07 18:28:46

Hi.
I was just able to get AVbin and install it, and afterwards just do
import pyglet
source=pyglet.source.load("path/to/blah.mp3")
player=pyglet.media.Player()
player.queue(source)
player.play()
What specificly are you having problems with?

This is not a signature.

2015-03-07 19:11:09

Rob, a guy on the pyglet list is doing something with AVbin to make it more friendly.
But I need something I can hand out to everyone on every platform that doesn't need them to do anything but run my game. AVbin currently requires them to install a 3rd party piece of software. Unacceptable in my standard. Because something will happen (like it did with my computer) where even after installing each binary for windows, I still got no sound from pyglet.


So that is your base screen. In the main loop it will pass each event to each method in the class.
So if I have:
class Jump(BaseScreen):
def on_key_down(self, key, modifiers):
  if key == "space":
   spk("Hello world")


stack.append(Jump())


Then in the main loop it runs a function to call the screens in the stack's functions if needed. For example:
for screen in stack:
if KEYDOWN:
  screen.on_key_down(key, mods)
elif KEYUP:
  screen.on_key_up(key, mods)
...

Put that in pygame's event for loop.
Is this correct?

2015-03-07 20:57:46

Yes.

My Blog
Twitter: @ajhicks1992

2015-03-07 23:22:16

I am going to experiment with both, but I am basically doing that, but in half the lines of code. I guess it may be a little more resource intensive as I am refreshing the dict each iteration of the loop, but not enough to matter...
I agree that the clarity of grouping all key_up code, all the tick code and all the key_down code is very easy to read, but there is no overlap or conflict in doing:
if actions['key'] == "space":
spk("Hello, I'm up")
elif actions['keyUp'] == "space":
spk("I am now up")
x += 1


There is conflict in screens, but when you group into screens like you said to do above, that removes having major screen conflict like:
if actions['key'] == "space" and screen == "start":
spk("Hello world")
elif actions['key'] == "space":
spk("This is space without anything")


But I don't know the advantage of having a class over a dict in this circumstance. You could group your code like:
def stuff(self, actions):
if actions['key']:
  self.key_down(actions['key'])
elif actions['keyUp']:
  self.key_up(actions['keyUp'])
self.tick()


I can easily create a format like this to test this style in pyaudiogame, so I'll do that and see what I think. But dicts are a lot more manageable in this circumstance than classes.


BTW, the developer of pyglet is looking for someone to take over development of pyglet...
And he is really
fed up with AVbin
He posted:
"""
Now that Pyglet seems to have been resurrected, perhaps someone would like to take the reins for Pyglet from me (see above link for more details).
I would be happy to add committers.  I would be even happier to transfer control of the entire project.  I'm really no longer involved except for as a distant observer wishing you guys well and cheering you on.
"""

2015-03-07 23:53:45

I was looking at pyglet again and I am wondering if anyone knows why with pygame, when I press a key like space, my screenreader is silent, but with pyglet, it says the letter or key, as if it is in an edit box? That is another reason why I didn't like pyglet.