-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemies.go
129 lines (97 loc) · 2.28 KB
/
enemies.go
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
package main
import (
"math/rand"
"rapidengine/child"
)
type EnemyManager struct {
AllEnemies map[int]Enemy
}
func InitializeEnemyManager() *EnemyManager {
em := EnemyManager{
AllEnemies: make(map[int]Enemy),
}
LoadGoblinTextures()
return &em
}
func (em *EnemyManager) Update() {
for i, enemy := range em.AllEnemies {
if enemy.Activator().IsActive() {
enemy.Update()
}
if enemy.GetCommon().Health <= 0 {
enemy.GetCommon().Kill()
}
if enemy.GetCommon().Dead {
delete(EM.AllEnemies, i)
}
}
}
func (em *EnemyManager) CheckPlayerCollision() Enemy {
for _, enemy := range em.AllEnemies {
pdist := Distance(
Player1.CenterX, Player1.CenterY,
enemy.GetChild().X, enemy.GetChild().Y,
)
if pdist > 200 {
continue
}
if Player1.CheckEnemyCollision(enemy) {
return enemy
}
}
return nil
}
func (em *EnemyManager) NewGoblin(radius float32) {
mat := NewGoblinMaterial()
goblinChild := Engine.ChildControl.NewChild2D()
goblinChild.AttachMaterial(mat)
goblinChild.ScaleX = 300
goblinChild.ScaleY = 300
screenSide := (rand.Intn(2) * 2) - 1
goblinChild.X = Player1.PlayerChild.X + float32(screenSide)*((float32(ScreenWidth/2)+100)+radius)
goblinChild.Y = float32(HeightMap[int(goblinChild.X)/BlockSize]*BlockSize) + 50
var g = Goblin{
common: &Common{
Health: 100,
MaxHealth: 100,
MonsterChild: goblinChild,
MonsterMaterial: mat,
VXMult: (rand.Float32()*2-1.0)*0.2 + 0.8,
VYMult: (rand.Float32()*2-1.0)*0.2 + 1.0,
GravMult: 1,
NumJumps: 1,
Hitbox1: NewHitBox(AABB{
X: -10,
Y: -10,
Width: 40,
Height: 120,
}, 5),
aHitbox: AABB{
OffX: 0,
OffY: 45,
Width: 55,
Height: 60,
},
State: "normal",
},
activator: Activator{},
}
g.common.Hitbox1.OffX = -13
g.common.Hitbox1.OffY = -20
g.common.HealthBar = Engine.UIControl.NewProgressBar()
g.common.HealthBar.SetDimensions(50, 10)
g.common.HealthBar.BackChild.Static = true
g.common.HealthBar.BarChild.Static = true
g.common.HOffsetY = -30
g.Activator().Activate()
V.AddBox(&g.common.Hitbox1)
V.AddAABB(&g.common.aHitbox)
em.AllEnemies[len(em.AllEnemies)-1] = &g
}
type Enemy interface {
Update()
Damage(amount float32)
GetChild() *child.Child2D
GetCommon() *Common
Activator() *Activator
}