Add animations to Tim

This commit is contained in:
Marvin Dalheimer 2024-01-27 20:34:39 +01:00
parent 86dec7501f
commit 2c7128aafd
5 changed files with 110 additions and 32 deletions

View File

@ -18,6 +18,7 @@ config/icon="res://icon.svg"
[autoload]
UserSettings="*res://settings/user_settings.gd"
Signals="*res://scenes/signals.gd"
[display]

View File

@ -5,29 +5,39 @@ extends Node2D
@export var tim_sprite : Sprite2D
@export var transmitter_area: Area2D
var default_texture: Texture2D = load("res://sprites/tim_side.png")
var ducking_texture: Texture2D = load("res://sprites/tim_ducking.svg")
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
Signals.hit_tim.connect(ouch)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_action_pressed("move_right"):
tim_sprite.flip_h = true
global_position += Vector2.RIGHT * delta * move_speed
if global_position.x > boundary.get_most_right_position():
global_position = Vector2(boundary.get_most_right_position(), global_position.y)
if Input.is_action_pressed("move_left"):
tim_sprite.flip_h = false
global_position += Vector2.LEFT * delta * move_speed
if global_position.x < boundary.get_most_left_position():
global_position = Vector2(boundary.get_most_left_position(), global_position.y)
if Input.is_action_pressed("move_right"):
tim_sprite.flip_h = true
global_position += Vector2.RIGHT * delta * move_speed
if global_position.x > boundary.get_most_right_position():
global_position = Vector2(boundary.get_most_right_position(), global_position.y)
if Input.is_action_pressed("move_left"):
tim_sprite.flip_h = false
global_position += Vector2.LEFT * delta * move_speed
if global_position.x < boundary.get_most_left_position():
global_position = Vector2(boundary.get_most_left_position(), global_position.y)
func _on_joke_button_button_pressed(joke):
for body in transmitter_area.get_overlapping_bodies():
var person = body.find_parent("Person")
if not (person is AudienceMember):
continue
person.on_joke(joke)
$AnimationPlayer.play("talking")
for body in transmitter_area.get_overlapping_bodies():
var person = body.find_parent("Person")
if not (person is AudienceMember):
continue
person.on_joke(joke)
func ouch():
$Sprite2D.texture = ducking_texture
await get_tree().create_timer(1).timeout
$Sprite2D.texture = default_texture

View File

@ -1,5 +1,7 @@
extends Sprite2D
signal hit_tim
@export var bottle_speed: float = 120;
var tim_global_position: Vector2
@ -7,26 +9,27 @@ var is_hidding: bool
# Called when the node enters the scene tree for the first time.
func _ready():
tim_global_position = get_node("/root/IngameScene/Stage/Tim/ThrowPoint").global_position
tim_global_position = get_node("/root/IngameScene/Stage/Tim/ThrowPoint").global_position
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var t = create_tween().set_parallel()
t.tween_property(self, "global_position", tim_global_position, 3.0)
t.tween_property(self, "rotation_degrees", rotation_degrees + 270, 3.0)
t.tween_callback(remove_bottle).set_delay(3.05)
var t = create_tween().set_parallel()
t.tween_property(self, "global_position", tim_global_position, 3.0)
t.tween_property(self, "rotation_degrees", rotation_degrees + 270, 3.0)
t.tween_callback(remove_bottle).set_delay(3.05)
func _on_bottle_area_entered(area):
is_hidding = true
is_hidding = true
func _on_bottle_area_exited(area):
is_hidding = false
is_hidding = false
func _on_growth_timer_timeout():
var t = create_tween()
t.tween_property(self, "scale", self.scale + Vector2(0.01, 0.01), 0.02)
var t = create_tween()
t.tween_property(self, "scale", self.scale + Vector2(0.01, 0.01), 0.02)
func remove_bottle():
if is_hidding:
print("Ouch")
queue_free()
if is_hidding:
print("Ouch")
Signals.hit_tim.emit()
queue_free()

