🎉 Initial Commit of Basic things like movement of player
This commit is contained in:
5
pkg/internal/common/vector2d.go
Normal file
5
pkg/internal/common/vector2d.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package common
|
||||
|
||||
type Vector2D struct {
|
||||
X, Y float64
|
||||
}
|
38
pkg/internal/entities/player.go
Normal file
38
pkg/internal/entities/player.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"git.solsynth.dev/highland/codingland/pkg/internal/common"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
)
|
||||
|
||||
const (
|
||||
Acceleration = 0.5
|
||||
Friction = 0.9
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
Position common.Vector2D
|
||||
Size common.Vector2D
|
||||
Velocity common.Vector2D
|
||||
}
|
||||
|
||||
func (p *Player) Move(deltaX, deltaY float64) {
|
||||
p.Velocity.X += deltaX * Acceleration
|
||||
p.Velocity.Y += deltaY * Acceleration
|
||||
|
||||
p.Position.X += p.Velocity.X
|
||||
p.Position.Y += p.Velocity.Y
|
||||
|
||||
p.Velocity.X *= Friction
|
||||
p.Velocity.Y *= Friction
|
||||
}
|
||||
|
||||
func (p *Player) Draw(pen *sdl.Renderer) {
|
||||
pen.SetDrawColor(255, 255, 255, 255)
|
||||
pen.FillRect(&sdl.Rect{
|
||||
X: int32(p.Position.X),
|
||||
Y: int32(p.Position.Y),
|
||||
W: int32(p.Size.X),
|
||||
H: int32(p.Size.Y),
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user