added transient entities: when crossed, turns into wall tile
This commit is contained in:
@@ -11,9 +11,9 @@ type Renderable struct {
|
||||
}
|
||||
|
||||
type Particle struct {
|
||||
Show bool
|
||||
Index int
|
||||
Particles []*ebiten.Image
|
||||
Show bool
|
||||
Index int
|
||||
Tiles []*ebiten.Image
|
||||
}
|
||||
|
||||
type Speed struct {
|
||||
@@ -26,4 +26,7 @@ type Solid struct{}
|
||||
type Floor struct{}
|
||||
type Player struct{}
|
||||
type Collectible struct{}
|
||||
type Obstacle struct{}
|
||||
|
||||
type Obstacle struct {
|
||||
Direction int
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package components
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"log/slog"
|
||||
. "openquell/config"
|
||||
)
|
||||
|
||||
@@ -90,13 +89,14 @@ func (tile *Position) Intersects(moving *Position, velocity *Velocity) (bool, *P
|
||||
|
||||
is := tile.Rect.Bounds().Intersect(object.Rect.Bounds())
|
||||
if is != image.ZR {
|
||||
slog.Debug("Intersect",
|
||||
"velocity", velocity.Data,
|
||||
"player", moving.Rect,
|
||||
"moved player", object.Rect,
|
||||
"collision at", is,
|
||||
)
|
||||
|
||||
/*
|
||||
slog.Debug("Intersect",
|
||||
"velocity", velocity.Data,
|
||||
"player", moving.Rect,
|
||||
"moved player", object.Rect,
|
||||
"collision at", is,
|
||||
)
|
||||
*/
|
||||
// collision, snap into neighbouring tile depending on the direction
|
||||
switch velocity.Direction {
|
||||
case West:
|
||||
|
||||
24
components/transient.go
Normal file
24
components/transient.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package components
|
||||
|
||||
import (
|
||||
"log"
|
||||
)
|
||||
|
||||
type Transient struct {
|
||||
Activated bool
|
||||
Sprites []string
|
||||
Current int // sprite index
|
||||
}
|
||||
|
||||
func (trans *Transient) GetNext() string {
|
||||
if len(trans.Sprites) > trans.Current {
|
||||
trans.Current++
|
||||
return trans.Sprites[trans.Current]
|
||||
}
|
||||
|
||||
log.Fatalf("not enough sprites in transient tile, have %d sprites, index requested: %d",
|
||||
len(trans.Sprites), trans.Current+1,
|
||||
)
|
||||
|
||||
return ""
|
||||
}
|
||||
@@ -6,8 +6,20 @@ import (
|
||||
|
||||
// movement in relation to position
|
||||
type Velocity struct {
|
||||
Data Position
|
||||
Direction int
|
||||
Data Position
|
||||
Direction int
|
||||
PointingAt int
|
||||
}
|
||||
|
||||
func (velocity *Velocity) Set(new *Velocity) {
|
||||
velocity.Direction = new.Direction
|
||||
velocity.Data.Set(&new.Data)
|
||||
}
|
||||
|
||||
func (velocity *Velocity) ResetDirectionAndStop() {
|
||||
velocity.Data.X = 0
|
||||
velocity.Data.Y = 0
|
||||
velocity.Direction = velocity.PointingAt
|
||||
}
|
||||
|
||||
func (velocity *Velocity) Change(direction int) {
|
||||
|
||||
Reference in New Issue
Block a user