seedpacket base
This commit is contained in:
parent
e1931f27e1
commit
2a7c402cd0
16 changed files with 345 additions and 24 deletions
10
resources/plants/aloe.tres
Normal file
10
resources/plants/aloe.tres
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
[gd_resource type="Resource" script_class="SeedpacketResource" load_steps=2 format=3 uid="uid://d1nwlatkrtkpe"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dtjdfji87kybn" path="res://scripts/resources/entity_resource.gd" id="1_giqbo"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_giqbo")
|
||||||
|
cost = 0.0
|
||||||
|
recharge_time = 3.0
|
||||||
|
initial_recharge_percent = 1.0
|
||||||
|
metadata/_custom_type_script = "uid://dtjdfji87kybn"
|
||||||
16
resources/plants/cucumber.tres
Normal file
16
resources/plants/cucumber.tres
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
[gd_resource type="Resource" script_class="SeedpacketResource" load_steps=4 format=3 uid="uid://bwsd31okx0yxc"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://dvldjlg0nr355" path="res://assets/sprites/atlases/atlas1.png" id="1_snnbv"]
|
||||||
|
[ext_resource type="Script" uid="uid://dtjdfji87kybn" path="res://scripts/resources/entity_resource.gd" id="2_fl6wr"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_fl6wr"]
|
||||||
|
atlas = ExtResource("1_snnbv")
|
||||||
|
region = Rect2(353, 241, 41, 65)
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_fl6wr")
|
||||||
|
preview = SubResource("AtlasTexture_fl6wr")
|
||||||
|
cost = 75.0
|
||||||
|
recharge_time = 5.0
|
||||||
|
initial_recharge_percent = 1.0
|
||||||
|
metadata/_custom_type_script = "uid://dtjdfji87kybn"
|
||||||
13
resources/plants/peashooter.tres
Normal file
13
resources/plants/peashooter.tres
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
[gd_resource type="Resource" script_class="SeedpacketResource" load_steps=3 format=3 uid="uid://bf8u3nwwn5e1d"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://ot1n4nval86w" path="res://assets/sprites/plants/peashooter.tres" id="1_o0b0s"]
|
||||||
|
[ext_resource type="Script" uid="uid://dtjdfji87kybn" path="res://scripts/resources/entity_resource.gd" id="2_jwk2v"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_jwk2v")
|
||||||
|
preview = ExtResource("1_o0b0s")
|
||||||
|
cost = 75.0
|
||||||
|
recharge_time = 5.0
|
||||||
|
initial_recharge_percent = 1.0
|
||||||
|
order = 0
|
||||||
|
metadata/_custom_type_script = "uid://dtjdfji87kybn"
|
||||||
13
resources/plants/sunflower.tres
Normal file
13
resources/plants/sunflower.tres
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
[gd_resource type="Resource" script_class="SeedpacketResource" load_steps=3 format=3 uid="uid://4epsulft2pub"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://iw75j816gbc" path="res://assets/sprites/plants/sunflower.tres" id="1_o7rt7"]
|
||||||
|
[ext_resource type="Script" uid="uid://dtjdfji87kybn" path="res://scripts/resources/entity_resource.gd" id="2_6ebgj"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_6ebgj")
|
||||||
|
preview = ExtResource("1_o7rt7")
|
||||||
|
cost = 50.0
|
||||||
|
recharge_time = 5.0
|
||||||
|
initial_recharge_percent = 0.0
|
||||||
|
order = 1
|
||||||
|
metadata/_custom_type_script = "uid://dtjdfji87kybn"
|
||||||
12
resources/plants/wallnut.tres
Normal file
12
resources/plants/wallnut.tres
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
[gd_resource type="Resource" script_class="SeedpacketResource" load_steps=3 format=3 uid="uid://dxe0cnfw2j1x0"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://g2oppl54efja" path="res://assets/sprites/plants/Wallnut.tres" id="1_ggq3n"]
|
||||||
|
[ext_resource type="Script" uid="uid://dtjdfji87kybn" path="res://scripts/resources/entity_resource.gd" id="2_10a4p"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_10a4p")
|
||||||
|
preview = ExtResource("1_ggq3n")
|
||||||
|
cost = 50.0
|
||||||
|
recharge_time = 24.0
|
||||||
|
initial_recharge_percent = 1.0
|
||||||
|
metadata/_custom_type_script = "uid://dtjdfji87kybn"
|
||||||
135
scenes/gui/seedpacket.tscn
Normal file
135
scenes/gui/seedpacket.tscn
Normal file
|
|
@ -0,0 +1,135 @@
|
||||||
|
[gd_scene load_steps=11 format=3 uid="uid://bi4c34ii72y46"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://dxyf557m4mq1p" path="res://assets/sprites/gui/EmptyPlantCard.png" id="1_4rm55"]
|
||||||
|
[ext_resource type="Script" uid="uid://cepaa3acqx70d" path="res://scripts/gui/seedpacket/seedpacket.gd" id="1_c8vxi"]
|
||||||
|
[ext_resource type="Script" uid="uid://bppehhpn0u7ep" path="res://scripts/gui/seedpacket/seedpacket_cost_label.gd" id="3_tntkr"]
|
||||||
|
[ext_resource type="Script" uid="uid://bx7k7g0ebkwef" path="res://scripts/gui/seedpacket/seedpacket_progressbar.gd" id="4_gr8e8"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://dvldjlg0nr355" path="res://assets/sprites/atlases/atlas1.png" id="5_2cmc5"]
|
||||||
|
|
||||||
|
[sub_resource type="LabelSettings" id="LabelSettings_c8vxi"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
font_size = 10
|
||||||
|
font_color = Color(0, 0, 0, 1)
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_tntkr"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_gr8e8"]
|
||||||
|
bg_color = Color(0.12, 0.12, 0.12, 0.490196)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_fon4l"]
|
||||||
|
atlas = ExtResource("5_2cmc5")
|
||||||
|
region = Rect2(475, 68, 39, 51)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_gtmhg"]
|
||||||
|
atlas = ExtResource("5_2cmc5")
|
||||||
|
region = Rect2(561, 78, 28, 33)
|
||||||
|
|
||||||
|
[node name="Seedpacket" type="AspectRatioContainer"]
|
||||||
|
anchors_preset = -1
|
||||||
|
anchor_right = 0.068
|
||||||
|
anchor_bottom = 0.14
|
||||||
|
offset_right = 0.199997
|
||||||
|
ratio = 0.7321
|
||||||
|
script = ExtResource("1_c8vxi")
|
||||||
|
|
||||||
|
[node name="TextureButton" type="TextureButton" parent="."]
|
||||||
|
clip_children = 2
|
||||||
|
layout_mode = 2
|
||||||
|
texture_normal = ExtResource("1_4rm55")
|
||||||
|
stretch_mode = 0
|
||||||
|
|
||||||
|
[node name="Cost" type="Label" parent="TextureButton"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = -1
|
||||||
|
anchor_left = 0.122
|
||||||
|
anchor_top = 0.714
|
||||||
|
anchor_right = 0.878
|
||||||
|
anchor_bottom = 0.911
|
||||||
|
offset_left = -0.00200033
|
||||||
|
offset_top = 0.0159988
|
||||||
|
offset_right = 0.0019989
|
||||||
|
offset_bottom = -0.0159988
|
||||||
|
label_settings = SubResource("LabelSettings_c8vxi")
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 1
|
||||||
|
text_overrun_behavior = 1
|
||||||
|
visible_characters_behavior = 1
|
||||||
|
script = ExtResource("3_tntkr")
|
||||||
|
|
||||||
|
[node name="PreviewContainer" type="Control" parent="TextureButton"]
|
||||||
|
clip_contents = true
|
||||||
|
layout_mode = 1
|
||||||
|
anchor_right = 0.976
|
||||||
|
anchor_bottom = 0.714
|
||||||
|
offset_left = -27.0
|
||||||
|
offset_top = -26.0
|
||||||
|
offset_right = 24.984
|
||||||
|
offset_bottom = -2.984
|
||||||
|
|
||||||
|
[node name="Preview" type="TextureRect" parent="TextureButton/PreviewContainer"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = -1
|
||||||
|
anchor_left = 0.297
|
||||||
|
anchor_top = 0.412
|
||||||
|
anchor_right = 0.74
|
||||||
|
anchor_bottom = 1.302
|
||||||
|
offset_left = -0.324001
|
||||||
|
offset_top = 0.0439987
|
||||||
|
offset_right = -0.0800018
|
||||||
|
offset_bottom = -0.0259933
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
expand_mode = 1
|
||||||
|
stretch_mode = 5
|
||||||
|
|
||||||
|
[node name="RechargeProgress" type="ProgressBar" parent="TextureButton"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
theme_override_styles/background = SubResource("StyleBoxEmpty_tntkr")
|
||||||
|
theme_override_styles/fill = SubResource("StyleBoxFlat_gr8e8")
|
||||||
|
max_value = 1.0
|
||||||
|
fill_mode = 3
|
||||||
|
show_percentage = false
|
||||||
|
script = ExtResource("4_gr8e8")
|
||||||
|
|
||||||
|
[node name="AvaiabilityRect" type="ColorRect" parent="TextureButton"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
color = Color(0, 0, 0, 0.247059)
|
||||||
|
|
||||||
|
[node name="Forbidden" type="TextureRect" parent="TextureButton"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
texture = SubResource("AtlasTexture_fon4l")
|
||||||
|
|
||||||
|
[node name="Locked" type="TextureRect" parent="TextureButton"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_left = 7.0
|
||||||
|
offset_top = 12.0
|
||||||
|
offset_right = -6.0
|
||||||
|
offset_bottom = -11.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
texture = SubResource("AtlasTexture_gtmhg")
|
||||||
|
|
||||||
|
[node name="RechargeTimer" type="Timer" parent="."]
|
||||||
|
|
||||||
|
[connection signal="pressed" from="TextureButton" to="." method="on_pressed"]
|
||||||
61
scripts/gui/seedpacket/seedpacket.gd
Normal file
61
scripts/gui/seedpacket/seedpacket.gd
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
extends AspectRatioContainer
|
||||||
|
|
||||||
|
@onready var button := $TextureButton
|
||||||
|
@onready var preview :=$TextureButton/PreviewContainer/Preview
|
||||||
|
@onready var cost := $TextureButton/Cost
|
||||||
|
@onready var avaibility := $TextureButton/AvaiabilityRect
|
||||||
|
@onready var recharge_timer := $RechargeTimer
|
||||||
|
@onready var forbidden_rect := $TextureButton/Forbidden
|
||||||
|
@onready var locked_rect := $TextureButton/Locked
|
||||||
|
|
||||||
|
var held_resource : SeedpacketResource
|
||||||
|
var forbidden : bool = false
|
||||||
|
var locked : bool = false
|
||||||
|
var hotbar : bool = false
|
||||||
|
var disabled : bool = false
|
||||||
|
|
||||||
|
#region Godot methods
|
||||||
|
func _ready() -> void:
|
||||||
|
LevelEventBus.entity_placed.connect(on_entity_placed)
|
||||||
|
LevelEventBus.sun_count_updated.connect(on_sun_count_updated)
|
||||||
|
LevelEventBus.state_changed.connect(on_level_state_changed)
|
||||||
|
|
||||||
|
func _process(_delta: float) -> void:
|
||||||
|
button.disabled = recharge_timer.time_left > 0 or forbidden or locked or disabled
|
||||||
|
update_contents()
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Signal methods
|
||||||
|
func on_pressed():
|
||||||
|
LevelEventBus.packet_selected.emit(held_resource)
|
||||||
|
if LevelData.state == LevelData.LevelStates.Game:
|
||||||
|
LevelEventBus.packet_selected_during_game.emit(held_resource)
|
||||||
|
|
||||||
|
func on_entity_placed(entity : SeedpacketResource):
|
||||||
|
if entity == held_resource:
|
||||||
|
recharge_timer.start()
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
func set_resource(to : SeedpacketResource):
|
||||||
|
held_resource = to
|
||||||
|
update_contents()
|
||||||
|
|
||||||
|
func update_contents():
|
||||||
|
cost.text = str(held_resource.cost)
|
||||||
|
preview.texture = held_resource.preview
|
||||||
|
avaibility.visible = forbidden or locked or disabled
|
||||||
|
locked_rect.visible = locked
|
||||||
|
forbidden_rect.visible = forbidden
|
||||||
|
|
||||||
|
func on_sun_count_updated(to : float):
|
||||||
|
if hotbar:
|
||||||
|
disabled = held_resource.cost < to
|
||||||
|
|
||||||
|
func on_level_state_changed(state : LevelData.LevelStates):
|
||||||
|
match state:
|
||||||
|
LevelData.LevelStates.Game:
|
||||||
|
disabled = held_resource.cost < LevelData.sun_count
|
||||||
|
LevelData.LevelStates.PlantPick:
|
||||||
|
disabled = false
|
||||||
|
_:
|
||||||
|
disabled = true
|
||||||
1
scripts/gui/seedpacket/seedpacket.gd.uid
Normal file
1
scripts/gui/seedpacket/seedpacket.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cepaa3acqx70d
|
||||||
8
scripts/gui/seedpacket/seedpacket_cost_label.gd
Normal file
8
scripts/gui/seedpacket/seedpacket_cost_label.gd
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
@tool
|
||||||
|
extends Label
|
||||||
|
|
||||||
|
const BASE_FONT_SIZE := 10
|
||||||
|
const BASE_HEIGHT := 11
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
label_settings.font_size = int(BASE_FONT_SIZE * (size.y/BASE_HEIGHT))
|
||||||
1
scripts/gui/seedpacket/seedpacket_cost_label.gd.uid
Normal file
1
scripts/gui/seedpacket/seedpacket_cost_label.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bppehhpn0u7ep
|
||||||
6
scripts/gui/seedpacket/seedpacket_progressbar.gd
Normal file
6
scripts/gui/seedpacket/seedpacket_progressbar.gd
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
extends ProgressBar
|
||||||
|
|
||||||
|
@onready var timer := $"../../RechargeTimer"
|
||||||
|
|
||||||
|
func _process(_delta: float) -> void:
|
||||||
|
value = timer.time_left/timer.wait_time
|
||||||
1
scripts/gui/seedpacket/seedpacket_progressbar.gd.uid
Normal file
1
scripts/gui/seedpacket/seedpacket_progressbar.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bx7k7g0ebkwef
|
||||||
20
scripts/level/level_data.gd
Normal file
20
scripts/level/level_data.gd
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
class_name LevelData
|
||||||
|
|
||||||
|
static var state : LevelStates = LevelStates.NotInGame
|
||||||
|
static var sun_count : float
|
||||||
|
|
||||||
|
## Possible states of level
|
||||||
|
enum LevelStates {
|
||||||
|
## The game is during plant pick stage
|
||||||
|
PlantPick,
|
||||||
|
## The game is not yet started
|
||||||
|
Pregame,
|
||||||
|
## Game started
|
||||||
|
Game,
|
||||||
|
## Game ended
|
||||||
|
Postgame,
|
||||||
|
## Not in a level,
|
||||||
|
NotInGame
|
||||||
|
}
|
||||||
1
scripts/level/level_data.gd.uid
Normal file
1
scripts/level/level_data.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://co3yto3q7mnm7
|
||||||
|
|
@ -4,6 +4,13 @@ extends Node
|
||||||
|
|
||||||
class_name LevelSignals
|
class_name LevelSignals
|
||||||
|
|
||||||
|
#region Field
|
||||||
|
|
||||||
|
## Emitted when entity is placed by player via seedpacket
|
||||||
|
signal entity_placed(entity : SeedpacketResource)
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Entity
|
#region Entity
|
||||||
|
|
||||||
## Called for every entity that enters game
|
## Called for every entity that enters game
|
||||||
|
|
@ -17,20 +24,20 @@ signal entity_hp_changed(context : Entity.HPChangedContext)
|
||||||
|
|
||||||
#region Seedpacket manipulation
|
#region Seedpacket manipulation
|
||||||
|
|
||||||
## Called when player selects EntityResource
|
## Called when player selects SeedpacketResource
|
||||||
signal packet_selected(packet : EntityResource)
|
signal packet_selected(packet : SeedpacketResource)
|
||||||
|
|
||||||
## Called when player selects EntityResource during game phase
|
## Called when player selects SeedpacketResource during game phase
|
||||||
signal packet_selected_during_game(packet : EntityResource)
|
signal packet_selected_during_game(packet : SeedpacketResource)
|
||||||
|
|
||||||
## Called when something requests EntityResource to be added to hotbar collection
|
## Called when something requests SeedpacketResource to be added to hotbar collection
|
||||||
signal requested_packet_add
|
signal requested_packet_add(packet : SeedpacketResource)
|
||||||
|
|
||||||
## Called when something requests EntityResource to be deleted from hotbar collection
|
## Called when something requests SeedpacketResourcesource to be deleted from hotbar collection
|
||||||
signal requested_packet_remove
|
signal requested_packet_remove(packet : SeedpacketResource)
|
||||||
|
|
||||||
## Called when selected packets are updated
|
## Called when selected packets are updated
|
||||||
signal hotbar_packets_update(selected : Array[EntityResource])
|
signal hotbar_packets_update(selected : Array[SeedpacketResource])
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Level Running
|
#region Level Running
|
||||||
|
|
@ -44,21 +51,10 @@ signal huge_wave
|
||||||
signal final_wave
|
signal final_wave
|
||||||
|
|
||||||
## Called when game is progressing through level stages
|
## Called when game is progressing through level stages
|
||||||
signal state_changed(state : LevelStates)
|
signal state_changed(state : LevelData.LevelStates)
|
||||||
|
|
||||||
## Called when something requests state to advance
|
## Called when something requests state to advance
|
||||||
signal state_advance_requested
|
signal state_advance_requested
|
||||||
|
## Called when sun counter updates to value [code]to[/code]
|
||||||
|
signal sun_count_updated(to : float)
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
## Possible states of level
|
|
||||||
enum LevelStates {
|
|
||||||
## The game is during plant pick stage
|
|
||||||
PlantPick,
|
|
||||||
## The game is not yet started
|
|
||||||
Pregame,
|
|
||||||
## Game started
|
|
||||||
Game,
|
|
||||||
## Game ended
|
|
||||||
Postgame
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,30 @@
|
||||||
extends Resource
|
extends Resource
|
||||||
|
|
||||||
class_name EntityResource
|
## Base class for every possible entity in game. Makes possible for entities to be spawned using seedpackets
|
||||||
|
class_name SeedpacketResource
|
||||||
|
|
||||||
|
## Thumbnail of an entity
|
||||||
|
@export var preview : Texture2D
|
||||||
|
|
||||||
|
## Cost of entity in local units
|
||||||
|
@export var cost : float
|
||||||
|
|
||||||
|
## Recharge time for seedpacket in seconds
|
||||||
|
@export_range(0.05,60,0.01,"or_greater","suffix:seconds") var recharge_time : float = 3
|
||||||
|
|
||||||
|
## Initial recharge fraction. Zero equals that seedpacket recharges instantly, one equals that packet starts uncharged
|
||||||
|
@export_range(0,1,0.01) var initial_recharge_percent : float = 1
|
||||||
|
|
||||||
|
## Scene that can be spawned
|
||||||
|
@export var scene : PackedScene
|
||||||
|
|
||||||
|
## Order to sort in almanach
|
||||||
|
@export_range(0,4056,1,"or_greater","hide_slider") var order : int
|
||||||
|
|
||||||
|
var gid : StringName = ""
|
||||||
|
|
||||||
|
func get_gid() -> StringName:
|
||||||
|
if gid == "":
|
||||||
|
var split_path = resource_path.split("/")
|
||||||
|
gid = split_path[split_path.size()].trim_suffix(".tres").to_lower()
|
||||||
|
return gid
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue