Commit 787344e5 authored by Gerard Gascón's avatar Gerard Gascón
Browse files

feat: dragon animations

parent 9f2b78c1
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -9,9 +9,8 @@ size = Vector2(108, 108)
[node name="Dragon" type="Area2D" node_paths=PackedStringArray("dragon")]
script = ExtResource("1_jccds")
dragon = NodePath("CollisionShape2D/Dragon")
animation_duration = 10.0
min_exit_time = 60.0
max_exit_time = 600.0
animation_duration = 7.0
max_exit_time = 10.0

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(-2, -4)
+18 −5
Original line number Diff line number Diff line
@@ -14,16 +14,24 @@ signal on_quit(dragon_id: int)
var rng: RandomNumberGenerator = RandomNumberGenerator.new()
var properties: DragonProperties

var _start_position: Vector2

var _is_flying: bool = false


func _ready() -> void:
	set_process_input(true)
	_play_initial_animation()


func _queue_exit():
	if not _is_flying:
		dragon.play_idle()
	await get_tree().create_timer(rng.randf_range(min_exit_time, max_exit_time)).timeout
	if not _is_flying:
		dragon.play_walk()
	dragon.walk_right()
	var tween: Tween = get_tree().create_tween()
	tween.tween_property($CollisionShape2D, "position", Vector2(get_window().size.x + 200, 0), animation_duration)
	tween.tween_property($CollisionShape2D, "position", _start_position, animation_duration)
	tween.tween_callback(_proceed_exit)


@@ -32,8 +40,13 @@ func _proceed_exit():
	queue_free()


func _play_initial_animation() -> void:
	$CollisionShape2D.position = Vector2(get_window().size.x + 200, 0)
func play_initial_animation(start_spot: Node2D) -> void:
	if get_parent().position.y < 150:
		_is_flying = true
		dragon.play_fly()
	
	$CollisionShape2D.position = start_spot.position
	_start_position = start_spot.position
	var tween = get_tree().create_tween()
	tween.tween_property($CollisionShape2D, "position", Vector2(0, 0), animation_duration)
	tween.tween_callback(_queue_exit)
@@ -43,7 +56,7 @@ func _input_event(_viewport, event, _shape_idx) -> void:
	if event is InputEventMouseButton \
	and event.button_index == MOUSE_BUTTON_LEFT \
	and event.is_pressed():
		properties.position = position + $CollisionShape2D.position
		properties.position = global_position + $CollisionShape2D.position
		on_pick.emit(properties)
		queue_free()

+8 −7
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ class_name GameManager
@export var dragon_ingame: PackedScene
@export var name_setter: PackedScene
@export var dragon_spots: Array[Node2D]
@export var dragon_start_spots: Dictionary[Node2D, Node2D]

var _filled_spots: Dictionary[Node2D, int]

@@ -70,7 +71,7 @@ func _instantiate_random_dragon():
		for d in _library.dragons:
			# TODO: Search for dragon and if is in library or in instantiated dragons continue next iteration
			pass
		var dragon_entity: DragonEntity = _generate_entity(spot.position, dragon)
		var dragon_entity: DragonEntity = _generate_entity(spot, dragon)
		_filled_spots[spot] = dragon_entity.properties.id
		return

@@ -82,9 +83,9 @@ func _get_free_spot() -> Node2D:
	return null


func _generate_entity(pos: Vector2, properties: DragonProperties) -> DragonEntity:
func _generate_entity(spot: Node2D, properties: DragonProperties) -> DragonEntity:
	properties.id = rng.randi()
	return _instantiate_dragon_ingame(pos, properties)
	return _instantiate_dragon_ingame(spot, properties)


func move_window_to_bottom_right():
@@ -106,7 +107,7 @@ func add_dragon(properties: DragonProperties):
	dragon_sharing.send(properties)
	for spot in dragon_spots:
		if not _filled_spots.has(spot):
			_instantiate_dragon_ingame(spot.position, properties)
			_instantiate_dragon_ingame(spot, properties)
			_filled_spots[spot] = id
			break

@@ -121,15 +122,15 @@ func _load_game():
	print(_save_load.contents_to_save)


func _instantiate_dragon_ingame(window_position: Vector2, properties: DragonProperties) -> DragonEntity:
func _instantiate_dragon_ingame(spot: Node2D, properties: DragonProperties) -> DragonEntity:
	var dragon: DragonEntity = dragon_ingame.instantiate()
	add_child(dragon)
	spot.add_child(dragon)
	dragon.dress(properties)
	dragon.properties = properties
	dragon.position = window_position
	dragon.on_pick.connect(_pick_dragon)
	dragon.on_quit.connect(_quit_dragon)
	_instantiated_dragons[properties.id] = dragon
	dragon.play_initial_animation(dragon_start_spots[spot])
	return dragon


+18 −4
Original line number Diff line number Diff line
@@ -13,12 +13,17 @@
[ext_resource type="Texture2D" uid="uid://b1w6y1qvetsaw" path="res://assets/sprites/environment/castle/DP_castle_front.png" id="17_0ld40"]
[ext_resource type="Script" path="res://scenes/dragon_sharing.gd" id="17_muem4"]

[node name="Base" type="Node2D" node_paths=PackedStringArray("dragon_spots")]
[node name="Base" type="Node2D" node_paths=PackedStringArray("dragon_spots", "dragon_start_spots")]
script = ExtResource("1_sugp2")
dragon_template = ExtResource("2_jyhfs")
dragon_ingame = ExtResource("4_jyhfs")
name_setter = ExtResource("4_trceg")
dragon_spots = [NodePath("DragonSpot1"), NodePath("DragonSpot2"), NodePath("DragonSpot3")]
dragon_start_spots = {
NodePath("DragonSpot1"): NodePath("DragonSpot1/StartSpot"),
NodePath("DragonSpot2"): NodePath("DragonSpot2/StartSpot"),
NodePath("DragonSpot3"): NodePath("DragonSpot3/StartSpot")
}
min_dragon_instantiation_time = 2.0
max_dragon_instantiation_time = 10.0

@@ -82,13 +87,22 @@ position = Vector2(395, 159)
texture = ExtResource("17_0ld40")

[node name="DragonSpot1" type="Node2D" parent="."]
position = Vector2(53, 249)
position = Vector2(106, 246)

[node name="StartSpot" type="Node2D" parent="DragonSpot1"]
position = Vector2(296, 0)

[node name="DragonSpot2" type="Node2D" parent="."]
position = Vector2(142, 118)
position = Vector2(257, 94)

[node name="StartSpot" type="Node2D" parent="DragonSpot2"]
position = Vector2(145, 152)

[node name="DragonSpot3" type="Node2D" parent="."]
position = Vector2(207, 252)
position = Vector2(207, 246)

[node name="StartSpot" type="Node2D" parent="DragonSpot3"]
position = Vector2(195, 0)

[node name="HTTPRequest" type="HTTPRequest" parent="."]
script = ExtResource("17_muem4")