61 lines
1.4 KiB
GDScript
61 lines
1.4 KiB
GDScript
class_name Player
|
|
extends Node2D
|
|
|
|
@export var speed = 80
|
|
var velocity := Vector2.ZERO
|
|
var hurt_collision: DanmakuCircle = DanmakuCircle.new()
|
|
var graze_collision: DanmakuCircle = DanmakuCircle.new()
|
|
const PLAYER_BODY_WIDTH_MULTIPLIER = 0.18
|
|
var alive: bool = true
|
|
|
|
func _ready() -> void:
|
|
$BodySprite.scale_sprite(PLAYER_BODY_WIDTH_MULTIPLIER * Globals.SERVER_SIZE.x)
|
|
|
|
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):
|
|
get_input()
|
|
|
|
if !alive:
|
|
return
|
|
|
|
# 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, null)
|
|
|
|
func set_position_data(pos: Vector2, hurtcircle_radius, grazecircle_radius):
|
|
position = pos
|
|
hurt_collision.set_position(pos.x, pos.y)
|
|
graze_collision.set_position(pos.x, pos.y)
|
|
|
|
if hurtcircle_radius:
|
|
hurt_collision.set_radius(hurtcircle_radius)
|
|
$HurtcircleSprite.scale_sprite(hurtcircle_radius*2)
|
|
|
|
if grazecircle_radius:
|
|
graze_collision.set_radius(grazecircle_radius)
|
|
$GrazecircleSprite.scale_sprite(grazecircle_radius*2)
|
|
|
|
|
|
func kill():
|
|
if alive == false:
|
|
return
|
|
|
|
alive = false
|
|
$AudioStreamPlayer.play()
|
|
self.hide()
|
|
|
|
func resurrect():
|
|
if alive == true:
|
|
return
|
|
|
|
alive = true
|
|
self.show()
|