Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- pygame.init()
- # Window settings
- size = [600, 500]
- win = pygame.display.set_mode(size)
- # Player Settings
- jump = False
- jumpcount = 10
- y = 430
- enemyX = 600
- def enemy():
- global enemyX
- enemyX -= 5
- pygame.draw.rect(win, (0, 150, 0), (enemyX, 450, 50, 50))
- run = True
- # Clock function
- clock = pygame.time.Clock()
- while run:
- clock.tick(30)
- # Checking for QUIT event
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- # keys is event for KEY-press
- keys = pygame.key.get_pressed()
- if not jump:
- if keys[pygame.K_SPACE]:
- jump = True
- else:
- if jumpcount >= -10:
- neg = 1
- if jumpcount < 0:
- neg = -1
- y -= (jumpcount ** 2) * 0.5 * neg
- jumpcount -= 1
- else:
- jump = False
- jumpcount = 10
- hitboxX = 30
- hitboxY = y
- if hitboxX + 70 >= enemyX and hitboxY >= 450 and hitboxX :
- print(" HIT ")
- win.fill((0, 0, 0))
- enemy()
- pygame.draw.rect(win, (250, 0, 0), (30, y, 70, 70))
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment