68 lines
1.7 KiB
GDScript
68 lines
1.7 KiB
GDScript
class_name Player
|
|
extends Node2D
|
|
|
|
@export var controlled = false
|
|
const SPEED = 80
|
|
var slow = false
|
|
var tick_vel := Vector2.ZERO
|
|
var delta_vel_since_last_broadcast := 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(delta):
|
|
slow = false
|
|
if Input.is_action_pressed("Slow Mode"):
|
|
slow = true
|
|
|
|
tick_vel = Input.get_vector("Left", "Right", "Up", "Down") * ((SPEED / 3) if slow else SPEED) * delta
|
|
delta_vel_since_last_broadcast += tick_vel
|
|
|
|
func _physics_process(delta: float):
|
|
get_input(delta)
|
|
|
|
#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 get_and_reset_delta_vel():
|
|
var ret = delta_vel_since_last_broadcast
|
|
delta_vel_since_last_broadcast = Vector2.ZERO
|
|
return ret
|
|
|
|
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()
|