2021-09-22 18:04:03 +02:00
|
|
|
extends KinematicBody
|
2021-09-08 18:36:41 +02:00
|
|
|
class_name Character
|
|
|
|
|
|
|
|
enum States {
|
|
|
|
Alive,
|
|
|
|
Dead
|
|
|
|
}
|
|
|
|
|
2021-09-22 18:04:03 +02:00
|
|
|
enum GroundType {
|
|
|
|
DIRT,
|
|
|
|
WATER,
|
|
|
|
WOOD
|
|
|
|
}
|
|
|
|
|
|
|
|
var UI: Control
|
|
|
|
export var gravity: float = 9.8
|
|
|
|
export var walk_speed: float = 10
|
|
|
|
export var max_weapons: int = 5
|
|
|
|
export var weapons: Array = []
|
|
|
|
var is_in_water: bool = false
|
|
|
|
export var collision_shape: Shape
|
|
|
|
|
|
|
|
var ground_type = GroundType.DIRT
|
|
|
|
|
|
|
|
var footstep_sounds = {
|
|
|
|
GroundType.DIRT: [
|
|
|
|
preload("res://assets/audio/Sounds/SR_FSDI1.xx_reaperlev1.gzp.wav"),
|
|
|
|
preload("res://assets/audio/Sounds/SR_FSDI2.xx_reaperlev1.gzp.wav")
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
export var health = 100
|
|
|
|
var state = States.Alive
|
|
|
|
|
|
|
|
func has_weapon(weapon: Weapon) -> bool:
|
|
|
|
if get_similar_weapon(weapon):
|
|
|
|
return true
|
|
|
|
else:
|
|
|
|
return false
|
|
|
|
|
|
|
|
func get_similar_weapon(weapon: Weapon) -> Weapon:
|
|
|
|
for weap in weapons:
|
|
|
|
if weap.name == weapon.name:
|
|
|
|
return weap
|
|
|
|
return null
|
2021-09-08 18:36:41 +02:00
|
|
|
|
2021-09-22 18:04:03 +02:00
|
|
|
func can_pickup_weapon(weapon: Weapon) -> bool:
|
|
|
|
return has_weapon(weapon) or len(weapons) < max_weapons
|
2021-09-08 18:36:41 +02:00
|
|
|
|
2021-09-22 18:04:03 +02:00
|
|
|
func pickup_weapon(weapon: Weapon) -> void:
|
|
|
|
var similar = get_similar_weapon(weapon)
|
|
|
|
if similar:
|
|
|
|
similar.current_ammo = clamp(similar.current_ammo + weapon.current_ammo, 0, weapon.max_ammo)
|
|
|
|
else:
|
|
|
|
weapons.append(weapon)
|
|
|
|
|
|
|
|
func take_damage(hitpts: float):
|
|
|
|
health -= hitpts
|
|
|
|
if health <= 0:
|
|
|
|
die()
|
|
|
|
|
|
|
|
func die():
|
|
|
|
state = States.Dead
|
2021-09-08 18:36:41 +02:00
|
|
|
|
2021-09-22 18:04:03 +02:00
|
|
|
func play_footstep():
|
|
|
|
var sound = footstep_sounds[ground_type][randi() % len(footstep_sounds[ground_type])]
|
|
|
|
Globals.play_sound(sound, "Sounds", self)
|