-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectile.go
49 lines (39 loc) · 939 Bytes
/
projectile.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
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
)
var (
defaultDamage float32 = 100
projSpeed float32 = 400
)
type Projectile struct {
damage float32
dir rl.Vector2
pos rl.Vector2
destroyed bool
}
func NewProj(initialPos rl.Vector2, direction rl.Vector2, damage float32) *Projectile {
dir := rl.Vector2Subtract(direction, initialPos)
dir = rl.Vector2Normalize(dir)
return &Projectile{
damage: damage,
pos: initialPos,
dir: dir,
}
}
func (p *Projectile) Destroyed() bool {
return p.destroyed
}
func (p *Projectile) Update(dt float64) {
dtspeed := dt * float64(projSpeed)
dir := rl.Vector2Scale(p.dir, float32(dtspeed))
p.pos = rl.Vector2Add(p.pos, dir)
// p.hitbox.X = p.pos.X
// p.hitbox.Y = p.pos.Y
}
func (p *Projectile) Render() {
rl.DrawCircle(int32(p.pos.X), int32(p.pos.Y), projSize, rl.Green)
}
func (p *Projectile) Position() rl.Vector2 {
return p.pos
}