Object-based land engine

This commit is contained in:
2024-07-18 13:59:06 +08:00
parent 4b7358a1d0
commit cd01069c89
7 changed files with 87 additions and 26 deletions

View File

@@ -0,0 +1,29 @@
package land
import "github.com/veandco/go-sdl2/sdl"
type Object interface {
Create()
Update()
}
type DrawableObject interface {
Draw(*sdl.Renderer)
}
type BaseObject struct {
Children []Object
}
func (p *BaseObject) Create() {}
func (p *BaseObject) Update() {
// Update each child
for _, child := range p.Children {
child.Update()
}
}
func (p *BaseObject) AddChild(child Object) {
p.Children = append(p.Children, child)
}

17
pkg/internal/land/root.go Normal file
View File

@@ -0,0 +1,17 @@
package land
import (
"github.com/veandco/go-sdl2/sdl"
)
type RootObject struct {
BaseObject
}
func (p *RootObject) Draw(pen *sdl.Renderer) {
for _, child := range p.Children {
if drawableChild, ok := child.(DrawableObject); ok {
drawableChild.Draw(pen)
}
}
}

View File

@@ -0,0 +1,5 @@
package land
type Vector2D struct {
X, Y float64
}