Skip to content

Commit

Permalink
Add healing on room change
Browse files Browse the repository at this point in the history
  • Loading branch information
Molytho committed Apr 15, 2024
1 parent 82f2f89 commit d4c43a6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/scenes/player_ui.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ label_settings = SubResource("LabelSettings_kmvbg")
vertical_alignment = 1

[node name="ScoreText" type="Label" parent="MarginContainer/VBoxContainer/MarginContainer/VBoxContainer/HPBar"]
layout_mode = 0
offset_left = 210.0
offset_top = 16.0
offset_right = 269.0
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/door.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ func enable():
modulate *= 2

func _on_body_entered(_body):
var player = _body as Player
player.heal(player.HEAL_ON_ROOM_CHANGE)
var score = get_parent().score
var world = get_tree().get_first_node_in_group("world")
world.add_score(score)
Expand Down
4 changes: 3 additions & 1 deletion src/scripts/hp-bar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ func set_value(val: int) -> void:
label.text = " " + str(val)

func _ready() -> void:
set_value(max_value)
var player = get_tree().get_first_node_in_group("player")
player.life_changed.connect(set_value)
set_value(player.life)
34 changes: 23 additions & 11 deletions src/scripts/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@ class_name Player

extends CharacterBody2D

const SPIKE_DAMAGE := 10
const SPIKE_DAMAGE_COOLDOWN := 0.7
const ATTACK_ANIMATION_LENGTH := 1.0
const KNOCKBACK_ENVELOPE: float = 0.86
const LOOK_AHEAD_MAX := 20.0
const LOOK_AHEAD_SPEED := 60.0
const MAX_LIFE: float = 100
const HEAL_ON_ROOM_CHANGE: float = MAX_LIFE / 2

# Ghosts
const Ghost = preload("res://scenes/ghost.tscn")

enum MovementPhase { STANDING = 0, ACCELERATING = 1, DECELERATING = 2, TURNING = 3 }

@onready var sprite := $Sprite
@onready var ui := $Camera2D/PlayerUI
@onready var hit_indicator := $HitIndicationAnimationPlayer
@onready var ghost_inventory := $GhostInventory
@onready var cam := $Camera2D

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var life = 100
const SPIKE_DAMAGE := 10
const SPIKE_DAMAGE_COOLDOWN := 0.7
var life := MAX_LIFE
var spike_damage_timer := 0.0
var colliding_spike := false
var shield_multiplier := 1.0
const ATTACK_ANIMATION_LENGTH := 1.0
var attack_animation_t := 0.0

# Movement
Expand All @@ -27,10 +39,6 @@ var DECELERATION_SPEED := 550.0
var TURNING_SPEED := 1500.0
var MAX_SPEED := 100.0
var EPSILON := 0.001
const KNOCKBACK_ENVELOPE: float = 0.86
const LOOK_AHEAD_MAX := 20.0
const LOOK_AHEAD_SPEED := 60.0
enum MovementPhase { STANDING = 0, ACCELERATING = 1, DECELERATING = 2, TURNING = 3 }
var movement_phase := MovementPhase.STANDING
var knockback := Vector2(0, 0)
var direction := 0.0
Expand All @@ -47,8 +55,7 @@ var jump_buffer := 0
var spell_inventory: Array[SpellBook.Spells] = []
var active_spells: Array[bool] = []

# Ghosts
const Ghost = preload("res://scenes/ghost.tscn")
signal life_changed(amount: int)

func _ready():
hit_indicator.play("RESET")
Expand Down Expand Up @@ -184,9 +191,14 @@ func game_over():
func take_damage(dmg: int):
SfxAudio.play_sfx(SfxAudio.Sound.HIT)
life -= dmg * shield_multiplier
get_tree().get_first_node_in_group('hp-bar').set_value(life)
life_changed.emit(life)
hit_indicator.play('hit')

func heal(amount: int):
life += amount
life = min(life, MAX_LIFE)
life_changed.emit(life)

func enable_shield(strength: float):
shield_multiplier = strength
$Shield.visible = true
Expand Down
4 changes: 3 additions & 1 deletion src/scripts/player_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func _ready() -> void:
ovrride_box.border_color = Color(1.0, 0.4, 0.6)
for box in [dflt_box, ovrride_box]:
box.set_border_width_all(4.0)
get_tree().get_first_node_in_group("world").score_changed.connect(_update_score)

var world = get_tree().get_first_node_in_group("world")
world.score_changed.connect(_update_score)

func add_spell_item_panel(spell: SpellBook.Spells):
var panel: MarginContainer = inPanel.duplicate()
Expand Down

0 comments on commit d4c43a6

Please sign in to comment.