Pygame

No description

fork
loading
Files
  • main.py
  • nohup.out
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pygame
pygame.init()

win = pygame.display.set_mode((500,500))
pygame.display.set_caption("First Game")

x = 50
y = 400
width = 40
height = 60
vel = 5

isJump = False
jumpCount = 10

run = True
while run:
  pygame.time.delay(50)
  #Create list of all events
  for event in pygame.event.get():
    #Click the 'X' to quit
    if event.type == pygame.QUIT:
      run = False
  keys = pygame.key.get_pressed()

 


  if keys[pygame.K_LEFT] and x > vel:
    x -= vel

  if keys[pygame.K_RIGHT] and x < 500 - width - vel:
    x += vel

  if not(isJump):
    if keys[pygame.K_UP] and y > vel:
      y -= vel
    
    if keys[pygame.K_DOWN] and y < 500 - height - vel:
      y += vel

    if keys[pygame.K_SPACE]:
      isJump = True

  else:
    if jumpCount >= -10:
      neg = 1
      if jumpCount < 0:
        neg = -1
      y -= (jumpCount ** 2) * 0.5 * neg
      jumpCount -= 1

    else:
      isJump = False
      jumpCount = 10


  win.fill((0,0,0))
  pygame.draw.rect(win, (255,0,0), (x, y, width, height))
  pygame.display.update()

pygame.quit()