mirror of
https://github.com/JohnBreaux/Boat-Battle.git
synced 2024-11-15 05:25:57 +00:00
Refactor ship extents logic
This commit is contained in:
parent
ecbf14c998
commit
dae4c56a2b
@ -46,27 +46,14 @@ func getSunk():
|
|||||||
# returns an array of the positions that the ship occupies
|
# returns an array of the positions that the ship occupies
|
||||||
func getExtent():
|
func getExtent():
|
||||||
var extent = []
|
var extent = []
|
||||||
|
# Find each tile of the ship
|
||||||
for i in size:
|
for i in size:
|
||||||
var x = boardposition.x - int(!orientation) * ((size - 1) / 2) + int(!orientation) * i
|
# Calculate the x axis position
|
||||||
var y = boardposition.y - orientation * ((size - 1) / 2) + orientation * i
|
var x = boardposition.x - (1 - orientation) * ( (size - 1) / 2 - i )
|
||||||
print(Vector2(x,y))
|
# Calculate the y axis position
|
||||||
|
var y = boardposition.y - orientation * ( (size - 1) / 2 - i )
|
||||||
#vertical orientation
|
# Append the point onto the array
|
||||||
if orientation == 1:
|
extent.push_back(Vector2(x,y))
|
||||||
for i in size:
|
|
||||||
var pos = Vector2(0,0)
|
|
||||||
pos.x = boardposition.x
|
|
||||||
pos.y = boardposition.y - ((size - 1) / 2) + i
|
|
||||||
extent.append(pos)
|
|
||||||
#horizontal orientation
|
|
||||||
if orientation == 0:
|
|
||||||
for i in size:
|
|
||||||
var pos = Vector2(0,0)
|
|
||||||
pos.x = boardposition.x - ((size - 1) / 2) + i
|
|
||||||
pos.y = boardposition.y
|
|
||||||
extent.append(pos)
|
|
||||||
print(extent)
|
|
||||||
return extent
|
return extent
|
||||||
|
|
||||||
# generates a texture at the spot (index should start at 0)
|
# generates a texture at the spot (index should start at 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user