Skip to content

Commit

Permalink
Merge pull request #4 from the-dev-bin/player-enemy-health-stats
Browse files Browse the repository at this point in the history
Add player health to global state, hook up enemy health to progress bar and labels
  • Loading branch information
tylercchase authored Jul 27, 2024
2 parents 8e3e670 + 4a241fd commit 964585e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 28 deletions.
17 changes: 15 additions & 2 deletions godot/ingredient_actions/actions/attack_action.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@ extends IngredientAction



func process_action(_player: Node, _enemies: Array[Node], _targeted_enemy: int) -> void:
print('deal ' + str(attack_range[0]) + ' damage')
func process_action(_player: Node, enemies: Array[Node], targeted_enemy: int) -> void:
var enemy: Node = enemies[targeted_enemy]
if enemy is EnemyNode:
var enemy_node: EnemyNode = enemy
var enemy_resource: Enemy = enemy_node.enemy
print('attacking for ' + str(attack_range[0]) + ' damage')
print('enemy health before: ' + str(enemy_resource.stats.current_health))
enemy_resource.stats.current_health -= attack_range[0]

enemy_node.current_health_label.text = str(enemy_resource.stats.current_health)
enemy_node.max_health_label.text = str(enemy_resource.stats.max_health)
var tween: Tween = enemy_node.create_tween()
tween.tween_property(enemy_node.health_bar, "value", enemy_resource.stats.current_health, 0.5)

print('enemy health after: ' + str(enemy_resource.stats.current_health))

func _to_string() -> String:
return "Deal " + str(attack_range[0]) + "-" + str(attack_range[1]) + " damage"
2 changes: 1 addition & 1 deletion godot/scenes/Stats.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ extends Resource
@export var max_health: int
var current_health: int
@export var defense: int
var conditions: Array[String] # might not use yet
var conditions: Array[String] # might not use yet
1 change: 1 addition & 0 deletions godot/scenes/enemy/enemy.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ offset_right = 80.0
offset_bottom = 120.0

[node name="HealthProgressBar" type="ProgressBar" parent="HealthBarContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 1
Expand Down
15 changes: 14 additions & 1 deletion godot/scenes/enemy/enemy_node.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ extends Node2D

@onready var enemy_sprite: Sprite2D = %EnemySprite
@onready var intent_icon: Sprite2D = %IntentIcon
@onready var health_bar: ProgressBar = %HealthProgressBar
@onready var current_health_label: Label = %CurrentHealthLabel
@onready var max_health_label: Label = %MaxHealthLabel


var enemy: Enemy
var previous_action: EnemyActionEntry
Expand All @@ -14,8 +18,17 @@ func _ready() -> void:

func setup(_enemy: Enemy) -> void:
enemy = _enemy
enemy.stats.current_health = enemy.stats.max_health
print('Enemy spawning with ' + str(enemy.stats.current_health) + ' health')
enemy_sprite.texture = ResourceLoader.load(enemy.sprite)

health_bar.min_value = 0
health_bar.max_value = enemy.stats.max_health
health_bar.value = enemy.stats.current_health

current_health_label.text = str(enemy.stats.current_health)
max_health_label.text = str(enemy.stats.max_health)

func get_action() -> EnemyActionEntry:
print(planned_action)
var current_action: EnemyActionEntry = planned_action.duplicate()
Expand All @@ -36,4 +49,4 @@ func update_intent() -> void:
if planned_action.intent == EnemyActionEntry.INTENT.DEFEND:
intent_icon.modulate = Color.BLUE
if planned_action.intent == EnemyActionEntry.INTENT.SUPPORT:
intent_icon.modulate = Color.PURPLE
intent_icon.modulate = Color.PURPLE
10 changes: 3 additions & 7 deletions godot/scenes/player/player.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
class_name Player
extends Node2D

@export var max_health: int = 10
var current_health: int


func _ready() -> void:
current_health = max_health # eventually make this carry over health between runs
print('current health ' + str(State.player_stats.current_health))


func damage(value: int) -> void:
current_health -= value
print('current health ' + str(current_health))
State.player_stats.current_health -= value
print('current health ' + str(State.player_stats.current_health))
13 changes: 12 additions & 1 deletion godot/singletons/State.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
extends Node

var player_deck : Array[Ingredient] = [load("res://scenes/ingredient_block/resources/godot_single.tres"),load("res://scenes/ingredient_block/resources/l_block.tres")]
var player_deck : Array[Ingredient] = [
load("res://scenes/ingredient_block/resources/godot_single.tres"),
load("res://scenes/ingredient_block/resources/l_block.tres")
]

var player_stats : Stats = Stats.new()

func _init(health: int = 5, max_health: int = 10) -> void:
player_stats.current_health = health
player_stats.max_health = max_health

print('starting health ' + str(player_stats.current_health))
32 changes: 16 additions & 16 deletions godot/ui/theme.tres

Large diffs are not rendered by default.

0 comments on commit 964585e

Please sign in to comment.