2024/Mar #14

Merged
gitea merged 19 commits from 2024/Mar into main 2024-04-09 10:13:41 -05:00
13 changed files with 216 additions and 90 deletions
Showing only changes of commit abde90e75f - Show all commits

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 120 KiB

View File

@@ -1,13 +0,0 @@
[gd_resource type="Resource" script_class="Interaction" load_steps=4 format=3 uid="uid://bo3e2jefukgdy"]
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_bglkk"]
[ext_resource type="Script" path="res://scripts/interaction.gd" id="2_h5okx"]
[sub_resource type="AtlasTexture" id="AtlasTexture_3e2ed"]
atlas = ExtResource("1_bglkk")
region = Rect2(960, 512, 64, 64)
[resource]
script = ExtResource("2_h5okx")
name = "Build"
image = SubResource("AtlasTexture_3e2ed")

View File

@@ -0,0 +1,13 @@
[gd_resource type="Resource" script_class="InteractionBuild" load_steps=4 format=3 uid="uid://bo3e2jefukgdy"]
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_bglkk"]
[ext_resource type="Script" path="res://data/interactions/build/interaction_build.gd" id="2_0g8r2"]
[sub_resource type="AtlasTexture" id="AtlasTexture_f6dt5"]
atlas = ExtResource("1_bglkk")
region = Rect2(960, 512, 64, 64)
[resource]
script = ExtResource("2_0g8r2")
name = "Build"
image = SubResource("AtlasTexture_f6dt5")

View File

@@ -0,0 +1,6 @@
extends Interaction
class_name InteractionBuild
func interact_at(pos: Vector2i, root: Node) -> Array[Interaction]:
print("Building at: %s" % pos)
return []

View File

@@ -1,13 +0,0 @@
[gd_resource type="Resource" script_class="Interaction" load_steps=4 format=3 uid="uid://r4evto2nkehg"]
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_cquks"]
[ext_resource type="Script" path="res://scripts/interaction.gd" id="1_m76d8"]
[sub_resource type="AtlasTexture" id="AtlasTexture_f8jvb"]
atlas = ExtResource("1_cquks")
region = Rect2(1024, 512, 64, 64)
[resource]
script = ExtResource("1_m76d8")
name = "Gather"
image = SubResource("AtlasTexture_f8jvb")

View File

@@ -0,0 +1,13 @@
[gd_resource type="Resource" script_class="InteractionGather" load_steps=4 format=3 uid="uid://r4evto2nkehg"]
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_cquks"]
[ext_resource type="Script" path="res://data/interactions/gather/interaction_gather.gd" id="2_4amum"]
[sub_resource type="AtlasTexture" id="AtlasTexture_jjmaq"]
atlas = ExtResource("1_cquks")
region = Rect2(1024, 512, 64, 64)
[resource]
script = ExtResource("2_4amum")
name = "Gather"
image = SubResource("AtlasTexture_jjmaq")

View File

@@ -0,0 +1,24 @@
extends Interaction
class_name InteractionGather
var interaction_display
var _pos
func interact_at(pos: Vector2i, root: Node) -> Array[Interaction]:
_pos = pos
print("Gathering at: %s" % pos)
interaction_display = ProgressBar.new()
interaction_display.position = Grid.grid_to_world_center(_pos) - Vector2(30, 10)
interaction_display.size = Vector2(60, 20)
interaction_display.show_percentage = false
var tween = root.create_tween()
tween.tween_property(interaction_display, "value", 100, 3)
tween.tween_callback(_cleanup_gather)
root.add_child(interaction_display)
return []
func _cleanup_gather() -> void:
interaction_display.queue_free()
var res: GameResource = Grid.get_location_data(_pos).get_resource()
res.gained_resource.emit(res)

View File

@@ -3,3 +3,6 @@ class_name Interaction
@export var name: String
@export var image: AtlasTexture
func interact_at(pos: Vector2i, root: Node) -> Array[Interaction]:
return []

View File

