From dae4c56a2b3110190d2ea2eac466dd79073d95a8 Mon Sep 17 00:00:00 2001 From: John Breaux Date: Sun, 14 Nov 2021 07:14:35 -0600 Subject: [PATCH] Refactor ship extents logic --- godot_ship/script/game/Gameplay/Ship.gd | 29 +++++++------------------ 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/godot_ship/script/game/Gameplay/Ship.gd b/godot_ship/script/game/Gameplay/Ship.gd index 6191e67..5952eab 100644 --- a/godot_ship/script/game/Gameplay/Ship.gd +++ b/godot_ship/script/game/Gameplay/Ship.gd @@ -46,29 +46,16 @@ func getSunk(): # returns an array of the positions that the ship occupies func getExtent(): var extent = [] - + # Find each tile of the ship for i in size: - var x = boardposition.x - int(!orientation) * ((size - 1) / 2) + int(!orientation) * i - var y = boardposition.y - orientation * ((size - 1) / 2) + orientation * i - print(Vector2(x,y)) - - #vertical orientation - if orientation == 1: - 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) + # Calculate the x axis position + var x = boardposition.x - (1 - orientation) * ( (size - 1) / 2 - i ) + # Calculate the y axis position + var y = boardposition.y - orientation * ( (size - 1) / 2 - i ) + # Append the point onto the array + extent.push_back(Vector2(x,y)) return extent - + # generates a texture at the spot (index should start at 0) func texture(index): var state = 0 # floating