-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunits.go
127 lines (104 loc) · 2.26 KB
/
units.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
package main
import (
"math/rand"
"github.com/google/uuid"
"github.com/hajimehoshi/ebiten/v2"
"github.com/ronoaldo/ld-50/assets"
)
// Unit stats for both player and enemy.
type Stats struct {
HP int
MaxHP int
Strengh int
Speed int
}
// Chip a stat modifier that can be applied to the player/enemy.
type Chip struct {
ID uuid.UUID
StatModifier Stats
Sprite *ebiten.Image
e *Entity
}
// NewChip creates a new random stat modifier
func NewChip() *Chip {
c := &Chip{}
c.ID = uuid.New()
// Randomize new chip stats player can choose
c.StatModifier.MaxHP = rand.Intn(11)
c.StatModifier.Strengh = rand.Intn(11)
c.StatModifier.Speed = rand.Intn(11)
// Randomize chip graphics
if c.StatModifier.MaxHP > c.StatModifier.Speed &&
c.StatModifier.MaxHP > c.StatModifier.Strengh {
c.Sprite = assets.ChipLife
} else if c.StatModifier.Strengh > c.StatModifier.MaxHP &&
c.StatModifier.Strengh > c.StatModifier.Speed {
c.Sprite = assets.ChipStrength
} else {
c.Sprite = assets.ChipSpeed
}
return c
}
// Droid is a base unit type that is a playable character.
type Droid struct {
Name string
Level int
BaseStats Stats
Chips [6]Chip
Sprite *ebiten.Image
e *Entity
Skills [3]Skill
}
func (d *Droid) Stats() Stats {
b := d.BaseStats
s := Stats{
HP: b.HP,
MaxHP: b.MaxHP,
Strengh: b.Strengh,
Speed: b.Speed,
}
for _, ch := range d.Chips {
s.MaxHP += ch.StatModifier.MaxHP
s.Strengh += ch.StatModifier.Strengh
s.Speed += ch.StatModifier.Speed
}
return s
}
type BattleUnit struct {
Name string
// Final stats from the base + modifiers
Stats Stats
// Skills this unit can use
Skills [3]Skill
}
type SkillEffect func(p, e *BattleUnit)
type Skill struct {
Name string
Effect SkillEffect
Sprite *ebiten.Image
}
var (
BasicAttackSkill = Skill{
Name: "Basic Attack",
Effect: func(p, e *BattleUnit) {
str := p.Stats.Strengh
e.Stats.HP -= str
},
}
UltimateAttackSkill = Skill{
Name: "Ultimate Attack",
Effect: func(p, e *BattleUnit) {
str := p.Stats.Strengh
e.Stats.HP -= 2 * str
},
}
HealSkill = Skill{
Name: "Heal Attack",
Effect: func(p, e *BattleUnit) {
p.Stats.HP += p.Stats.Strengh
if p.Stats.HP > p.Stats.MaxHP {
p.Stats.HP = p.Stats.MaxHP
}
},
}
)