[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Strategies for platformers



----- Original Message -----
From: "Shandy Brown" <shandy@geeky.net>
To: <pygame-users@seul.org>
Sent: Monday, January 06, 2003 5:35 AM
Subject: [pygame] Strategies for platformers


> I'd appreciate anyone's opinions or discussion on general ways to do
> platform-type games.
>
> I've taken this approach:
>
> 1 - the charactor (mario, shinobi, etc) has a "state" of his movement in
> each direction, x and y.  We're interested in moveStateY.



I have put the "state" (= movement speed along a direction) in two Python
lists; this is supposed to be useful to allow other "enemy" characters to
move along "patterns" (e.g. up and down, then left and right, ecc.).




> 2 - before displaying the charactor, subtract a set amount from
> moveStateY.  If the charactor is currently moving up, say jumping, it
> slows him down, if the charactor is at rest (moveStateY == 0) he
> accelerates downwards



I have not followed this "gravity" approach, but it seems a very good idea.
However in my approach I use a jump "pattern" (see above) to make the jump
look more realistic (e.g. in the first part of the jump the movement is
faster, then it is slows down till the climax, and then it speeds up again
till the end of the jump)



> 3 - (still before displaying the charactor) calculate where the
> character WOULD be if he moved by moveStateY on the screen.  See if
> there are any other objects in that new position (pygame gives us some
> handy functions for doing this).
>
> 4 - If there is a platform in that new position, change the position of
> the charactor so that it just on top of the platform.
>
> This strategy basically makes the charactor always be 'falling', which
> is handy because we don't have to detect when he walks off the end of a
> platform.



Yes. Anyway, you do have to detect if there are other objects in any new
position; so it is not a big trouble setting the "falling" (= "gravity")
flag to 1 if no objects have been detected.



-------------------

Those above are my comments on this subject, but please note that I am a
real newbie in Pygame, so my knowledge is very limited.

I also have troubles trying to develop a simple platmorm game; in particular
I need some help on the following points :

1-How to make characters move at different speeds (es. hero, enemy). I tried
to use different "pixel steps" (=speeds), but it is not a satisfactory
solution since :
a - I lose "smoothness" of character animation (move, say, 5 pixels per
frame)
b - Sometimes collisions occurring "between frames" are not detected (see
below - point 4)
 I think the solution to this is to update movements basing on time, instead
of a frame-by-frame approach, but still I could not figure out how to do
this.

2- How to stop jumping when hero is landing on a platform coming from the
bottom. I did this by checking if the jump is in the "descending" part and
then stopping jumping only in this case.

3 - How to avoid collision detection for "transparent" pixels (= use of
colorkey).

4 - How to avoid collisions with platforms when hero jumps from the bottom.
I did this by setting up an "upper edge" rect (for platforms) and a "bottom
edge" rect (for hero) and detecting collision on this "edges" instead of on
the full "sprite" rect. This approach does not work fine if movement is more
than one pixel per frame, as collision might occur "between frame".


Fabrizio

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org