merge with main
This commit is contained in:
206
Player/Player.gd
206
Player/Player.gd
@@ -9,168 +9,162 @@ signal frozen
|
||||
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
|
||||
set_weapon_position(Vector2(1, 0))
|
||||
return
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var input_vector: Vector2 = Vector2.ZERO
|
||||
var input_vector: Vector2 = Vector2.ZERO
|
||||
|
||||
input_vector.x = Input.get_action_strength('player_right') \
|
||||
- Input.get_action_strength('player_left')
|
||||
input_vector.y = Input.get_action_strength('player_down') \
|
||||
- Input.get_action_strength('player_up')
|
||||
input_vector = input_vector.normalized()
|
||||
input_vector.x = Input.get_action_strength('player_right') \
|
||||
- Input.get_action_strength('player_left')
|
||||
input_vector.y = Input.get_action_strength('player_down') \
|
||||
- Input.get_action_strength('player_up')
|
||||
input_vector = input_vector.normalized()
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
velocity = move_and_slide(velocity)
|
||||
return
|
||||
velocity = move_and_slide(velocity)
|
||||
return
|
||||
|
||||
|
||||
func load_hud(node: CanvasLayer) -> void:
|
||||
hud = node
|
||||
if hud.connect('add_currency', self, 'add_currency') != OK:
|
||||
print('ERROR: HUD "add_currency" signal already connected.')
|
||||
hud = node
|
||||
if hud.connect('add_currency', self, 'add_currency') != OK:
|
||||
print('ERROR: HUD "add_currency" signal already connected.')
|
||||
|
||||
hud.update_health(HEALTH_SLICES[health_index])
|
||||
hud.update_currency($Inventory.get_currency())
|
||||
return
|
||||
hud.update_health(HEALTH_SLICES[health_index])
|
||||
hud.update_currency($Inventory.get_currency())
|
||||
return
|
||||
|
||||
|
||||
func set_weapon_position(pos: Vector2) -> void:
|
||||
# facing left
|
||||
if pos[0] < 0:
|
||||
$Sword.rotation_degrees = -90
|
||||
$Javelin.rotation_degrees = -90
|
||||
# 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 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 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
|
||||
# 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
|
||||
$Inventory.add_currency(amount)
|
||||
return
|
||||
|
||||
|
||||
func has_item(item: String) -> bool:
|
||||
return $Inventory.contains(item)
|
||||
return $Inventory.contains(item)
|
||||
|
||||
|
||||
func add_item(item: String) -> void:
|
||||
$Inventory.add(item)
|
||||
return
|
||||
$Inventory.add(item)
|
||||
return
|
||||
|
||||
|
||||
func remove_item(item: String) -> void:
|
||||
$Inventory.remove(item)
|
||||
return
|
||||
$Inventory.remove(item)
|
||||
return
|
||||
|
||||
|
||||
func _on_Inventory_update_currency(amount: int) -> void:
|
||||
hud.update_currency(amount)
|
||||
return
|
||||
hud.update_currency(amount)
|
||||
return
|
||||
|
||||
|
||||
func _on_hitbox_area_entered(area: Area2D) -> void:
|
||||
var hit: int = 0
|
||||
var hit: int = 0
|
||||
|
||||
if area.is_in_group('enemy_hitbox_1') or area.is_in_group('enemy_projectile_1'):
|
||||
hit = 1
|
||||
elif area.is_in_group('enemy_hitbox_2') or area.is_in_group('enemy_projectile_2'):
|
||||
hit = 2
|
||||
elif area.is_in_group('enemy_hitbox_3') or area.is_in_group('enemy_projectile_3'):
|
||||
hit = 3
|
||||
elif area.is_in_group('freeze'):
|
||||
emit_signal('frozen')
|
||||
modulate = Color(0,.5,1)
|
||||
else:
|
||||
return
|
||||
#var timer = Timer.new()
|
||||
if area.is_in_group('enemy_hitbox_1') or area.is_in_group('enemy_projectile_1'):
|
||||
hit = 1
|
||||
elif area.is_in_group('enemy_hitbox_2') or area.is_in_group('enemy_projectile_2'):
|
||||
hit = 2
|
||||
elif area.is_in_group('enemy_hitbox_3') or area.is_in_group('enemy_projectile_3'):
|
||||
hit = 3
|
||||
elif area.is_in_group('freeze'):
|
||||
emit_signal('frozen')
|
||||
modulate = Color(0,.5,1)
|
||||
else:
|
||||
return
|
||||
|
||||
if health_index != 0:
|
||||
health_index -= hit
|
||||
if health_index < 0:
|
||||
health_index = 0
|
||||
|
||||
#if body.name.begins_with("blue_snowman"):
|
||||
# MAX_SPEED = 20
|
||||
# yield(get_tree().create_timer(3.0), "timeout")
|
||||
# MAX_SPEED = 120
|
||||
hud.update_health(HEALTH_SLICES[health_index])
|
||||
else:
|
||||
get_tree().change_scene('res://Levels/Hub World.tscn')
|
||||
|
||||
if health_index != 0:
|
||||
health_index -= hit
|
||||
if health_index < 0:
|
||||
health_index = 0
|
||||
return
|
||||
|
||||
hud.update_health(HEALTH_SLICES[health_index])
|
||||
else:
|
||||
get_tree().change_scene('res://Levels/Hub World.tscn')
|
||||
|
||||
return
|
||||
|
||||
|
||||
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('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')
|
||||
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')
|
||||
|
||||
img.flip_y()
|
||||
img.flip_y()
|
||||
|
||||
var time: Dictionary = OS.get_datetime_from_unix_time(OS.get_unix_time())
|
||||
var time_msecs: int = OS.get_system_time_msecs()
|
||||
var time: Dictionary = OS.get_datetime_from_unix_time(OS.get_unix_time())
|
||||
var time_msecs: int = OS.get_system_time_msecs()
|
||||
|
||||
if img.save_png('user://Screenshot_%d%d%d_%d.png' % [time.year, time.month, time.day, time_msecs]) != OK:
|
||||
print('ERROR: Failed saving screenshot.')
|
||||
return
|
||||
|
||||
if img.save_png('user://Screenshot_%d%d%d_%d.png' % [time.year, time.month, time.day, time_msecs]) != OK:
|
||||
print('ERROR: Failed saving screenshot.')
|
||||
return
|
||||
|
||||
|
||||
func _on_Hitbox_area_entered(area: Area2D) -> void:
|
||||
print(area.name)
|
||||
print(area.name)
|
||||
|
||||
if area.name == 'detection':
|
||||
return
|
||||
|
||||
if 'freeze' in area.get_parent().get_groups():
|
||||
emit_signal('frozen')
|
||||
return
|
||||
if area.name == 'detection':
|
||||
return
|
||||
|
||||
if 'freeze' in area.get_parent().get_groups():
|
||||
emit_signal('frozen')
|
||||
return
|
||||
|
||||
if 'enemies' in area.get_parent().get_groups() or area.name != 'detection' or 'damage' in area.get_groups():
|
||||
if health_index != 0:
|
||||
health_index -= 1
|
||||
hud.update_health(HEALTH_SLICES[health_index])
|
||||
else:
|
||||
get_tree().change_scene('res://Levels/Hub World.tscn')
|
||||
return
|
||||
if 'enemies' in area.get_parent().get_groups() or area.name != 'detection' or 'damage' in area.get_groups():
|
||||
if health_index != 0:
|
||||
health_index -= 1
|
||||
hud.update_health(HEALTH_SLICES[health_index])
|
||||
else:
|
||||
get_tree().change_scene('res://Levels/Hub World.tscn')
|
||||
return
|
||||
|
||||
|
||||
func _on_SlowTime_unfreeze() -> void:
|
||||
modulate = Color(1,1,1)
|
||||
modulate = Color(1,1,1)
|
||||
|
||||
|
@@ -1,11 +0,0 @@
|
||||
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
|
@@ -3,7 +3,7 @@
|
||||
[ext_resource path="res://Sprites/Items/Javelin.png" type="Texture" id=1]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=3]
|
||||
extents = Vector2( 2.2, 3 )
|
||||
extents = Vector2( 4, 9 )
|
||||
|
||||
[sub_resource type="Animation" id=2]
|
||||
resource_name = "swing"
|
||||
@@ -15,34 +15,46 @@ tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0.01, 0.21 ),
|
||||
"times": PoolRealArray( 0, 0.2 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 0,
|
||||
"update": 1,
|
||||
"values": [ Vector2( 0, 0 ), Vector2( 0, -7 ) ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Animation/Javelin:visible")
|
||||
tracks/1/path = NodePath("Animation:position")
|
||||
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 ]
|
||||
"times": PoolRealArray( 0.01, 0.19 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector2( 0, 0 ), Vector2( 0, -7 ) ]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/path = NodePath("Animation:monitorable")
|
||||
tracks/2/path = NodePath("Animation/Javelin:visible")
|
||||
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 ),
|
||||
"times": PoolRealArray( 0, 0.01, 0.4 ),
|
||||
"transitions": PoolRealArray( 1, 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ false, true, false ]
|
||||
}
|
||||
tracks/3/type = "value"
|
||||
tracks/3/path = NodePath("Animation/CollisionShape2D:disabled")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/keys = {
|
||||
"times": PoolRealArray( 0.01, 0.2 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ true, false ]
|
||||
"values": [ false, true ]
|
||||
}
|
||||
|
||||
[node name="Javelin" type="Node2D"]
|
||||
@@ -50,26 +62,24 @@ 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 )
|
||||
position = Vector2( 0, -10 )
|
||||
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 )
|
||||
position = Vector2( 0, -13 )
|
||||
shape = SubResource( 3 )
|
||||
disabled = true
|
||||
|
||||
[node name="Javelin Animation" type="AnimationPlayer" parent="."]
|
||||
anims/swing = SubResource( 2 )
|
||||
|
@@ -1,26 +0,0 @@
|
||||
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
|
@@ -1,9 +1,24 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=5 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 )
|
||||
extents = Vector2( 2.5, 10 )
|
||||
|
||||
[sub_resource type="Animation" id=7]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Animation:rotation_degrees")
|
||||
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": [ -45.0 ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=5]
|
||||
resource_name = "swing"
|
||||
@@ -27,22 +42,34 @@ tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0.01, 0.19 ),
|
||||
"times": PoolRealArray( 0, 0.2 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 0,
|
||||
"update": 1,
|
||||
"values": [ -45.0, 45.0 ]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/path = NodePath("Animation:monitorable")
|
||||
tracks/2/path = NodePath("Animation:rotation_degrees")
|
||||
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 ),
|
||||
"times": PoolRealArray( 0.01, 0.19 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 0,
|
||||
"values": [ -45.0, 45.0 ]
|
||||
}
|
||||
tracks/3/type = "value"
|
||||
tracks/3/path = NodePath("Animation/CollisionShape2D:disabled")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/keys = {
|
||||
"times": PoolRealArray( 0.01, 0.2 ),
|
||||
"transitions": PoolRealArray( 1, 1 ),
|
||||
"update": 1,
|
||||
"values": [ true, false ]
|
||||
"values": [ false, true ]
|
||||
}
|
||||
|
||||
[node name="Sword" type="Node2D"]
|
||||
@@ -50,26 +77,27 @@ light_mask = 0
|
||||
|
||||
[node name="Animation" type="Area2D" parent="." groups=["player_weapon_1"]]
|
||||
light_mask = 0
|
||||
rotation = 0.785398
|
||||
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 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
texture = ExtResource( 1 )
|
||||
offset = Vector2( -16, -16 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Animation"]
|
||||
visible = false
|
||||
light_mask = 0
|
||||
position = Vector2( 0, -13 )
|
||||
position = Vector2( 0, -14 )
|
||||
shape = SubResource( 6 )
|
||||
disabled = true
|
||||
|
||||
[node name="Sword Animation" type="AnimationPlayer" parent="."]
|
||||
anims/RESET = SubResource( 7 )
|
||||
anims/swing = SubResource( 5 )
|
||||
|
Reference in New Issue
Block a user