Merged with daniel-hell-level and modified weapon handling
This commit is contained in:
@@ -7,10 +7,17 @@ export var FRICTION: int = 1000
|
||||
const HEALTH_SLICES: Array = [0, 18, 35, 50, 65, 82, 100]
|
||||
var health_index: int = 6
|
||||
|
||||
var l5_gems: int = 0
|
||||
|
||||
var hud: CanvasLayer = null
|
||||
var velocity: Vector2 = Vector2.ZERO
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_weapon_position(Vector2(1, 0))
|
||||
return
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var input_vector: Vector2 = Vector2.ZERO
|
||||
|
||||
@@ -23,6 +30,7 @@ func _physics_process(delta: float) -> void:
|
||||
if input_vector != Vector2.ZERO:
|
||||
$AnimationTree.set('parameters/Idle/blend_position', input_vector)
|
||||
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
|
||||
set_weapon_position(input_vector)
|
||||
else:
|
||||
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
|
||||
|
||||
@@ -40,6 +48,29 @@ func load_hud(node: CanvasLayer) -> void:
|
||||
return
|
||||
|
||||
|
||||
func set_weapon_position(pos: Vector2) -> void:
|
||||
# facing left
|
||||
if pos[0] < 0:
|
||||
$Sword.rotation_degrees = -90
|
||||
$Javelin.rotation_degrees = -90
|
||||
|
||||
# facing right
|
||||
elif pos[0] > 0:
|
||||
$Sword.rotation_degrees = 90
|
||||
$Javelin.rotation_degrees = 90
|
||||
|
||||
# facing up
|
||||
elif pos[1] < 0:
|
||||
$Sword.rotation_degrees = 0
|
||||
$Javelin.rotation_degrees = 0
|
||||
|
||||
# facing down
|
||||
elif pos[1] > 0:
|
||||
$Sword.rotation_degrees = 180
|
||||
$Javelin.rotation_degrees = 180
|
||||
return
|
||||
|
||||
|
||||
func add_currency(amount: int) -> void:
|
||||
$Inventory.add_currency(amount)
|
||||
return
|
||||
@@ -85,10 +116,16 @@ func _on_hitbox_area_entered(area: Area2D) -> void:
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed('player_attack'):
|
||||
if hud.weapon == 'sword':
|
||||
$'Sword/Sword Animation'.play('swing')
|
||||
elif hud.weapon == 'javelin':
|
||||
$'Javelin/Javelin Animation'.play('swing')
|
||||
|
||||
if event.is_action_pressed('screenshot'):
|
||||
var img: Image = get_viewport().get_texture().get_data()
|
||||
yield(get_tree(), "idle_frame")
|
||||
yield(get_tree(), "idle_frame")
|
||||
yield(get_tree(), 'idle_frame')
|
||||
yield(get_tree(), 'idle_frame')
|
||||
|
||||
img.flip_y()
|
||||
|
||||
|
@@ -1,16 +1,18 @@
|
||||
[gd_scene load_steps=20 format=2]
|
||||
[gd_scene load_steps=22 format=2]
|
||||
|
||||
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Sprites/Player/Player.png" type="Texture" id=2]
|
||||
[ext_resource path="res://Sprites/Player/Player_Down.png" type="Texture" id=3]
|
||||
[ext_resource path="res://Sprites/Player/Player_Up.png" type="Texture" id=4]
|
||||
[ext_resource path="res://Player/Inventory.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://Player/Weapons/Javelin.tscn" type="PackedScene" id=6]
|
||||
[ext_resource path="res://Player/Weapons/Sword.tscn" type="PackedScene" id=7]
|
||||
|
||||
[sub_resource type="SpriteFrames" id=1]
|
||||
animations = [ {
|
||||
"frames": [ ExtResource( 3 ) ],
|
||||
"frames": [ ExtResource( 2 ) ],
|
||||
"loop": false,
|
||||
"name": "look_down",
|
||||
"name": "look_left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ ExtResource( 2 ) ],
|
||||
@@ -18,15 +20,15 @@ animations = [ {
|
||||
"name": "look_right",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ ExtResource( 2 ) ],
|
||||
"loop": false,
|
||||
"name": "look_left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ ExtResource( 4 ) ],
|
||||
"loop": false,
|
||||
"name": "look_up",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [ ExtResource( 3 ) ],
|
||||
"loop": false,
|
||||
"name": "look_down",
|
||||
"speed": 5.0
|
||||
} ]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id=2]
|
||||
@@ -186,6 +188,7 @@ script = ExtResource( 1 )
|
||||
|
||||
[node name="Sprite" type="AnimatedSprite" parent="."]
|
||||
light_mask = 2
|
||||
z_index = 1
|
||||
frames = SubResource( 1 )
|
||||
animation = "look_right"
|
||||
offset = Vector2( 0, -4 )
|
||||
@@ -221,5 +224,11 @@ parameters/Idle/blend_position = Vector2( 0.0760697, 0 )
|
||||
|
||||
[node name="Inventory" parent="." instance=ExtResource( 5 )]
|
||||
|
||||
[node name="Sword" parent="." instance=ExtResource( 7 )]
|
||||
position = Vector2( 0, -4 )
|
||||
|
||||
[node name="Javelin" parent="." instance=ExtResource( 6 )]
|
||||
position = Vector2( 0, -4 )
|
||||
|
||||
[connection signal="area_entered" from="Hitbox" to="." method="_on_hitbox_area_entered"]
|
||||
[connection signal="update_currency" from="Inventory" to="." method="_on_Inventory_update_currency"]
|
||||
|
11
Player/Weapons/Javelin.gd
Normal file
11
Player/Weapons/Javelin.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
func _on_javelin_animation_animation_started(anim_name: String) -> void:
|
||||
$Animation/CollisionShape2D.set_deferred('monitorable', true)
|
||||
return
|
||||
|
||||
|
||||
func _on_javelin_animation_animation_finished(anim_name: String) -> void:
|
||||
$Animation/CollisionShape2D.set_deferred('monitorable', false)
|
||||
return
|
75
Player/Weapons/Javelin.tscn
Normal file
75
Player/Weapons/Javelin.tscn
Normal file
@@ -0,0 +1,75 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Sprites/Items/Javelin.png" type="Texture" id=1]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=3]
|
||||
extents = Vector2( 2.2, 3 )
|
||||
|
||||
[sub_resource type="Animation" id=2]
|
||||
resource_name = "swing"
|
||||
length = 0.4
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Animation:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0.01, 0.21 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector2( 0, 0 ), Vector2( 0, -7 ) ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Animation/Javelin:visible")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0, 0.01, 0.4 ),
|
||||
"transitions": PoolRealArray( 1, 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ false, true, false ]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/path = NodePath("Animation:monitorable")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/keys = {
|
||||
"times": PoolRealArray( 0.02, 0.22 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ true, false ]
|
||||
}
|
||||
|
||||
[node name="Javelin" type="Node2D"]
|
||||
light_mask = 0
|
||||
|
||||
[node name="Animation" type="Area2D" parent="." groups=["player_weapon_2"]]
|
||||
light_mask = 0
|
||||
position = Vector2( 0, -7 )
|
||||
collision_layer = 0
|
||||
collision_mask = 4
|
||||
input_pickable = false
|
||||
monitoring = false
|
||||
monitorable = false
|
||||
|
||||
[node name="Javelin" type="Sprite" parent="Animation"]
|
||||
visible = false
|
||||
light_mask = 8
|
||||
position = Vector2( 0, -7 )
|
||||
rotation = 0.785398
|
||||
scale = Vector2( 0.65, 0.65 )
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Animation"]
|
||||
visible = false
|
||||
light_mask = 0
|
||||
position = Vector2( 0, -11.5 )
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[node name="Javelin Animation" type="AnimationPlayer" parent="."]
|
||||
anims/swing = SubResource( 2 )
|
26
Player/Weapons/Sword.gd
Normal file
26
Player/Weapons/Sword.gd
Normal file
@@ -0,0 +1,26 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a: int = 2
|
||||
# var b: String = "text"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta: float) -> void:
|
||||
# pass
|
||||
|
||||
|
||||
func _on_SwordAttack_animation_started(anim_name: String) -> void:
|
||||
$Sword.visible = true
|
||||
return
|
||||
|
||||
|
||||
func _on_SwordAttack_animation_finished(anim_name: String) -> void:
|
||||
$Sword.visible = false
|
||||
return
|
75
Player/Weapons/Sword.tscn
Normal file
75
Player/Weapons/Sword.tscn
Normal file
@@ -0,0 +1,75 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://Sprites/Items/Sword.png" type="Texture" id=1]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=6]
|
||||
extents = Vector2( 1.5, 4.2 )
|
||||
|
||||
[sub_resource type="Animation" id=5]
|
||||
resource_name = "swing"
|
||||
length = 0.2
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Animation/Sword:visible")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0, 0.01, 0.2 ),
|
||||
"transitions": PoolRealArray( 1, 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ false, true, false ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Animation:rotation_degrees")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0.01, 0.19 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ -45.0, 45.0 ]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/path = NodePath("Animation:monitorable")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/keys = {
|
||||
"times": PoolRealArray( 0.02, 0.2 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ true, false ]
|
||||
}
|
||||
|
||||
[node name="Sword" type="Node2D"]
|
||||
light_mask = 0
|
||||
|
||||
[node name="Animation" type="Area2D" parent="." groups=["player_weapon_1"]]
|
||||
light_mask = 0
|
||||
rotation = 0.785398
|
||||
collision_layer = 0
|
||||
collision_mask = 4
|
||||
input_pickable = false
|
||||
monitoring = false
|
||||
monitorable = false
|
||||
|
||||
[node name="Sword" type="Sprite" parent="Animation"]
|
||||
visible = false
|
||||
light_mask = 8
|
||||
rotation = 0.785398
|
||||
scale = Vector2( 0.5, 0.5 )
|
||||
texture = ExtResource( 1 )
|
||||
offset = Vector2( -16, -16 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Animation"]
|
||||
visible = false
|
||||
light_mask = 0
|
||||
position = Vector2( 0, -13 )
|
||||
shape = SubResource( 6 )
|
||||
|
||||
[node name="Sword Animation" type="AnimationPlayer" parent="."]
|
||||
anims/swing = SubResource( 5 )
|
Reference in New Issue
Block a user