-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgar_io.py
More file actions
186 lines (159 loc) · 4.73 KB
/
Agar_io.py
File metadata and controls
186 lines (159 loc) · 4.73 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#By: Adedayo Ogunnoiki
from scene import *
from random import *
class Particle(Rect):
def __init__(self, wh):
global particlew, particleh
particlew = wh.w
particleh = wh.h
self.x = randint(particlew*-1, particlew)
self.y = randint(particleh*-1, particleh)
self.colour = Color(random(), random(), random())
self.cells=Rect(self.x, self.y, 10, 10)
def update(self):
self.cells=Rect(self.x, self.y, 10, 10)
def draw(self):
fill(*self.colour)
ellipse(*self.cells)
global attackx, attacky
attackx, attacky = self.x, self.y
class Bots(Rect):
def __init__(self, wh):
self.w = wh.w
self.h = wh.h
self.x = randint(self.w*-1, self.w)
self.y = randint(self.h*-1, self.h)
self.colour = Color(random(), random(), random())
self.bsize=11
def update(self):
self.attackers=Rect(self.x, self.y, self.bsize, self.bsize)
def draw(self):
fill(*self.colour)
ellipse(*self.attackers)
class Intro(Scene):
def setup(self):
self.count = 0
self.psize = 11
self.plocx = self.size.w/2 - self.psize/2
self.plocy = self.size.h/2 - self.psize/2
self.player = Rect(self.plocx, self.plocy, self.psize, self.psize)
self.colour = Color(random(), random(), random())
self.particles = [Particle(self.size) for i in xrange(50)]
self.bots = [Bots(self.size)]
self.lw=self.size.w*-1
self.rw=self.size.w
self.bh=self.size.h*-1
self.th=self.size.h
self.points = self.psize
def touch_began(self, touch):
self.x1, self.y1 = touch.location
def touch_moved(self, touch):
self.x, self.y = touch.location
self.count = 1
def movecells(self):
for p in self.particles:
p.update()
if self.x > self.x1:
addx=(self.x-self.x1)/30
self.newcellx=p.x+addx
if self.x < self.x1:
subx=(self.x-self.x1)/30
self.newcellx=p.x+subx
if self.y > self.y1:
addy=(self.y-self.y1)/30
self.newcelly=p.y+addy
if self.y < self.y1:
suby=(self.y-self.y1)/30
self.newcelly=p.y+suby
while self.newcellx != p.x and self.newcellx > p.x and self.lw < self.plocx:
p.x += 1
self.lw += 0.02
self.rw += 0.02
while self.newcellx != p.x and self.newcellx < p.x and self.rw > self.plocx:
p.x-= 1
self.lw -= 0.02
self.rw -= 0.02
while self.newcelly != p.y and self.newcelly > p.y and self.bh < self.plocy:
p.y += 1
self.bh += 0.02
self.th += 0.02
while self.newcelly != p.y and self.newcelly < p.y and self.th > self.plocy:
p.y -= 1
self.bh -= 0.02
self.th -= 0.02
for b in self.bots:
if b.x > self.rw:
b.x -= 2
elif b.x < self.lw:
b.x += 2
if b.y < self.bh:
b.y += 2
elif b.y > self.th:
b.y -= 2
def keep_in_bounds(self):
global attackx, attacky
for p in self.particles:
p.update()
p.draw()
if attackx > self.rw or attackx < self.lw or attacky > self.th or attacky < self.bh:
self.particles.remove(p)
for p in range(1):
self.particles.append(Particle(self.size))
def bound_block(self):
rect(self.rw+self.psize, self.bh-self.size.h/2, self.size.w, self.size.h*3)
rect(self.lw-self.size.w/2, self.bh-self.size.h/2, self.size.w/2, self.size.h*3)
rect(self.lw-self.size.w/2, self.bh-self.size.h/2, self.size.w*3, self.size.h/2)
rect(self.lw, self.th+self.psize, self.size.w*2+self.psize, self.size.h/2)
def bots_life(self):
for b in self.bots:
b.update()
b.draw()
if b.x < attackx and b.x < self.rw:
b.x += 2
elif b.x > attackx and b.x > self.lw:
b.x -= 2
if b.y < attacky and b.y < self.th:
b.y += 2
elif b.y > attacky and b.y > self.bh:
b.y -= 2
for p in self.particles:
if b.attackers.intersects(p.cells):
self.particles.remove(p)
b.bsize += 0.5
for p in range(1):
self.particles.append(Particle(self.size))
self.keep_in_bounds()
if self.player.intersects(b.attackers):
if int(b.bsize) > int(self.psize):
self.die()
if int(self.psize) > int(b.bsize):
self.psize += b.bsize
def die(self):
sys.exit()
def draw(self):
background(0.00, 0.05, 0.20)
global attackx, attackx
self.plocx = self.size.w/2 - self.psize/2
self.plocy = self.size.h/2 - self.psize/2
if self.count == 1:
self.movecells()
for p in self.particles:
p.update()
p.draw()
if self.player.intersects(p.cells):
self.particles.remove(p)
self.psize += 0.2
self.points += 1
for p in range(1):
self.particles.append(Particle(self.size))
self.keep_in_bounds()
self.bots_life()
self.player = Rect(self.plocx, self.plocy, self.psize, self.psize)
fill(*self.colour)
ellipse(*self.player)
fill(0,0,0)
self.bound_block()
text('Score: %i' % self.points, x=self.size.w/4, y=self.size.h/4*3.6, font_size=20)
def should_rotate(self, orientation):
return True
run(Intro())