This repository was archived by the owner on Oct 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuperMeleeEnemy.py
More file actions
89 lines (75 loc) · 2.68 KB
/
superMeleeEnemy.py
File metadata and controls
89 lines (75 loc) · 2.68 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
try:
import simplegui
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
from vector import Vector
from enemy import Enemy
import globals
from health import Health
CANVAS_WIDTH = globals.CANVAS_DIMS[0]
CANVAS_HEIGHT = globals.CANVAS_DIMS[1]
class SuperMeleeEnemy(Enemy):
# pos: coordinates to spawn the enemy at
def __init__(self, pos):
super().__init__("https://raw.githubusercontent.com/CalhamZeKoala/GameImg/master/fancycircle.png",
(80, 80), pos, 1)
self.radius = 40
self.border = 1
self.dazeCount = 0
self.count = 0
self.health = Health()
self.health.health = 10
self.currentlyAttacking = True
self.attackCount = 0
def dazed(self):
self.dazeCount = 1 # Change for different 'Dazed' times (Larger Number = Longer)
# other: object to check if colliding with
def collides(self, other):
if self == other:
return False
else:
dist = (self.pos - other.pos).length()
collisionDist = (self.radius + self.border) + (other.radius + other.border)
return dist <= collisionDist
# normal: vector to use as the normal
def bounce(self, normal):
self.vel.reflect(normal)
# target: Boolean for whether targetting is active
def set_target(self, target):
self.currentlyTargeting = target
def update(self):
super().update()
self.attack_cycle()
if self.outX():
self.pos.x %= CANVAS_WIDTH
if self.vel.x >= 0:
self.pos.x -= self.radius
else:
self.pos.x += self.radius
if self.outY():
self.pos.y %= CANVAS_HEIGHT
if self.vel.y >= 0:
self.pos.y -= 2 * self.radius
else:
self.pos.y += 2 * self.radius
def outX(self):
return (self.pos.x + self.radius < 0 or
self.pos.x - self.radius > CANVAS_WIDTH)
def outY(self):
return (self.pos.y + self.radius < 0 or
self.pos.y - self.radius > CANVAS_HEIGHT)
def target(self, pos):
if self.currentlyTargeting and self.dazeCount == 0:
self.vel = Vector(pos.get_p()[0] - self.pos.get_p()[0], pos.get_p()[1] - self.pos.get_p()[1]).normalize()
else:
self.daze_cycle()
def attacked(self):
if self.currentlyAttacking:
self.attackCount = 120
self.currentlyAttacking = False
def attack_cycle(self):
if self.attackCount > 0:
self.attackCount -= 1
else:
self.attackCount = 0
self.currentlyAttacking = True