interaction wheel
cancel interaction wheel
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 106 KiB |
13
data/interactions/build.tres
Normal file
13
data/interactions/build.tres
Normal file
@@ -0,0 +1,13 @@
|
||||
[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")
|
||||
13
data/interactions/gather.tres
Normal file
13
data/interactions/gather.tres
Normal file
@@ -0,0 +1,13 @@
|
||||
[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")
|
||||
@@ -27,6 +27,63 @@ gdscript/warnings/untyped_declaration=1
|
||||
|
||||
theme/custom="res://data/world_theme.tres"
|
||||
|
||||
[input]
|
||||
|
||||
view_right={
|
||||
"deadzone": 0.5,
|
||||
"events": [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":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
view_left={
|
||||
"deadzone": 0.5,
|
||||
"events": [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":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
view_up={
|
||||
"deadzone": 0.5,
|
||||
"events": [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":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
view_down={
|
||||
"deadzone": 0.5,
|
||||
"events": [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":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
move_left={
|
||||
"deadzone": 0.5,
|
||||
"events": [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":65,"key_label":0,"unicode":97,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
move_right={
|
||||
"deadzone": 0.5,
|
||||
"events": [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":68,"key_label":0,"unicode":100,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
move_up={
|
||||
"deadzone": 0.5,
|
||||
"events": [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":87,"key_label":0,"unicode":119,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
move_down={
|
||||
"deadzone": 0.5,
|
||||
"events": [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":83,"key_label":0,"unicode":115,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
select={
|
||||
"deadzone": 0.5,
|
||||
"events": [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,"echo":false,"script":null)
|
||||
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
textures/canvas_textures/default_texture_filter=0
|
||||
|
||||
49
scene/interaction_wheel.tscn
Normal file
49
scene/interaction_wheel.tscn
Normal file
@@ -0,0 +1,49 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://bq0jhdgh104y6"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_1ljdt"]
|
||||
[ext_resource type="Script" path="res://scripts/interaction_wheel.gd" id="1_gdnx3"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_7xl34"]
|
||||
atlas = ExtResource("1_1ljdt")
|
||||
region = Rect2(832, 512, 128, 128)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_gdnoe"]
|
||||
atlas = ExtResource("1_1ljdt")
|
||||
region = Rect2(1024, 512, 64, 64)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ci5w3"]
|
||||
atlas = ExtResource("1_1ljdt")
|
||||
region = Rect2(960, 576, 64, 64)
|
||||
|
||||
[node name="InteractionWheel" type="Node2D"]
|
||||
script = ExtResource("1_gdnx3")
|
||||
|
||||
[node name="Wheel" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_7xl34")
|
||||
|
||||
[node name="Interactions" type="Node2D" parent="."]
|
||||
|
||||
[node name="SpriteNorth" type="Sprite2D" parent="Interactions"]
|
||||
position = Vector2(0, -96)
|
||||
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"]
|
||||
visible = false
|
||||
position = Vector2(-96, 0)
|
||||
texture = SubResource("AtlasTexture_gdnoe")
|
||||
|
||||
[node name="SpriteSouth" type="Sprite2D" parent="Interactions"]
|
||||
visible = false
|
||||
position = Vector2(0, 96)
|
||||
texture = SubResource("AtlasTexture_gdnoe")
|
||||
|
||||
[node name="Cursor" type="Sprite2D" parent="."]
|
||||
visible = false
|
||||
texture = SubResource("AtlasTexture_ci5w3")
|
||||
centered = false
|
||||
offset = Vector2(0, -32)
|
||||
@@ -1,6 +1,9 @@
|
||||
class_name CellData
|
||||
extends Resource
|
||||
|
||||
const BUILD = preload("res://data/interactions/build.tres")
|
||||
const GATHER = preload("res://data/interactions/gather.tres")
|
||||
|
||||
@export var layer_info: Dictionary = {
|
||||
Constants.TilemapLayers.CORRUPTION: false
|
||||
}
|
||||
@@ -27,6 +30,9 @@ func get_resource() -> GameResource:
|
||||
|
||||
func has_resource() -> bool:
|
||||
return has_layer(Constants.TilemapLayers.ENVIRONMENT)
|
||||
|
||||
func has_building() -> bool:
|
||||
return has_layer(Constants.TilemapLayers.BUILDINGS)
|
||||
|
||||
func is_corrupted() -> bool:
|
||||
return layer_info[Constants.TilemapLayers.CORRUPTION]
|
||||
@@ -35,7 +41,7 @@ func has_layer(layer: int) -> bool:
|
||||
return layer_info.has(layer)
|
||||
|
||||
func interact(timer: Timer) -> void:
|
||||
var is_interactable := has_resource() or has_layer(Constants.TilemapLayers.BUILDINGS)
|
||||
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)
|
||||
@@ -47,6 +53,14 @@ func interact(timer: Timer) -> void:
|
||||
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():
|
||||
interactions.append(GATHER)
|
||||
if not has_building():
|
||||
interactions.append(BUILD)
|
||||
return interactions
|
||||
|
||||
func _on_interaction_finished(timer: Timer) -> void:
|
||||
timer.timeout.disconnect(_on_interaction_finished)
|
||||
|
||||
5
scripts/interaction.gd
Normal file
5
scripts/interaction.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
extends Resource
|
||||
class_name Interaction
|
||||
|
||||
@export var name: String
|
||||
@export var image: AtlasTexture
|
||||
24
scripts/interaction_wheel.gd
Normal file
24
scripts/interaction_wheel.gd
Normal file
@@ -0,0 +1,24 @@
|
||||
extends Node2D
|
||||
class_name InteractionWheel
|
||||
|
||||
var interactions: Array[Interaction]
|
||||
|
||||
@onready var interaction_icons: Array[Node] = $Interactions.get_children()
|
||||
@onready var cursor: Sprite2D = $Cursor
|
||||
|
||||
func initialize(interaction_location: Vector2i, interactions: Array[Interaction]) -> void:
|
||||
position = Grid.grid_to_world_center(interaction_location)
|
||||
self.interactions = interactions
|
||||
|
||||
func _ready() -> void:
|
||||
for i in range(interactions.size()):
|
||||
interaction_icons[i].texture = interactions[i].image
|
||||
interaction_icons[i].show()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var selection_direction = Input.get_vector("view_left", "view_right", "view_up", "view_down")
|
||||
if selection_direction:
|
||||
cursor.rotation = selection_direction.angle()
|
||||
cursor.show()
|
||||
if Input.is_action_just_pressed("select"):
|
||||
pass
|
||||
@@ -5,16 +5,21 @@ class_name Player
|
||||
|
||||
var last_direction = 0
|
||||
var interaction_location: Vector2i
|
||||
var _interaction_options: InteractionWheel
|
||||
|
||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||
@onready var interaction_timer: Timer = $InteractionTimer
|
||||
const INTERACTION_WHEEL = preload("res://scene/interaction_wheel.tscn")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var input_direction := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||
var input_direction := Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
velocity = input_direction * SPEED / delta
|
||||
move_and_slide()
|
||||
|
||||
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
|
||||
@@ -25,9 +30,12 @@ func _physics_process(delta: float) -> void:
|
||||
animation_player.stop()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_accept"):
|
||||
Grid.get_location_data(interaction_location).interact(interaction_timer)
|
||||
print("interaction started")
|
||||
if event.is_action_pressed("select") and not _interaction_options:
|
||||
var interactions: Array[Interaction] = Grid.get_location_data(interaction_location).get_interaction_options()
|
||||
if interactions.size() > 0:
|
||||
_interaction_options = INTERACTION_WHEEL.instantiate()
|
||||
_interaction_options.initialize(interaction_location, interactions)
|
||||
add_sibling(_interaction_options)
|
||||
|
||||
func _finished_interaction(results: Dictionary) -> void:
|
||||
print("interaction finished: %s" % results)
|
||||
|
||||
Reference in New Issue
Block a user