Untitled
unknown
plain_text
a year ago
1.1 kB
9
Indexable
from pygame import *
font.init()
win = display.set_mode((600,600))
display.set_caption('Trash')
clock = time.Clock()
gravity = .5
y_speed = 0
jump_strength = -10
on_ground = True
player = Rect(250, 0, 50, 50)
platforms = [(0,600,600,1), (400, 500, 150, 10)]
run = True
while run:
for e in event.get():
if e.type == QUIT:
run = False
keys = key.get_pressed()
if keys[K_d] and player.x < 550:
player.x += 4
if keys[K_a] and player.x > 0:
player.x -= 4
if keys[K_SPACE] and on_ground:
y_speed = jump_strength
player.y += y_speed
y_speed += gravity
if y_speed < 0:
on_ground = False
win.fill((30,160,220))
draw.rect(win, (255, 255, 36), player)
for platform in platforms:
platform_rect = Rect(platform)
draw.rect(win, (43, 255, 36), platform_rect)
if player.colliderect(platform_rect) and y_speed > 0:
player.bottom = platform_rect.top
on_ground = True
y_speed = 0
display.update()
clock.tick(30)Editor is loading...
Leave a Comment