No scrolling

This commit is contained in:
2024-01-08 06:19:39 +01:00
parent 156e3ed43c
commit a838fcec48
4 changed files with 39 additions and 24 deletions

View File

@@ -10,6 +10,7 @@ import (
"image"
"image/color"
"log"
"slices"
"time"
)
@@ -131,13 +132,9 @@ func (h *Hero) DrawHero(screen *ebiten.Image) {
p := movementPositions[h.direction][h.step%8]
op := &ebiten.DrawImageOptions{}
screenWidth := screen.Bounds().Max.X
screenHeight := screen.Bounds().Max.Y
// ground
op.GeoM.Reset()
h.X = float64(screenWidth/2 - 16)
h.Y = float64(screenHeight/2 - 16)
op.GeoM.Translate(h.X, h.Y)
//op.GeoM.Translate(float64(i*tileSize-floorMod(g.cameraX, tileSize)),
// float64((ny-1)*tileSize-floorMod(g.cameraY, tileSize)))
@@ -193,6 +190,8 @@ func NewHero() *Hero {
Health: 100,
gunLoaded: true,
}
hero.X = float64(10)
hero.Y = float64(10)
go func() {
for {
@@ -284,3 +283,18 @@ func (h *Hero) Fire(offsetX float64, offsetY float64) (bullet *weapons.Handgun)
return nil
}
}
func (h *Hero) Move() {
if slices.Contains([]configuration.Direction{configuration.North, configuration.NorthEast, configuration.NorthWest}, h.direction) {
h.Y -= 3
}
if slices.Contains([]configuration.Direction{configuration.South, configuration.SouthEast, configuration.SouthWest}, h.direction) {
h.Y += 3
}
if slices.Contains([]configuration.Direction{configuration.East, configuration.NorthEast, configuration.SouthEast}, h.direction) {
h.X += 3
}
if slices.Contains([]configuration.Direction{configuration.West, configuration.NorthWest, configuration.SouthWest}, h.direction) {
h.X -= 3
}
}