Thanks to everyone who posted.  I was able to get a huge speed
increase by implementing some of these suggestions.

I have run into a couple of new problems that I'm having trouble
solving. These are not pyglet issues, so I apologize if this is too
off-topic.

My game is a Super Mario style scrolling platformer.  Sprites have an
additional "moving" flag, plus xv and yv.

First, I check for key presses - a jump sets the player's sprite.yv to
20, and left/right sets xv -2 or +2.

Then, I loop through all sprites flagged as "moving":

First, I decrease yv and xv by 1 (for gravity and wind/air
resistance).
Next, I do "sprite.y += sprite.yv" (and the same for x).

Finally, I check for collisions. Depending on where I hit the other
sprite (top, bottom, left or right), I correct the sprite's x/y, and
zero out the yv/xv.  This is the first part I am having trouble with -
how do you know what side of the other sprite you touched?

If you were moving diagonally, and you had been both above and to the
left of the other sprite, you could have either collided with the
other sprite's top, or its left side.

I have figured out how to catch the majority of collisions - if you
were directly above it, or directly to the left of it, etc.  But if
you were moving diagonally from the upper/bottom + left/right, I am
lost.

The second issue is, what if your yv or xv is so great that you pass
through objects?  If the player fires a shot (a 2x2 pixel sprite), and
it has a xv of 20, it will not be collision checked against things in
between it and it's next due x/y.  Or, if the player is falling for a
long time, his yv could become so great, he falls right through
things.

One idea would be to move objects only as far as they are wide/tall,
then do collision checking, then move them again, looping until they
reach their destination.  But that would make "fast moving" objects
really expensive.  Also, I do not know how to calculate something step-
by-step that is moving diagonally (ie yv=7, xv=19).

As an alternative, I figured I could calculate a box, with the
sprite's starting x/y and ending x/y, and check that box for
collisions first. But, if there is a hit, I don't know how to
calculate which specific other sprite I hit. Mainly because the moving
sprite could have been moving diagonaly.

Again, sorry if this is too off topic. I will say, for someone who has
never really written a game before, I am amazed at what I've slapped
together so far. Pyglet has made this really, really easy!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to