Skip to content

Commit

Permalink
Make magic wood casting be LOS
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Jan 9, 2021
1 parent f471ad6 commit 3bb0b16
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ Bugs:
- Cannot move from magic wood tree to dark citadel
- Players can attack walls?
- Magic wood, make it gift players with a spell sometimes if they are mounted.
- Make magic wood casting be line of sight
- Line of sight calculation seems a bit harsh currently
9 changes: 9 additions & 0 deletions grid/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,12 @@ func (grid *GameGrid) AnimationTick(odd bool) {
func (grid *GameGrid) AsRect() logical.Rect {
return logical.R(grid.MaxX(), grid.MaxY())
}

func (grid *GameGrid) HaveLineOfSight(from, to logical.Vec) bool {
for _, pathV := range to.Subtract(from).Path() {
if !grid.GetGameObject(from.Add(pathV)).IsEmpty() {
return false
}
}
return true
}
2 changes: 1 addition & 1 deletion screen/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (screen *RangedCombat) Step(ctx screeniface.GameCtx) screeniface.GameScreen
textBottom("Out of range", ss, batch)
screen.OutOfRange = true
} else {
if !HaveLineOfSight(characterLocation, attackPosition, grid) {
if !grid.HaveLineOfSight(characterLocation, attackPosition) {
textBottom("No line of sight", ss, batch)
screen.OutOfRange = true
} else {
Expand Down
2 changes: 1 addition & 1 deletion screen/castspell.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (screen *TargetSpellScreen) Step(ctx screeniface.GameCtx) screeniface.GameS
fmt.Printf("Out of range! Spell cast range %d but distance to target is %d\n", spell.GetCastRange(), target.Distance(thisPlayer.BoardPosition))
screen.MessageShown = true
} else {
if spell.NeedsLineOfSight() && !HaveLineOfSight(thisPlayer.BoardPosition, target, grid) {
if spell.NeedsLineOfSight() && !grid.HaveLineOfSight(thisPlayer.BoardPosition, target) {
textBottom("No line of sight", ss, batch)
screen.MessageShown = true
} else {
Expand Down
9 changes: 0 additions & 9 deletions screen/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ func WeHaveAWinner(players []*player.Player) bool {
return c == 1
}

func HaveLineOfSight(from, to logical.Vec, grid *grid.GameGrid) bool {
for _, pathV := range to.Subtract(from).Path() {
if !grid.GetGameObject(from.Add(pathV)).IsEmpty() {
return false
}
}
return true
}

var numKeyMap map[pixelgl.Button]int
var spellKeyMap map[pixelgl.Button]int
var directionKeyMap map[pixelgl.Button]logical.Vec
Expand Down
4 changes: 3 additions & 1 deletion spellswithscreen/magic_wood.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func getMagicWoodTiles(ctx screeniface.GameCtx, playerIdx int) []logical.Vec {
if !grid.GetGameObject(possibleVec).IsEmpty() {
continue
}
// FIXME - adjacent to the player is OK
if !grid.HaveLineOfSight(fromPosition, possibleVec) {
continue
}
if adjacentsAreNotMagicWood(ctx, possibleVec) {
//fmt.Printf("Add possible Vec X%d Y%d\n", possibleVec.X, possibleVec.Y)
maybeTiles = append(maybeTiles, possibleVec)
Expand Down

0 comments on commit 3bb0b16

Please sign in to comment.