Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WIDTH = 800
- HEIGHT = 500
- player = Rect((20, HEIGHT - 70), (50, 50))
- jumping = False
- velocity = 8
- gravity = 1
- ground = HEIGHT - 70
- platforms = [
- Rect((0, HEIGHT-20), (WIDTH, 10)),
- Rect((100, HEIGHT - 100), (100, 10)),
- Rect((300, HEIGHT - 200), (100, 10)),
- Rect((500, HEIGHT - 250), (100, 10)),
- ]
- def player_move():
- global jumping, velocity, ground
- ''' Horizontal Movement '''
- if keyboard.left and player.left > 20:
- player.x -= 20
- if keyboard.right and player.right < WIDTH -20:
- player.x += 20
- ''' Jumping '''
- if not jumping and keyboard[keys.SPACE]:
- jumping = True
- elif jumping:
- if velocity > 0:
- up_force = (velocity ** 2)
- else:
- up_force = (-velocity ** 2)
- player.y -= up_force
- velocity -= gravity
- if player.y > ground:
- player.y = ground
- jumping = False
- velocity = 8
- ground = platforms[0].y-50
- for platform in platforms:
- if player.colliderect(platform):
- ground = platform.y - 50
- def draw():
- screen.fill((0,100,200))
- for platform in platforms:
- screen.draw.filled_rect(platform, (255,0,0))
- screen.draw.filled_rect(player, (200, 200, 0))
- def update():
- player_move()
Add Comment
Please, Sign In to add comment