2020-07-17 09:51:46 -05:00
|
|
|
extends KinematicBody2D
|
2020-07-17 00:27:22 -05:00
|
|
|
|
2020-07-17 11:03:22 -05:00
|
|
|
signal grounded_updated(is_grounded)
|
2020-07-17 19:18:59 -05:00
|
|
|
signal health_updated(new_health)
|
|
|
|
signal energy_updated(new_energy)
|
2020-07-17 11:03:22 -05:00
|
|
|
|
|
|
|
var velocity = Vector2()
|
|
|
|
var input_direction: int = 0
|
|
|
|
var speed = 10 * 16
|
|
|
|
var gravity
|
|
|
|
var max_jump_velocity
|
|
|
|
var min_jump_velocity
|
|
|
|
var walljump_velocity
|
|
|
|
var max_jump_height = 2.75 * 16
|
|
|
|
var min_jump_height = 0.6 * 16
|
|
|
|
var walljump_height = 2.25 * 16
|
|
|
|
var jump_duration = 0.35
|
|
|
|
var is_grounded
|
2020-07-22 00:41:29 -05:00
|
|
|
var touching_wall = 0
|
2020-07-17 11:03:22 -05:00
|
|
|
|
|
|
|
onready var Spr: Sprite = $Sprite
|
|
|
|
onready var Occluder: LightOccluder2D = $Sprite/LightOccluder2D
|
|
|
|
onready var Anim: AnimationPlayer = $AnimationPlayer
|
|
|
|
onready var CoyoteTimer: Timer = $CoyoteTimer
|
2020-07-17 15:43:22 -05:00
|
|
|
onready var ShootDelay: Timer = $ShootDelay
|
2020-07-17 11:03:22 -05:00
|
|
|
onready var StateMachine: Node = $PlayerStateMachine
|
2020-07-19 18:36:36 -05:00
|
|
|
onready var WandPosition: Node2D = $WandPosition
|
2020-07-17 15:21:22 -05:00
|
|
|
onready var ProjectileSpawn: Node2D = $HoldPosition/ProjectileSpawn
|
2020-07-18 15:58:23 -05:00
|
|
|
onready var Inventory: CanvasLayer = $Inventory
|
2020-07-17 19:18:59 -05:00
|
|
|
onready var Stats = $Stats
|
2020-07-22 00:41:29 -05:00
|
|
|
onready var Cam: Camera2D = $Camera
|
2020-07-17 11:03:22 -05:00
|
|
|
|
2020-07-21 15:50:32 -05:00
|
|
|
onready var HitSound: AudioStreamPlayer2D = $"Enemy Hit"
|
|
|
|
|
2020-07-17 19:18:59 -05:00
|
|
|
onready var health = Stats.health setget set_health, get_health
|
|
|
|
onready var energy = Stats.energy setget set_energy, get_energy
|
2020-07-17 11:03:22 -05:00
|
|
|
|
2020-07-21 15:50:32 -05:00
|
|
|
func play_hitsound():
|
|
|
|
HitSound.play(0.0)
|
2020-07-21 23:22:33 -05:00
|
|
|
$HitAnimation.play("Hit")
|
2020-07-21 15:50:32 -05:00
|
|
|
|
2020-07-22 13:12:24 -05:00
|
|
|
|
|
|
|
|
2020-07-19 18:36:36 -05:00
|
|
|
func get_current_conduit():
|
|
|
|
return Inventory.active_conduit
|
|
|
|
|
|
|
|
func get_current_projectile():
|
|
|
|
return Inventory.active_projectile
|
|
|
|
|
2020-07-18 02:27:01 -05:00
|
|
|
func get_type():
|
|
|
|
return "player"
|
|
|
|
|
2020-07-17 19:18:59 -05:00
|
|
|
func set_health(value):
|
|
|
|
Stats.set_health(value)
|
2020-07-20 23:24:09 -05:00
|
|
|
emit_signal("health_updated", value)
|
2020-07-17 19:18:59 -05:00
|
|
|
|
|
|
|
func get_health():
|
|
|
|
return Stats.get_health()
|
|
|
|
|
|
|
|
func set_energy(value):
|
|
|
|
Stats.set_energy(value)
|
2020-07-20 23:24:09 -05:00
|
|
|
emit_signal("energy_updated", value)
|
2020-07-17 19:18:59 -05:00
|
|
|
|
|
|
|
func get_energy():
|
|
|
|
return Stats.get_energy()
|
2020-07-17 15:43:22 -05:00
|
|
|
|
2020-07-17 11:03:22 -05:00
|
|
|
func _ready():
|
|
|
|
gravity = 2 * max_jump_height / pow(jump_duration, 2)
|
|
|
|
max_jump_velocity = -sqrt(2 * gravity * max_jump_height)
|
|
|
|
min_jump_velocity = -sqrt(2 * gravity * min_jump_height)
|
|
|
|
walljump_velocity = -sqrt(2 * gravity * walljump_height)
|
|
|
|
|
2020-07-17 09:51:46 -05:00
|
|
|
func _physics_process(delta):
|
2020-07-20 23:24:09 -05:00
|
|
|
Player.position = global_position - Vector2(0, 10)
|
2020-07-17 11:03:22 -05:00
|
|
|
emit_signal("grounded_updated", is_on_floor())
|
2020-07-18 17:07:40 -05:00
|
|
|
if get_health() <= 0:
|
2020-07-19 11:58:12 -05:00
|
|
|
get_tree().change_scene("res://Title/Death Screen'.tscn")
|
2020-07-17 11:03:22 -05:00
|
|
|
|
2020-07-22 00:41:29 -05:00
|
|
|
|
|
|
|
|
2020-07-17 11:03:22 -05:00
|
|
|
func handle_move_input():
|
|
|
|
input_direction = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left"))
|
|
|
|
velocity.x = lerp(velocity.x, speed * input_direction, get_movement_weight())
|
2020-07-19 18:36:36 -05:00
|
|
|
WandPosition.look_at(get_global_mouse_position())
|
2020-07-17 11:03:22 -05:00
|
|
|
|
|
|
|
if input_direction > 0:
|
|
|
|
Spr.flip_h = false
|
|
|
|
Occluder.scale.x = 1
|
|
|
|
|
|
|
|
if input_direction < 0:
|
|
|
|
Spr.flip_h = true
|
|
|
|
Occluder.scale.x = -1
|
|
|
|
|
|
|
|
func jump():
|
|
|
|
velocity.y = max_jump_velocity
|
|
|
|
CoyoteTimer.stop()
|
|
|
|
|
|
|
|
func apply_gravity(delta, modifier = 1):
|
|
|
|
velocity.y += gravity * delta * modifier
|
|
|
|
|
|
|
|
func apply_movement():
|
|
|
|
if velocity.x > -1 and velocity.x < 1:
|
|
|
|
velocity.x = 0
|
|
|
|
var was_on_floor = is_on_floor()
|
|
|
|
velocity = move_and_slide(velocity, Vector2.UP)
|
|
|
|
if !is_on_floor() and was_on_floor and velocity.y >= 0:
|
|
|
|
CoyoteTimer.start()
|
2020-07-17 11:26:02 -05:00
|
|
|
if !was_on_floor and is_on_floor():
|
|
|
|
emit_signal("grounded_updated", is_on_floor())
|
2020-07-17 11:03:22 -05:00
|
|
|
var was_grounded = is_grounded
|
|
|
|
is_grounded = is_on_floor()
|
|
|
|
|
|
|
|
func get_movement_weight():
|
2020-07-17 09:51:46 -05:00
|
|
|
if is_on_floor():
|
2020-07-17 11:03:22 -05:00
|
|
|
return 0.2
|
|
|
|
else:
|
|
|
|
return 0.07
|
|
|
|
|
2020-07-22 13:12:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
func _on_Leap_body_entered(body):
|
|
|
|
$AnimationPlayer.play("Black Fade in")
|