ichigo/main.go

93 lines
2.5 KiB
Go
Raw Normal View History

2021-07-23 13:12:54 +10:00
package main
import (
2021-07-25 14:15:39 +10:00
"embed"
"image"
_ "image/png"
2021-07-23 13:12:54 +10:00
"log"
"drjosh.dev/gurgle/engine"
"github.com/hajimehoshi/ebiten/v2"
)
const screenWidth, screenHeight = 320, 240
2021-07-26 21:19:12 +10:00
//go:embed assets
2021-07-25 14:15:39 +10:00
var assets embed.FS
2021-07-23 13:12:54 +10:00
func main() {
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
2021-07-25 14:15:39 +10:00
ebiten.SetWindowTitle("TODO")
2021-07-29 14:19:47 +10:00
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)
}
boxesFile.Close()
2021-07-25 15:03:10 +10:00
2021-07-29 15:11:56 +10:00
staticTiles := [][]engine.StaticTile{
2021-07-29 15:09:00 +10:00
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 1},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{2, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 3},
}
tiles := make([][]engine.Tile, len(staticTiles))
for j := range staticTiles {
tiles[j] = make([]engine.Tile, len(staticTiles[j]))
for i := range staticTiles[j] {
2021-07-29 15:11:56 +10:00
tiles[j][i] = staticTiles[j][i]
2021-07-29 15:09:00 +10:00
}
}
2021-07-29 15:29:26 +10:00
tiles[3][5] = &engine.AnimatedTile{
AnimDef: []engine.TileAnimFrameDef{
{Tile: 0, DurationTicks: 15},
{Tile: 1, DurationTicks: 15},
{Tile: 2, DurationTicks: 15},
{Tile: 3, DurationTicks: 15},
{Tile: 4, DurationTicks: 15},
{Tile: 5, DurationTicks: 15},
{Tile: 6, DurationTicks: 15},
{Tile: 7, DurationTicks: 15},
{Tile: 8, DurationTicks: 15},
{Tile: 9, DurationTicks: 15},
},
}
2021-07-29 15:09:00 +10:00
tilemap := &engine.Tilemap{
Map: tiles,
2021-07-25 14:15:39 +10:00
Src: ebiten.NewImageFromImage(boxesPNG),
TileSize: 16,
}
2021-07-25 15:03:10 +10:00
game := &engine.Game{
2021-07-23 13:12:54 +10:00
ScreenHeight: screenHeight,
ScreenWidth: screenWidth,
Components: []interface{}{
2021-07-29 15:09:00 +10:00
tilemap,
2021-07-25 15:03:10 +10:00
engine.PerfDisplay{},
2021-07-23 13:12:54 +10:00
},
2021-07-25 15:03:10 +10:00
}
game.SetNeedsSort()
if err := ebiten.RunGame(game); err != nil {
2021-07-23 14:59:49 +10:00
log.Fatalf("Game error: %v", err)
2021-07-23 13:12:54 +10:00
}
}