From 1c06faf017b1317d9bb05147d1307d7585736e9c Mon Sep 17 00:00:00 2001 From: Chance Atkinson Date: Wed, 24 Nov 2021 00:10:58 -0600 Subject: [PATCH] Hit/Miss sprites rendered Added texture function to Fire.gd to load the correct sprites for a hit/miss and make it so that the player cannot fire on positions that they have already fired at. --- ...s.png-47e352b9aa0deb2bd08f554355b13c14.md5 | 3 + ....png-47e352b9aa0deb2bd08f554355b13c14.stex | Bin 0 -> 1214 bytes .../assets/game/HitMissAtlas.png.import | 34 +++++++++++ godot_ship/light_theme.tres | 4 +- godot_ship/scenes/Game/Fire.tscn | 2 +- godot_ship/script/game/Gameplay/Fire.gd | 54 ++++++++++++++---- 6 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 godot_ship/.import/HitMissAtlas.png-47e352b9aa0deb2bd08f554355b13c14.md5 create mode 100644 godot_ship/.import/HitMissAtlas.png-47e352b9aa0deb2bd08f554355b13c14.stex create mode 100644 godot_ship/assets/game/HitMissAtlas.png.import diff --git a/godot_ship/.import/HitMissAtlas.png-47e352b9aa0deb2bd08f554355b13c14.md5 b/godot_ship/.import/HitMissAtlas.png-47e352b9aa0deb2bd08f554355b13c14.md5 new file mode 100644 index 0000000..1dfc95e --- /dev/null +++ b/godot_ship/.import/HitMissAtlas.png-47e352b9aa0deb2bd08f554355b13c14.md5 @@ -0,0 +1,3 @@ +source_md5="e860aab5fa3b6ce9c5831b3624861eb0" +dest_md5="a265f8881bf649748bb86076a1059462" + diff --git a/godot_ship/.import/HitMissAtlas.png-47e352b9aa0deb2bd08f554355b13c14.stex b/godot_ship/.import/HitMissAtlas.png-47e352b9aa0deb2bd08f554355b13c14.stex new file mode 100644 index 0000000000000000000000000000000000000000..55bfb08e5607fca9fab78d7bed21051e7c543c13 GIT binary patch literal 1214 zcmV;v1VQ^pL{n5i0000W000040000001yWO0001@1ONa~PDdb#P)Px(SV=@dRA_;NHv%(l?wcE3UQg39@4Gp0obT(Ic)lYAFJ3OA zk3XHBMr|h_->MyJ`Wo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f)F?=MF0Q* literal 0 HcmV?d00001 diff --git a/godot_ship/assets/game/HitMissAtlas.png.import b/godot_ship/assets/game/HitMissAtlas.png.import new file mode 100644 index 0000000..4ce2f51 --- /dev/null +++ b/godot_ship/assets/game/HitMissAtlas.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/HitMissAtlas.png-47e352b9aa0deb2bd08f554355b13c14.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/game/HitMissAtlas.png" +dest_files=[ "res://.import/HitMissAtlas.png-47e352b9aa0deb2bd08f554355b13c14.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/light_theme.tres b/godot_ship/light_theme.tres index f7605a8..da4e5b0 100644 --- a/godot_ship/light_theme.tres +++ b/godot_ship/light_theme.tres @@ -19,7 +19,7 @@ corner_radius_bottom_right = 3 corner_radius_bottom_left = 3 shadow_size = 3 -[sub_resource type="DynamicFont" id=4] +[sub_resource type="DynamicFont" id=3] outline_size = 1 extra_spacing_top = 5 extra_spacing_bottom = 3 @@ -27,7 +27,7 @@ extra_spacing_char = 1 font_data = ExtResource( 1 ) [resource] -default_font = SubResource( 4 ) +default_font = SubResource( 3 ) Button/colors/font_color = Color( 0.0784314, 0.0784314, 0.0784314, 1 ) Button/colors/font_color_disabled = Color( 0.9, 0.9, 0.9, 0.2 ) Button/colors/font_color_hover = Color( 0, 0, 0, 1 ) diff --git a/godot_ship/scenes/Game/Fire.tscn b/godot_ship/scenes/Game/Fire.tscn index 7f42da6..fb9cde5 100644 --- a/godot_ship/scenes/Game/Fire.tscn +++ b/godot_ship/scenes/Game/Fire.tscn @@ -40,7 +40,7 @@ __meta__ = { pause_mode = 2 margin_right = 83.0 margin_bottom = 58.0 -dialog_text = "You can't fire outside the board" +dialog_text = "You must select a valid position" [connection signal="pressed" from="Fire" to="." method="_on_Fire_pressed"] [connection signal="confirmed" from="FireDialog" to="." method="_on_FireDialog_confirmed"] diff --git a/godot_ship/script/game/Gameplay/Fire.gd b/godot_ship/script/game/Gameplay/Fire.gd index 6095e69..a172f14 100644 --- a/godot_ship/script/game/Gameplay/Fire.gd +++ b/godot_ship/script/game/Gameplay/Fire.gd @@ -1,5 +1,9 @@ extends Control +var atlas = preload("res://assets/game/HitMissAtlas.png") +var sprites = [] +var hits = [] + # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. @@ -7,22 +11,48 @@ func _ready(): # Signal to pass the fire location back to yet-unknown nodes signal fire_at +func _init(topBoard): + hits = topBoard + func _on_Fire_pressed(): var crosshair = get_node("Crosshair") # Check if the crosshair is in a valid position - if crosshair.validate_position(crosshair.position) == true: + if crosshair.validate_position(crosshair.position): var crosshair_pos = crosshair.world_to_board_space(crosshair.position) - # fires at position - print("Fire at position: ", crosshair_pos) - emit_signal("fire_at", crosshair_pos) - # Close the Firing menu - queue_free() - else: - #if invalid position popup appears - var dialog = get_node("FireDialog") - dialog.popup_centered() - pass # Replace with function body. + if(hits[crosshair_pos.x][crosshair_pos.y] == 0): + # fires at position + print("Fire at position: ", crosshair_pos) + emit_signal("fire_at", crosshair_pos) + # Close the Firing menu + queue_free() + return + #if invalid position popup appears + var dialog = get_node("FireDialog") + dialog.popup_centered() func _on_FireDialog_confirmed(): get_node("Crosshair").visible = true - pass # Replace with function body. + +const OFFSET = Vector2(18, 18) + +func texture(index): + if(hits[index.x][index.y] != 0): + var textureSize = 32 + # It's okay to create a new texture every time, as resources are refcounted + var t = AtlasTexture.new() + t.set_atlas(atlas) + t.margin = Rect2(0, 0, 0, 0) + t.region = Rect2( + 0 if(hits[index.x][index.y] < 0) else textureSize, + 0, + textureSize, + textureSize + ) + # Create a new Sprite to house the texture, or use the existing sprite + var sprite = Sprite.new() + sprite.texture = t + sprite.position = Vector2(index.x, index.y) * textureSize + OFFSET + + printt(t.get_height(), t.get_width()) + + $board_blue.add_child(sprite)