Managed to incorporate a frame based position offset which is cyclic for moving objects, called in function RepositionTest()

This commit is contained in:
dbenavid
2023-09-05 07:54:59 -04:00
parent 8341fa9933
commit 6cd2b8186c

View File

@@ -10,6 +10,7 @@ import (
"math/rand" "math/rand"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/vector" "github.com/hajimehoshi/ebiten/v2/vector"
_ "embed" _ "embed"
@@ -104,6 +105,17 @@ func NewParallax() Parallax {
func (p *Parallax) Update() error { func (p *Parallax) Update() error {
p.increment++ p.increment++
var keysPressed []ebiten.Key
keysPressed = inpututil.AppendJustPressedKeys(keysPressed[:0])
//check for user input to transition scene
if inpututil.IsKeyJustPressed(ebiten.KeyQ) {
if p.events[groovy.COMPLETED] != nil {
p.events[groovy.COMPLETED]()
}
}
return nil return nil
} }
@@ -251,4 +263,27 @@ func (p *Parallax) RepositionTest(screen *ebiten.Image) {
vs[i].ColorA = 1 vs[i].ColorA = 1
} }
screen.DrawTriangles(vs, is, whiteSubImage, nil) screen.DrawTriangles(vs, is, whiteSubImage, nil)
//minX := x0 - xd
maxX := x0 + xd
//minY := y0 - yd
//maxY := y0 + yd
//178x229
roX := float64(178 / 4)
roY := float64(229 / 4)
startX := float64(maxX) + roX
startY := float64(y0) + roY/2
adjustment := 400.0
currentX := startX - float64(p.increment) + adjustment*math.Floor(float64(p.increment)/adjustment)
op := &ebiten.DrawImageOptions{}
op.GeoM.Scale(.5, .5)
op.GeoM.Translate(-roX, -roY)
op.GeoM.Rotate(-float64(p.increment) / (math.Pi * 12.0))
op.GeoM.Translate(currentX, startY)
screen.DrawImage(roids[1], op)
} }