birb/main character.gd
Travis Gatlin 37b0069108 VS-4/player-health-system (#11)
UPDATED TO GODOT 4.4!!!

Added:

an open source font just to have something different than Godot's default

Semblance of a framework for the UI

a health bar

a label that shows your time in seconds. Should probably make it show minutes and seconds

a menu that appears in the player's death state that shows the amount of time the player lived and their kill count. Also has a working quit button and non-working try again button.

a button that instantly kills you, which is "T."

Co-authored-by: ysandler <ysandler@tzed.io>
Reviewed-on: #11
Reviewed-by: Yehoshua Sandler <ysandler@beitzah.net>
2025-03-23 07:18:43 -05:00

46 lines
1.2 KiB
GDScript

extends CharacterBody2D
@onready var global = $"/root/Player"
var playerHealth = 100.0
var dead = false
const SPEED = 350.0
var charAngle = 0.0
func _physics_process(delta: float) -> void:
global.emit_signal("playerPosition",self.global_position)
if dead != true:
movement()
func _process(delta: float) -> void:
if dead != false:
setAnimation("Death")
if Input.is_action_just_pressed("test"):
playerDamage(100)
func setAnimation(anim):
if $"Birb".animation != anim:
$Birb.animation = anim
$"Birb".play()
func movement():
var vertical = Input.get_axis("up","down")
var horizontal = Input.get_axis("left","right")
var rotVector = Vector2(vertical*-1,horizontal)
if rotVector != Vector2(0,0):
self.set_rotation(rotVector.angle())
#limiting diagonal speed
if is_equal_approx(abs(vertical),1.0) and is_equal_approx(abs(horizontal),1.0):
velocity.y = SPEED*vertical/2
velocity.x = SPEED*horizontal/2
else:
velocity.y = SPEED * vertical
velocity.x = SPEED * horizontal
move_and_slide()
#$"../UI/Label".text = (str(charAngle*180/PI))
func playerDamage(amount):
if dead == false:
playerHealth -= amount
global.emit_signal("playerHealth",playerHealth)
if playerHealth <= 0 and dead == false:
dead = true
global.emit_signal("playerDeath")