-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (61 loc) · 2.16 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
from imports import *
from scene_manager import SceneManager
from objects import Player, Line, Enemy
from map_utility import load_map_by_csv
pygame.init()
## SETTINGS
display_info = pygame.display.Info()
clock = pygame.time.Clock()
FPS = 60
SCALE = 1 / 2
WW, WH = 600, 400
WINDOW = pygame.display.set_mode((WW, WH))
SW, SH = WW * SCALE, WH * SCALE
display = pygame.Surface((SW, SH))
def main():
## SETUP
player = Player()
enemy = Enemy()
level, map_size = load_map_by_csv(os.path.join("maps", "map.csv"))
scroll = vec()
## MAIN LOOP
while True:
clock.tick(FPS)
display.fill(color("#A5CBC3"))
scroll.x += (player.rect.centerx - scroll.x - SW / 2) // 10
scroll.y += (player.rect.centery - scroll.y - SH / 2) // 10
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
manager.exit()
return
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
player.direction["right"] = True
enemy.direction["right"] = True
if event.key == pygame.K_LEFT:
player.direction["left"] = True
enemy.direction["left"] = True
if event.key == pygame.K_UP:
player.direction["up"] = True
if event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT:
player.direction["right"] = False
enemy.direction["right"] = False
if event.key == pygame.K_LEFT:
player.direction["left"] = False
enemy.direction["left"] = False
if event.key == pygame.K_UP:
player.direction["up"] = False
player.update(level)
player.move()
player.render(display, scroll)
enemy.update()
enemy.move()
enemy.render(display, scroll)
for tile in level:
tile.draw(display, scroll)
WINDOW.blit(pygame.transform.scale(display, (WW, WH)), (0, 0))
pygame.display.update()
manager = SceneManager(main)
manager.run()