feat: instantiating dragons to ingame position
This commit is contained in:
parent
fc921cc900
commit
610d623653
8 changed files with 64 additions and 19 deletions
|
@ -1,9 +1,16 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://baa8gpicw2yg0"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://miutbdsgccd1"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://assets/sprites/icon.svg" id="1_ixu8j"]
|
||||
[ext_resource type="Script" uid="uid://csb23v0fr12e0" path="res://scenes/dragons/dragon_entity_dragger.gd" id="1_jccds"]
|
||||
[ext_resource type="PackedScene" uid="uid://baa8gpicw2yg0" path="res://scenes/dragons/dragon_sprite.tscn" id="2_l1h0r"]
|
||||
|
||||
[node name="Dragon" type="Node2D"]
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_6eaxg"]
|
||||
size = Vector2(128, 128)
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="."]
|
||||
[node name="Dragon" type="Area2D"]
|
||||
script = ExtResource("1_jccds")
|
||||
|
||||
[node name="Dragon" parent="." instance=ExtResource("2_l1h0r")]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 1)
|
||||
texture = ExtResource("1_ixu8j")
|
||||
shape = SubResource("RectangleShape2D_6eaxg")
|
||||
|
|
17
scenes/dragons/dragon_entity_dragger.gd
Normal file
17
scenes/dragons/dragon_entity_dragger.gd
Normal file
|
@ -0,0 +1,17 @@
|
|||
extends Area2D
|
||||
class_name DragonEntity
|
||||
|
||||
|
||||
signal on_pick(position)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_process_input(true)
|
||||
|
||||
|
||||
func _input_event(viewport, event, shape_idx) -> void:
|
||||
if event is InputEventMouseButton \
|
||||
and event.button_index == MOUSE_BUTTON_LEFT \
|
||||
and event.is_pressed():
|
||||
on_pick.emit(position)
|
||||
queue_free()
|
1
scenes/dragons/dragon_entity_dragger.gd.uid
Normal file
1
scenes/dragons/dragon_entity_dragger.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://csb23v0fr12e0
|
9
scenes/dragons/dragon_sprite.tscn
Normal file
9
scenes/dragons/dragon_sprite.tscn
Normal file
|
@ -0,0 +1,9 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://baa8gpicw2yg0"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://assets/sprites/icon.svg" id="1_ixu8j"]
|
||||
|
||||
[node name="Dragon" type="Node2D"]
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="."]
|
||||
position = Vector2(0, 1)
|
||||
texture = ExtResource("1_ixu8j")
|
|
@ -2,13 +2,14 @@ extends Node
|
|||
|
||||
|
||||
@export var dragon_template: PackedScene
|
||||
@export var dragon_ingame: PackedScene
|
||||
@export var dragon_spots: Array[Node2D]
|
||||
|
||||
var _instantiator: DragonInstantiator
|
||||
|
||||
|
||||
func _ready():
|
||||
_instantiator = DragonInstantiator.new(dragon_template, dragon_spots, get_viewport(), get_window())
|
||||
_instantiator = DragonInstantiator.new(dragon_template, get_viewport(), get_window())
|
||||
|
||||
await get_tree().process_frame
|
||||
move_window_to_bottom_right()
|
||||
|
@ -28,11 +29,23 @@ func move_window_to_bottom_right():
|
|||
DisplayServer.window_set_position(new_position)
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_accept"):
|
||||
var dragon: Dragon = _instantiator.instantiate()
|
||||
dragon.place_back.connect(_dragon_place_back)
|
||||
add_child(dragon)
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_pressed() and event.is_action("ui_accept"):
|
||||
_instantiate_dragon_ingame(dragon_spots[0].position)
|
||||
|
||||
|
||||
func _instantiate_dragon_ingame(position: Vector2):
|
||||
var dragon: DragonEntity = dragon_ingame.instantiate()
|
||||
add_child(dragon)
|
||||
dragon.position = position
|
||||
dragon.on_pick.connect(_pick_dragon)
|
||||
|
||||
|
||||
func _pick_dragon(position: Vector2):
|
||||
print(position)
|
||||
var dragon: Dragon = _instantiator.instantiate(position)
|
||||
dragon.place_back.connect(_dragon_place_back)
|
||||
add_child(dragon)
|
||||
|
||||
|
||||
func _dragon_place_back(dragon: Dragon):
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://ctytpqaed0yqx"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://ctytpqaed0yqx"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://3kyt3shje5r1" path="res://scenes/main.gd" id="1_sugp2"]
|
||||
[ext_resource type="PackedScene" uid="uid://c7nfcgjxqeg7l" path="res://scenes/window/dragon_popup.tscn" id="2_jyhfs"]
|
||||
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://assets/sprites/icon.svg" id="3_tbgi4"]
|
||||
[ext_resource type="PackedScene" uid="uid://miutbdsgccd1" path="res://scenes/dragons/dragon.tscn" id="4_jyhfs"]
|
||||
|
||||
[node name="Base" type="Node2D" node_paths=PackedStringArray("dragon_spots")]
|
||||
script = ExtResource("1_sugp2")
|
||||
dragon_template = ExtResource("2_jyhfs")
|
||||
dragon_ingame = ExtResource("4_jyhfs")
|
||||
dragon_spots = [NodePath("DragonSpot1"), NodePath("DragonSpot2"), NodePath("DragonSpot3")]
|
||||
|
||||
[node name="Icon" type="Sprite2D" parent="."]
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[ext_resource type="Script" uid="uid://bmlkcni4km614" path="res://scenes/window/dragon.gd" id="1_ctdir"]
|
||||
[ext_resource type="Script" uid="uid://ch7d3wo8ucskb" path="res://scenes/window/draggable.gd" id="2_2r6si"]
|
||||
[ext_resource type="PackedScene" uid="uid://baa8gpicw2yg0" path="res://scenes/dragons/dragon.tscn" id="3_ctdir"]
|
||||
[ext_resource type="PackedScene" uid="uid://baa8gpicw2yg0" path="res://scenes/dragons/dragon_sprite.tscn" id="3_ctdir"]
|
||||
|
||||
[node name="DragonPopup" type="Window"]
|
||||
disable_3d = true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue