Sun, Shovel, Fastforward, GUI Improvements

This commit is contained in:
Фёдор Веселов 2024-09-16 09:57:11 +05:00
commit 63935d5978
28 changed files with 546 additions and 45 deletions

View file

@ -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);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

View file

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

7
assets/sprites/cone.tres Normal file
View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 B

View file

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

View file

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

View file

@ -4,4 +4,4 @@
[resource] [resource]
atlas = ExtResource("1_cq0f1") atlas = ExtResource("1_cq0f1")
region = Rect2(36, 264, 36, 36) region = Rect2(72, 264, 36, 36)

View file

@ -4,4 +4,4 @@
[resource] [resource]
atlas = ExtResource("1_s2rs0") atlas = ExtResource("1_s2rs0")
region = Rect2(14, 145, 51, 47) region = Rect2(0, 145, 51, 47)

View file

@ -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) , 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] [layer_names]

View file

@ -11,4 +11,4 @@ Scene = ExtResource("1_rqf2x")
ReloadTime = 5.0 ReloadTime = 5.0
StartReloadTime = 0.0 StartReloadTime = 0.0
Preview = ExtResource("1_rnq6r") Preview = ExtResource("1_rnq6r")
layer = 1 Layer = 1

View file

@ -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="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="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://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://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://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"] [node name="debug_lvl" type="Node2D"]
@ -19,7 +21,6 @@ metadata/_edit_lock_ = true
[node name="RuntimeLevelData" type="Node" parent="."] [node name="RuntimeLevelData" type="Node" parent="."]
script = ExtResource("1_i3bf5") script = ExtResource("1_i3bf5")
SunCount = 5000
[node name="Pools" parent="." instance=ExtResource("3_jv7x4")] [node name="Pools" parent="." instance=ExtResource("3_jv7x4")]
@ -27,9 +28,20 @@ SunCount = 5000
layer = 10 layer = 10
[node name="RuntimeGUI" parent="GuiLayer" instance=ExtResource("6_0baou")] [node name="RuntimeGUI" parent="GuiLayer" instance=ExtResource("6_0baou")]
metadata/_edit_lock_ = true
[node name="Overlay" type="CanvasLayer" parent="."] [node name="Overlay" type="CanvasLayer" parent="."]
layer = 5 layer = 6
follow_viewport_enabled = true follow_viewport_enabled = true
[node name="FieldController" parent="Overlay" instance=ExtResource("5_lwpg6")] [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"]

View file

@ -62,6 +62,7 @@ resource_local_to_scene = true
b = Vector2(5.865, 0) b = Vector2(5.865, 0)
[node name="Peashooter" type="Node2D"] [node name="Peashooter" type="Node2D"]
y_sort_enabled = true
script = ExtResource("1_f4h5i") script = ExtResource("1_f4h5i")
[node name="Sprite" type="Sprite2D" parent="."] [node name="Sprite" type="Sprite2D" parent="."]

View file

@ -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="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"] [node name="FastForwardButton" type="TextureButton"]
anchors_preset = -1 anchors_preset = -1
@ -10,3 +13,9 @@ size_flags_vertical = 4
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
texture_normal = ExtResource("1_ta3h7") texture_normal = ExtResource("1_ta3h7")
stretch_mode = 0 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"]

View file

@ -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://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="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="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"] [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 offset_right = -0.200005
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
texture_normal = ExtResource("5_2k0xq") texture_normal = ExtResource("5_2k0xq")
texture_disabled = ExtResource("2_odd6g")
texture_focused = ExtResource("2_5mpv8") texture_focused = ExtResource("2_5mpv8")
stretch_mode = 0 stretch_mode = 0
script = ExtResource("3_eer7n") script = ExtResource("3_eer7n")

View file

@ -25,6 +25,7 @@ anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
mouse_filter = 2
theme = ExtResource("1_xf6ra") theme = ExtResource("1_xf6ra")
[node name="Hotbar" type="HBoxContainer" parent="."] [node name="Hotbar" type="HBoxContainer" parent="."]
@ -34,7 +35,7 @@ anchor_right = 1.0
anchor_bottom = 0.14 anchor_bottom = 0.14
offset_bottom = -29.0 offset_bottom = -29.0
grow_horizontal = 2 grow_horizontal = 2
metadata/_edit_use_anchors_ = true mouse_filter = 2
[node name="SunCounter" parent="Hotbar" instance=ExtResource("1_le3od")] [node name="SunCounter" parent="Hotbar" instance=ExtResource("1_le3od")]
layout_mode = 2 layout_mode = 2
@ -45,6 +46,7 @@ theme_override_styles/panel = SubResource("StyleBoxTexture_ps2iw")
[node name="Seedpackets" type="HBoxContainer" parent="Hotbar/PanelContainer"] [node name="Seedpackets" type="HBoxContainer" parent="Hotbar/PanelContainer"]
layout_mode = 2 layout_mode = 2
mouse_filter = 2
theme_override_constants/separation = 0 theme_override_constants/separation = 0
[node name="FirstSlot" parent="Hotbar/PanelContainer/Seedpackets" instance=ExtResource("2_cjtsw")] [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")] [node name="ShovelButton" parent="Hotbar" instance=ExtResource("3_bheea")]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 1
size_flags_vertical = 4
[node name="FastForwardButton" parent="Hotbar" instance=ExtResource("4_66uy4")] [node name="FastForwardButton" parent="Hotbar" instance=ExtResource("4_66uy4")]
layout_mode = 2 layout_mode = 2

View file

@ -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://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"] [node name="ShovelButton" type="TextureButton"]
anchors_preset = -1 anchors_preset = -1
@ -11,5 +13,18 @@ offset_bottom = -6.8
size_flags_horizontal = 4 size_flags_horizontal = 4
size_flags_vertical = 0 size_flags_vertical = 0
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
toggle_mode = true
texture_normal = ExtResource("1_46afk") texture_normal = ExtResource("1_46afk")
texture_pressed = ExtResource("2_pw2pj")
stretch_mode = 0 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"]

View file

@ -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="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="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"] [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_right = -0.200001
offset_bottom = 0.199999 offset_bottom = 0.199999
size_flags_vertical = 0 size_flags_vertical = 0
theme = ExtResource("1_vhhcn")
texture = ExtResource("1_e5x4k") texture = ExtResource("1_e5x4k")
[node name="Sun" type="TextureRect" parent="."] [node name="Sun" type="TextureRect" parent="."]
@ -37,11 +39,11 @@ anchors_preset = -1
anchor_left = 0.122 anchor_left = 0.122
anchor_top = 0.222 anchor_top = 0.222
anchor_right = 0.878 anchor_right = 0.878
anchor_bottom = 0.778 anchor_bottom = 0.815
offset_left = 0.0219994 offset_left = 0.0219994
offset_top = 0.00599957 offset_top = 0.00599957
offset_right = -0.0219994 offset_right = -0.0219994
offset_bottom = -0.00600243 offset_bottom = -0.00500107
label_settings = SubResource("LabelSettings_lxkq5") label_settings = SubResource("LabelSettings_lxkq5")
horizontal_alignment = 1 horizontal_alignment = 1
vertical_alignment = 1 vertical_alignment = 1

174
scenes/sun.tscn Normal file
View file

@ -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"]

View file

@ -4,15 +4,36 @@ using System;
public partial class Cursor : Node public partial class Cursor : Node
{ {
public static Cursor Instance { get; private set; } public static Cursor Instance { get; private set; }
public bool shovel = false;
public bool plant = false;
public override void _Ready() public override void _Ready()
{ {
Instance = this; Instance = this;
SetDefaultCursor(); SetDefaultCursor();
} }
public void UpdateCursor()
{
if (shovel)
{
SetShovelCursor();
return;
}
if (plant)
{
SetPlantCursor();
return;
}
SetDefaultCursor() ;
}
public void SetDefaultCursor() public void SetDefaultCursor()
{ {
Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("res://assets/sprites/atlases/cursor/default_arrow.png")); Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("res://assets/sprites/atlases/cursor/default_arrow.png"),shape:Input.CursorShape.Arrow);
Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("res://assets/sprites/atlases/cursor/default_point.png"),shape:Input.CursorShape.PointingHand); Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("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<Texture2D>("res://assets/sprites/atlases/cursor/plant_arrow.png")); Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("res://assets/sprites/atlases/cursor/plant_arrow.png"));
} }
public void SetShovelCursor()
{
Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("res://assets/sprites/atlases/cursor/shovel_arrow.png"));
}
} }

