Added the structures I am gonna need to implement colliders and more.
This commit is contained in:
parent
fb10beda75
commit
a89db46fe7
11 changed files with 103 additions and 47 deletions
|
@ -1,12 +0,0 @@
|
||||||
package gx
|
|
||||||
|
|
||||||
// Implementing the interface lets
|
|
||||||
// the engine to work faster about
|
|
||||||
// collisions because it first checks
|
|
||||||
// if the the bigger rectangles that
|
|
||||||
// contain more complicated structure
|
|
||||||
// do collide.
|
|
||||||
type ColliderSimplifier interface {
|
|
||||||
ColliderSimplify() Rect
|
|
||||||
}
|
|
||||||
|
|
32
src/gx/collider.go
Normal file
32
src/gx/collider.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package gx
|
||||||
|
|
||||||
|
// Implementing the interface lets
|
||||||
|
// the engine to work faster about
|
||||||
|
// collisions because it first checks
|
||||||
|
// if the the bigger collider that
|
||||||
|
// contain more complicated structure
|
||||||
|
// do collide.
|
||||||
|
type ColliderSimplifier interface {
|
||||||
|
ColliderSimplify() Rect
|
||||||
|
}
|
||||||
|
|
||||||
|
// The structure represents all
|
||||||
|
// information on collision.
|
||||||
|
type Collision struct {
|
||||||
|
Other Collider
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every collider has to implement
|
||||||
|
// collision with every other type of collider
|
||||||
|
// for optimization. Not good for custom colliders
|
||||||
|
// but is fast.
|
||||||
|
type Collider interface {
|
||||||
|
Collides(Collider) *Collision
|
||||||
|
}
|
||||||
|
|
||||||
|
// happening collision getting the Collision as
|
||||||
|
// argument.
|
||||||
|
type CollideEventer interface {
|
||||||
|
Collide(*Collision)
|
||||||
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Image = ebiten.Image
|
type Image = ebiten.Image
|
||||||
type Rectangle = image.Rectangle
|
|
||||||
type Point = image.Point
|
|
||||||
|
|
||||||
// The interface describes anything that can be
|
// The interface describes anything that can be
|
||||||
// drawn. It will be drew corresponding to
|
// drawn. It will be drew corresponding to
|
||||||
|
|
7
src/gx/line-segment.go
Normal file
7
src/gx/line-segment.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package gx
|
||||||
|
|
||||||
|
type LineSegment struct {
|
||||||
|
P Point
|
||||||
|
V Vector
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// The type is used in all Engine interactions
|
||||||
|
// where you need floating values.
|
||||||
|
type Float = float64
|
||||||
|
|
||||||
// The type represents order of drawing.
|
// The type represents order of drawing.
|
||||||
type Layer int
|
type Layer int
|
||||||
|
|
||||||
|
|
9
src/gx/matrix.go
Normal file
9
src/gx/matrix.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package gx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
//"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Matrix = ebiten.GeoM
|
||||||
|
|
3
src/gx/misc.go
Normal file
3
src/gx/misc.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
package gx
|
||||||
|
|
||||||
|
|
4
src/gx/point.go
Normal file
4
src/gx/point.go
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
package gx
|
||||||
|
|
||||||
|
type Point Vector
|
||||||
|
|
7
src/gx/ray.go
Normal file
7
src/gx/ray.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package gx
|
||||||
|
|
||||||
|
type Ray struct {
|
||||||
|
P Point
|
||||||
|
V Vector
|
||||||
|
}
|
||||||
|
|
|
@ -1,47 +1,18 @@
|
||||||
package gx
|
package gx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
//"github.com/hajimehoshi/ebiten/v2"
|
||||||
"math"
|
//"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Matrix = ebiten.GeoM
|
|
||||||
type Float = float64
|
|
||||||
|
|
||||||
type Vector struct {
|
|
||||||
X, Y Float
|
|
||||||
}
|
|
||||||
|
|
||||||
type Transform struct {
|
type Transform struct {
|
||||||
// Position, scale, rotate around.
|
// Position, scale, rotate around(relatively of position, not absolute).
|
||||||
P, S, RA Vector
|
P, S, RA Vector
|
||||||
// Rotation angle in radians.
|
// Rotation angle in radians.
|
||||||
R Float
|
R Float
|
||||||
}
|
}
|
||||||
|
|
||||||
func V(x, y Float) Vector {
|
// Returns empty Transform.
|
||||||
return Vector{x, y}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the vector with the matrix applied
|
|
||||||
func (v Vector) Apply(m *Matrix) Vector {
|
|
||||||
x, y := m.Apply(v.X, v.Y)
|
|
||||||
return V(x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the vector rotated by "a" angle in radians.
|
|
||||||
func (v Vector) Rotate(a Float) Vector {
|
|
||||||
m := &Matrix{}
|
|
||||||
m.Rotate(a)
|
|
||||||
return v.Apply(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the normalized vector.
|
|
||||||
func (v Vector) Norm() Vector {
|
|
||||||
l := math.Sqrt(v.X*v.X + v.Y*v.Y)
|
|
||||||
return V(v.X / l, v.Y / l)
|
|
||||||
}
|
|
||||||
|
|
||||||
func T() Transform {
|
func T() Transform {
|
||||||
ret := Transform{}
|
ret := Transform{}
|
||||||
return ret
|
return ret
|
||||||
|
|
33
src/gx/vector.go
Normal file
33
src/gx/vector.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package gx
|
||||||
|
|
||||||
|
import (
|
||||||
|
//"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Vector struct {
|
||||||
|
X, Y Float
|
||||||
|
}
|
||||||
|
|
||||||
|
func V(x, y Float) Vector {
|
||||||
|
return Vector{x, y}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the vector with the matrix applied
|
||||||
|
func (v Vector) Apply(m *Matrix) Vector {
|
||||||
|
x, y := m.Apply(v.X, v.Y)
|
||||||
|
return V(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the vector rotated by "a" angle in radians.
|
||||||
|
func (v Vector) Rotate(a Float) Vector {
|
||||||
|
m := &Matrix{}
|
||||||
|
m.Rotate(a)
|
||||||
|
return v.Apply(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the normalized vector.
|
||||||
|
func (v Vector) Norm() Vector {
|
||||||
|
l := math.Sqrt(v.X*v.X + v.Y*v.Y)
|
||||||
|
return V(v.X / l, v.Y / l)
|
||||||
|
}
|
Loading…
Reference in a new issue