feat: Implement core game mechanics including player, enemies, bullets, HUD, and level setup.
This commit is contained in:
47
scripts/player.gd
Normal file
47
scripts/player.gd
Normal file
@@ -0,0 +1,47 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
|
||||
@export var max_speed: float = 150.0
|
||||
@export var acceleration: float = 250.0
|
||||
@export var deceleration: float = 120.0
|
||||
@export var rotation_speed: float = 2.5
|
||||
@export var max_health: float = 100.0
|
||||
|
||||
signal health_changed(current, max)
|
||||
signal died
|
||||
|
||||
var current_health: float
|
||||
|
||||
func _ready():
|
||||
add_to_group("player")
|
||||
current_health = max_health
|
||||
health_changed.emit(current_health, max_health)
|
||||
|
||||
func take_damage(amount: float):
|
||||
current_health -= amount
|
||||
health_changed.emit(current_health, max_health)
|
||||
|
||||
if current_health <= 0:
|
||||
die()
|
||||
|
||||
func die():
|
||||
died.emit()
|
||||
|
||||
func _physics_process(delta):
|
||||
#rotate
|
||||
var turn_input = Input.get_action_strength("kb_d") - Input.get_action_strength("kb_a")
|
||||
rotation += turn_input * rotation_speed * delta
|
||||
|
||||
#move
|
||||
var move_input = Input.get_action_strength("kb_w") - Input.get_action_strength("kb_s")
|
||||
|
||||
#current hull direction
|
||||
var forward_dir = Vector2.RIGHT.rotated(rotation)
|
||||
|
||||
#calc velocity
|
||||
var forward_speed = velocity.dot(forward_dir)
|
||||
var target_speed = move_input * max_speed
|
||||
forward_speed = move_toward(forward_speed, target_speed, (acceleration if move_input != 0 else deceleration) * delta)
|
||||
velocity = forward_dir * forward_speed
|
||||
|
||||
move_and_slide()
|
||||
Reference in New Issue
Block a user