-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.go
73 lines (60 loc) Β· 1.34 KB
/
enemy.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
package main
import rl "github.com/gen2brain/raylib-go/raylib"
type EnemyType = int32
const (
Slime EnemyType = iota
NotSlime
)
type Intention = int32
const (
Neutral Intention = iota
Offensive
Defansive
)
type Enemy struct {
TexturePath string
AttackRange []float32
Health float32
Defence float32
Type EnemyType
CurrentIntention Intention
Texture rl.Texture2D
}
// TODO: load texture on setup()
func DefineEnemy(enemyType EnemyType, atkRange []float32, health, defence float32, path string) Enemy {
return Enemy{
Type: enemyType,
Health: health,
AttackRange: atkRange,
Defence: defence,
CurrentIntention: Neutral,
Texture: rl.LoadTexture(path),
}
}
func (node *Node) assingEnemy(enemy Enemy) {
node.Spawner.Enemy = &enemy
}
func (node *Node) killEnemy() {
node.Spawner.Enemy = nil
}
func (node *Node) SetSpawner(enemyType EnemyType) {
e, found := Scene.Enemies[enemyType]
if !found {
panic("Enemy type not defined")
}
node.assingEnemy(e)
}
func (e *Enemy) attackPlayer(p *Player, dmg float32) {
var unblocked float32 = 0
if p.Defence-dmg >= 0 {
p.Defence -= dmg
} else {
unblocked = dmg - p.Defence
p.Defence = 0
}
p.Health -= unblocked
if e.Health <= 0 {
// TODO: handle player death
}
}
func (e *Enemy) block() {}