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

Re: [pygame] Strategies for platformers



> >
> > 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.).

> 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)
> 

so a jump "pattern" might look something like this in the y direction:
[4,2,1,0,-1,-2,4] ? Am I following you correctly?

What are the pros and cons of this strategy?

> >
> > 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.
> 
> 

Well, what I was trying to say above is that if you don't have the
charactor always falling (ie, if you set moveStateY=0), then as the
charactor moved sideways you'd have to check both the charactor's new
position for obstacles, and just underneath the charactor's new position
for support.


> 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.

This is one approach I've seen discussed before.  On the mailing list
look for the subject "Smooth animation".  I don't know if a conclusion
was ever reached, though.


> 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.

Could you explain this problem better? I don't understand.

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

My approach here is to give a sprite an extra rectangle (call it
solidRect) that corresponds roughly to the opaque parts of the image,
and when I'm checking for collisions, I don't use mySprite.rect, I use
mySprite.solidRect instead.


> 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".

So you want the charactor to 'bump his head' on platforms above him when
he jumps into them?  Or to pass right through them on the way up?

-- 
+-------------------------------------------------------------+
| Shandy Brown                               Digital Thinkery |
| shandy@geeky.net             http://www.digitalthinkery.com |
+-------------------------------------------------------------+

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