This commit is contained in:
Andrey Parhomenko 2023-02-18 09:46:33 +05:00
parent 95a7b27ff8
commit f35332a822
5 changed files with 29 additions and 4 deletions

View file

@ -34,7 +34,9 @@ func (p *Player) Update(e *gx.Engine) {
//p.Sprite.Object.T.P.Y += 40 * e.DT()
dt := e.DT()
c := e.Camera()
c.Object.T.P.X += 40 * dt
//c.Object.T.P.X += 40 * dt
//c.Object.T.S.X += .01 * dt
c.Object.T.R += .2 * dt
}
func main() {

5
src/gix/main.go Normal file
View file

@ -0,0 +1,5 @@
package gix
import (
"github.com/hajimehoshi/ebiten/v2/inpututil"
)

View file

@ -14,8 +14,8 @@ func (c *Camera)Matrix(scale bool) Matrix {
g := &Matrix{}
g.Translate(
c.Object.T.RA.X,
c.Object.T.RA.Y,
-c.Object.T.RA.X,
-c.Object.T.RA.Y,
)
g.Rotate(c.Object.T.R)

8
src/gx/keys.go Normal file
View file

@ -0,0 +1,8 @@
package gx
import (
"github.com/hajimehoshi/ebiten/v2"
)
type Key = ebiten.Key

View file

@ -2,6 +2,7 @@ package gx
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/surdeus/godat/src/sparsex"
//"fmt"
"time"
@ -23,6 +24,7 @@ type Engine struct {
lastTime time.Time
dt Float
camera *Camera
keys []Key
}
type engine Engine
@ -31,6 +33,10 @@ func (e *Engine) Camera() *Camera {
return e.camera
}
func (e *Engine) Keys() []Key {
return e.keys
}
func New(
cfg *WindowConfig,
) *Engine {
@ -43,7 +49,8 @@ func New(
camera: &Camera{
Object: &Object{
T: Transform{
S: Vector{0.1, 1},
S: Vector{1, 1},
RA: Vector{480, 320},
},
},
},
@ -85,6 +92,9 @@ func (e *Engine) AddBehaver(b Behaver) {
func (e *engine) Update() error {
eng := (*Engine)(e)
e.keys = inpututil.
AppendPressedKeys(e.keys[:0])
e.dt = time.Since(e.lastTime).Seconds()
for _, v := range eng.behavers {
v.Update(eng)