game: add player stats and modifiers
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
class_name Player
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var camera: Camera2D
|
||||
@export var main_ui: MainUI
|
||||
@export var default_movement_speed: float = 200.0
|
||||
@export var default_max_health: float = 50.0
|
||||
|
||||
@onready var sprite_2d: Sprite2D = $Sprite2D
|
||||
|
||||
var movement_speed: float
|
||||
var max_health: float
|
||||
var health: float
|
||||
var player_stats: PlayerStats = PlayerStats.new()
|
||||
var modifiers: Array[PlayerStatsModifier] = []
|
||||
var dead: bool = false
|
||||
var death_anim_done: bool = false
|
||||
var god_mode: bool = false
|
||||
@@ -17,9 +15,6 @@ var god_mode: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
camera.position = global_position
|
||||
movement_speed = default_movement_speed
|
||||
max_health = default_max_health
|
||||
health = max_health
|
||||
main_ui.player_ui.set_hp(100)
|
||||
GlobalConst.sig_debug_god_mode.connect(toggle_god_mode)
|
||||
|
||||
@@ -28,7 +23,8 @@ func _physics_process(delta: float) -> void:
|
||||
if dead:
|
||||
return
|
||||
var input_direction = Input.get_vector("left", "right", "up", "down")
|
||||
velocity = input_direction * movement_speed
|
||||
var move_speed = player_stats.get_final("move_speed", modifiers)
|
||||
velocity = input_direction * move_speed
|
||||
move_and_slide()
|
||||
|
||||
|
||||
@@ -42,14 +38,13 @@ func _process(delta: float) -> void:
|
||||
func take_damage(value: float) -> void:
|
||||
if dead or god_mode:
|
||||
return
|
||||
health -= value
|
||||
print_debug("player took damage. now has %s hp" % health)
|
||||
player_stats.current_health -= value
|
||||
var dm = preload("res://scenes/damage_numbers.tscn").instantiate()
|
||||
dm.damage_taken = value
|
||||
dm.player_damage = false
|
||||
add_child(dm)
|
||||
main_ui.player_ui.set_hp(health / max_health * 100)
|
||||
if health <= 0:
|
||||
main_ui.player_ui.set_hp((player_stats.current_health / player_stats.get_final("max_health", modifiers)) * 100)
|
||||
if player_stats.current_health <= 0:
|
||||
die()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user