48 lines
		
	
	
		
			917 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			917 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) OnEvent(event land.UserEventType, args ...any) {
 | 
						|
	if event == land.UserEventMouseDown {
 | 
						|
		log.Printf("user clicked tile: %s", args[0].(land.Vector2D).String())
 | 
						|
	}
 | 
						|
}
 |