diff --git a/godot_ship/.import/RedCrosshair.png-ed59a214d85db7c21233257c8daddbef.md5 b/godot_ship/.import/RedCrosshair.png-ed59a214d85db7c21233257c8daddbef.md5 new file mode 100644 index 0000000..4daad2d --- /dev/null +++ b/godot_ship/.import/RedCrosshair.png-ed59a214d85db7c21233257c8daddbef.md5 @@ -0,0 +1,3 @@ +source_md5="f6d6cf59e576f46ace6228c7c6fbcd43" +dest_md5="5fbfd5548d2fd8ed92f2a987ce11d3c4" + diff --git a/godot_ship/.import/RedCrosshair.png-ed59a214d85db7c21233257c8daddbef.stex b/godot_ship/.import/RedCrosshair.png-ed59a214d85db7c21233257c8daddbef.stex new file mode 100644 index 0000000..217971f Binary files /dev/null and b/godot_ship/.import/RedCrosshair.png-ed59a214d85db7c21233257c8daddbef.stex differ diff --git a/godot_ship/assets/game/RedCrosshair.png b/godot_ship/assets/game/RedCrosshair.png new file mode 100644 index 0000000..4c96e0d Binary files /dev/null and b/godot_ship/assets/game/RedCrosshair.png differ diff --git a/godot_ship/assets/game/RedCrosshair.png.import b/godot_ship/assets/game/RedCrosshair.png.import new file mode 100644 index 0000000..dac2332 --- /dev/null +++ b/godot_ship/assets/game/RedCrosshair.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/RedCrosshair.png-ed59a214d85db7c21233257c8daddbef.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/game/RedCrosshair.png" +dest_files=[ "res://.import/RedCrosshair.png-ed59a214d85db7c21233257c8daddbef.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/godot_ship/scenes/Gameplay.tscn b/godot_ship/scenes/Gameplay.tscn index 3518ee1..e4cdb33 100644 --- a/godot_ship/scenes/Gameplay.tscn +++ b/godot_ship/scenes/Gameplay.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://assets/game/board_blue.png" type="Texture" id=1] [ext_resource path="res://script/title screen/Title-Screen-Background.png" type="Texture" id=2] @@ -8,6 +8,8 @@ [ext_resource path="res://scenes/ships/3ShipB.tscn" type="PackedScene" id=6] [ext_resource path="res://scenes/ships/3shipA.tscn" type="PackedScene" id=7] [ext_resource path="res://scenes/ships/4Ship.tscn" type="PackedScene" id=8] +[ext_resource path="res://assets/game/RedCrosshair.png" type="Texture" id=9] +[ext_resource path="res://script/game/Gameplay/Crosshair.gd" type="Script" id=10] [node name="Game" type="Control"] anchor_right = 1.0 @@ -38,6 +40,11 @@ __meta__ = { "_edit_lock_": true } +[node name="Crosshair" type="Sprite" parent="."] +visible = false +texture = ExtResource( 9 ) +script = ExtResource( 10 ) + [node name="VBoxContainer" type="VBoxContainer" parent="."] anchor_left = 0.912 anchor_top = 0.932 @@ -131,7 +138,19 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="Fire" type="Button" parent="."] +visible = false +margin_left = 443.545 +margin_top = 264.473 +margin_right = 528.545 +margin_bottom = 318.473 +text = "FIRE" +__meta__ = { +"_edit_use_anchors_": false +} + [connection signal="pressed" from="VBoxContainer/Forfeit" to="." method="_on_Forfeit_pressed"] [connection signal="about_to_show" from="ConfirmationDialog" to="." method="_on_ConfirmationDialog_about_to_show"] [connection signal="pressed" from="Confirm Placement" to="." method="_on_Confirm_Placement_pressed"] [connection signal="pressed" from="Clear" to="." method="_on_Clear_pressed"] +[connection signal="pressed" from="Fire" to="." method="_on_Fire_pressed"] diff --git a/godot_ship/script/game/Gameplay.gd b/godot_ship/script/game/Gameplay.gd index 2f8f64b..5f404c3 100644 --- a/godot_ship/script/game/Gameplay.gd +++ b/godot_ship/script/game/Gameplay.gd @@ -1,7 +1,12 @@ extends Control onready var Ships = ["2Ship", "3ShipA", "3ShipB", "4Ship", "5Ship"] +onready var Crosshair +class Location: + var Coor: Vector2 + var Length: int + var Orientation: bool #vertical is true, (Trueship = vertical) (Falseship = horizontal) # Called when the node enters the scene tree for the first time. func _ready(): @@ -25,10 +30,50 @@ func _on_Confirm_Placement_pressed(): print ("Placement: ", valid) if valid == false: get_node("AcceptDialog").popup() + else: + #Saves the location of ships and length of ship into an array + var shipLocation = [] + for ship in Ships: + var location = Location.new() + location.Coor = get_node(ship).position + location.Length = get_node(ship).get("ship_length") + location.Orientation = get_node(ship).get("vertical") + shipLocation.append(location) + + #print out the array for testing + for x in shipLocation: + print("Ship Length: ", x.Length, ", Ship Orientation: ", x.Orientation, "Ship Coor: ", x.Coor) + + #Hides the ship placement UI + var confirmButton = get_node("Confirm Placement") + var clearButton = get_node("Clear") + var ship1 = get_node("2Ship") + var ship2 = get_node("3ShipA") + var ship3 = get_node("3ShipB") + var ship4 = get_node("4Ship") + var ship5 = get_node("5Ship") + confirmButton.visible = false + clearButton.visible = false + ship1.visible = false + ship2.visible = false + ship3.visible = false + ship4.visible = false + ship5.visible = false + + #Changes to firing mode, makes the fireing mode UI visible (The location of this can be changed later. This position is for testing) + var crosshair = get_node("Crosshair") + var fireButton = get_node("Fire") + crosshair.visible = true + fireButton.visible = true return valid # Replace with function body. - func _on_Clear_pressed(): for ship in Ships: get_node(ship).clear() pass # Replace with function body. + + +func _on_Fire_pressed(): + var crosshair = get_node("Crosshair") + print("Fire at position: ", crosshair.position) + pass # Replace with function body. diff --git a/godot_ship/script/game/Gameplay/Crosshair.gd b/godot_ship/script/game/Gameplay/Crosshair.gd new file mode 100644 index 0000000..3790674 --- /dev/null +++ b/godot_ship/script/game/Gameplay/Crosshair.gd @@ -0,0 +1,29 @@ +extends Sprite + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +var snapped = false #when snapped if true crosshair stops following mouse + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +func _physics_process(delta): + if snapped == false: + position += (get_global_mouse_position() - position)/10 + +func _input(event): + #Check if left click is being clicked and the sprite is visible (i.e only checks for inputs after ship positions are confirmed) + if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and visible == true: + #Locks the position of the crosshair with left click + snapped = true + if event is InputEventMouseButton and event.button_index == BUTTON_RIGHT and visible == true: + #Unlocks the position of the crosshair with right click + snapped = false + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass