added hatches!
This commit is contained in:
parent
9947cdfc45
commit
3433dae09c
10 changed files with 267 additions and 18 deletions
30
objects/environment/hatch/hatch.gd
Normal file
30
objects/environment/hatch/hatch.gd
Normal file
|
@ -0,0 +1,30 @@
|
|||
extends Node2D
|
||||
|
||||
onready var anims = $SpriteAnim
|
||||
onready var down_prompt = $DownPrompt
|
||||
onready var snap_position = $Position2D
|
||||
var can_interact = false
|
||||
var player = null
|
||||
|
||||
func _physics_process(delta):
|
||||
if Input.is_action_just_pressed("enter_hatch") && can_interact:
|
||||
anims.play("open")
|
||||
player.enter_hatch(position + snap_position.position)
|
||||
down_prompt.scale.y = -1
|
||||
down_prompt.visible = true
|
||||
player.connect("hatch_exited", self, "exit_hatch", [], CONNECT_ONESHOT)
|
||||
|
||||
func exit_hatch():
|
||||
anims.play("open")
|
||||
down_prompt.scale.y = 1
|
||||
|
||||
func _on_TriggerArea_area_entered(area):
|
||||
down_prompt.visible = true
|
||||
down_prompt.scale.y = 1
|
||||
can_interact = true
|
||||
player = area.get_owner()
|
||||
|
||||
func _on_TriggerArea_area_exited(area):
|
||||
if down_prompt.scale.y == 1:
|
||||
down_prompt.visible = false
|
||||
can_interact = false
|
78
objects/environment/hatch/hatch.tscn
Normal file
78
objects/environment/hatch/hatch.tscn
Normal file
|
@ -0,0 +1,78 @@
|
|||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://graphics/hatch/hatch.png" type="Texture" id=1]
|
||||
[ext_resource path="res://graphics/hud/down_prompt.png" type="Texture" id=2]
|
||||
[ext_resource path="res://objects/environment/hatch/hatch.gd" type="Script" id=3]
|
||||
|
||||
[sub_resource type="Animation" id=1]
|
||||
resource_name = "open"
|
||||
length = 0.9
|
||||
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.7, 0.8 ),
|
||||
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ 0, 1, 2, 1, 0 ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=2]
|
||||
resource_name = "idle"
|
||||
loop = true
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("DownPrompt:position")
|
||||
tracks/0/interp = 0
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0, 0.5, 1 ),
|
||||
"transitions": PoolRealArray( 1, 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector2( 4, -18 ), Vector2( 4, -16 ), Vector2( 4, -18 ) ]
|
||||
}
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=3]
|
||||
extents = Vector2( 4, 4 )
|
||||
|
||||
[node name="Hatch" type="Node2D"]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
position = Vector2( 6, 3 )
|
||||
texture = ExtResource( 1 )
|
||||
hframes = 3
|
||||
|
||||
[node name="SpriteAnim" type="AnimationPlayer" parent="."]
|
||||
anims/open = SubResource( 1 )
|
||||
|
||||
[node name="DownPrompt" type="Sprite" parent="."]
|
||||
visible = false
|
||||
position = Vector2( 4, -18 )
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="ArrowAnim" type="AnimationPlayer" parent="."]
|
||||
autoplay = "idle"
|
||||
anims/idle = SubResource( 2 )
|
||||
|
||||
[node name="TriggerArea" type="Area2D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 2
|
||||
monitorable = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="TriggerArea"]
|
||||
position = Vector2( 4, 4 )
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[node name="Position2D" type="Position2D" parent="."]
|
||||
position = Vector2( 4, -2 )
|
||||
__meta__ = {
|
||||
"_gizmo_extents_": 0.0
|
||||
}
|
||||
|
||||
[connection signal="area_entered" from="TriggerArea" to="." method="_on_TriggerArea_area_entered"]
|
||||
[connection signal="area_exited" from="TriggerArea" to="." method="_on_TriggerArea_area_exited"]
|
|
@ -1,5 +1,7 @@
|
|||
extends KinematicBody2D
|
||||
|
||||
signal hatch_exited
|
||||
|
||||
const ArrowProjectile = preload("res://objects/player/arrow_projectile.tscn")
|
||||
|
||||
##CLEAN UP CODE LATER
|
||||
|
@ -20,10 +22,12 @@ onready var sword_hitbox = $SwordArea
|
|||
onready var death_particles = $DeathSplatter
|
||||
onready var dust_particles = $DustParticles
|
||||
onready var iframe_timer = $IframeTimer
|
||||
onready var hitbox = $Area2D/CollisionShape2D2
|
||||
|
||||
#Map
|
||||
onready var map = get_owner()
|
||||
##States
|
||||
enum State {IDLE,WALK,JUMP,FALL,STUNNED,CLIMB,SWORD,SHOOT,INACTIVE,TRANSPORT}
|
||||
enum State {IDLE,WALK,JUMP,FALL,STUNNED,CLIMB,SWORD,SHOOT,INACTIVE,TRANSPORT,HATCH}
|
||||
var current_state = State.IDLE
|
||||
var can_die = true
|
||||
##Runtime
|
||||
|
@ -83,6 +87,9 @@ func _physics_process(delta):
|
|||
State.TRANSPORT:
|
||||
_process_transport(delta)
|
||||
return
|
||||
State.HATCH:
|
||||
_process_hatch(delta)
|
||||
return
|
||||
|
||||
#Gravity
|
||||
if current_state != State.CLIMB:
|
||||
|
@ -217,6 +224,11 @@ func _process_shoot():
|
|||
func _process_transport(delta):
|
||||
position += transport_direction * transport_speed * delta
|
||||
|
||||
func _process_hatch(delta):
|
||||
if Input.is_action_just_pressed("exit_hatch"):
|
||||
anims.play("enter hatch", -1, -1.25,true)
|
||||
emit_signal("hatch_exited")
|
||||
|
||||
func spawn_arrow():
|
||||
Audio.play_sound(Audio.a_shoot,Audio.ac_jump)
|
||||
var arrow = ArrowProjectile.instance()
|
||||
|
@ -299,6 +311,13 @@ func enter_transport(speed, direction):
|
|||
func exit_transport():
|
||||
current_state = State.FALL
|
||||
|
||||
func enter_hatch(snap_position):
|
||||
position = snap_position
|
||||
current_state = State.INACTIVE
|
||||
hitbox.disabled = true
|
||||
collision_layer = 0
|
||||
anims.play("enter hatch", -1, 1.25)
|
||||
|
||||
func die():
|
||||
if can_die:
|
||||
Audio.ac_climb.set_stream(null) # stop climbing sound\
|
||||
|
@ -346,6 +365,16 @@ func die():
|
|||
sprite.visible = true
|
||||
|
||||
func _on_AnimationPlayer_animation_finished(anim_name):
|
||||
#Set hatch state
|
||||
if anim_name == "enter hatch":
|
||||
match current_state:
|
||||
State.INACTIVE:
|
||||
current_state = State.HATCH
|
||||
return
|
||||
State.HATCH:
|
||||
current_state = State.IDLE
|
||||
hitbox.disabled = false
|
||||
collision_layer = 2
|
||||
if current_state == State.INACTIVE:
|
||||
return
|
||||
#Return to idle after slash
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=34 format=2]
|
||||
[gd_scene load_steps=35 format=2]
|
||||
|
||||
[ext_resource path="res://objects/player/player.gd" type="Script" id=1]
|
||||
[ext_resource path="res://graphics/player/sg_walk.png" type="Texture" id=2]
|
||||
|
@ -170,6 +170,45 @@ tracks/4/keys = {
|
|||
"values": [ 0.0, 0.0, 90.0, 90.0, 180.0, 180.0, 270.0, 270.0, 360.0 ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=45]
|
||||
resource_name = "enter hatch"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Sprite:offset")
|
||||
tracks/0/interp = 2
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0, 0.1, 0.3, 0.5 ),
|
||||
"transitions": PoolRealArray( 1, 1, 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector2( 0, 0 ), Vector2( 0, -6 ), Vector2( 0, 0 ), Vector2( 0, 10 ) ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Sprite:texture")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ ExtResource( 5 ) ]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/path = NodePath("Sprite:region_rect")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/keys = {
|
||||
"times": PoolRealArray( 0, 0.3, 0.5 ),
|
||||
"transitions": PoolRealArray( 1, 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Rect2( 1, 0, 20, 20 ), Rect2( 1, 0, 20, 20 ), Rect2( 1, 0, 20, 0 ) ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=30]
|
||||
resource_name = "idle"
|
||||
length = 0.5
|
||||
|
@ -621,9 +660,9 @@ max_fall_speed = 255.0
|
|||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
material = SubResource( 38 )
|
||||
texture = ExtResource( 3 )
|
||||
texture = ExtResource( 5 )
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 0, 0, 20, 20 )
|
||||
region_rect = Rect2( 1, 0, 20, 20 )
|
||||
script = ExtResource( 17 )
|
||||
|
||||
[node name="SwordSprite" type="Sprite" parent="."]
|
||||
|
@ -664,6 +703,7 @@ collide_with_bodies = false
|
|||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
anims/climb = SubResource( 29 )
|
||||
anims/doublejump = SubResource( 35 )
|
||||
"anims/enter hatch" = SubResource( 45 )
|
||||
anims/idle = SubResource( 30 )
|
||||
anims/jump = SubResource( 31 )
|
||||
"anims/shoot air" = SubResource( 37 )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue