Implement tilemap

This commit is contained in:
Josh Deprez 2021-07-25 14:15:39 +10:00 committed by Josh Deprez
parent 680b2d5269
commit 293b013db4
2 changed files with 39 additions and 1 deletions

BIN
assets/boxes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

40
main.go
View file

@ -1,6 +1,9 @@
package main
import (
"embed"
"image"
_ "image/png"
"log"
"drjosh.dev/gurgle/engine"
@ -9,13 +12,48 @@ import (
const screenWidth, screenHeight = 320, 240
//go:embed assets/*
var assets embed.FS
func main() {
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("ebiten")
ebiten.SetWindowTitle("TODO")
boxesFile, err := assets.Open("assets/boxes.png")
if err != nil {
log.Fatalf("Couldn't open asset: %v", err)
}
boxesPNG, _, err := image.Decode(boxesFile)
if err != nil {
log.Fatalf("Couldn't decode asset: %v", err)
}
tiles := &engine.Tilemap{
Map: [][]int{
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
},
Src: ebiten.NewImageFromImage(boxesPNG),
TileSize: 16,
}
if err := ebiten.RunGame(&engine.Game{
ScreenHeight: screenHeight,
ScreenWidth: screenWidth,
Components: []interface{}{
tiles,
engine.TPSDisplay{},
},
}); err != nil {