Face traps with arrows

This commit is contained in:
Sagi Dayan 2020-11-12 23:45:32 -05:00
parent 834b3ed53f
commit 53b88e5553
10 changed files with 361 additions and 2 deletions

BIN
assets/Traps/arrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/arrow.png-6ef2cedb65ee67b68492baae0a925137.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/Traps/arrow.png"
dest_files=[ "res://.import/arrow.png-6ef2cedb65ee67b68492baae0a925137.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

BIN
assets/Traps/mask_trap.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

BIN
assets/Traps/mask_trap.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/mask_trap.png-818f650db1c37c9c6869abab749ce2d9.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/Traps/mask_trap.png"
dest_files=[ "res://.import/mask_trap.png-818f650db1c37c9c6869abab749ce2d9.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

File diff suppressed because one or more lines are too long

34
src/Hazards/Arrow.gd Normal file
View file

@ -0,0 +1,34 @@
extends Node2D
export var speed := 230
var _fly := true
var _pin_angle := 0
func _ready() -> void:
seed(self.get_instance_id())
var options = range(-30, 30, 5)
options.shuffle()
_pin_angle = options[0]
func _physics_process(delta: float) -> void:
if _fly:
position.x += speed * scale.x * delta
func _on_HitZone_body_entered(body:Node) -> void:
remove_child($HitZone)
if body.name == "Player":
body.die()
_fly = false
$AnimationPlayer.play("fade_out")
pass
func _on_PinZone_body_entered(body:Node) -> void:
remove_child($HitZone)
rotation_degrees = _pin_angle
print(rotation_degrees)
_fly = false
yield(get_tree().create_timer(5), "timeout")
$AnimationPlayer.play("fade_out")
pass

86
src/Hazards/Arrow.tscn Normal file
View file

@ -0,0 +1,86 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://assets/Traps/arrow.png" type="Texture" id=1]
[ext_resource path="res://src/Hazards/Arrow.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 2.5, 2.5 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 1.5, 1.5 )
[sub_resource type="Animation" id=3]
resource_name = "fade_out"
length = 0.2
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
}
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.2 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "queue_free"
} ]
}
[sub_resource type="Animation" id=4]
resource_name = "idle"
length = 0.1
tracks/0/type = "value"
tracks/0/path = NodePath("Sprite:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ) ]
}
[node name="Arrow" type="Node2D"]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( -7, -1 )
texture = ExtResource( 1 )
[node name="HitZone" type="Area2D" parent="."]
collision_layer = 0
collision_mask = 3
[node name="CollisionShape2D" type="CollisionShape2D" parent="HitZone"]
position = Vector2( -2.5, -0.5 )
shape = SubResource( 1 )
[node name="PinZone" type="Area2D" parent="."]
collision_layer = 0
collision_mask = 8
[node name="CollisionShape2D" type="CollisionShape2D" parent="PinZone"]
position = Vector2( -6, -0.5 )
shape = SubResource( 2 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "idle"
anims/fade_out = SubResource( 3 )
anims/idle = SubResource( 4 )
[connection signal="body_entered" from="HitZone" to="." method="_on_HitZone_body_entered"]
[connection signal="body_entered" from="PinZone" to="." method="_on_PinZone_body_entered"]

62
src/Hazards/MaskTrap.gd Normal file
View file

@ -0,0 +1,62 @@
extends Node2D
export var ammo:int = 1
export var timeout:= 2.0
export var enabled := true
var _activated := false
var _can_activate := true
onready var _ammo = ammo
var Arrow = load("res://src/Hazards/Arrow.tscn")
func _physics_process(delta: float) -> void:
if enabled && _can_activate && _did_trigger():
_can_activate = false
_activated = true
$AnimationPlayer.play("fire")
func _did_trigger()->bool:
if $TopRayCast.is_colliding():
var collider = $TopRayCast.get_collider()
if collider.name == "SolidsTileMap":
var new_cast = $TopRayCast.cast_to
new_cast.x = to_local($TopRayCast.get_collision_point()).x - 1
$TopRayCast.cast_to = new_cast
if collider.name == "Player":
return true
if $BottomRayCast.is_colliding():
var collider = $BottomRayCast.get_collider()
if collider.name == "SolidsTileMap":
var new_cast = $BottomRayCast.cast_to
new_cast.x = to_local($BottomRayCast.get_collision_point()).x - 1
$BottomRayCast.cast_to = new_cast
if $BottomRayCast.get_collider().name == "Player":
return true
return false
func _on_fire_animation_ended():
print("Fire!")
var arrow = Arrow.instance()
arrow.position = Vector2(8,-3)
add_child(arrow)
_ammo -= 1
if _ammo == 0:
$AnimationPlayer.play("idle")
_activated = false
$TimeoutTimer.start(timeout)
else:
$AnimationPlayer.play("fire")
pass
func _on_TimeoutTimer_timeout()->void:
_can_activate = true;
$AnimationPlayer.play("armed")
_ammo = ammo

100
src/Hazards/MaskTrap.tscn Normal file
View file

@ -0,0 +1,100 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://assets/Traps/mask_trap.png" type="Texture" id=1]
[ext_resource path="res://src/Hazards/MaskTrap.gd" type="Script" id=2]
[sub_resource type="Animation" id=1]
resource_name = "armed"
length = 0.1
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 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ 1 ]
}
[sub_resource type="Animation" id=2]
resource_name = "fire"
length = 0.3
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": [ 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.3 ),
"transitions": PoolRealArray( 1 ),
"values": [ {
"args": [ ],
"method": "_on_fire_animation_ended"
} ]
}
[sub_resource type="Animation" id=3]
resource_name = "idle"
length = 0.1
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 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ 0 ]
}
[node name="MaskTrap" type="Node2D"]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 7, -8 )
texture = ExtResource( 1 )
hframes = 6
frame = 1
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "armed"
anims/armed = SubResource( 1 )
anims/fire = SubResource( 2 )
anims/idle = SubResource( 3 )
[node name="TopRayCast" type="RayCast2D" parent="."]
position = Vector2( 3, -16 )
enabled = true
cast_to = Vector2( 150, 0 )
collision_mask = 9
[node name="BottomRayCast" type="RayCast2D" parent="."]
position = Vector2( 3, 0 )
enabled = true
cast_to = Vector2( 150, 0 )
collision_mask = 9
[node name="VisibilityEnabler2D" type="VisibilityEnabler2D" parent="."]
position = Vector2( 7, -8 )
[node name="TimeoutTimer" type="Timer" parent="."]
one_shot = true
[connection signal="timeout" from="TimeoutTimer" to="." method="_on_TimeoutTimer_timeout"]