mirror of
https://github.com/mvvasilev/last_light.git
synced 2025-04-19 12:49:52 +03:00
Arrow sprites
This commit is contained in:
parent
855fa8dfc1
commit
9445958338
4 changed files with 53 additions and 11 deletions
|
@ -62,6 +62,32 @@ func (p Position) WithOffset(xOffset int, yOffset int) Position {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p Position) Diff(other Position) Position {
|
||||||
|
p.x = p.x - other.x
|
||||||
|
p.y = p.y - other.y
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Position) Sign() Position {
|
||||||
|
p.x = IntSign(p.x)
|
||||||
|
p.y = IntSign(p.y)
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func IntSign(i int) int {
|
||||||
|
if i < 0 {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
if i > 0 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
type Sized struct {
|
type Sized struct {
|
||||||
size Size
|
size Size
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"mvvasilev/last_light/engine"
|
"mvvasilev/last_light/engine"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProjectileSprite rune
|
type ArrowSprite rune
|
||||||
|
|
||||||
//
|
//
|
||||||
// \ | /
|
// \ | /
|
||||||
|
@ -15,10 +15,10 @@ type ProjectileSprite rune
|
||||||
// / | \
|
// / | \
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ProjectileSprite_NorthSouth ProjectileSprite = '|'
|
ProjectileSprite_NorthSouth ArrowSprite = '|'
|
||||||
ProjectileSprite_EastWest = '─'
|
ProjectileSprite_EastWest ArrowSprite = '─'
|
||||||
ProjectileSprite_NorthEastSouthWest = '/'
|
ProjectileSprite_NorthEastSouthWest ArrowSprite = '/'
|
||||||
ProjectileSprite_NorthWestSouthEast = '\\'
|
ProjectileSprite_NorthWestSouthEast ArrowSprite = '\\'
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProjectileBehavior(eventLog *engine.GameEventLog, dungeon *Dungeon) func(npc Entity) (complete bool, requeue bool) {
|
func ProjectileBehavior(eventLog *engine.GameEventLog, dungeon *Dungeon) func(npc Entity) (complete bool, requeue bool) {
|
||||||
|
|
|
@ -12,11 +12,11 @@ const (
|
||||||
ImpClaws specialItemType = 100_000 + iota
|
ImpClaws specialItemType = 100_000 + iota
|
||||||
)
|
)
|
||||||
|
|
||||||
func Entity_ArrowProjectile(source Entity, path *engine.Path, eventLog *engine.GameEventLog, dungeon *Dungeon) Entity {
|
func Entity_Projectile(name string, symbol rune, style tcell.Style, source Entity, path *engine.Path, eventLog *engine.GameEventLog, dungeon *Dungeon) Entity {
|
||||||
return CreateEntity(
|
return CreateEntity(
|
||||||
WithName("Arrow"),
|
WithName(name),
|
||||||
WithPosition(path.From()),
|
WithPosition(path.From()),
|
||||||
WithPresentation('?', tcell.StyleDefault),
|
WithPresentation(symbol, style),
|
||||||
WithProjectileData(source, path),
|
WithProjectileData(source, path),
|
||||||
WithBehavior(1, ProjectileBehavior(eventLog, dungeon)),
|
WithBehavior(1, ProjectileBehavior(eventLog, dungeon)),
|
||||||
)
|
)
|
||||||
|
|
|
@ -103,10 +103,11 @@ func (ls *LookState) ShootEquippedWeapon() {
|
||||||
|
|
||||||
// TODO: Projectiles
|
// TODO: Projectiles
|
||||||
dX, dY := ls.lookCursorCoordsToDungeonCoords()
|
dX, dY := ls.lookCursorCoordsToDungeonCoords()
|
||||||
|
cursorPos := engine.PositionAt(dX, dY)
|
||||||
|
|
||||||
distance := engine.PositionAt(dX, dY).Distance(ls.player.Position())
|
distance := cursorPos.Distance(ls.player.Position())
|
||||||
|
|
||||||
if distance >= 12 {
|
if distance > 12 {
|
||||||
ls.eventLog.Log("Can't see in the dark that far")
|
ls.eventLog.Log("Can't see in the dark that far")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -122,7 +123,22 @@ func (ls *LookState) ShootEquippedWeapon() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
projectile := model.Entity_ArrowProjectile(ls.player, path, ls.eventLog, ls.dungeon)
|
direction := ls.player.Position().Diff(cursorPos).Sign()
|
||||||
|
|
||||||
|
sprites := map[engine.Position]model.ArrowSprite{
|
||||||
|
engine.PositionAt(-1, -1): model.ProjectileSprite_NorthWestSouthEast,
|
||||||
|
engine.PositionAt(+1, -1): model.ProjectileSprite_NorthWestSouthEast,
|
||||||
|
engine.PositionAt(-1, +1): model.ProjectileSprite_NorthEastSouthWest,
|
||||||
|
engine.PositionAt(+1, +1): model.ProjectileSprite_NorthEastSouthWest,
|
||||||
|
engine.PositionAt(0, +1): model.ProjectileSprite_NorthSouth,
|
||||||
|
engine.PositionAt(0, -1): model.ProjectileSprite_NorthSouth,
|
||||||
|
engine.PositionAt(-1, 0): model.ProjectileSprite_EastWest,
|
||||||
|
engine.PositionAt(+1, 0): model.ProjectileSprite_EastWest,
|
||||||
|
}
|
||||||
|
|
||||||
|
sprite := sprites[direction]
|
||||||
|
|
||||||
|
projectile := model.Entity_Projectile("Arrow", rune(sprite), tcell.StyleDefault, ls.player, path, ls.eventLog, ls.dungeon)
|
||||||
|
|
||||||
ls.turnSystem.Schedule(
|
ls.turnSystem.Schedule(
|
||||||
projectile.Behavior().Speed,
|
projectile.Behavior().Speed,
|
||||||
|
|
Loading…
Add table
Reference in a new issue