-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
66 lines (49 loc) · 1.39 KB
/
game.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
import pyxel
from bug import Bug
from food import Food
import random
import math
pyxel.init(255, 255)
food = [Food(random.uniform(10, 246), random.uniform(10, 246)) for _ in range(20)]
bugs = [Bug(random.uniform(10, 246), random.uniform(10, 246)) for _ in range(40)]
show_labels = False
eye_debug = False
def update():
global show_labels, eye_debug
if pyxel.btnp(pyxel.KEY_Q):
pyxel.quit()
if pyxel.btnp(pyxel.KEY_T):
show_labels = not show_labels
if pyxel.btnp(pyxel.KEY_D):
eye_debug = not eye_debug
for bug in bugs:
bug.update(food, bugs)
for bit in food:
bit.update()
for bit in list(food):
if bit.eaten:
food.remove(bit)
if pyxel.frame_count % 4 == 0:
empty_spot = False
while empty_spot == False:
x = random.uniform(10, 246)
y = random.uniform(10, 246)
empty_spot = True
for bug in bugs:
dist = math.sqrt((x-bug.x) ** 2 + (y-bug.y) ** 2)
if dist < 30:
empty_spot = False
break
food.append(Food(x, y, False))
for bug in list(bugs):
if bug.dead:
bugs.remove(bug)
if len(bugs) < 15:
bugs.append(Bug(random.uniform(10, 246), random.uniform(10, 246)))
def draw():
global show_labels, eye_debug
pyxel.cls(0)
for drawable in food + bugs:
drawable.draw(show_labels, eye_debug)
pyxel.text(10, 10, "TOTAL BUGS: "+str(len(bugs)), 10)
pyxel.run(update, draw)