Lesson: Explosion and Jump Effects + Review
This commit is contained in:
parent
842f567ed7
commit
147199a012
4 changed files with 99 additions and 1 deletions
45
metroidvania/Scenes/Effects/ExplosionEffect.tscn
Normal file
45
metroidvania/Scenes/Effects/ExplosionEffect.tscn
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Scenes/Effects/Effect.tscn" type="PackedScene" id=1]
|
||||||
|
[ext_resource path="res://Assets/Effects/ExplosionEffect.png" type="Texture" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=1]
|
||||||
|
resource_name = "Animate"
|
||||||
|
length = 0.5
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath("Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
|
||||||
|
"update": 1,
|
||||||
|
"values": [ 0, 1, 2, 3, 4 ]
|
||||||
|
}
|
||||||
|
tracks/1/type = "method"
|
||||||
|
tracks/1/path = NodePath(".")
|
||||||
|
tracks/1/interp = 1
|
||||||
|
tracks/1/loop_wrap = true
|
||||||
|
tracks/1/imported = false
|
||||||
|
tracks/1/enabled = true
|
||||||
|
tracks/1/keys = {
|
||||||
|
"times": PoolRealArray( 0.5 ),
|
||||||
|
"transitions": PoolRealArray( 1 ),
|
||||||
|
"values": [ {
|
||||||
|
"args": [ ],
|
||||||
|
"method": "queue_free"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="ExplosionEffect" instance=ExtResource( 1 )]
|
||||||
|
|
||||||
|
[node name="Sprite" parent="." index="0"]
|
||||||
|
texture = ExtResource( 2 )
|
||||||
|
hframes = 5
|
||||||
|
frame = 4
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" parent="." index="1"]
|
||||||
|
autoplay = "Animate"
|
||||||
|
anims/Animate = SubResource( 1 )
|
45
metroidvania/Scenes/Effects/JumpEffect.tscn
Normal file
45
metroidvania/Scenes/Effects/JumpEffect.tscn
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Scenes/Effects/Effect.tscn" type="PackedScene" id=1]
|
||||||
|
[ext_resource path="res://Assets/Effects/JumpEffect.png" type="Texture" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=1]
|
||||||
|
resource_name = "Animate"
|
||||||
|
length = 0.4
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath("Sprite:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PoolRealArray( 0, 0.1, 0.2, 0.3 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1, 1 ),
|
||||||
|
"update": 1,
|
||||||
|
"values": [ 0, 1, 2, 3 ]
|
||||||
|
}
|
||||||
|
tracks/1/type = "method"
|
||||||
|
tracks/1/path = NodePath(".")
|
||||||
|
tracks/1/interp = 1
|
||||||
|
tracks/1/loop_wrap = true
|
||||||
|
tracks/1/imported = false
|
||||||
|
tracks/1/enabled = true
|
||||||
|
tracks/1/keys = {
|
||||||
|
"times": PoolRealArray( 0.4 ),
|
||||||
|
"transitions": PoolRealArray( 1 ),
|
||||||
|
"values": [ {
|
||||||
|
"args": [ ],
|
||||||
|
"method": "queue_free"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="JumpEffect" instance=ExtResource( 1 )]
|
||||||
|
|
||||||
|
[node name="Sprite" parent="." index="0"]
|
||||||
|
position = Vector2( 0, -8 )
|
||||||
|
texture = ExtResource( 2 )
|
||||||
|
hframes = 4
|
||||||
|
|
||||||
|
[node name="AnimationPlayer" parent="." index="1"]
|
||||||
|
autoplay = "Animate"
|
||||||
|
anims/Animate = SubResource( 1 )
|
|
@ -1,5 +1,7 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
|
const ExplosionEffect = preload("res://Scenes/Effects/ExplosionEffect.tscn")
|
||||||
|
|
||||||
var velocity = Vector2.ZERO
|
var velocity = Vector2.ZERO
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
|
@ -12,9 +14,11 @@ func _on_VisibilityNotifier2D_viewport_exited(_viewport):
|
||||||
|
|
||||||
func _on_Hitbox_body_entered(_body):
|
func _on_Hitbox_body_entered(_body):
|
||||||
# When we collide with the world
|
# When we collide with the world
|
||||||
|
Utils.instance_scene_on_main(ExplosionEffect, global_position)
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
|
||||||
func _on_Hitbox_area_entered(_area):
|
func _on_Hitbox_area_entered(_area):
|
||||||
# When we collide with an enemy (a hurtbox)
|
# When we collide with an enemy (a hurtbox)
|
||||||
|
Utils.instance_scene_on_main(ExplosionEffect, global_position)
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
|
@ -2,6 +2,7 @@ extends KinematicBody2D
|
||||||
|
|
||||||
const DustEffect = preload("res://Scenes/Effects/DustEffect.tscn")
|
const DustEffect = preload("res://Scenes/Effects/DustEffect.tscn")
|
||||||
const PlayerBullet = preload("res://Scenes/Player/PlayerBullet.tscn")
|
const PlayerBullet = preload("res://Scenes/Player/PlayerBullet.tscn")
|
||||||
|
const JumpEffect = preload("res://Scenes/Effects/JumpEffect.tscn")
|
||||||
|
|
||||||
export (int) var acceleration = 512
|
export (int) var acceleration = 512
|
||||||
export (int) var max_speed = 64
|
export (int) var max_speed = 64
|
||||||
|
@ -70,6 +71,7 @@ func update_snap_vector():
|
||||||
func jump_check():
|
func jump_check():
|
||||||
if is_on_floor() or coyoteJumpTimer.time_left > 0:
|
if is_on_floor() or coyoteJumpTimer.time_left > 0:
|
||||||
if Input.is_action_just_pressed("ui_select"):
|
if Input.is_action_just_pressed("ui_select"):
|
||||||
|
Utils.instance_scene_on_main(JumpEffect, global_position)
|
||||||
motion.y = -jump_force
|
motion.y = -jump_force
|
||||||
snap_vector = Vector2.ZERO
|
snap_vector = Vector2.ZERO
|
||||||
just_jumped = true
|
just_jumped = true
|
||||||
|
@ -107,7 +109,9 @@ func move():
|
||||||
if was_on_air and is_on_floor():
|
if was_on_air and is_on_floor():
|
||||||
# Keep previous momentum when landing on slopes
|
# Keep previous momentum when landing on slopes
|
||||||
motion.x = last_motion.x
|
motion.x = last_motion.x
|
||||||
create_dust_effect()
|
#create_dust_effect()
|
||||||
|
Utils.instance_scene_on_main(JumpEffect, global_position)
|
||||||
|
|
||||||
|
|
||||||
# Just left ground
|
# Just left ground
|
||||||
if was_on_floor and not is_on_floor() and not just_jumped:
|
if was_on_floor and not is_on_floor() and not just_jumped:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue