twitchapon-anim

Basic Twitchapon Receiver/Visuals
git clone git://bsandro.tech/twitchapon-anim
Log | Files | Refs | README | LICENSE

commit 9859f5cb0354d76d58ce8d9931dbc1111fb01238
parent e12d9bd75d6224c80d221f27f7ae7c6b65bb8a6f
Author: bsandro <brian.drosan@gmail.com>
Date:   Sun, 15 Nov 2020 23:02:12 +0300

correct bouncing

Diffstat:
Mebitest.go | 23++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/ebitest.go b/ebitest.go @@ -15,7 +15,7 @@ import ( ) const S_FRAMERATE = 60 -const S_SPEED = 100.0 +const S_SPEED = 200.0 var ScreenSize struct { width, height int @@ -69,23 +69,22 @@ func (sprite *Sprite) Update() error { dx := delta * math.Cos(sprite.angle) dy := delta * math.Sin(sprite.angle) - fmt.Printf("dx=%0.2f dy=%0.2f angle=%0.2f\n", dx, dy, sprite.angle) - x := sprite.x + dx y := sprite.y + dy - fmt.Printf("x=%0.2f y=%0.2f, +size: x=%0.2f y=%0.2f\n", x, y, x+w, y+h) - scrW, scrH := float64(ScreenSize.width), float64(ScreenSize.height) + bounce := false // bouncing off walls - if x+w >= scrW || x <= 0 || y+h >= scrH || y <= 0 { - fmt.Println("bounce") - //sprite.angle = math.Pi*2 + math.Mod(math.Pi-sprite.angle, math.Pi / 2.0) - sprite.angle = math.Pi * 0.75 + sprite.angle - - sprite.angle = math.Mod(sprite.angle, math.Pi*2.0) + if x+w >= scrW || x <= 0 { + sprite.angle = math.Pi*3 - sprite.angle + bounce = true + } else if y+h >= scrH || y <= 0 { + sprite.angle = math.Pi*2 - sprite.angle + bounce = true + } + if (bounce) { dx = delta * math.Cos(sprite.angle) dy = delta * math.Sin(sprite.angle) x = sprite.x + dx @@ -110,7 +109,6 @@ func (g *Game) Draw(screen *ebiten.Image) { defer g.ShowDebug(screen) for _, sprite := range g.sprites { - //fmt.Printf("%d - %d:%d\n", ind, sprite.x, sprite.y) sprite.opt.GeoM.Reset() sprite.opt.GeoM.Translate(float64(sprite.x), float64(sprite.y)) screen.DrawImage(sprite.img, &sprite.opt) @@ -118,7 +116,6 @@ func (g *Game) Draw(screen *ebiten.Image) { } func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) { - //fmt.Printf("layout %d:%d\n", outsideWidth, outsideHeight) return ScreenSize.width, ScreenSize.height }