diff --git a/cmd/test/camera.go b/cmd/test/camera.go index d25f98e..a4c430e 100644 --- a/cmd/test/camera.go +++ b/cmd/test/camera.go @@ -59,9 +59,11 @@ func (cam *Camera) OnUpdate(c gg.Context) { for _, key := range c.Engine().GetKeyboardKeys() { switch key { case gg.KeyF: - cam.AddScale(mx.V2(d*cam.ScaleSpeed * dt)) + cam.AddScale(mx.VX(d*cam.ScaleSpeed * dt)) + case gg.KeyG: + cam.AddScale(mx.VY(d*cam.ScaleSpeed * dt)) case gg.KeyR: - cam.Rotate(d*mx.Pi * cam.ScaleSpeed * dt) + cam.Rotate(d*mx.Pi * cam.RotationSpeed * dt) } } } diff --git a/cmd/test/debug.go b/cmd/test/debug.go index aab4958..3b3c2f3 100644 --- a/cmd/test/debug.go +++ b/cmd/test/debug.go @@ -5,8 +5,8 @@ import "surdeus.su/core/gg/ox" import "surdeus.su/core/gg/mx" import ( - "strings" - "fmt" + //"strings" + //"fmt" ) type Debug struct { @@ -34,82 +34,40 @@ func (d *Debug) Draw(c Context) *gg.Drawing { e := c.Engine() relTri := tri.Rel() relPlayer := player.Rel() + keys := c.Engine().GetKeyboardKeys() - keyStrs := []string{} - keyStrs = append(keyStrs, fmt.Sprintf( - "counter: %d", counter, - )) - keyStrs = append(keyStrs, fmt.Sprintf( - "tps: %d", int(c.Engine().TPS()), - )) - keyStrs = append(keyStrs, fmt.Sprintf( - "fps: %d", int(c.Engine().FPS()), - )) - keyStrs = append(keyStrs, fmt.Sprintf( - "dframe: %d", int(c.Engine().Dframe()), - )) - keyStrs = append(keyStrs, fmt.Sprintf( - "frame: %d", int(c.Engine().Frame()), - )) - keyStrs = append(keyStrs, fmt.Sprintf( - "relPlayerPos: %v", relPlayer.GetPosition(), - )) - keyStrs = append(keyStrs, fmt.Sprintf( - "absPlayerPos: %v", player.GetPosition(), - )) + c.Dprint( + "counter = ", counter, "\n", + "tps = ", int(c.Engine().TPS()), "\n", + "fps = ", int(c.Engine().FPS()), "\n", + "dframe = ", int(c.Engine().Dframe()), "\n", + "frame = ", int(c.Engine().Frame()), "\n", + "relPlayerPos = ", relPlayer.GetPosition(), "\n", + "absPlayerPos = ", player.GetPosition(), "\n", + "relTriPos = ", relTri.GetPosition(), "\n", + "absTriPos = ", tri.GetPosition(), "\n", + "absTriRot = " , mx.Degree(tri.GetRotation()), "\n", + "keys = ", keys, "\n", - keyStrs = append(keyStrs, fmt.Sprintf( - "relTriPos: %v", relTri.GetPosition(), - )) - keyStrs = append(keyStrs, fmt.Sprintf( - "absTriPos: %v", tri.GetPosition(), - )) - keyStrs = append(keyStrs, fmt.Sprintf( - "absTriRot: %v", mx.Degree(tri.GetRotation()), - )) + "GetMouseButtons(...) = ", + c.Engine().GetMouseButtons(), "\n", - keys := []string{} - for _, k := range e.GetKeyboardKeys() { - keys = append(keys, k.String()) - } - keyStrs = append(keyStrs, fmt.Sprintf( - "keys: %s", strings.Join(keys, ", "), - )) + "GetMouseWheel(...) = ", "\n", + c.Engine().GetMouseWheel(), "\n", - keyStrs = append(keyStrs, fmt.Sprintf( - "buttons: %v", c.Engine().MouseButtons(), - )) - keyStrs = append(keyStrs, fmt.Sprintf( - "wheel: %v", c.Engine().Wheel(), - )) - /*if rectMove.ContainsPoint(e.AbsCursorPosition()) { - keyStrs = append(keyStrs, "contains cursor") - } - - if rectMove.Vertices().Contained(rect).Len() > 0 || - rect.Vertices().Contained(rectMove).Len() > 0 { - keyStrs = append(keyStrs, "rectangles intersect") - }*/ - - keyStrs = append(keyStrs, fmt.Sprintf( - "camera position: %v %v", + "camera.GetPosition(...) = ", camera.GetPosition().X, - camera.GetPosition().Y, - )) - keyStrs = append(keyStrs, fmt.Sprintf( - "realCursorPos: %v", e.GetRealCursorPosition())) - keyStrs = append(keyStrs, fmt.Sprintf( - "absCursorPos: %v", e.GetAbsCursorPosition() )) + camera.GetPosition().Y, "\n", - keyStrs = append(keyStrs, - fmt.Sprintf( - "absWinSize: %v", - c.Engine().GetAbsWinSize(), - ), + "GetRealCursorPosition(...) = ", + e.GetRealCursorPosition(), "\n", + + "GetAbsCursorPos(...) = ", + e.GetAbsCursorPosition(), "\n", + + "GetAbsWinSize(...) = ", + c.Engine().GetAbsWinSize(), "\n", ) - e.DebugPrint(c.Image(), - strings.Join(keyStrs, "\n")) - return nil } diff --git a/context.go b/context.go index 51dfd2c..00ef58a 100644 --- a/context.go +++ b/context.go @@ -1,5 +1,7 @@ package gg +import "fmt" + // The type is used to provide // custom behaviour for drawing and updating etc. type Context struct { @@ -33,3 +35,15 @@ func (c Context) Events() Events { return c.events } +func (c Context) Dprint(v ...any) { + c.Engine().DebugPrint(c.Image(), fmt.Sprint(v...)) +} + +func (c Context) Dprintln(v ...any) { + c.Engine().DebugPrint(c.Image(), fmt.Sprintln(v...)) +} + +func (c Context) Dprintf(format string, v ...any) { + c.Engine().DebugPrint(c.Image(), fmt.Sprintf(format, v...)) +} + diff --git a/engine.go b/engine.go index 6d74f07..55cd04e 100644 --- a/engine.go +++ b/engine.go @@ -94,7 +94,7 @@ func (e *Engine) GraphicsLibrary() GraphicsLibrary { } // Returns currently pressed buttons. -func (e *Engine) MouseButtons() []MouseButton { +func (e *Engine) GetMouseButtons() []MouseButton { ret := make([]MouseButton, len(e.buttons)) i := 0 for v := range e.buttons { @@ -185,7 +185,7 @@ func (e *Engine) IsButtoned(b MouseButton) bool { return ok } -func (e *Engine) Wheel() mx.Vector { +func (e *Engine) GetMouseWheel() mx.Vector { return e.wheel }