1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2024-11-14 21:15:58 +00:00

Commented my code

Deals with ship placement on board and ship rotation on board
This commit is contained in:
tommy-l-ngo 2021-11-11 15:08:14 -06:00
parent eaa1617b9a
commit f9592f425e

View File

@ -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: