From f9592f425e780bb668f0331da22126bf5e551083 Mon Sep 17 00:00:00 2001 From: tommy-l-ngo Date: Thu, 11 Nov 2021 15:08:14 -0600 Subject: [PATCH] Commented my code Deals with ship placement on board and ship rotation on board --- godot_ship/script/game/moveShip.gd | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/godot_ship/script/game/moveShip.gd b/godot_ship/script/game/moveShip.gd index a64aba7..80ac020 100644 --- a/godot_ship/script/game/moveShip.gd +++ b/godot_ship/script/game/moveShip.gd @@ -4,14 +4,14 @@ extends RigidBody2D # var a = 2 # var b = "text" var held = false -var originalPos -var snapOriginalPos = false -var vertical = true -var startingPos +var originalPos # Position before moving the ship +var snapOriginalPos = false # Gets the original position +var vertical = true # Gets ship which is either vertical or horizonal +var startingPos # Starting position of ships before being placed # Called when the node enters the scene tree for the first time. func _ready(): - startingPos = position + startingPos = position # Sets the position of ships when game is started to the startingPos variable pass var click_radius = 16 @@ -26,14 +26,17 @@ func _input(event): if held and not event.pressed: held = false; + # If ship is placed on board, snap to board if (position.x > 17.4 and position.x < 335.5) and (position.y > 20.2 and position.y < 335.5): - position = position.snapped(Vector2(32, 32)) + Vector2(4, 4) - else: + position = position.snapped(Vector2(32, 32)) + Vector2(4, 4) # Position snapping on board + else: # If not placed on board, ships are placed back at the starting position if originalPos != null: position = originalPos rotation = 0 vertical = true + # Lines 40-98 make sure that the ships placed on the board are not able to hang off the board + # 2-Ship if (get_parent().get_node("2Ship").rotation_degrees == 0): if (get_parent().get_node("2Ship").position.y > 308): @@ -119,6 +122,7 @@ func _input(event): rotate(PI/2) vertical = true + # Lines 126-196 move the ship back accordingly after being rotated to make sure that the ships do not hang off the board if(position.x > 17.4 and position.x < 335.5) and (position.y > 20.2 and position.y < 335.5): # 2-Ship if (get_parent().get_node("2Ship").rotation_degrees == 0): @@ -208,7 +212,7 @@ func drop(impulse=Vector2.ZERO): held = false snapOriginalPos = false -func checkOriginalPos(): +func checkOriginalPos(): # Checks whether the position of the ship is the stating position of the ship if position == startingPos: return true else: