CodingLand/pkg/internal/land/object.go

36 lines
560 B
Go
Raw Normal View History

2024-07-18 05:59:06 +00:00
package land
import "github.com/veandco/go-sdl2/sdl"
type Object interface {
Create()
Update()
2024-07-18 09:46:36 +00:00
AddChild(child Object)
GetChildren() []Object
2024-07-18 05:59:06 +00:00
}
type DrawableObject interface {
2024-07-18 09:21:25 +00:00
Draw(pen *sdl.Renderer)
2024-07-18 05:59:06 +00:00
}
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)
}
2024-07-18 09:46:36 +00:00
func (p *BaseObject) GetChildren() []Object {
return p.Children
}