forked from amanirmk/AMISTAD-intention-exp3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassProjectile.py
More file actions
56 lines (43 loc) · 2.1 KB
/
classProjectile.py
File metadata and controls
56 lines (43 loc) · 2.1 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
from typeDirection import *
from typeThick import *
import simulation as s
import magicVariables as mv
class Projectile:
def __init__(self, start_x, start_y, direction, thickType, ownerBoard, timeStep):
self.direction = direction
self.strength = self.assignStrength(thickType)
self.x = start_x
self.y = start_y
self.ownerBoard = ownerBoard
self.landProjectile(timeStep)
def landProjectile(self, timeStep):
"""this method figures out where the projectile lands when moving in the given direction"""
s.gopher.trapTriggered() #tells gopher that trap has been triggered
while self.x >= 0 and self.x < self.ownerBoard.rowLength and self.y >= 0 and self.y < self.ownerBoard.colLength:
#while in bounds of trap
if self.checkHitGopher(timeStep):
break
if self.direction in [DirectionType.right, DirectionType.upperright, DirectionType.lowerright]:
self.x += 1
if self.direction in [DirectionType.left, DirectionType.upperleft, DirectionType.lowerleft]:
self.x -= 1
if self.direction in [DirectionType.up, DirectionType.upperleft, DirectionType.upperright]:
self.y -= 1
if self.direction in [DirectionType.down, DirectionType.lowerleft, DirectionType.lowerright]:
self.y += 1
def checkHitGopher(self, timeStep):
"""determines if the gopher has been hit and tells the gopher it has been hit if so"""
if self.x == s.gopher.x and self.y == s.gopher.y:
s.gopher.hitByProjectile(self, timeStep)
return True
return False
def assignStrength(self, thicktype):
"""assigns strength based on thick type"""
if(thicktype == ThickType.skinny):
return mv.SKINNY_PROJECTILE_STRENGTH
elif(thicktype == ThickType.normal):
return mv.NORMAL_PROJECTILE_STRENGTH
elif(thicktype == ThickType.wide):
return mv.WIDE_PROJECTILE_STRENGTH
else:
raise Exception("Invalid thicktype")