colordance
This commit is contained in:
@ -1,10 +1,13 @@
|
||||
package basic
|
||||
|
||||
import (
|
||||
"github.com/jcerise/gogue/gamemap"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"math"
|
||||
)
|
||||
|
||||
//fixme store separate FovMap, add method IsInMap to it
|
||||
|
||||
type FieldOfVision struct {
|
||||
cosTable map[int]float64
|
||||
sinTable map[int]float64
|
||||
@ -31,15 +34,15 @@ func (f *FieldOfVision) SetTorchRadius(radius int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FieldOfVision) SetAllInvisible(gameMap *gamemap.Map) {
|
||||
for x := 0; x < gameMap.Width; x++ {
|
||||
for y := 0; y < gameMap.Height; y++ {
|
||||
gameMap.Tiles[x][y].Visible = false
|
||||
func (f *FieldOfVision) SetAllInvisible(level *gamemap.Level) {
|
||||
for x := 0; x < level.W; x++ {
|
||||
for y := 0; y < level.H; y++ {
|
||||
level.Tiles[x][y].Visible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FieldOfVision) RayCast(playerX, playerY int, gameMap *gamemap.Map) {
|
||||
func (f *FieldOfVision) RayCast(playerCoords types.Coords, level *gamemap.Level) {
|
||||
// Cast out rays each degree in a 360 circle from the player. If a ray passes over a floor (does not block sight)
|
||||
// tile, keep going, up to the maximum torch radius (view radius) of the player. If the ray intersects a wall
|
||||
// (blocks sight), stop, as the player will not be able to see past that. Every visible tile will get the Visible
|
||||
@ -50,11 +53,11 @@ func (f *FieldOfVision) RayCast(playerX, playerY int, gameMap *gamemap.Map) {
|
||||
ax := f.sinTable[i]
|
||||
ay := f.cosTable[i]
|
||||
|
||||
x := float64(playerX)
|
||||
y := float64(playerY)
|
||||
x := float64(playerCoords.X)
|
||||
y := float64(playerCoords.Y)
|
||||
|
||||
// Mark the players current position as explored
|
||||
tile := gameMap.Tiles[playerX][playerY]
|
||||
tile := level.Tiles[playerCoords.X][playerCoords.Y]
|
||||
tile.Explored = true
|
||||
tile.Visible = true
|
||||
|
||||
@ -65,17 +68,17 @@ func (f *FieldOfVision) RayCast(playerX, playerY int, gameMap *gamemap.Map) {
|
||||
roundedX := int(Round(x))
|
||||
roundedY := int(Round(y))
|
||||
|
||||
if x < 0 || x > float64(gameMap.Width-1) || y < 0 || y > float64(gameMap.Height-1) {
|
||||
if x < 0 || x > float64(level.W -1) || y < 0 || y > float64(level.H -1) {
|
||||
// If the ray is cast outside of the gamemap, stop
|
||||
break
|
||||
}
|
||||
|
||||
tile := gameMap.Tiles[roundedX][roundedY]
|
||||
tile := level.Tiles[roundedX][roundedY]
|
||||
|
||||
tile.Explored = true
|
||||
tile.Visible = true
|
||||
|
||||
if gameMap.Tiles[roundedX][roundedY].BlocksSight == true {
|
||||
if level.Tiles[roundedX][roundedY].BlocksSight == true {
|
||||
// The ray hit a wall, go no further
|
||||
break
|
||||
}
|
||||
@ -85,4 +88,4 @@ func (f *FieldOfVision) RayCast(playerX, playerY int, gameMap *gamemap.Map) {
|
||||
|
||||
func Round(f float64) float64 {
|
||||
return math.Floor(f + .5)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user