ecs baby
This commit is contained in:
parent
a1a276ddce
commit
5b30626244
1 changed files with 23 additions and 4 deletions
27
game.go
27
game.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
@ -11,15 +10,35 @@ import (
|
||||||
|
|
||||||
const screenWidth, screenHeight = 320, 240
|
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 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *game) Draw(screen *ebiten.Image) {
|
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()))
|
ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f", ebiten.CurrentTPS()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue