-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
78 lines (67 loc) · 2.2 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
import random
import pyxel
import events
import input
import sounds
from constants import LANES, SCREEN_HEIGHT, SCREEN_WIDTH
from entities import Garden, Hive
from resources import Game
def get_random_lane():
return random.randint(1, 7)
class App:
def __init__(self):
pyxel.init(SCREEN_WIDTH, SCREEN_HEIGHT, title="Beehive Classic", fps=60)
pyxel.load("assets.pyxres")
pyxel.images[1].load(0, 0, "flower.png")
sounds.init()
self.game = Game()
self.hive = Hive()
self.garden = Garden()
events.spider_attack.append(self.game.handle_spider_attack)
events.game_over.append(self.garden.handle_game_over)
events.game_over.append(self.hive.handle_game_over)
pyxel.run(self.update, self.draw)
def update(self):
if input.quit():
pyxel.quit()
if self.game.is_active:
self.garden.update()
self.hive.update()
spiders = [spider for spider in self.garden.spiders if spider.y < 100]
for bee in self.hive.residents:
for flower in self.garden.blooming_flowers:
if bee.collision_space & flower.collision_space:
self.game.increment_score()
bee.recall()
flower.collect()
for spider in spiders:
if bee.collision_space & spider.collision_space:
spider.destroy()
bee.recall()
self.game.update()
def draw_exit(self, x):
height = 5
pyxel.rect(
x,
y=SCREEN_HEIGHT - height,
w=16,
h=height,
col=pyxel.COLOR_LIME,
)
def draw(self):
pyxel.cls(pyxel.COLOR_LIME)
self.game.draw()
if self.game.is_active:
pyxel.bltm(0, 16, 0, 0, 0, 160, 100, pyxel.COLOR_LIME)
pyxel.rect(
x=0,
y=115,
w=SCREEN_WIDTH,
h=5,
col=pyxel.COLOR_NAVY,
)
for lane in LANES:
self.draw_exit(lane)
self.garden.draw()
self.hive.draw()
App()