From 5b30626244ceeccbdc5f24435b8e61668fc29536 Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Fri, 16 Jul 2021 15:41:46 +1000 Subject: [PATCH] ecs baby --- game.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/game.go b/game.go index 478248e..8eda72c 100644 --- a/game.go +++ b/game.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "image/color" "log" "github.com/hajimehoshi/ebiten/v2" @@ -11,15 +10,35 @@ import ( const screenWidth, screenHeight = 320, 240 -type game struct{} +type updater interface { + Update() error +} + +type drawer interface { + Draw(*ebiten.Image) +} + +type game struct { + components []interface{} +} func (g *game) Update() error { - // TODO + for _, c := range g.components { + if u, ok := c.(updater); ok { + if err := u.Update(); err != nil { + return err + } + } + } return nil } func (g *game) Draw(screen *ebiten.Image) { - screen.Fill(color.RGBA{50, 50, 50, 255}) + for _, c := range g.components { + if d, ok := c.(drawer); ok { + d.Draw(screen) + } + } ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f", ebiten.CurrentTPS())) }