Permalink
Browse files

Prevent jumping in the air.

  • Loading branch information...
1 parent b3de108 commit 0ab5966020d257598bd8c709cec28ad57adc16b0 @luciferous committed Apr 2, 2010
Showing with 6 additions and 1 deletion.
  1. +6 −1 gamelib/player.py
View
@@ -13,14 +13,17 @@ def __init__(self, x, y):
super(Player, self).__init__(x*40, y*40, 40, 40)
self.velocity = Vector()
self.terminal_velocity = 5.0
+ self.airborne = False
def update(self, delta):
self.velocity += gravity * delta
if self.velocity.y > self.terminal_velocity:
self.velocity.y = self.terminal_velocity
self.velocity.add_to_rect(self.rect)
+ self.airborne = True
sprites = pygame.sprite.spritecollide(self, self.level.platforms, dokill=False)
if sprites:
self.rect.y = sprites[0].rect.y - 40
+ self.airborne = False
def is_updatable(self):
return True
def setup(self, level):
@@ -35,6 +38,8 @@ def right_down(self):
def right_up(self):
self.velocity += left
def jump_start(self):
- self.velocity += up
+ if not self.airborne:
+ self.airborne = True
+ self.velocity += up
def jump_end(self):
pass

0 comments on commit 0ab5966

Please sign in to comment.