31
scripts/Sun.cs Normal file
View file

@ -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");
}
}
}

View file

@ -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;
}
}

View file

@ -8,11 +8,21 @@ public partial class PlantSlot : TextureButton
[Export] private TextureRect _icon; [Export] private TextureRect _icon;
[Export] private Timer _timer; [Export] private Timer _timer;
private bool _recharging;
public override void _Ready() public override void _Ready()
{ {
if (_resource != null) if (_resource != null)
UpdateContents(); 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 ) public void SetPlantResource( PlantResource resource )
{ {
@ -43,8 +53,7 @@ public partial class PlantSlot : TextureButton
public void Recharge() public void Recharge()
{ {
Disabled = true; _recharging = true;
FocusMode = FocusModeEnum.None;
ReleaseFocus(); ReleaseFocus();
@ -53,7 +62,6 @@ public partial class PlantSlot : TextureButton
private void Timeout() private void Timeout()
{ {
Disabled = false; _recharging = false;
FocusMode = FocusModeEnum.All;
} }
} }

View file

@ -0,0 +1,39 @@
using Godot;
using System;
public partial class ShovelButton : TextureButton
{
private RayCast2D _shovelCast;
public override void _Ready()
{
_shovelCast = GetNode<RayCast2D>("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;
}
}
}

View file

@ -7,6 +7,7 @@ public partial class PlantField : Node2D
private PlantResource _resource; private PlantResource _resource;
private PlantSlot _slot; private PlantSlot _slot;
private bool _previousCanPlace;
public override void _Ready() public override void _Ready()
{ {
LevelController.Instance.PlantField = this; 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 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 && inBoundary
&& LevelController.Instance.Pools.EntityField[_resource.Layer].ContainsKey(expected_pos) == false && LevelController.Instance.Pools.EntityField[_resource.Layer].ContainsKey(expected_pos) == false
&& LevelController.Instance.LevelData.CheckSpendSun(_resource.Cost); && LevelController.Instance.LevelData.CheckSpendSun(_resource.Cost);
// Setting visuals // Setting visuals
if (_canPlace) if (_previousCanPlace != canPlace)
{ {
Material.Set("shader_parameter/amount", 0); if (canPlace)
Cursor.Instance.SetPlantCursor(); {
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; _plantSetter.GlobalPosition = expected_pos;
}
else
{
Cursor.Instance.SetDefaultCursor();
Material.Set("shader_parameter/amount", 1);
}
_plantSetter.Texture = _resource == null ? null : _resource.Preview; _plantSetter.Texture = _resource == null ? null : _resource.Preview;
}
// Spawning plant public override void _UnhandledInput(InputEvent @event)
if (Input.IsMouseButtonPressed(MouseButton.Left) {
&& _canPlace ) if (@event.IsActionPressed("cancel_plant") && _slot != null)
{
_slot.ReleaseFocus();
}
if (@event.IsActionPressed("primary_action") && _previousCanPlace)
{ {
var plant = _resource.Scene.Instantiate<RuntimePlantData>(); var plant = _resource.Scene.Instantiate<RuntimePlantData>();
LevelController.Instance.Pools.Plants.AddChild(plant); 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); LevelController.Instance.LevelData.SpendSun(_resource.Cost);
// Unfocusing and recharging slot // Unfocusing and recharging slot
_slot.Recharge(); _slot.Recharge();
}
}
public override void _Input(InputEvent @event)
{
if (@event.IsActionPressed("cancel_plant"))
{
_slot.ReleaseFocus();
} }
} }
} }

View file

@ -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<Sun>();
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);
}
}

View file

@ -38,8 +38,13 @@ public partial class RuntimePlantData : Node2D, IEntity
if (_hp <= 0) if (_hp <= 0)
{ {
LevelController.Instance.Pools.EntityField[Layer].Remove(GlobalPosition); Kill();
QueueFree();
} }
} }
public void Kill()
{
LevelController.Instance.Pools.EntityField[Layer].Remove(GlobalPosition);
QueueFree();
}
} }