Moveable viewport. Absolute positioning (for UI etc) is possible. Added distance-based bounder for projectiles etc as 'screen' is no longer a suitable bounder. Removed debug msg.

This commit is contained in:
stevenhowes
2022-03-27 17:02:32 +01:00
parent bfa9ab0037
commit 428e2d175c
7 changed files with 88 additions and 24 deletions
+9 -2
View File
@@ -1,10 +1,13 @@
package GoRetro
import "fmt"
/*
* --------------------
* BounderScreen
* --------------------
* A bounder which triggers if the element isn't on the screen
* TODO: Use dimensions of the entity
*/
type bounderScreen struct {
@@ -13,6 +16,10 @@ type bounderScreen struct {
}
func NewBounderScreen(container *Element, callback func(element *Element)) *bounderScreen {
if !container.PositionAbsolute {
fmt.Println("Added screen bounder to non-absolute positioned element")
}
return &bounderScreen{
container: container,
callbackFunc: callback,
@@ -26,8 +33,8 @@ func (bounder *bounderScreen) onDraw() error {
func (bounder *bounderScreen) onUpdate() error {
b := bounder.container
if b.Position.X > float64(Config.ScreenWidth) || b.Position.X < 0 ||
b.Position.Y > float64(Config.ScreenHeight) || b.Position.Y < 0 {
if b.Position.X > float64(Config.WindowSize.X) || b.Position.X < 0 ||
b.Position.Y > float64(Config.WindowSize.Y) || b.Position.Y < 0 {
bounder.callbackFunc(bounder.container)
}