camera movement & music
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
extends Node2D
|
||||
extends CharacterBody2D
|
||||
|
||||
# ActionState should probably be expandable to
|
||||
enum ActionState {None, Cycling, Firing, Charging}
|
||||
@@ -8,9 +8,11 @@ enum MoveState {Still, Moving, Dashing, Knockback}
|
||||
@export var dash_cooldown = 0.3
|
||||
@export var hand_size = 3
|
||||
|
||||
@onready var camera: Camera2D = %PlayerCamera
|
||||
@onready var sprite: AnimatedSprite2D = $PlayerSprite
|
||||
|
||||
var shield_active = true;
|
||||
var move_direction = Vector2.ZERO;
|
||||
var velocity = Vector2.ZERO # The player's movement vector.
|
||||
var target = Vector2.ZERO # The position of the player's cursor.
|
||||
|
||||
const drawpile = [];
|
||||
@@ -43,6 +45,14 @@ func update_move_direction():
|
||||
|
||||
func update_target_coords():
|
||||
target = get_viewport().get_mouse_position()
|
||||
var self_view_position = self.position - camera.position + screen_size / 2
|
||||
sprite.look_at(target - self_view_position)
|
||||
|
||||
func update_camera_position():
|
||||
if not camera:
|
||||
return;
|
||||
var camera_target = (target - screen_size / 2) / 4
|
||||
camera.position = camera.position.lerp(camera_target, 0.1)
|
||||
|
||||
func charge():
|
||||
# Charge attack
|
||||
@@ -106,6 +116,7 @@ func _ready():
|
||||
|
||||
func _process(delta):
|
||||
update_target_coords();
|
||||
update_camera_position();
|
||||
if (move_state != MoveState.Dashing):
|
||||
update_move_direction();
|
||||
|
||||
@@ -126,9 +137,8 @@ func _process(delta):
|
||||
move_state = MoveState.Moving;
|
||||
else:
|
||||
move_state = MoveState.Still;
|
||||
|
||||
position += velocity * delta
|
||||
position = position.clamp(Vector2.ZERO, screen_size)
|
||||
|
||||
move_and_slide();
|
||||
|
||||
# Handle action_state
|
||||
if Input.is_action_pressed("play_card"):
|
||||
|
||||
Reference in New Issue
Block a user