CodingLand/pkg/internal/tiles/tile.go
2024-07-18 17:46:36 +08:00

46 lines
844 B
Go

package tiles
import (
"git.solsynth.dev/highland/codingland/pkg/internal/land"
"github.com/veandco/go-sdl2/sdl"
"log"
)
type Tile struct {
land.BaseObject
Position land.Vector2D
Size land.Vector2D
}
func (p *Tile) Draw(pen *sdl.Renderer) {
pen.SetDrawColor(255, 255, 255, 255)
pen.FillRect(&sdl.Rect{
X: int32(p.Position.X),
Y: int32(p.Position.Y),
W: int32(p.Size.X),
H: int32(p.Size.Y),
})
for _, child := range p.Children {
if drawableChild, ok := child.(land.DrawableObject); ok {
drawableChild.Draw(pen)
}
}
}
func (p *Tile) GetPosition() land.Vector2D {
return p.Position
}
func (p *Tile) GetSize() land.Vector2D {
return p.Size
}
func (p *Tile) OnCollide(other land.CollidableObject) {
}
func (p *Tile) OnClick(mousePos land.Vector2D) {
log.Printf("user clicked tile: %s", mousePos.String())
}