gg/cmd/test/rect.go

54 lines
1,010 B
Go
Raw Normal View History

2023-12-23 00:09:07 +03:00
package main
2024-05-19 21:11:58 +03:00
import "surdeus.su/core/gg"
2024-06-01 16:07:28 +03:00
import "surdeus.su/core/gg/ox"
import "surdeus.su/core/gg/mx"
2023-12-23 00:09:07 +03:00
type Rect struct {
2024-06-01 16:07:28 +03:00
ox.DrawableRectangle
2023-12-23 00:09:07 +03:00
}
func NewRect() *Rect {
ret := &Rect{}
2024-06-01 16:07:28 +03:00
ret.SetScale(mx.V(5, 5))
ret.Color = gg.RGBA(1, 0, 0, 1)
ret.Layer = LayerRect
ret.Visible = true
//ret.Collidable = true
ret.Width = 100
ret.Height = 200
2023-12-23 00:09:07 +03:00
return ret
}
2024-06-01 16:07:28 +03:00
func (r *Rect) OnUpdate(c Context) {
2023-12-23 00:09:07 +03:00
//r.R += 0.3 * e.DT()
2024-06-01 16:07:28 +03:00
e := c.Engine()
dt := e.DT().Seconds()
shiftPressed := e.IsPressed(gg.KeyShift)
d := float64(1)
if shiftPressed {
d *= -1
}
2023-12-23 00:09:07 +03:00
//r.Position = c.AbsCursorPosition()
2024-06-01 16:07:28 +03:00
for _, v := range e.GetKeyboardKeys() {
2024-05-19 21:11:58 +03:00
switch v {
case gg.KeyArrowUp:
2024-06-01 16:07:28 +03:00
r.Move(mx.VY(-10 * dt))
2024-05-19 21:11:58 +03:00
case gg.KeyArrowDown:
2024-06-01 16:07:28 +03:00
r.Move(mx.VY(10 * dt))
2024-05-19 21:11:58 +03:00
case gg.KeyArrowLeft:
2024-06-01 16:07:28 +03:00
r.Move(mx.VX(-10 * dt))
2024-05-19 21:11:58 +03:00
case gg.KeyArrowRight:
2024-06-01 16:07:28 +03:00
r.Move(mx.VX(10 * dt))
case gg.KeyLeftBracket:
r.Rotate(d*mx.Pi * 0.3 * dt)
2024-05-19 21:11:58 +03:00
}
}
2023-12-23 00:09:07 +03:00
}
2024-06-01 16:07:28 +03:00
/*func (r *Rect) CollisionType() gg.CollisionType {
return gg.CollisionStaticPhysics
}*/