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:
a.vx = 0
}
a.MoveX(a.vx, nil)
a.MoveY(a.vy, nil)
a.MoveX(a.vx, func() {
a.vx = 0
})
a.MoveY(a.vy, func() {
a.vy = 0
})
return nil
}

47
main.go
View file

@ -2,6 +2,7 @@ package main
import (
"embed"
"fmt"
"image"
_ "image/png"
"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)},
}
game := &engine.Game{
ScreenHeight: screenHeight,
ScreenWidth: screenWidth,
Scene: &engine.Scene{
ID: "root",
Components: []interface{}{
&engine.GobDumper{
KeyCombo: []ebiten.Key{ebiten.KeyControl, ebiten.KeyD},
},
&engine.Scene{
level1 := &engine.Scene{
ID: "level_1",
Components: []interface{}{
&engine.Tilemap{
@ -77,24 +69,20 @@ func main() {
},
&engine.SolidRect{
ID: "ceiling",
Rect: image.Rect(0, -2, 320, -1),
Rect: image.Rect(0, -1, 320, 0),
},
&engine.SolidRect{
ID: "left_wall",
Rect: image.Rect(-2, 0, -1, 240),
Rect: image.Rect(-1, 0, 0, 240),
},
&engine.SolidRect{
ID: "right_wall",
Rect: image.Rect(320, 0, 321, 240),
},
&engine.SolidRect{
/*&engine.SolidRect{
ID: "ground",
Rect: image.Rect(0, 192, 320, 240),
},
&engine.SolidRect{
ID: "a_red_tile",
Rect: image.Rect(16, 144, 31, 159),
},
},*/
&engine.Actor{
ID: "protagonist",
Position: image.Pt(100, 100),
@ -102,7 +90,30 @@ func main() {
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{},
},
},