✨ Object-based land engine
This commit is contained in:
29
pkg/internal/land/object.go
Normal file
29
pkg/internal/land/object.go
Normal 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
17
pkg/internal/land/root.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
5
pkg/internal/land/vector2d.go
Normal file
5
pkg/internal/land/vector2d.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package land
|
||||
|
||||
type Vector2D struct {
|
||||
X, Y float64
|
||||
}
|
Reference in New Issue
Block a user