-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemyT.py
97 lines (94 loc) · 4.89 KB
/
EnemyT.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
from tkinter import W
from cmu_graphics import *
from Enemy import *
from EnemyX import *
from LevelLists import *
from BreakWall import *
from Shield import *
class EnemyT(Enemy):
enemyTList = []
def __init__(self, cX, y1, y2, lW, health, speed, damage, grounded, level, room, group, *, maxInv = 45, knockbackResist = 0, boss = False):
self.grounded = grounded
self.boss = boss
self.direction = 0
self.enemyChecking = True
super().__init__(cX, y1, y2, lW, health, speed, damage, level, room, group, maxInv, knockbackResist)
EnemyT.enemyTList[level - 1][room].append(self)
def enemyCollisionCheck(self, e):
if e != self.shape and e != None:
if e.opacity != 0:
return True
return False
def enemyCheck(self, pushBack, pushDirection, pushingEnemy, startEnemy, *, times = 1, enemiesHit = set()):
enemiesHit.add(self)
#for e in enemiesHit:
# print(e)
if startEnemy == self and times != 1:
self.shape.centerX = rounded(self.shape.centerX/2.5)*2.5
return
a = 0
while pushingEnemy.shape.right > self.shape.right > pushingEnemy.shape.left or pushingEnemy.shape.left < self.shape.left < pushingEnemy.shape.right:
self.shape.centerX += pushBack * pushDirection
self.shape.centerX = rounded(self.shape.centerX/2.5)*2.5
a += 1
if (
(self.grounded and (not hitCheckAllOr(self.bottom)) and (not hitCheck(groundGroupList, self.bottom))) or
(pushDirection == 1 and hitCheckAllOr(self.right)) or
(pushDirection == -1 and hitCheckAllOr(self.left))
):
self.shape.centerX -= pushBack * pushDirection
self.shape.centerX = rounded(self.shape.centerX/2.5)*2.5
if ((pushDirection == 1 and hitCheck(enemyGroupList, self.left)) or (pushDirection == -1 and hitCheck(enemyGroupList, self.right))):
if pushDirection == -1:
e = hitFindNotObject(Enemy.enemyList, self, self.right)
else:
e = hitFindNotObject(Enemy.enemyList, self, self.left)
if e != None:
e.enemyCheck(pushBack, -pushDirection, self, self, times = times+1, enemiesHit = enemiesHit)
elif ((pushDirection == 1 and hitCheck(enemyGroupList, self.right)) or (pushDirection == -1 and hitCheck(enemyGroupList, self.left))):
if pushDirection == 1:
e = hitFindNotObject(Enemy.enemyList, self, self.right)
else:
e = hitFindNotObject(Enemy.enemyList, self, self.left)
if e != None:
e.enemyCheck(pushBack, pushDirection, self, startEnemy, times = times+1, enemiesHit = enemiesHit)
def move(self):
if self.health > 0:
if self.invTime <= 0:
if self.shape.centerX < character.shape.centerX:
self.direction = 1
elif self.shape.centerX > character.shape.centerX:
self.direction = -1
else:
self.direction = 0
self.shape.centerX += self.speed * self.direction
if self.grounded:
if not hitCheckAllOr(self.bottom) and not hitCheck(groundGroupList, self.bottom):
self.shape.centerX -= self.speed * self.direction
if (
(self.direction == 1 and hitCheckAllOr(self.right)) or
(self.direction == -1 and hitCheckAllOr(self.left))
):
self.shape.centerX -= self.speed * self.direction
if self.shape.hitsShape(shield.shape) and shield.shape.visible:
shield.health -= self.damage
self.invTime = self.maxInv
self.health -= shield.damage
self.shape.centerX -= (shield.pushMulti - self.knockbackResist) * self.speed * self.direction
else:
self.damageCheck()
if self.shape.hitsShape(character.shape):
if ((self.direction == -1 and not hitCheckAllOr(character.left)) or (self.direction == 1 and not hitCheckAllOr(character.right))):
character.shape.centerX += self.speed * self.direction
e = hitFindNotObject(Enemy.enemyList, self, self.left)
if e != None:
e.enemyCheck(self.speed, -1, self, self)
e = hitFindNotObject(Enemy.enemyList, self, self.right)
if e != None:
e.enemyCheck(self.speed, 1, self, self)
if app.level == 12:
groupShapes(self.shape, self.light, 0, 0)
else:
self.shape.opacity = 0
if self.level == 12:
self.light.visible = False