mirror of
https://github.com/stevenhowes/GoRetro.git
synced 2026-05-26 15:53:31 +01:00
Merge the two screen bounders to use callbacks
This commit is contained in:
@@ -4,16 +4,19 @@ package GoRetro
|
||||
* --------------------
|
||||
* BounderScreen
|
||||
* --------------------
|
||||
* A bounder which sets active = false on anything which
|
||||
* has left the screen
|
||||
* A bounder which triggers if the element isn't on the screen
|
||||
*/
|
||||
|
||||
type bounderScreen struct {
|
||||
container *Element
|
||||
callbackFunc func(element *Element)
|
||||
}
|
||||
|
||||
func NewBounderScreen(container *Element) *bounderScreen {
|
||||
return &bounderScreen{container: container}
|
||||
func NewBounderScreen(container *Element, callback func(element *Element)) *bounderScreen {
|
||||
return &bounderScreen{
|
||||
container: container,
|
||||
callbackFunc: callback,
|
||||
}
|
||||
}
|
||||
|
||||
func (bounder *bounderScreen) onDraw() error {
|
||||
@@ -23,12 +26,9 @@ func (bounder *bounderScreen) onDraw() error {
|
||||
func (bounder *bounderScreen) onUpdate() error {
|
||||
b := bounder.container
|
||||
|
||||
// If the position is outside the screen bounds then set it as inactive
|
||||
// and mark for deletion
|
||||
if b.Position.X > float64(Config.ScreenWidth) || b.Position.X < 0 ||
|
||||
b.Position.Y > float64(Config.ScreenHeight) || b.Position.Y < 0 {
|
||||
b.Active = false
|
||||
b.Delete = true
|
||||
bounder.callbackFunc(bounder.container)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package GoRetro
|
||||
|
||||
/*
|
||||
* --------------------
|
||||
* BounderScreen
|
||||
* --------------------
|
||||
* A bounder which resets the position to the opposite of
|
||||
* whichever bound was hit
|
||||
*/
|
||||
|
||||
type bounderScreenResetting struct {
|
||||
container *Element
|
||||
}
|
||||
|
||||
func NewBounderScreenResetting(container *Element) *bounderScreenResetting {
|
||||
return &bounderScreenResetting{container: container}
|
||||
}
|
||||
|
||||
func (bounder *bounderScreenResetting) onDraw() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bounder *bounderScreenResetting) onUpdate() error {
|
||||
b := bounder.container
|
||||
|
||||
// If any position exceeds the screen dimensions, wrap it to the
|
||||
// opposite side
|
||||
if b.Position.X > float64(Config.ScreenWidth) {
|
||||
b.Position.X = 0
|
||||
}
|
||||
if b.Position.X < 0 {
|
||||
b.Position.X = float64(Config.ScreenWidth)
|
||||
}
|
||||
if b.Position.Y > float64(Config.ScreenHeight) {
|
||||
b.Position.Y = 0
|
||||
}
|
||||
if b.Position.Y < 0 {
|
||||
b.Position.Y = float64(Config.ScreenWidth)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bounder *bounderScreenResetting) onCollision(other *Element) error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user