/
Wizard.py
216 lines (156 loc) · 8.46 KB
/
Wizard.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import random
from Creature import Creature
from Building import Building
from Paintable import loadImage
from Lightning import Lightning
from Swordsman import Swordsman
from Constants import *
class Wizard(Creature):
def __init__(self, x, y, team):
Creature.__init__(self, x, y, WIZARD_SPEED, WIZARD_LIFE, WIZARD_REGENERATION, team)
self.attack = WIZARD_ATTACK
self.attackSpeed = WIZARD_ATTACK_SPEED
self.lastAttack = 0
self.movement = 0
if self.team == 0:
self.image = loadImage("art/wizard.png", (255,255,255))
else:
self.image = loadImage("art/egyptian_magician.png", (255,255,255))
def process(self, powerPopulation, buildingPopulation, terrain):
Creature.process(self, powerPopulation, buildingPopulation, terrain)
self.lastAttack += TIME_QUANTUM
if(self.lastAttack > self.attackSpeed):
for i in range(7):
for j in range(7):
thing = terrain.getThingOcupying(self.x+i-3,self.y+j-3)
'''If there is a creature near by that's an enemy'''
if(isinstance(thing, Creature)):
if(thing.getTeam() != self.team and thing.isAlive()):
'''move towards it'''
powerPopulation.addPower(Lightning(self.x, self.y, random.randint(0, self.attack), thing))
self.lastAttack = 0
return
if(self.moving == False):
self.moveEvil(terrain)
def movePurposefully(self, terrain, buildingPopulation):
for i in range(7):
for j in range(7):
'''Find if there is a building'''
thing = terrain.getThingOcupying(self.x+i-1,self.y+j-1)
if isinstance(thing, Building):
self.moveDirection = abs(self.x + thing.getX())%4
elif isinstance(thing, Creature):
if(thing.getTeam() != self.team):
'''avoid it like the plague'''
self.moveDirection = abs(self.x - thing.getX())%4
#self.engage(thing)
elif(thing.getTeam() == self.team):
self.moveDirection = abs(self.x + thing.getX())%4
else:
self.moveDirection = random.randint(0,3)
newX = self.x + DIRECTION[self.moveDirection][0]
newY = self.y + DIRECTION[self.moveDirection][1]
if(terrain.walkable(newX, newY)):
self.moving = True
self.timeMoving = 0
self.x = newX
self.y = newY
terrain.setThingOcupying(self.x, self.y, self)
else:
self.moving = False
def moveEvil(self, terrain):
for i in range(7):
for j in range(7):
thing = terrain.getThingOcupying(self.x+i-3,self.y+j-3)
if(isinstance(thing, Swordsman)):
if(thing.getTeam() != self.team):
if(i-5>0 and j-5>0):
if(random.randint(0,1)==0):
self.moveDirection = 1
else:
self.moveDirection = 3
elif(i-5<0 and j-5<0):
if(random.randint(0,1)==0):
self.moveDirection = 0
else:
self.moveDirection = 2
elif(i-5<0 and j-5>0):
if(random.randint(0,1)==0):
self.moveDirection = 3
else:
self.moveDirection = 0
elif(i-5>0 and j-5<0):
if(random.randint(0,1)==0):
self.moveDirection = 2
else:
self.moveDirection = 1
elif(i-5>0):
self.moveDirection = 2
elif(i-5<0):
self.moveDirection = 3
elif(j-5>0):
self.moveDirection = 0
elif(j-5<0):
self.moveDirection = 1
newX = self.x + DIRECTION[self.moveDirection][0]
newY = self.y + DIRECTION[self.moveDirection][1]
if(terrain.walkable(newX, newY)):
self.moving = True
self.x = newX
self.y = newY
terrain.setThingOcupying(self.x, self.y, self)
self.timeMoving = 0
return
elif(isinstance(thing, Creature)):
if(thing.getTeam() != self.team):
if(i-5<0 and j-5<0):
if(random.randint(0,1)==0):
self.moveDirection = 1
else:
self.moveDirection = 3
elif(i-5>0 and j-5>0):
if(random.randint(0,1)==0):
self.moveDirection = 0
else:
self.moveDirection = 2
elif(i-5>0 and j-5<0):
if(random.randint(0,1)==0):
self.moveDirection = 3
else:
self.moveDirection = 0
elif(i-5<0 and j-5>0):
if(random.randint(0,1)==0):
self.moveDirection = 2
else:
self.moveDirection = 1
elif(i-5<0):
self.moveDirection = 2
elif(i-5>0):
self.moveDirection = 3
elif(j-5<0):
self.moveDirection = 0
elif(j-5>0):
self.moveDirection = 1
newX = self.x + DIRECTION[self.moveDirection][0]
newY = self.y + DIRECTION[self.moveDirection][1]
if(terrain.walkable(newX, newY)):
self.moving = True
self.x = newX
self.y = newY
terrain.setThingOcupying(self.x, self.y, self)
self.timeMoving = 0
return
self.moveRandomly(terrain)
def moveRandomly(self, terrain):
if(random.randint(0,5) == 0):
self.moveDirection = random.randint(0,3)
newX = self.x + DIRECTION[self.moveDirection][0]
newY = self.y + DIRECTION[self.moveDirection][1]
if(terrain.walkable(newX, newY)):
self.moving = True
self.timeMoving = 0
self.x = newX
self.y = newY
terrain.setThingOcupying(self.x, self.y, self)
else:
self.moving = False