-
Notifications
You must be signed in to change notification settings - Fork 0
/
powerup.go
72 lines (63 loc) · 1.18 KB
/
powerup.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
package main
import (
"math/rand"
rl "github.com/gen2brain/raylib-go/raylib"
)
type powerup struct {
active bool
duration int64
set int64
t string
x, y int32
invisible bool
damage int
}
var (
powerups []*powerup
powerUpsList = []string{clusterBomb, minigun, missle}
timeLookUp = map[string]int64{
missle: missleTime,
minigun: minigunTime,
}
)
func updatePowerUpPos() {
for _, v := range powerups {
v.y += enemyMoveSpeed
}
}
func drawPowerUps() {
for _, v := range powerups {
txt := missleTexture2D
switch v.t {
case clusterBomb:
txt = clusterBombTexture2D
break
case minigun:
txt = minigunTexture2D
break
}
rl.DrawTexture(txt, v.x, v.y, rl.White)
//rl.DrawRectangle(v.x, v.y, powerUpRes, powerUpRes, rl.Red)
}
}
func spawnPowerUp() {
if rand.Intn(200) != 1 {
return
}
p := powerUpsList[rand.Intn(len(powerUpsList))]
damage := 0
switch p {
case missle:
damage = missleDamage
break
}
x := rand.Int31n(windowWidth-10-powerUpRes) + 10
y := rand.Int31n(enemyYConst)
powerups = append(powerups, &powerup{
t: p,
x: x,
y: y,
duration: timeLookUp[p],
damage: damage,
})
}