68 lines
1.4 KiB
GDScript
68 lines
1.4 KiB
GDScript
extends KinematicBody
|
|
class_name Character
|
|
|
|
enum States {
|
|
Alive,
|
|
Dead
|
|
}
|
|
|
|
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
|
|
|
|
func can_pickup_weapon(weapon: Weapon) -> bool:
|
|
return has_weapon(weapon) or len(weapons) < max_weapons
|
|
|
|
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
|
|
|
|
func play_footstep():
|
|
var sound = footstep_sounds[ground_type][randi() % len(footstep_sounds[ground_type])]
|
|
Globals.play_sound(sound, "Sounds", self)
|