all the tiles collide

This commit is contained in:
Josh Deprez 2021-08-03 20:06:17 +10:00 committed by Josh Deprez
parent 152fc7d528
commit 4ea31970e5
2 changed files with 55 additions and 40 deletions

View file

@ -79,8 +79,12 @@ func (a *Actor) Update() error {
default: default:
a.vx = 0 a.vx = 0
} }
a.MoveX(a.vx, nil) a.MoveX(a.vx, func() {
a.MoveY(a.vy, nil) a.vx = 0
})
a.MoveY(a.vy, func() {
a.vy = 0
})
return nil return nil
} }

47
main.go
View file

@ -2,6 +2,7 @@ package main
import ( import (
"embed" "embed"
"fmt"
"image" "image"
_ "image/png" _ "image/png"
"log" "log"
@ -56,16 +57,7 @@ func main() {
{engine.StaticTile(9), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(9)}, {engine.StaticTile(9), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(9)},
} }
game := &engine.Game{ level1 := &engine.Scene{
ScreenHeight: screenHeight,
ScreenWidth: screenWidth,
Scene: &engine.Scene{
ID: "root",
Components: []interface{}{
&engine.GobDumper{
KeyCombo: []ebiten.Key{ebiten.KeyControl, ebiten.KeyD},
},
&engine.Scene{
ID: "level_1", ID: "level_1",
Components: []interface{}{ Components: []interface{}{
&engine.Tilemap{ &engine.Tilemap{
@ -77,24 +69,20 @@ func main() {
}, },
&engine.SolidRect{ &engine.SolidRect{
ID: "ceiling", ID: "ceiling",
Rect: image.Rect(0, -2, 320, -1), Rect: image.Rect(0, -1, 320, 0),
}, },
&engine.SolidRect{ &engine.SolidRect{
ID: "left_wall", ID: "left_wall",
Rect: image.Rect(-2, 0, -1, 240), Rect: image.Rect(-1, 0, 0, 240),
}, },
&engine.SolidRect{ &engine.SolidRect{
ID: "right_wall", ID: "right_wall",
Rect: image.Rect(320, 0, 321, 240), Rect: image.Rect(320, 0, 321, 240),
}, },
&engine.SolidRect{ /*&engine.SolidRect{
ID: "ground", ID: "ground",
Rect: image.Rect(0, 192, 320, 240), Rect: image.Rect(0, 192, 320, 240),
}, },*/
&engine.SolidRect{
ID: "a_red_tile",
Rect: image.Rect(16, 144, 31, 159),
},
&engine.Actor{ &engine.Actor{
ID: "protagonist", ID: "protagonist",
Position: image.Pt(100, 100), Position: image.Pt(100, 100),
@ -102,7 +90,30 @@ func main() {
ZPos: 1, ZPos: 1,
}, },
}, },
}
// TODO: something better...
for j, row := range tiles {
for i, tile := range row {
if tile != nil {
level1.Components = append(level1.Components, &engine.SolidRect{
ID: engine.ID(fmt.Sprintf("tile_%d_%d", j, i)),
Rect: image.Rect(i*16, j*16, (i+1)*16, (j+1)*16),
})
}
}
}
game := &engine.Game{
ScreenHeight: screenHeight,
ScreenWidth: screenWidth,
Scene: &engine.Scene{
ID: "root",
Components: []interface{}{
&engine.GobDumper{
KeyCombo: []ebiten.Key{ebiten.KeyControl, ebiten.KeyD},
}, },
level1,
engine.PerfDisplay{}, engine.PerfDisplay{},
}, },
}, },