53 lines
1.3 KiB
GDScript
53 lines
1.3 KiB
GDScript
class_name Player
|
|
extends Node2D
|
|
|
|
@export var speed = 80
|
|
var velocity := Vector2.ZERO
|
|
var collision: DanmakuCircle = DanmakuCircle.new()
|
|
|
|
# This is temporary, it should be defined per-sprite when I get to the skin system
|
|
const PLAYER_BODY_WIDTH_MULTIPLIER = 0.18
|
|
|
|
# Temp
|
|
var flash_timer = 0.0
|
|
var flashing = false
|
|
|
|
func _ready() -> void:
|
|
$BodySprite.scale_sprite(PLAYER_BODY_WIDTH_MULTIPLIER)
|
|
|
|
func get_input():
|
|
if Input.is_action_pressed("Slow Mode"):
|
|
speed = 30
|
|
else:
|
|
speed = 80
|
|
|
|
velocity = Input.get_vector("Left", "Right", "Up", "Down") * speed
|
|
|
|
func _physics_process(delta: float):
|
|
# Temp
|
|
if flashing:
|
|
flash_timer -= delta
|
|
$BodySprite.modulate = Color(1, 1, 1, 1)
|
|
flashing = false
|
|
|
|
get_input()
|
|
|
|
# Bounds checking
|
|
var attempted_position := position + (velocity * delta)
|
|
attempted_position = attempted_position.clamp(Vector2(0, 0), Globals.SERVER_SIZE)
|
|
|
|
set_position_data(attempted_position, null)
|
|
|
|
func set_position_data(pos: Vector2, hurtcircle_scale_multiplier):
|
|
position = pos
|
|
collision.set_position(pos.x, pos.y)
|
|
|
|
if hurtcircle_scale_multiplier:
|
|
collision.set_radius(Globals.SERVER_SIZE.x*hurtcircle_scale_multiplier)
|
|
$HurtcircleSprite.scale_sprite(hurtcircle_scale_multiplier*2)
|
|
|
|
func kill():
|
|
# Temp
|
|
$BodySprite.modulate = Color(1, 0, 0, 1)
|
|
flash_timer = 0.5
|
|
flashing = true
|