diff options
| -rw-r--r-- | input/input.go | 4 | ||||
| -rw-r--r-- | objs/cursor.go | 14 | ||||
| -rw-r--r-- | objs/root.go | 4 | ||||
| -rw-r--r-- | render/render.go | 4 |
4 files changed, 19 insertions, 7 deletions
diff --git a/input/input.go b/input/input.go index 94f4e56..48eeb02 100644 --- a/input/input.go +++ b/input/input.go @@ -19,8 +19,8 @@ func ProcessTree(root any, ev Event) { if inp, ok := root.(Handler); ok { inp.Process(ev) } - if g, ok := root.(*ecs.GameObject); ok { - for _, c := range g.Children { + if g, ok := root.(ecs.IsGameObject); ok { + for _, c := range g.GO().Children { if c == nil { continue } diff --git a/objs/cursor.go b/objs/cursor.go index b1fdca3..dd09a8b 100644 --- a/objs/cursor.go +++ b/objs/cursor.go @@ -12,12 +12,24 @@ type Cursor struct { func (c *Cursor) Render(renderer *sdl.Renderer) { renderer.SetDrawColor(255, 0, 0, 255) - renderer.RenderPoint(c.Position.X, c.Position.Y) + r := &sdl.FRect{ + X: c.Position.X - 5, + Y: c.Position.Y - 5, + W: 10, + H: 10, + } + renderer.RenderRect(r) } func (c *Cursor) Process(ev input.Event) { c.Position.X += ev.Dx c.Position.Y += ev.Dy + if c.Position.X < 0 { + c.Position.X = 0 + } + if c.Position.Y < 0 { + c.Position.Y = 0 + } } func (c *Cursor) GO() *ecs.GameObject { diff --git a/objs/root.go b/objs/root.go index 59e0c6a..649200d 100644 --- a/objs/root.go +++ b/objs/root.go @@ -10,7 +10,7 @@ type Root struct { } func (root *Root) Render(r *sdl.Renderer) { - r.SetDrawColor(255, 255, 255, 255) + r.SetDrawColor(0, 0, 0, 255) r.Clear() } @@ -21,5 +21,5 @@ func NewRoot(children ...ecs.IsGameObject) ecs.IsGameObject { Children: children, }, } - return r.GameObject + return r } diff --git a/render/render.go b/render/render.go index 83fc2d0..0f0beaf 100644 --- a/render/render.go +++ b/render/render.go @@ -13,8 +13,8 @@ func Render(root any, renderer *sdl.Renderer) { if r, ok := root.(Renders); ok { r.Render(renderer) } - if g, ok := root.(*ecs.GameObject); ok { - for _, c := range g.Children { + if g, ok := root.(ecs.IsGameObject); ok { + for _, c := range g.GO().Children { if c == nil { continue } |
