-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
115 lines (92 loc) · 2.71 KB
/
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import sys, pygame, math
from player import Player
pygame.init()
#Colors
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
darkBlue = (0,0,128)
white = (255,255,255)
black = (0,0,0)
pink = (255,200,200)
#
blockSize = 16
#Screen
size = width, height = 16 * blockSize, 16 * blockSize
screen = pygame.display.set_mode(size)
#Player
player = Player((40,40), blockSize, blue)
player.accelerate((math.pi/3,2))
#Variables
gravity = 0.1
#Flags
moveLeft = False
moveRight = False
jump = False
playerCollX = False
playerCollY = False
falling = True
#Level
level = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
[2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]
levelBlocks = []
blockOffsetX = 0
blockOffsetY = 0
for x in range (0,16):
for y in range (0,16):
if level[y][x] == 1:
levelBlocks.append(pygame.Rect(blockOffsetX,blockOffsetY, blockSize, blockSize))
if level[y][x] == 2:
player.x = blockOffsetX
player.y = blockOffsetY
blockOffsetY += blockSize
blockOffsetY = 0
blockOffsetX += blockSize
#Main loop
while 1:
#Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
moveLeft = True
if event.key == pygame.K_RIGHT:
moveRight = True
if event.key == pygame.K_UP:
jump = True
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
moveLeft = False
dx = 0
if event.key == pygame.K_RIGHT:
moveRight = False
dx = 0
if event.key == pygame.K_UP:
jump = False
dy = 0
player.move()
#Print inside screen
screen.fill(black)
#Handle everything related to the levelblocks
for block in levelBlocks:
#Print
pygame.draw.rect(screen,white,block)
pygame.draw.rect(screen,blue,player.rect)
pygame.time.Clock().tick(10) #Change?
pygame.display.flip()