Re: [pygame] Help Starting/doing The Main Code

2008-09-26 Thread Jake b
I'd suggest making a clone of pong, and asteroids and maybe missile
command. (They will be easier to write than a shooting platformer, and
be more gradual that jumping right into too much at once )

Your main loop looks something like this:

class Game():
"""game logic class"""

def __init__(self, width=1024, height=768):
# ... snipped 

def loop(self):
"""main game loop"""
self.bDone = false

while not self.bDone:
# handle events, physics/updates, and render
self.handle_events()
self.update()
self.draw()

def handle_events(self):
"""input"""
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
# event: keydown
elif event.type == KEYDOWN:
# exit on 'escape'
if (event.key == K_ESCAPE): self.bDone = True

def draw(self):
"""render screen"""
# clear screen
self.screen.fill( pygame.color.Color("black") )

# render sprites
# flip
pygame.display.flip()

def update(self):
"""update units, check for collisions(if needed), etc..."""
# ... snipped ...

--
Jake


Re: [pygame] Window move oddity

2008-09-26 Thread René Dudfield
Indeed.  That's what it does.

You should be able to put a maximum elapsed time for your frames.
That handles the moving window thing, and also if there's some other
pause from the OS.  Like if firefox plays a flash animation in the
background that uses up heaps of cpu blocking your program for a
while.

cu.

On Sat, Sep 27, 2008 at 4:17 AM, Aaron Maupin <[EMAIL PROTECTED]> wrote:
>
> Well, immediately after posting I figured it out.  ;)  Moving the window 
> causes the program to pause and thus when it comes back the delta time 
> difference between frames spikes.  And then my screwy collision detection 
> teleports the character much further than should be possible.
>
>> In certain situations, moving the game window (800x600) on the Windows 
>> desktop sometimes causes the main character to teleport upwards on screen to 
>> the next available platform.


Re: [pygame] Window move oddity

2008-09-26 Thread Aaron Maupin
Well, immediately after posting I figured it out.  ;)  Moving the window 
causes the program to pause and thus when it comes back the delta time 
difference between frames spikes.  And then my screwy collision 
detection teleports the character much further than should be possible.


In certain situations, moving the game window (800x600) on the Windows 
desktop sometimes causes the main character to teleport upwards on 
screen to the next available platform. 


[pygame] Window move oddity

2008-09-26 Thread Aaron Maupin
I'm currently working on a simple platform game engine using Python 
2.5.2 win32 and Pygame 1.8.1.


The main character's location is defined by x and y floats.  The levels 
are stored in a tree format to allow for vast open spaces.  Nothing 
ground-breaking.  I've been working on the collision system.


In certain situations, moving the game window (800x600) on the Windows 
desktop sometimes causes the main character to teleport upwards on 
screen to the next available platform.  Does anyone know if moving the 
pygame display window sends some kind of event to Pygame?  Printing all 
events in pygame.event.get() reveals no event occurring when the window 
moves and the character teleports.  It doesn't always happen, but when 
it does it doesn't matter if I move the window 1 pixel or across the 
desktop.


Where the character teleports and how is obviously because of my screwy 
unfinished collision detection, because if I comment out the collision 
detection calls the oddity doesn't appear.


But I just wondered if anyone knows why moving the window would trigger 
anything?


Aaron