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

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

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

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.

Are there any other ways people have approached this problem?

Shandy

On Sat, 2003-01-04 at 15:59, Fabrizio wrote:
>  
> Hi,
>  
> I am a Pygame newbie. 
> I have modified the "movit" tutorial trying to develop a very basic
> platform game.
>  
> I have troubles in making my hero standing on the platforms; it
> "sinks" in the platforms more or less deeply according to the hero and
> to the platform positions.
>  
> I guess the mistake is in the following code I use to detect the
> platform "support" for my hero. 
>  
>  
> # check if hero is on a platform 
>    flag = 0
>    for t in pl_list :
>       #print t.pos,hero.pos,t.pos.colliderect(hero.pos)
>       if t.pos.colliderect(hero.pos) == 1 :         
>          hero.support = 1
>          flag = 1
>          if hero.s > 3 :
>          # if the jump is alraedy in the
>          #descending part then it
>          # stops jumping
>             hero.s = 0
>             j = 0
>          
>        
>    if flag == 0 :   
>    # hero is not on a platform  
>       hero.support = 0
>  
>    if hero.support == 0 and j == 0:
>    # hero has support and is not jumping
>       hero.fall()
>       hero.move()
>    elif j == 1 :
>    #hero is jumping
>       hero.jump(dir)
>    else :
>       hero.move()
>  
>  
> However I enclose the full code (see below), since the problem might
> be somewhere else.
>  
> Thanks in advance for your help.
>  
>  
> Fabrizio .
>  
>  
>       
>  
> ------------------------------------------
>  
-- 
+-------------------------------------------------------------+
| Shandy Brown                               Digital Thinkery |
| shandy@geeky.net             http://www.digitalthinkery.com |
+-------------------------------------------------------------+

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