@@ -24,17 +24,23 @@ texture = SubResource("AtlasTexture_7xl34")
[node name="Interactions" type="Node2D" parent="."]
[node name="SpriteNorth" type="Sprite2D" parent="Interactions"]
visible = false
position = Vector2(0, -96)
texture = SubResource("AtlasTexture_gdnoe")
[node name="SpriteNorthEast" type="Sprite2D" parent="Interactions"]
visible = false
position = Vector2(68, -68)
texture = SubResource("AtlasTexture_gdnoe")
[node name="SpriteEast" type="Sprite2D" parent="Interactions"]
visible = false
position = Vector2(96, 0)
texture = SubResource("AtlasTexture_gdnoe")
[node name="SpriteWest" type="Sprite2D" parent="Interactions"]
[node name="SpriteSouthEast" type="Sprite2D" parent="Interactions"]
visible = false
position = Vector2(-96, 0)
position = Vector2(68, 68)
texture = SubResource("AtlasTexture_gdnoe")
[node name="SpriteSouth" type="Sprite2D" parent="Interactions"]
@@ -42,8 +48,49 @@ visible = false
position = Vector2(0, 96)
texture = SubResource("AtlasTexture_gdnoe")
[node name="Cursor" type="Sprite2D" parent="."]
[node name="SpriteSouthWest" type="Sprite2D" parent="Interactions"]
visible = false
position = Vector2(-68, 68)
texture = SubResource("AtlasTexture_gdnoe")
[node name="SpriteWest" type="Sprite2D" parent="Interactions"]
visible = false
position = Vector2(-96, 0)
texture = SubResource("AtlasTexture_gdnoe")
[node name="SpriteNorthWest" type="Sprite2D" parent="Interactions"]
visible = false
position = Vector2(-68, -68)
texture = SubResource("AtlasTexture_gdnoe")
[node name="Cursor" type="Sprite2D" parent="."]
texture = SubResource("AtlasTexture_ci5w3")
centered = false
offset = Vector2(0, -32)
[node name="InformationPanel" type="Panel" parent="."]
visible = false
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -20.0
offset_right = 20.0
offset_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2
[node name="InteractionLabel" type="Label" parent="InformationPanel"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -20.0
offset_right = 20.0
offset_bottom = 24.0
grow_horizontal = 2
theme_override_font_sizes/font_size = 8
text = "Build"
horizontal_alignment = 1

View File

@@ -1,51 +1,95 @@
[gd_scene load_steps=7 format=3 uid="uid://dkvcye4mhvshd"]
[gd_scene load_steps=12 format=3 uid="uid://dkvcye4mhvshd"]
[ext_resource type="Script" path="res://scripts/player.gd" id="1_j0htm"]
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_vqdy1"]
[sub_resource type="AtlasTexture" id="AtlasTexture_8yvc7"]
[sub_resource type="AtlasTexture" id="AtlasTexture_rbmjr"]
atlas = ExtResource("1_vqdy1")
region = Rect2(640, 192, 64, 64)
region = Rect2(832, 640, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_xx5oc"]
atlas = ExtResource("1_vqdy1")
region = Rect2(832, 640, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_2ckq3"]
atlas = ExtResource("1_vqdy1")
region = Rect2(896, 704, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_vet2c"]
atlas = ExtResource("1_vqdy1")
region = Rect2(960, 704, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_fqxfq"]
atlas = ExtResource("1_vqdy1")
region = Rect2(832, 640, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_03ery"]
atlas = ExtResource("1_vqdy1")
region = Rect2(896, 640, 64, 64)
[sub_resource type="AtlasTexture" id="AtlasTexture_ix8o6"]
atlas = ExtResource("1_vqdy1")
region = Rect2(960, 640, 64, 64)
[sub_resource type="SpriteFrames" id="SpriteFrames_tj1nq"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_rbmjr")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_xx5oc")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_2ckq3")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xx5oc")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_vet2c")
}],
"loop": true,
"name": &"interact",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_fqxfq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_03ery")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fqxfq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ix8o6")
}],
"loop": true,
"name": &"walk",
"speed": 5.0
}]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jav3v"]
size = Vector2(40, 45)
[sub_resource type="Animation" id="Animation_47lv4"]
resource_name = "walk"
length = 1.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.2, 0.4, 0.6, 0.8, 1, 1.2),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1),
"update": 0,
"values": [Vector2(0, 0), Vector2(0, -1), Vector2(0, -2), Vector2(0, -1), Vector2(0, 0), Vector2(0, 1), Vector2(0, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_ditnu"]
_data = {
"walk": SubResource("Animation_47lv4")
}
[node name="Player" type="CharacterBody2D"]
motion_mode = 1
script = ExtResource("1_j0htm")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = SubResource("AtlasTexture_8yvc7")
[node name="Sprite" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_tj1nq")
frame_progress = 0.850199
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_jav3v")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_ditnu")
}
[node name="Camera2D" type="Camera2D" parent="."]
[node name="InteractionTimer" type="Timer" parent="."]

View File

@@ -40,20 +40,6 @@ func is_corrupted() -> bool:
func has_layer(layer: int) -> bool:
return layer_info.has(layer)
func interact(timer: Timer) -> void:
var is_interactable := has_resource() or not has_building()
if is_interactable and not interaction_display:
timer.timeout.connect(_on_interaction_finished.bind(timer))
timer.start(3)
interaction_display = ProgressBar.new()
interaction_display.position = Grid.grid_to_world_center(_pos) - Vector2(30, 10)
interaction_display.size = Vector2(60, 20)
interaction_display.show_percentage = false
var tween = timer.get_tree().create_tween()
tween.tween_property(interaction_display, "value", 100, 3)
timer.get_parent().add_sibling(interaction_display)
func get_interaction_options() -> Array[Interaction]:
var interactions: Array[Interaction] = []
if has_resource():
@@ -61,9 +47,3 @@ func get_interaction_options() -> Array[Interaction]:
if not has_building():
interactions.append(BUILD)
return interactions
func _on_interaction_finished(timer: Timer) -> void:
timer.timeout.disconnect(_on_interaction_finished)
if has_resource():
interaction_display.queue_free()
get_resource().gained_resource.emit(get_resource())

View File

@@ -1,12 +1,18 @@
extends Node2D
class_name InteractionWheel
signal closed
var interactions: Array[Interaction]
var grid_position: Vector2i
@onready var interaction_icons: Array[Node] = $Interactions.get_children()
@onready var cursor: Sprite2D = $Cursor
@onready var information_panel: Panel = $InformationPanel
@onready var interaction_label: Label = $InformationPanel/InteractionLabel
func initialize(interaction_location: Vector2i, interactions: Array[Interaction]) -> void:
grid_position = interaction_location
position = Grid.grid_to_world_center(interaction_location)
self.interactions = interactions
@@ -20,5 +26,21 @@ func _process(delta: float) -> void:
if selection_direction:
cursor.rotation = selection_direction.angle()
cursor.show()
if Input.is_action_just_pressed("select"):
pass
var selection = _get_selection_index(cursor.rotation)
if selection < interactions.size():
information_panel.show()
interaction_label.text = interactions[selection].name
else:
information_panel.hide()
if Input.is_action_just_pressed("select") and cursor.visible:
var selection = _get_selection_index(cursor.rotation)
print("Selection: %s Rotation: %s" % [selection, cursor.rotation])
if selection < interactions.size():
var next_interactions = interactions[selection].interact_at(grid_position, get_tree().root)
if next_interactions.is_empty():
closed.emit()
queue_free()
func _get_selection_index(angle: float) -> int:
var adjusted_angle = fposmod(angle + (PI / 2.0), 2.0 * PI)
return floor(((int(floor(adjusted_angle / (PI / 8.0))) + 1) % 16) / 2.0)

View File

@@ -7,7 +7,7 @@ var last_direction = 0
var interaction_location: Vector2i
var _interaction_options: InteractionWheel
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var sprite: AnimatedSprite2D = $Sprite
@onready var interaction_timer: Timer = $InteractionTimer
const INTERACTION_WHEEL = preload("res://scene/interaction_wheel.tscn")
@@ -19,15 +19,14 @@ func _physics_process(delta: float) -> void:
if input_direction:
if _interaction_options:
_interaction_options.queue_free()
_interaction_options = null
animation_player.current_animation = "walk"
animation_player.play()
last_direction = input_direction.angle() + 3 * PI / 2
_on_interation_options_closed()
sprite.play("walk")
last_direction = input_direction.angle() + PI / 2
rotation = last_direction
interaction_location = Grid.world_to_grid(position) + Vector2i(input_direction.round())
Grid.set_selected_tile(interaction_location)
else:
animation_player.stop()
sprite.stop()
func _input(event: InputEvent) -> void:
if event.is_action_pressed("select") and not _interaction_options:
@@ -35,10 +34,11 @@ func _input(event: InputEvent) -> void:
if interactions.size() > 0:
_interaction_options = INTERACTION_WHEEL.instantiate()
_interaction_options.initialize(interaction_location, interactions)
_interaction_options.closed.connect(_on_interation_options_closed)
add_sibling(_interaction_options)
func _finished_interaction(results: Dictionary) -> void:
print("interaction finished: %s" % results)
func _on_interation_options_closed() -> void:
_interaction_options = null
func _unhandled_input(event):
if event is InputEventMouseButton: