package main import ( "embed" "fmt" "image" _ "image/png" "log" "drjosh.dev/gurgle/engine" "github.com/hajimehoshi/ebiten/v2" ) const screenWidth, screenHeight = 320, 240 //go:embed assets var assets embed.FS func main() { ebiten.SetWindowSize(screenWidth*2, screenHeight*2) ebiten.SetWindowTitle("TODO") engine.AssetFS = assets engine.AnimDefs = map[string]*engine.AnimDef{ "green_tiles": { Frames: []engine.AnimFrame{ {Frame: 0, Duration: 16}, {Frame: 1, Duration: 16}, {Frame: 2, Duration: 16}, }, }, "red_tiles": { Frames: []engine.AnimFrame{ {Frame: 3, Duration: 12}, {Frame: 4, Duration: 12}, {Frame: 5, Duration: 12}, {Frame: 6, Duration: 12}, }, }, } tiles := [][]engine.Tile{ {engine.StaticTile(9), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, engine.StaticTile(9)}, {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, &engine.AnimatedTile{AnimRef: engine.AnimRef{Key: "red_tiles"}}, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, &engine.AnimatedTile{AnimRef: engine.AnimRef{Key: "red_tiles"}}, nil, nil, nil}, {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {nil, nil, &engine.AnimatedTile{AnimRef: engine.AnimRef{Key: "green_tiles"}}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {nil, nil, nil, nil, nil, &engine.AnimatedTile{AnimRef: engine.AnimRef{Key: "red_tiles"}}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, &engine.AnimatedTile{AnimRef: engine.AnimRef{Key: "green_tiles"}}, nil, nil, nil, nil, nil, nil}, {nil, nil, nil, nil, &engine.AnimatedTile{AnimRef: engine.AnimRef{Key: "green_tiles"}}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, &engine.AnimatedTile{AnimRef: engine.AnimRef{Key: "green_tiles"}}, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {nil, &engine.AnimatedTile{AnimRef: engine.AnimRef{Key: "red_tiles"}}, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}, {engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), &engine.AnimatedTile{AnimRef: engine.AnimRef{Key: "red_tiles"}}, engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8), engine.StaticTile(8)}, {engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), &engine.AnimatedTile{AnimRef: engine.AnimRef{Key: "red_tiles"}}, 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.AnimatedTile{AnimRef: engine.AnimRef{Key: "green_tiles"}}, engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7), engine.StaticTile(7)}, {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)}, } level1 := &engine.Scene{ ID: "level_1", Components: []interface{}{ &engine.Tilemap{ ID: "terrain", Map: tiles, Src: engine.ImageRef{Path: "assets/boxes.png"}, TileSize: 16, ZPos: 0, }, &engine.SolidRect{ ID: "ceiling", Rect: image.Rect(0, -1, 320, 0), }, &engine.SolidRect{ ID: "left_wall", Rect: image.Rect(-1, 0, 0, 240), }, &engine.SolidRect{ ID: "right_wall", Rect: image.Rect(320, 0, 321, 240), }, /*&engine.SolidRect{ ID: "ground", Rect: image.Rect(0, 192, 320, 240), },*/ &engine.Actor{ ID: "protagonist", Position: image.Pt(100, 100), Size: image.Pt(16, 16), 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{}, }, }, } game.Build() if err := ebiten.RunGame(game); err != nil { log.Fatalf("Game error: %v", err) } }