Skip to content

Commit

Permalink
Changed float position to float64
Browse files Browse the repository at this point in the history
  • Loading branch information
k-karuna committed Jul 16, 2024
1 parent 80a0287 commit f40eff4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cardinal/component/position.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package component

type Position struct {
Island [2]int `json:"island"`
Island [2]float64 `json:"island"`
Shipwreck [2]float64 `json:"shipwreck"`
}

Expand Down
4 changes: 2 additions & 2 deletions cardinal/query/global_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type GlobalMapResponse struct {
}

type ResourcePoint struct {
Position [2]int `json:"position"`
Position [2]float64 `json:"position"`
Resources []comp.Resource `json:"resources"`
}

Expand All @@ -43,7 +43,7 @@ func GlobalMap(world cardinal.WorldContext, _ *GlobalMapRequest) (*[]GlobalMapRe
Resources: playerResources.Resources,
},
Shipwreck: ResourcePoint{
Position: position.Island,
Position: position.Shipwreck,
Resources: shipwreckResources.Resources,
},
}
Expand Down
16 changes: 8 additions & 8 deletions cardinal/system/global_map_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,28 @@ func getNextDirection(current Direction) (next Direction) {
}
}

func getNextPointPosition(currentDirection Direction, currentPoint [2]int) (nextPoint [2]int) {
func getNextPointPosition(currentDirection Direction, currentPoint [2]float64) (nextPoint [2]float64) {
switch currentDirection {
case Left:
return [2]int{currentPoint[0] - 1, currentPoint[1]}
return [2]float64{currentPoint[0] - 1, currentPoint[1]}
case Top:
return [2]int{currentPoint[0], currentPoint[1] + 1}
return [2]float64{currentPoint[0], currentPoint[1] + 1}
case Right:
return [2]int{currentPoint[0] + 1, currentPoint[1]}
return [2]float64{currentPoint[0] + 1, currentPoint[1]}
case Bottom:
return [2]int{currentPoint[0], currentPoint[1] - 1}
return [2]float64{currentPoint[0], currentPoint[1] - 1}
default:
err := errors.New("unexpected Direction value")
panic(err)
}
}

func getIslandCoordinates(n int) [2]int {
func getIslandCoordinates(n int) [2]float64 {
objectsInRow := InitialRowLength
direction := Left
currentIslandsInRow := 0
points := make([][2]int, 0, n)
points = append(points, [2]int{0, 0})
points := make([][2]float64, 0, n)
points = append(points, [2]float64{0, 0})
for range n {
if currentIslandsInRow == objectsInRow {
direction = getNextDirection(direction)
Expand Down
6 changes: 3 additions & 3 deletions cardinal/system/math_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"golang.org/x/exp/rand"
)

func getRandomPointOnCircle(x, y int, r float64) [2]float64 {
func getRandomPointOnCircle(x, y, r float64) [2]float64 {
angle := rand.Float64() * constants.TwoPi
var points [2]float64
points[0] = float64(x) + r*math.Cos(angle)
points[1] = float64(y) + r*math.Sin(angle)
points[0] = x + r*math.Cos(angle)
points[1] = y + r*math.Sin(angle)
return points
}

0 comments on commit f40eff4

Please sign in to comment.