-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (44 loc) · 1.75 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
from imports import *
import engine
from engine import *
from npc import make_npc
import test
pygame.init()
display = pygame.display.set_mode(size=(800, 400))
display.fill(color=SCREEN_GREY)
camera = Camera(display)
engine.camera = camera
protagonist = Entity(Rect(0,0, 24, 24), color=(250,250,250), speed=2)
statics = []
for i in range(20):
entity = Entity(Rect(i*20+60,i*20, 16, 16), parallax=1, color=(250,150,150))
entity.add_destination(Vector2d(50, 380))
entity.add_destination(Vector2d(randint(0, display.get_width()), randint(0, display.get_height())))
entity.add_destination(Vector2d(randint(0, display.get_width()), randint(0, display.get_height())))
entity.add_destination(Vector2d(randint(0, display.get_width()), randint(0, display.get_height())))
statics.append(entity)
# elements = statics + [protagonist]
elements = Entities(protagonist, statics)
def main_loop():
while True:
for event in pygame.event.get():
EventManager.manage_event(event, protagonist)
display.fill(color=(150,150,150))
camera.move()
camera.shake()
# protagonist.move()
# manage collisions with protagonist
elements.tick()
protagonist.move()
# for element in sorted(elements, key=lambda e: e.parallax, reverse=False):
for element in sorted(elements.entities, key=lambda e: e.parallax, reverse=False):
element.move()
for element in sorted(elements.entities+[protagonist], key=lambda e: e.parallax, reverse=False):
pygame.draw.rect(camera.surface, color=element.color, rect=camera_draw(camera, element.rect, element.parallax))
pygame.display.update()
##
# TESTING
# #####
# test.screen = display
# test.mydo()
main_loop()