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/mx"
import "surdeus.su/core/gg" import "surdeus.su/core/gg"
import "log"
var ( var (
camera = &Camera{ camera *Camera
Camera: ox.NewCamera(),
ScaleSpeed: 5.,
RotationSpeed: .3,
}
) )
type Camera struct { type Camera struct {
ox.ObjectImpl
ox.Camera ox.Camera
ScaleSpeed mx.Float ScaleSpeed mx.Float
RotationSpeed 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) { func (cam *Camera) OnUpdate(c gg.Context) {
dt := c.Engine().DT().Seconds() dt := c.Engine().DT().Seconds()
mov := c.Events().Mouse.Move mov := c.Events().Mouse.Move
@ -38,8 +43,15 @@ func (cam *Camera) OnUpdate(c gg.Context) {
// Scale. // Scale.
if wheel != nil { if wheel != nil {
cam.AddScale(mx.V2( k := 1.5
wheel.Offset.Y * dt * cam.ScaleSpeed * 40, 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) GetLayer() gg.Layer {return LayerHighest}
func (d *Debug) Draw(c Context) *gg.Drawing { func (d *Debug) Draw(c Context) *gg.Drawing {

View file

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

View file

@ -4,7 +4,7 @@ import "surdeus.su/core/gg"
import "surdeus.su/core/gg/ox" import "surdeus.su/core/gg/ox"
import "surdeus.su/core/gg/mx" import "surdeus.su/core/gg/mx"
import "time" import "time"
import "log" //import "log"
type Player struct { type Player struct {
ox.AnimatedSprite ox.AnimatedSprite
@ -18,7 +18,7 @@ func NewPlayer() *Player {
//ret.Transform = ox.T() //ret.Transform = ox.T()
ret.AnimatedSprite = ox.NewAnimatedSprite( ret.AnimatedSprite = ox.NewAnimatedSprite(
playerAnimations, 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) { func (p *Player) OnUpdate(c Context) {
log.Println(p.IsVisible()) //log.Println("OnUpdate(...)")
if p.Spawned { if p.Spawned {
return return
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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