feat: FUCKING DID IT.

This commit is contained in:
Andrey Parhomenko 2024-06-02 00:01:17 +05:00
parent cde993db48
commit 5cd9a65dfb
15 changed files with 78 additions and 42 deletions

View file

@ -4,21 +4,26 @@ import "surdeus.su/core/gg/ox"
import "surdeus.su/core/gg/mx"
import "surdeus.su/core/gg"
import "log"
var (
camera = &Camera{
Camera: ox.NewCamera(),
ScaleSpeed: 5.,
RotationSpeed: .3,
}
camera *Camera
)
type Camera struct {
ox.ObjectImpl
ox.Camera
ScaleSpeed mx.Float
RotationSpeed mx.Float
}
func NewCamera() *Camera {
camera := &Camera{}
camera.Camera = ox.NewCamera()
camera.ScaleSpeed = 5.
camera.RotationSpeed = .3
return camera
}
func (cam *Camera) OnUpdate(c gg.Context) {
dt := c.Engine().DT().Seconds()
mov := c.Events().Mouse.Move
@ -38,8 +43,15 @@ func (cam *Camera) OnUpdate(c gg.Context) {
// Scale.
if wheel != nil {
cam.AddScale(mx.V2(
wheel.Offset.Y * dt * cam.ScaleSpeed * 40,
k := 1.5
log.Println(wheel.Offset.Y)
if wheel.Offset.Y < 0 {
k = 1/k
}
cam.Scale(mx.V2(
k,
//wheel.Offset.Y * dt * cam.ScaleSpeed * 40,
))
}

View file

@ -24,6 +24,10 @@ func (d *Debug) OnUpdate(c Context) {
}
}
func (d *Debug) OnStart(c Context) {
d.Visible = true
}
func (d *Debug) GetLayer() gg.Layer {return LayerHighest}
func (d *Debug) Draw(c Context) *gg.Drawing {

View file

@ -78,6 +78,7 @@ func main() {
VSync: true,
Fullscreen: false,
})
camera = NewCamera()
e.SetCamera(camera)
e.Spawn(camera)
@ -89,13 +90,16 @@ func main() {
rect = NewRect()
playerAnimations, _ = ax.AnimationSetFromImage(
playerAnimations, err = ax.AnimationSetFromImage(
playerImg,
8, 3,
10, 1,
ax.AD(Stand).DefRow(0, 0, 1, 2, 3, 4),
ax.AD(Walk).DefRow(1, 0, 1, 2, 3, 4, 5, 6, 7),
)
if err != nil {
panic(err)
}
player = NewPlayer()
tri = NewTri()

View file

@ -4,7 +4,7 @@ import "surdeus.su/core/gg"
import "surdeus.su/core/gg/ox"
import "surdeus.su/core/gg/mx"
import "time"
import "log"
//import "log"
type Player struct {
ox.AnimatedSprite
@ -18,7 +18,7 @@ func NewPlayer() *Player {
//ret.Transform = ox.T()
ret.AnimatedSprite = ox.NewAnimatedSprite(
playerAnimations,
time.Second / 1,
time.Second / 10,
)
@ -52,7 +52,7 @@ func (p *Player) Draw(c Context) *gg.Drawing {
}
func (p *Player) OnUpdate(c Context) {
log.Println(p.IsVisible())
//log.Println("OnUpdate(...)")
if p.Spawned {
return
}

View file

@ -5,7 +5,6 @@ import "surdeus.su/core/gg/ox"
import "surdeus.su/core/gg/mx"
type Rect struct {
ox.ObjectImpl
ox.DrawableRectangle
}

View file

@ -4,13 +4,13 @@ import "surdeus.su/core/gg"
import "surdeus.su/core/gg/ox"
import "surdeus.su/core/gg/mx"
//import "fmt"
//import "log"
var (
counter int
)
type Tri struct {
ox.ObjectImpl
ox.DrawablePolygon
Spawned bool
}
@ -37,6 +37,7 @@ func NewTri() *Tri {
}
func (t *Tri) OnUpdate(c Context) {
//log.Println("onup:", t.IsVisible())
//redges := rect.Edges()
//tedges := t.Edges()
//crosses, ok := tedges.CrossWithEdges(redges)

View file

@ -7,6 +7,7 @@ import "surdeus.su/core/gg/mx"
// Default camera implementation.
var _ = gg.Camera(&Camera{})
type Camera struct {
ObjectImpl
// The Transform to interact with
// to change camera position, rotation etc.
Transform

View file

@ -4,11 +4,12 @@ import "surdeus.su/core/gg"
type Drawity struct {
ObjectImpl
Visibility
Colority
Shaderity
Floatity
Layerity
Layer
}
// Feat to emded for turning antialias on and off.
@ -24,7 +25,7 @@ func (v Visibility) IsVisible() bool {
return v.Visible
}
func (v Visibility) ToggleVisibility() bool {
func (v *Visibility) ToggleVisibility() bool {
v.Visible = !v.Visible
return v.IsVisible()
}
@ -52,4 +53,4 @@ func (s Floatity) IsFloating() bool {
return s.Floating
}
type Layerity = gg.Layer
type Layer = gg.Layer

View file

@ -23,3 +23,4 @@ type ObjectImpl struct {
DrawerImpl
BeherImpl
}

View file

@ -7,7 +7,6 @@ import (
// Grouped triangles type.
type Polygon struct {
ObjectImpl
Transform
mx.Triangles
}
@ -45,7 +44,6 @@ var _ = gg.Drawer(&DrawablePolygon{})
// Polygon that can be drawn.
type DrawablePolygon struct {
Polygon
Drawity
}

View file

@ -12,7 +12,6 @@ import "surdeus.su/core/gg/mx"
// The type describes rectangle geometry with
// way to move, rotate and scale it.
type Rectangle struct {
ObjectImpl
Transform
Width, Height mx.Float
}
@ -23,10 +22,12 @@ func (r Rectangle) Vertices() mx.Vectors {
wh := mx.Vector{r.Width, r.Height}
t.SetAround(t.GetAround().Mul(wh))
m := t.GetMatrice()
p1 := mx.Vector{0, 0}.Apply(m)
p2 := mx.Vector{wh.X, 0}.Apply(m)
p3 := mx.Vector{wh.X, wh.Y}.Apply(m)
p4 := mx.Vector{0, wh.Y}.Apply(m)
return mx.Vectors{p1, p2, p3, p4}
}

View file

@ -11,7 +11,6 @@ import "surdeus.su/core/gg"
var _ = gg.Drawer(&Sprite{})
type Sprite struct {
Transform
Drawity
}

View file

@ -8,14 +8,8 @@ import "github.com/hajimehoshi/ebiten/v2"
// The type implements basic drawable text.
// (Now needs to implement rotation, scaling etc, cause now only position)
type Text struct {
ObjectImpl
Transform
Colority
Visibility
Shaderity
Floatity
Drawity
Face gg.Face
Data string
}

View file

@ -37,6 +37,7 @@ func T() Transform {
// Rotate around the center.
around: mx.V2(.5),
}
ret.dirty = true
return ret
}
@ -52,45 +53,59 @@ func (t *Transform) GetTransform() *Transform {
}
// Set the absolute object position.
func (t *Transform) SetPosition(position mx.Vector) {
func (t *Transform) SetPosition(position mx.Vector) *Transform {
t.dirty = true
t.parentDirty = true
if t.parent == nil {
t.position = position
return
return t
}
_, mi := t.parent.GetMatriceForParenting()
t.position = position.Apply(mi)
return t
}
// Set the absolute object rotation.
func (t *Transform) SetRotation(rotation mx.Float) {
func (t *Transform) SetRotation(rotation mx.Float) *Transform {
t.dirty = true
t.parentDirty = true
if t.parent == nil {
t.rotation = rotation
return
return t
}
t.rotation -= t.parent.GetRotation()
return t
}
// Set the absolute object scale.
func (t *Transform) SetScale(scale mx.Vector) {
func (t *Transform) SetScale(scale mx.Vector) *Transform {
t.dirty = true
t.parentDirty = true
t.scale = scale
return t
}
func (t *Transform) AddScale(add mx.Vector) {
func (t *Transform) AddScale(add mx.Vector) *Transform {
t.dirty = true
//t.parentDirty = true
t.scale = t.scale.Add(add)
return t
}
func (t *Transform) SetAround(around mx.Vector) {
func (t *Transform) Scale(mul mx.Vector) *Transform {
t.dirty = true
t.scale = t.scale.Mul(mul)
return t
}
func (t *Transform) SetAround(around mx.Vector) *Transform {
t.dirty = true
t.around = around
return t
}
// Get the absolute representation of the transform.
@ -143,10 +158,12 @@ func (t *Transform) GetRotation() mx.Float {
return t.rotation + t.parent.GetRotation()
}
func (t *Transform) Rotate(rot mx.Float) {
func (t *Transform) Rotate(rot mx.Float) *Transform {
t.dirty = true
t.parentDirty = true
t.rotation += rot
return t
}
func (t *Transform) GetAround() mx.Vector {
return t.around
@ -160,9 +177,9 @@ func (t *Transform) IsConnected() bool {
// Connect the object to another one making
// it its parent.
func (t *Transform) Connect(parent Transformer) {
func (t *Transform) Connect(parent Transformer) *Transform {
if parent == nil {
return
return t
}
if t.parent != nil {
t.Disconnect()
@ -174,17 +191,22 @@ func (t *Transform) Connect(parent Transformer) {
t.parent = parent.GetTransform()
t.SetPosition(position)
t.SetRotation(rotation)
return t
}
// Disconnect from the parent.
func (t *Transform) Disconnect() {
func (t *Transform) Disconnect() *Transform {
if t.parent == nil {
return
return t
}
*t = t.Abs()
return t
}
// Return the matrix and the inverted one for parenting children.
// Return the matrix and the inverted
// one for parenting children.
func (t *Transform) GetMatriceForParenting(
) (mx.Matrice, mx.Matrice) {
var m, mi mx.Matrice

View file

@ -6,7 +6,6 @@ import "surdeus.su/core/gg"
type DrawableTriangles struct {
mx.Triangles
Drawity
}