Текст программы — различия между версиями
Ilia (обсуждение | вклад) (Новая страница: «import pygame pygame.init() win = pygame.display.set_mode((500,500)) pygame.display.set_caption("First Game") x = 50 y = 50 width = 40 height = 60 vel = 10 run…») |
Ilia (обсуждение | вклад) |
||
Строка 6: | Строка 6: | ||
x = 50 | x = 50 | ||
− | y = | + | y = 425 |
width = 40 | width = 40 | ||
height = 60 | height = 60 | ||
− | vel = 10 | + | vel = 5 |
+ | |||
+ | isJump = False | ||
+ | JumpCount = 10 | ||
run = True | run = True | ||
while run: | while run: | ||
− | pygame.time.delay( | + | pygame.time.delay(50) |
for event in pygame.event.get(): | for event in pygame.event.get(): | ||
Строка 28: | Строка 31: | ||
x += vel | x += vel | ||
− | if keys[pygame.K_UP] and y > 5: | + | if not(isJump): |
− | y -= | + | |
+ | if keys[pygame.K_UP] and y > 5: | ||
+ | y -= vel | ||
+ | |||
+ | if keys[pygame.K_DOWN] and y < 500 - height - 15: | ||
+ | y += vel | ||
+ | |||
+ | if keys[pygame.K_SPACE]: | ||
+ | isJump = True | ||
+ | else: | ||
+ | if JumpCount >= -10: | ||
+ | y -= JumpCount * 2 | ||
+ | JumpCount -= 1 | ||
− | + | else: | |
− | + | isJump = False | |
+ | JumpCount = 10 | ||
win.fill((0,0,0)) | win.fill((0,0,0)) |
Версия 09:56, 11 февраля 2022
import pygame pygame.init()
win = pygame.display.set_mode((500,500)) pygame.display.set_caption("First Game")
x = 50 y = 425 width = 40 height = 60 vel = 5
isJump = False JumpCount = 10
run = True
while run:
pygame.time.delay(50)
for event in pygame.event.get(): if event.type == pygame.QUIT: run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and x > 5: x -= vel
if keys[pygame.K_RIGHT] and x < 500 - width - 5: x += vel
if not(isJump):
if keys[pygame.K_UP] and y > 5: y -= vel
if keys[pygame.K_DOWN] and y < 500 - height - 15: y += vel
if keys[pygame.K_SPACE]: isJump = True else: if JumpCount >= -10: y -= JumpCount * 2 JumpCount -= 1
else: isJump = False JumpCount = 10
win.fill((0,0,0)) pygame.draw.rect(win, (0,0,255), (x, y, width, height)) pygame.display.update()
pygame.quit()