blob: 38a46367c6ab1ba2a7b1a5d3aab9ff38ed497b93 (
plain)
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
|
package components
import (
coreobjects "github.com/DegustatorPonos/RuinesOfRafdolon/CoreObjects"
rl "github.com/gen2brain/raylib-go/raylib"
)
type Player struct {
Position rl.Vector2
Texture rl.Texture2D
}
func (base *Player) Create(_ coreobjects.SceneManager) {
}
func (base *Player) Destroy() {
}
func (base *Player) Update() {
var speed = 150 * rl.GetFrameTime()
if rl.IsKeyDown(rl.KeyW) {
base.Position.Y -= speed
}
if rl.IsKeyDown(rl.KeyS) {
base.Position.Y += speed
}
if rl.IsKeyDown(rl.KeyA) {
base.Position.X -= speed
}
if rl.IsKeyDown(rl.KeyD) {
base.Position.X += speed
}
}
func (base *Player) Draw() {
rl.DrawTexture(base.Texture,
int32(base.Position.X),
int32(base.Position.Y),
rl.White)
}
func (base Player) SnapCamera (camera *rl.Camera2D) {
var offset = rl.Vector2 {
X: float32(base.Texture.Width) / 2,
Y: float32(base.Texture.Height) / 2,
}
camera.Target = rl.Vector2Add(base.Position, offset)
camera.Offset.X = float32(rl.GetScreenWidth()) / 2
camera.Offset.Y = float32(rl.GetScreenHeight()) / 2
}
|