diff --git a/assets/shaders/shared_outline.gdshader b/assets/shaders/shared_outline.gdshader new file mode 100644 index 0000000..374e3fc --- /dev/null +++ b/assets/shaders/shared_outline.gdshader @@ -0,0 +1,23 @@ +shader_type canvas_item; + +uniform vec3 line_colour: source_color = vec3(1.0); +uniform int line_thickness: hint_range(0, 50) = 1; +uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest; + +void fragment() { + vec2 size = SCREEN_PIXEL_SIZE * float(line_thickness); + float line_alpha = 0.0; + for (float i = -size.x; i <= size.x; i += SCREEN_PIXEL_SIZE.x) { + for (float j = -size.y; j <= size.y; j += SCREEN_PIXEL_SIZE.y) { + line_alpha += texture(screen_texture, SCREEN_UV + vec2(i, j)).a; + } + } + vec4 colour = textureLod(screen_texture, SCREEN_UV,0.0); + + if (colour.a > 0.0001) { + colour.rgb /= colour.a; + } + + vec4 outline = vec4(line_colour, min(line_alpha, 1.0)); + COLOR *= mix(outline, colour, colour.a); +} diff --git a/assets/sprites/atlases/atlas1.png b/assets/sprites/atlases/atlas1.png index 5bf7eaa..7e1c4d0 100644 Binary files a/assets/sprites/atlases/atlas1.png and b/assets/sprites/atlases/atlas1.png differ diff --git a/assets/sprites/atlases/sun_atlas.png b/assets/sprites/atlases/sun_atlas.png new file mode 100644 index 0000000..4c69423 Binary files /dev/null and b/assets/sprites/atlases/sun_atlas.png differ diff --git a/assets/sprites/atlases/sun_atlas.png.import b/assets/sprites/atlases/sun_atlas.png.import new file mode 100644 index 0000000..9d043ac --- /dev/null +++ b/assets/sprites/atlases/sun_atlas.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bkmphus5wjadi" +path="res://.godot/imported/sun_atlas.png-b9a6b053b94a7c890cd3dc831a1947ed.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/sprites/atlases/sun_atlas.png" +dest_files=["res://.godot/imported/sun_atlas.png-b9a6b053b94a7c890cd3dc831a1947ed.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/sprites/cone.tres b/assets/sprites/cone.tres new file mode 100644 index 0000000..80b838a --- /dev/null +++ b/assets/sprites/cone.tres @@ -0,0 +1,7 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://ceqvdmude7cgg"] + +[ext_resource type="Texture2D" uid="uid://brj0buevfwv21" path="res://assets/sprites/atlases/zombies/basic.png" id="1_yijc6"] + +[resource] +atlas = ExtResource("1_yijc6") +region = Rect2(0, 0, 31, 33) diff --git a/assets/sprites/gui/DisabledEmptyCard.png b/assets/sprites/gui/DisabledEmptyCard.png new file mode 100644 index 0000000..358042a Binary files /dev/null and b/assets/sprites/gui/DisabledEmptyCard.png differ diff --git a/assets/sprites/gui/DisabledEmptyCard.png.import b/assets/sprites/gui/DisabledEmptyCard.png.import new file mode 100644 index 0000000..ac3a262 --- /dev/null +++ b/assets/sprites/gui/DisabledEmptyCard.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cxlr34yh0bqch" +path="res://.godot/imported/DisabledEmptyCard.png-7f5482b96bf2d482bb3d5df447102c95.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/sprites/gui/DisabledEmptyCard.png" +dest_files=["res://.godot/imported/DisabledEmptyCard.png-7f5482b96bf2d482bb3d5df447102c95.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/sprites/gui/EmptyShovel.tres b/assets/sprites/gui/EmptyShovel.tres new file mode 100644 index 0000000..3171281 --- /dev/null +++ b/assets/sprites/gui/EmptyShovel.tres @@ -0,0 +1,7 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://fd6drk2su0df"] + +[ext_resource type="Texture2D" uid="uid://dvldjlg0nr355" path="res://assets/sprites/atlases/atlas1.png" id="1_i8m7w"] + +[resource] +atlas = ExtResource("1_i8m7w") +region = Rect2(355, 68, 51, 47) diff --git a/assets/sprites/gui/FastForward2.tres b/assets/sprites/gui/FastForward2.tres index f290aac..281bf4e 100644 --- a/assets/sprites/gui/FastForward2.tres +++ b/assets/sprites/gui/FastForward2.tres @@ -4,4 +4,4 @@ [resource] atlas = ExtResource("1_cq0f1") -region = Rect2(36, 264, 36, 36) +region = Rect2(72, 264, 36, 36) diff --git a/assets/sprites/gui/Shovel.tres b/assets/sprites/gui/Shovel.tres index 0b03406..3ccba3b 100644 --- a/assets/sprites/gui/Shovel.tres +++ b/assets/sprites/gui/Shovel.tres @@ -4,4 +4,4 @@ [resource] atlas = ExtResource("1_s2rs0") -region = Rect2(14, 145, 51, 47) +region = Rect2(0, 145, 51, 47) diff --git a/project.godot b/project.godot index b86019d..bc4f520 100644 --- a/project.godot +++ b/project.godot @@ -43,6 +43,11 @@ cancel_plant={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) ] } +primary_action={ +"deadzone": 0.5, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(49, 18),"global_position":Vector2(58, 57),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} [layer_names] diff --git a/resources/plants/Peashooter.tres b/resources/plants/Peashooter.tres index 1cc275a..e8db69e 100644 --- a/resources/plants/Peashooter.tres +++ b/resources/plants/Peashooter.tres @@ -11,4 +11,4 @@ Scene = ExtResource("1_rqf2x") ReloadTime = 5.0 StartReloadTime = 0.0 Preview = ExtResource("1_rnq6r") -layer = 1 +Layer = 1 diff --git a/scenes/debug_lvl.tscn b/scenes/debug_lvl.tscn index 6be467f..1cfc78b 100644 --- a/scenes/debug_lvl.tscn +++ b/scenes/debug_lvl.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=6 format=3 uid="uid://crxsvv7drckpw"] +[gd_scene load_steps=8 format=3 uid="uid://crxsvv7drckpw"] [ext_resource type="Script" path="res://scripts/components/level/RuntimeLevelData.cs" id="1_i3bf5"] [ext_resource type="Texture2D" uid="uid://b0tb2hjum40aw" path="res://assets/sprites/summertime_saga.png" id="2_vmxhy"] [ext_resource type="PackedScene" uid="uid://cg8713v6c5w15" path="res://scenes/pools.tscn" id="3_jv7x4"] [ext_resource type="PackedScene" uid="uid://devn21c7luf45" path="res://scenes/level components/field_controller.tscn" id="5_lwpg6"] [ext_resource type="PackedScene" uid="uid://cfnmspei3k4p7" path="res://scenes/gui/runtime_gui.tscn" id="6_0baou"] +[ext_resource type="PackedScene" uid="uid://bpekho7leatr5" path="res://scenes/sun.tscn" id="6_ay12k"] +[ext_resource type="Script" path="res://scripts/components/level/SunSpawner.cs" id="6_lkguy"] [node name="debug_lvl" type="Node2D"] @@ -19,7 +21,6 @@ metadata/_edit_lock_ = true [node name="RuntimeLevelData" type="Node" parent="."] script = ExtResource("1_i3bf5") -SunCount = 5000 [node name="Pools" parent="." instance=ExtResource("3_jv7x4")] @@ -27,9 +28,20 @@ SunCount = 5000 layer = 10 [node name="RuntimeGUI" parent="GuiLayer" instance=ExtResource("6_0baou")] +metadata/_edit_lock_ = true [node name="Overlay" type="CanvasLayer" parent="."] -layer = 5 +layer = 6 follow_viewport_enabled = true [node name="FieldController" parent="Overlay" instance=ExtResource("5_lwpg6")] + +[node name="SunSpawner" type="Node" parent="."] +script = ExtResource("6_lkguy") +SunScene = ExtResource("6_ay12k") + +[node name="Timer" type="Timer" parent="SunSpawner"] +wait_time = 5.0 +autostart = true + +[connection signal="timeout" from="SunSpawner/Timer" to="SunSpawner" method="Spawn"] diff --git a/scenes/entities/plants/peashooter.tscn b/scenes/entities/plants/peashooter.tscn index 1eddc8d..82c37e0 100644 --- a/scenes/entities/plants/peashooter.tscn +++ b/scenes/entities/plants/peashooter.tscn @@ -62,6 +62,7 @@ resource_local_to_scene = true b = Vector2(5.865, 0) [node name="Peashooter" type="Node2D"] +y_sort_enabled = true script = ExtResource("1_f4h5i") [node name="Sprite" type="Sprite2D" parent="."] diff --git a/scenes/gui/fast_forward_button.tscn b/scenes/gui/fast_forward_button.tscn index 1894c21..fdc01d7 100644 --- a/scenes/gui/fast_forward_button.tscn +++ b/scenes/gui/fast_forward_button.tscn @@ -1,6 +1,9 @@ -[gd_scene load_steps=2 format=3 uid="uid://cgm7td1hgs0rr"] +[gd_scene load_steps=5 format=3 uid="uid://cgm7td1hgs0rr"] [ext_resource type="Texture2D" uid="uid://bjsar1x67xk1t" path="res://assets/sprites/gui/FastForward1.tres" id="1_ta3h7"] +[ext_resource type="Script" path="res://scripts/components/gui/FastForwardButton.cs" id="2_wle4k"] +[ext_resource type="Texture2D" uid="uid://dfr5ofieigu5j" path="res://assets/sprites/gui/FastForward2.tres" id="3_fj838"] +[ext_resource type="Texture2D" uid="uid://qgmsoocd4p1o" path="res://assets/sprites/gui/FastForward3.tres" id="4_2wmv1"] [node name="FastForwardButton" type="TextureButton"] anchors_preset = -1 @@ -10,3 +13,9 @@ size_flags_vertical = 4 mouse_default_cursor_shape = 2 texture_normal = ExtResource("1_ta3h7") stretch_mode = 0 +script = ExtResource("2_wle4k") +firstSpeed = ExtResource("1_ta3h7") +secondSpeed = ExtResource("3_fj838") +thirdSpeed = ExtResource("4_2wmv1") + +[connection signal="pressed" from="." to="." method="OnPressed"] diff --git a/scenes/gui/plant_card.tscn b/scenes/gui/plant_card.tscn index c3bf4ea..e5ef501 100644 --- a/scenes/gui/plant_card.tscn +++ b/scenes/gui/plant_card.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=9 format=3 uid="uid://c8qru1yhnbbkl"] +[gd_scene load_steps=10 format=3 uid="uid://c8qru1yhnbbkl"] [ext_resource type="Texture2D" uid="uid://cabpf23ndlvx0" path="res://assets/sprites/gui/Selection.tres" id="2_5mpv8"] +[ext_resource type="Texture2D" uid="uid://cxlr34yh0bqch" path="res://assets/sprites/gui/DisabledEmptyCard.png" id="2_odd6g"] [ext_resource type="Script" path="res://scripts/components/gui/PlantSlot.cs" id="3_eer7n"] [ext_resource type="Shader" path="res://assets/shaders/gui_masking.gdshader" id="4_bryew"] [ext_resource type="Texture2D" uid="uid://dxyf557m4mq1p" path="res://assets/sprites/gui/EmptyPlantCard.png" id="5_2k0xq"] @@ -22,6 +23,7 @@ anchor_bottom = 0.28 offset_right = -0.200005 mouse_default_cursor_shape = 2 texture_normal = ExtResource("5_2k0xq") +texture_disabled = ExtResource("2_odd6g") texture_focused = ExtResource("2_5mpv8") stretch_mode = 0 script = ExtResource("3_eer7n") diff --git a/scenes/gui/runtime_gui.tscn b/scenes/gui/runtime_gui.tscn index 7787a43..9a4f185 100644 --- a/scenes/gui/runtime_gui.tscn +++ b/scenes/gui/runtime_gui.tscn @@ -25,6 +25,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 theme = ExtResource("1_xf6ra") [node name="Hotbar" type="HBoxContainer" parent="."] @@ -34,7 +35,7 @@ anchor_right = 1.0 anchor_bottom = 0.14 offset_bottom = -29.0 grow_horizontal = 2 -metadata/_edit_use_anchors_ = true +mouse_filter = 2 [node name="SunCounter" parent="Hotbar" instance=ExtResource("1_le3od")] layout_mode = 2 @@ -45,6 +46,7 @@ theme_override_styles/panel = SubResource("StyleBoxTexture_ps2iw") [node name="Seedpackets" type="HBoxContainer" parent="Hotbar/PanelContainer"] layout_mode = 2 +mouse_filter = 2 theme_override_constants/separation = 0 [node name="FirstSlot" parent="Hotbar/PanelContainer/Seedpackets" instance=ExtResource("2_cjtsw")] @@ -79,6 +81,8 @@ layout_mode = 2 [node name="ShovelButton" parent="Hotbar" instance=ExtResource("3_bheea")] layout_mode = 2 +size_flags_horizontal = 1 +size_flags_vertical = 4 [node name="FastForwardButton" parent="Hotbar" instance=ExtResource("4_66uy4")] layout_mode = 2 diff --git a/scenes/gui/shovel_button.tscn b/scenes/gui/shovel_button.tscn index b147ab6..079a13f 100644 --- a/scenes/gui/shovel_button.tscn +++ b/scenes/gui/shovel_button.tscn @@ -1,6 +1,8 @@ -[gd_scene load_steps=2 format=3 uid="uid://t0vpmycj6c8j"] +[gd_scene load_steps=4 format=3 uid="uid://t0vpmycj6c8j"] [ext_resource type="Texture2D" uid="uid://cw73vihkrfenc" path="res://assets/sprites/gui/Shovel.tres" id="1_46afk"] +[ext_resource type="Texture2D" uid="uid://fd6drk2su0df" path="res://assets/sprites/gui/EmptyShovel.tres" id="2_pw2pj"] +[ext_resource type="Script" path="res://scripts/components/gui/ShovelButton.cs" id="3_u6gir"] [node name="ShovelButton" type="TextureButton"] anchors_preset = -1 @@ -11,5 +13,18 @@ offset_bottom = -6.8 size_flags_horizontal = 4 size_flags_vertical = 0 mouse_default_cursor_shape = 2 +toggle_mode = true texture_normal = ExtResource("1_46afk") +texture_pressed = ExtResource("2_pw2pj") stretch_mode = 0 +script = ExtResource("3_u6gir") + +[node name="RayCast2D" type="RayCast2D" parent="."] +enabled = false +target_position = Vector2(0, 0) +collision_mask = 2 +hit_from_inside = true +collide_with_areas = true +collide_with_bodies = false + +[connection signal="focus_exited" from="." to="." method="OnFocusExited"] diff --git a/scenes/gui/sun_counter.tscn b/scenes/gui/sun_counter.tscn index b16ee0f..034a2ab 100644 --- a/scenes/gui/sun_counter.tscn +++ b/scenes/gui/sun_counter.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=5 format=3 uid="uid://ky35veswaytr"] +[gd_scene load_steps=6 format=3 uid="uid://ky35veswaytr"] [ext_resource type="Texture2D" uid="uid://bhp3vuvwf7lak" path="res://assets/sprites/gui/suncounter.tres" id="1_e5x4k"] +[ext_resource type="Theme" uid="uid://b8l285cjcgeyi" path="res://resources/GameStyle.tres" id="1_vhhcn"] [ext_resource type="Texture2D" uid="uid://c47rflkf2wap0" path="res://assets/sprites/sun.tres" id="2_gugre"] [ext_resource type="Script" path="res://scripts/components/gui/SunCounter.cs" id="3_qhmb8"] @@ -15,6 +16,7 @@ anchor_bottom = 0.067 offset_right = -0.200001 offset_bottom = 0.199999 size_flags_vertical = 0 +theme = ExtResource("1_vhhcn") texture = ExtResource("1_e5x4k") [node name="Sun" type="TextureRect" parent="."] @@ -37,11 +39,11 @@ anchors_preset = -1 anchor_left = 0.122 anchor_top = 0.222 anchor_right = 0.878 -anchor_bottom = 0.778 +anchor_bottom = 0.815 offset_left = 0.0219994 offset_top = 0.00599957 offset_right = -0.0219994 -offset_bottom = -0.00600243 +offset_bottom = -0.00500107 label_settings = SubResource("LabelSettings_lxkq5") horizontal_alignment = 1 vertical_alignment = 1 diff --git a/scenes/sun.tscn b/scenes/sun.tscn new file mode 100644 index 0000000..4d40d07 --- /dev/null +++ b/scenes/sun.tscn @@ -0,0 +1,174 @@ +[gd_scene load_steps=13 format=3 uid="uid://bpekho7leatr5"] + +[ext_resource type="Shader" path="res://assets/shaders/shared_outline.gdshader" id="1_jcu1f"] +[ext_resource type="Script" path="res://scripts/Sun.cs" id="2_m8xcj"] +[ext_resource type="Texture2D" uid="uid://bkmphus5wjadi" path="res://assets/sprites/atlases/sun_atlas.png" id="2_phn3y"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_u0o5k"] +shader = ExtResource("1_jcu1f") +shader_parameter/line_colour = Color(1, 0.568627, 0.4, 1) +shader_parameter/line_thickness = 3 + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_n4y82"] +shader = ExtResource("1_jcu1f") +shader_parameter/line_colour = Color(1, 0.568627, 0.4, 1) +shader_parameter/line_thickness = 3 + +[sub_resource type="Animation" id="Animation_jfrge"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CanvasGroup/DownerStar:rotation") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [0.0] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("CanvasGroup/UpperStar:rotation") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [0.0] +} + +[sub_resource type="Animation" id="Animation_rvj0j"] +resource_name = "main" +length = 10.0 +loop_mode = 1 +step = 0.5 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CanvasGroup/DownerStar:rotation") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 5, 10), +"transitions": PackedFloat32Array(1, 1, 1), +"update": 0, +"values": [0.0, 6.28319, 12.5664] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("CanvasGroup/UpperStar:rotation") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 10), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [0.0, -6.28319] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_juv2v"] +_data = { +"RESET": SubResource("Animation_jfrge"), +"main": SubResource("Animation_rvj0j") +} + +[sub_resource type="Animation" id="Animation_t53pt"] +length = 0.001 +tracks/0/type = "bezier" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CanvasGroup:modulate:a") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"handle_modes": PackedInt32Array(0), +"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0) +} + +[sub_resource type="Animation" id="Animation_xyill"] +resource_name = "main" +loop_mode = 1 +tracks/0/type = "bezier" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CanvasGroup:modulate:a") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"handle_modes": PackedInt32Array(0, 0, 0), +"points": PackedFloat32Array(1, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0, 0.5, 0.986673) +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_p7c0n"] +_data = { +"RESET": SubResource("Animation_t53pt"), +"main": SubResource("Animation_xyill") +} + +[sub_resource type="CircleShape2D" id="CircleShape2D_7hl7x"] +radius = 19.0 + +[node name="Sun" type="Area2D" node_paths=PackedStringArray("_deathTimer", "_rotation", "_fade")] +material = SubResource("ShaderMaterial_u0o5k") +script = ExtResource("2_m8xcj") +_deathTimer = NodePath("DeathTimer") +_rotation = NodePath("RotationAnimation") +_fade = NodePath("FadeAnimation") + +[node name="CanvasGroup" type="CanvasGroup" parent="."] +material = SubResource("ShaderMaterial_n4y82") + +[node name="DownerStar" type="Sprite2D" parent="CanvasGroup"] +show_behind_parent = true +texture = ExtResource("2_phn3y") +vframes = 3 + +[node name="UpperStar" type="Sprite2D" parent="CanvasGroup"] +show_behind_parent = true +texture = ExtResource("2_phn3y") +vframes = 3 +frame = 1 + +[node name="Circle" type="Sprite2D" parent="CanvasGroup"] +show_behind_parent = true +texture = ExtResource("2_phn3y") +vframes = 3 +frame = 2 + +[node name="RotationAnimation" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_juv2v") +} +autoplay = "main" + +[node name="FadeAnimation" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_p7c0n") +} + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_7hl7x") + +[node name="DeathTimer" type="Timer" parent="."] +wait_time = 30.0 +one_shot = true +autostart = true + +[node name="CursorControl" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_left = -19.0 +offset_top = -19.0 +offset_right = 19.0 +offset_bottom = 19.0 +mouse_filter = 1 +mouse_default_cursor_shape = 2 + +[connection signal="timeout" from="DeathTimer" to="." method="queue_free"] diff --git a/scripts/Cursor.cs b/scripts/Cursor.cs index 0159278..2e96119 100644 --- a/scripts/Cursor.cs +++ b/scripts/Cursor.cs @@ -4,15 +4,36 @@ using System; public partial class Cursor : Node { public static Cursor Instance { get; private set; } + + public bool shovel = false; + public bool plant = false; + public override void _Ready() { Instance = this; SetDefaultCursor(); } + public void UpdateCursor() + { + if (shovel) + { + SetShovelCursor(); + return; + } + + if (plant) + { + SetPlantCursor(); + return; + } + + SetDefaultCursor() ; + } + public void SetDefaultCursor() { - Input.SetCustomMouseCursor(ResourceLoader.Load("res://assets/sprites/atlases/cursor/default_arrow.png")); + Input.SetCustomMouseCursor(ResourceLoader.Load("res://assets/sprites/atlases/cursor/default_arrow.png"),shape:Input.CursorShape.Arrow); Input.SetCustomMouseCursor(ResourceLoader.Load("res://assets/sprites/atlases/cursor/default_point.png"),shape:Input.CursorShape.PointingHand); } @@ -20,4 +41,9 @@ public partial class Cursor : Node { Input.SetCustomMouseCursor(ResourceLoader.Load("res://assets/sprites/atlases/cursor/plant_arrow.png")); } + + public void SetShovelCursor() + { + Input.SetCustomMouseCursor(ResourceLoader.Load("res://assets/sprites/atlases/cursor/shovel_arrow.png")); + } } diff --git a/scripts/Sun.cs b/scripts/Sun.cs new file mode 100644 index 0000000..bba8a44 --- /dev/null +++ b/scripts/Sun.cs @@ -0,0 +1,31 @@ +using Godot; +using System; + +public partial class Sun : Area2D +{ + [Export] public int amount = 25; + [Export] private Timer _deathTimer; + [Export] private AnimationPlayer _rotation; + [Export] private AnimationPlayer _fade; + + public override void _Ready() + { + _rotation.SpeedScale = 1.0f + GD.Randf() / 2.0f; + } + public override void _InputEvent(Viewport viewport, InputEvent @event, int shapeIdx) + { + if (@event.IsActionPressed("primary_action")) + { + LevelController.Instance.LevelData.AddSun(amount); + QueueFree(); + } + } + + public override void _Process(double delta) + { + if (_deathTimer.TimeLeft/_deathTimer.WaitTime <= 0.25) + { + _fade.Play("main"); + } + } +} diff --git a/scripts/components/gui/FastForwardButton.cs b/scripts/components/gui/FastForwardButton.cs new file mode 100644 index 0000000..206edbe --- /dev/null +++ b/scripts/components/gui/FastForwardButton.cs @@ -0,0 +1,31 @@ +using Godot; +using System; + +public partial class FastForwardButton : TextureButton +{ + [Export] private Texture2D firstSpeed; + [Export] private Texture2D secondSpeed; + [Export] private Texture2D thirdSpeed; + + private int speed = 1; + + public void OnPressed() + { + speed = Mathf.Wrap(speed+1, 1, 4); + + switch (speed) + { + case 1: + TextureNormal = firstSpeed; + break; + case 2: + TextureNormal = secondSpeed; + break; + case 3: + TextureNormal = thirdSpeed; + break; + } + + Engine.TimeScale = speed; + } +} diff --git a/scripts/components/gui/PlantSlot.cs b/scripts/components/gui/PlantSlot.cs index f18302f..4537b5c 100644 --- a/scripts/components/gui/PlantSlot.cs +++ b/scripts/components/gui/PlantSlot.cs @@ -8,11 +8,21 @@ public partial class PlantSlot : TextureButton [Export] private TextureRect _icon; [Export] private Timer _timer; + private bool _recharging; + public override void _Ready() { if (_resource != null) UpdateContents(); } + public override void _Process(double delta) + { + if (_resource != null) + { + Disabled = _recharging || LevelController.Instance.LevelData.SunCount < _resource.Cost; + FocusMode = Disabled ? FocusModeEnum.None : FocusModeEnum.All; + } + } public void SetPlantResource( PlantResource resource ) { @@ -43,8 +53,7 @@ public partial class PlantSlot : TextureButton public void Recharge() { - Disabled = true; - FocusMode = FocusModeEnum.None; + _recharging = true; ReleaseFocus(); @@ -53,7 +62,6 @@ public partial class PlantSlot : TextureButton private void Timeout() { - Disabled = false; - FocusMode = FocusModeEnum.All; + _recharging = false; } } diff --git a/scripts/components/gui/ShovelButton.cs b/scripts/components/gui/ShovelButton.cs new file mode 100644 index 0000000..35a281f --- /dev/null +++ b/scripts/components/gui/ShovelButton.cs @@ -0,0 +1,39 @@ +using Godot; +using System; + +public partial class ShovelButton : TextureButton +{ + private RayCast2D _shovelCast; + public override void _Ready() + { + _shovelCast = GetNode("RayCast2D"); + _shovelCast.CallDeferred("reparent", GetTree().CurrentScene); + } + private void OnFocusExited() + { + ButtonPressed = false; + } + public override void _Process(double delta) + { + _shovelCast.GlobalPosition = _shovelCast.GetGlobalMousePosition(); + } + public override void _Toggled(bool toggledOn) + { + _shovelCast.Enabled = toggledOn; + + Cursor.Instance.shovel = toggledOn; + Cursor.Instance.UpdateCursor(); + } + + public override void _Input(InputEvent @event) + { + if (@event.IsActionPressed("primary_action")) + { + if (_shovelCast.IsColliding() && (_shovelCast.GetCollider() as CollisionObject2D).GetParent() is RuntimePlantData plant) + { + plant.Kill(); + } + ButtonPressed = false; + } + } +} diff --git a/scripts/components/level/PlantField.cs b/scripts/components/level/PlantField.cs index b690a96..aaaf5ab 100644 --- a/scripts/components/level/PlantField.cs +++ b/scripts/components/level/PlantField.cs @@ -7,6 +7,7 @@ public partial class PlantField : Node2D private PlantResource _resource; private PlantSlot _slot; + private bool _previousCanPlace; public override void _Ready() { LevelController.Instance.PlantField = this; @@ -32,49 +33,52 @@ public partial class PlantField : Node2D bool inBoundary = expected_pos.X > Utility.LeftFieldBoundary.X && expected_pos.X < Utility.RightFieldBoundary.X && expected_pos.Y > Utility.LeftFieldBoundary.Y && expected_pos.Y < Utility.RightFieldBoundary.Y; - bool _canPlace = _resource != null + bool canPlace = _resource != null && inBoundary && LevelController.Instance.Pools.EntityField[_resource.Layer].ContainsKey(expected_pos) == false && LevelController.Instance.LevelData.CheckSpendSun(_resource.Cost); // Setting visuals - if (_canPlace) + if (_previousCanPlace != canPlace) { - Material.Set("shader_parameter/amount", 0); - Cursor.Instance.SetPlantCursor(); + if (canPlace) + { + Material.Set("shader_parameter/amount", 0); + } + else + { + Material.Set("shader_parameter/amount", 1); + } + Cursor.Instance.plant = canPlace; + Cursor.Instance.UpdateCursor(); + } + _previousCanPlace = canPlace; + + if (canPlace) _plantSetter.GlobalPosition = expected_pos; - } - else - { - Cursor.Instance.SetDefaultCursor(); - Material.Set("shader_parameter/amount", 1); - } - _plantSetter.Texture = _resource == null ? null : _resource.Preview; + } - // Spawning plant - if (Input.IsMouseButtonPressed(MouseButton.Left) - && _canPlace ) + public override void _UnhandledInput(InputEvent @event) + { + if (@event.IsActionPressed("cancel_plant") && _slot != null) + { + _slot.ReleaseFocus(); + } + + if (@event.IsActionPressed("primary_action") && _previousCanPlace) { var plant = _resource.Scene.Instantiate(); LevelController.Instance.Pools.Plants.AddChild(plant); - plant.GlobalPosition = expected_pos; + plant.GlobalPosition = (_plantSetter.GlobalPosition / tile).Ceil() * tile - new Vector2(20, 14); + plant.Layer = _resource.Layer; - LevelController.Instance.Pools.EntityField[_resource.Layer].Add(expected_pos, plant as IEntity); + LevelController.Instance.Pools.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant as IEntity); LevelController.Instance.LevelData.SpendSun(_resource.Cost); // Unfocusing and recharging slot _slot.Recharge(); - - } - } - - public override void _Input(InputEvent @event) - { - if (@event.IsActionPressed("cancel_plant")) - { - _slot.ReleaseFocus(); } } } diff --git a/scripts/components/level/SunSpawner.cs b/scripts/components/level/SunSpawner.cs new file mode 100644 index 0000000..6b29156 --- /dev/null +++ b/scripts/components/level/SunSpawner.cs @@ -0,0 +1,28 @@ +using Godot; +using System; + +public partial class SunSpawner : Node +{ + [Export] + public int MinSun = 25; + [Export] + public int MaxSun = 25; + + [Export] + private PackedScene SunScene; + + public void Spawn() + { + float x = GD.Randf()*9*Utility.TileWidth; + uint y = GD.Randi() % 5; + + var sun = SunScene.Instantiate(); + LevelController.Instance.Pools.Projectiles.AddChild(sun); + + sun.GlobalPosition = new Vector2(Utility.LeftFieldBoundary.X + x, -90); + + var moveTween = CreateTween(); + moveTween.TweenProperty(sun,"global_position", new Vector2(Utility.LeftFieldBoundary.X + x, + Utility.LeftFieldBoundary.Y + Utility.TileHeight * y + Utility.TileHeight/2.0f),9-y); + } +} diff --git a/scripts/components/plants/RuntimePlantData.cs b/scripts/components/plants/RuntimePlantData.cs index cd24cc7..fe72a3e 100644 --- a/scripts/components/plants/RuntimePlantData.cs +++ b/scripts/components/plants/RuntimePlantData.cs @@ -38,8 +38,13 @@ public partial class RuntimePlantData : Node2D, IEntity if (_hp <= 0) { - LevelController.Instance.Pools.EntityField[Layer].Remove(GlobalPosition); - QueueFree(); + Kill(); } } + + public void Kill() + { + LevelController.Instance.Pools.EntityField[Layer].Remove(GlobalPosition); + QueueFree(); + } }