3
godot/scenes/signals.gd Normal file
View File

@ -0,0 +1,3 @@
extends Node
signal hit_tim

View File

@ -1,10 +1,12 @@
[gd_scene load_steps=8 format=3 uid="uid://cicyfp5xjvvu4"]
[gd_scene load_steps=14 format=3 uid="uid://cicyfp5xjvvu4"]
[ext_resource type="Texture2D" uid="uid://bg85if5rrrdmm" path="res://sprites/room/buehne.svg" id="1_32lst"]
[ext_resource type="Script" path="res://scenes/Tim.gd" id="1_g3k2b"]
[ext_resource type="Texture2D" uid="uid://kq63ictuirhc" path="res://sprites/tim_side.png" id="1_saxit"]
[ext_resource type="Script" path="res://scenes/Boundary.gd" id="2_8p6ir"]
[ext_resource type="PackedScene" uid="uid://r1i7ln2hpwq5" path="res://scenes/joke_button.tscn" id="3_0t41i"]
[ext_resource type="Texture2D" uid="uid://b8tb4o75kjffn" path="res://sprites/tim_talk.svg" id="3_e1fvx"]
[ext_resource type="Texture2D" uid="uid://d2264dy2o4q6d" path="res://sprites/tim_side.svg" id="6_qpa7m"]
[sub_resource type="CircleShape2D" id="CircleShape2D_jfw8v"]
radius = 23.0217
@ -12,6 +14,59 @@ radius = 23.0217
[sub_resource type="RectangleShape2D" id="RectangleShape2D_wmfel"]
size = Vector2(250, 10000)
[sub_resource type="Animation" id="Animation_kkrfv"]
resource_name = "talking"
length = 4.0
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:texture")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 3.95),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
"update": 1,
"values": [ExtResource("1_saxit"), ExtResource("3_e1fvx"), ExtResource("6_qpa7m"), ExtResource("3_e1fvx"), ExtResource("6_qpa7m"), ExtResource("3_e1fvx"), ExtResource("6_qpa7m"), ExtResource("3_e1fvx"), ExtResource("1_saxit"), ExtResource("3_e1fvx"), ExtResource("6_qpa7m"), ExtResource("3_e1fvx"), ExtResource("6_qpa7m"), ExtResource("3_e1fvx"), ExtResource("6_qpa7m"), ExtResource("3_e1fvx"), ExtResource("1_saxit")]
}
[sub_resource type="Animation" id="Animation_n0bwh"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:texture")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [ExtResource("3_e1fvx")]
}
[sub_resource type="Animation" id="Animation_5tnw3"]
resource_name = "idle"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:texture")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1),
"transitions": PackedFloat32Array(1, 1),
"update": 1,
"values": [ExtResource("6_qpa7m"), ExtResource("6_qpa7m")]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_xvfym"]
_data = {
"RESET": SubResource("Animation_n0bwh"),
"idle": SubResource("Animation_5tnw3"),
"talking": SubResource("Animation_kkrfv")
}
[node name="Stage" type="Node2D"]
z_index = 100
@ -39,10 +94,11 @@ shape = SubResource("CircleShape2D_jfw8v")
z_index = 110
position = Vector2(-12, -142)
scale = Vector2(0.4, 0.4)
texture = ExtResource("1_saxit")
texture = ExtResource("3_e1fvx")
offset = Vector2(0, 50)
[node name="Joke Buttons" type="Node2D" parent="Tim"]
visible = false
z_index = 120
position = Vector2(0, -25)
@ -64,6 +120,11 @@ action = "joke_button_3"
[node name="CollisionShape2D" type="CollisionShape2D" parent="Tim/Joke Transmitter/Area2D"]
shape = SubResource("RectangleShape2D_wmfel")
[node name="AnimationPlayer" type="AnimationPlayer" parent="Tim"]
libraries = {
"": SubResource("AnimationLibrary_xvfym")
}
[node name="Boundary" type="Node2D" parent="."]
script = ExtResource("2_8p6ir")