add active ability use, still needs balancing. simplified health and resource updates.

This commit is contained in:
tonydero 2024-10-30 15:47:53 -06:00
parent b986b4cb7a
commit bd6b21a2ec
7 changed files with 127 additions and 50 deletions

View File

@ -58,6 +58,36 @@ game_speed_slower={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":45,"key_label":0,"unicode":45,"location":0,"echo":false,"script":null)
]
}
use_A1={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":49,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null)
]
}
use_A2={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null)
]
}
use_A3={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
]
}
use_A4={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":52,"key_label":0,"unicode":52,"location":0,"echo":false,"script":null)
]
}
use_B1={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null)
]
}
use_B2={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
]
}
[physics]

View File

@ -1,16 +1,43 @@
[gd_scene load_steps=3 format=3 uid="uid://dvwo26vsk46tl"]
[gd_scene load_steps=5 format=3 uid="uid://dvwo26vsk46tl"]
[ext_resource type="Texture2D" uid="uid://dvvtnenxps3yu" path="res://assets/high-shot.svg" id="1_djmgc"]
[ext_resource type="Script" path="res://scripts/AbilityPlayer.gd" id="2_l8ort"]
[node name="AbilityPlayer" type="TextureRect"]
offset_right = 512.0
offset_bottom = 512.0
texture = ExtResource("1_djmgc")
expand_mode = 1
[sub_resource type="Curve" id="Curve_kjbdd"]
_data = [Vector2(0.605263, 0.767048), 0.0, 0.0, 0, 0]
point_count = 1
[sub_resource type="CurveTexture" id="CurveTexture_4mo46"]
texture_mode = 1
curve = SubResource("Curve_kjbdd")
[node name="Ability" type="PanelContainer"]
offset_right = 64.0
offset_bottom = 64.0
size_flags_horizontal = 4
size_flags_vertical = 4
script = ExtResource("2_l8ort")
[node name="IdleCooldown" type="Timer" parent="."]
autostart = true
[node name="AttackCooldown" type="Timer" parent="."]
one_shot = true
[node name="AbilityIcon" type="TextureRect" parent="."]
layout_mode = 2
texture = ExtResource("1_djmgc")
expand_mode = 1
[node name="CooldownIndicator" type="TextureProgressBar" parent="."]
modulate = Color(1, 1, 1, 0.631373)
layout_mode = 2
max_value = 0.2
step = 0.01
value = 0.09
fill_mode = 4
nine_patch_stretch = true
texture_progress = SubResource("CurveTexture_4mo46")
[connection signal="timeout" from="IdleCooldown" to="." method="_on_idle_cooldown_timeout"]
[connection signal="timeout" from="AttackCooldown" to="AbilityIcon" method="_on_attack_cooldown_timeout"]

View File

@ -1,6 +1,6 @@
# base ability class containing the main definitions
class_name AbilityBase
extends TextureRect
extends PanelContainer
@export var attack_range := 0

View File

@ -21,7 +21,10 @@ enum TargetType {
@export var target_type := TargetType.SINGLE
@export var target_angle := PI # mobs can't get behind
@export var base_cooldown := 0.2
@export var attack_damage := 400
@export var attack_damage := 100
@export var ability_cost := 1
var ability_ready:bool
func _ready() -> void:
middleX = get_viewport_rect().size.x / 2
@ -30,6 +33,7 @@ func _ready() -> void:
func _process(_delta: float) -> void:
playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75))
$IdleCooldown.wait_time = auto_speed
$CooldownIndicator.value = $AttackCooldown.time_left
func _get_enemies() -> Array:
@ -50,7 +54,7 @@ func _get_angle_to_player(enemy: Node) -> float:
return enemy.position.angle_to_point(playerPos)
func _get_target(enemies) -> Node:
func _get_target_in_range(enemies) -> Node:
# var numEnemies := _get_num_enemies()
var enemyDists
var closestEnemy
@ -102,21 +106,50 @@ func _apply_status() -> void:
func _deal_idle_damage(enemiesList) -> void:
var total_damage = auto_damage
match target_type:
TargetType.SINGLE:
var target = _get_target(enemiesList)
var target = _get_target_in_range(enemiesList)
if target:
target.damageTaken += auto_damage
target.damageTaken += total_damage
_:
var targets = _get_targets_in_range(enemiesList)
if targets:
for target in targets:
target.damageTaken += auto_damage
target.damageTaken += total_damage
func _deal_damage(enemiesList, damage) -> void:
match target_type:
TargetType.SINGLE:
var target = _get_target_in_range(enemiesList)
if target:
target.damageTaken += damage
_:
var targets = _get_targets_in_range(enemiesList)
if targets:
for target in targets:
target.damageTaken += damage
func _on_idle_cooldown_timeout() -> void:
var total_damage = auto_damage
var enemiesList = _get_enemies()
if not enemiesList.is_empty() and self.visible:
_deal_idle_damage(enemiesList)
_deal_damage(enemiesList, total_damage)
# TODO: implement active damage with signal to send resources spent to player cast/charge-time based instead of cooldowns for active abilities, but still uses "cooldown" value
func _input(event: InputEvent) -> void:
if event.is_action_pressed("use_A1"):
var total_damage = attack_damage
var current_cooldown = base_cooldown
var enemiesList = _get_enemies()
if not enemiesList.is_empty() and self.visible and $AttackCooldown.is_stopped() and PlayerState.current_resource > ability_cost:
_deal_damage(enemiesList, total_damage)
$CooldownIndicator.max_value = current_cooldown
$AttackCooldown.start(current_cooldown)
SignalBus.player_used_ability.emit(ability_cost)
func _on_attack_cooldown_timeout() -> void:
print("%s off cooldown!" % self.name)

View File

@ -4,11 +4,9 @@ extends VBoxContainer
@export var health_regen := 1
@export var resource_regen := 1
@export var resource_regen := 10
var area_exp := 0.0
var current_health: int
var current_resource: int
var max_health
var max_resource
@ -17,10 +15,11 @@ func _ready() -> void:
SignalBus.enemy_died.connect(_on_enemy_died)
SignalBus.quest_completed.connect(_on_quest_completed)
SignalBus.enemy_damaged_player.connect(_on_enemy_damaged_player)
SignalBus.player_used_ability.connect(_on_player_used_ability)
max_health = _set_player_health()
max_resource = _set_player_resource()
_set_player_health_display()
_set_player_resource_display()
_init_player_health_display()
_init_player_resource_display()
$PlayerExpBar.value = _get_level_progress_percent()
$PlayerLabel/PlayerLevel.text = str(floor(PlayerState.level))
@ -60,59 +59,44 @@ func _on_enemy_died(enemyDifficulty, enemyTier, _enemyFaction) -> void:
# Engine.time_scale = 0.0001
func _set_player_health_display() -> void:
current_health = max_health
func _init_player_health_display() -> void:
$PlayerHealthBar/PlayerHealthMax.text = str(max_health)
$PlayerHealthBar/PlayerHealthCurrent.text = str(current_health)
$PlayerHealthBar.value = current_health
$PlayerHealthBar/PlayerHealthCurrent.text = str(max_health)
$PlayerHealthBar.value = max_health
func _update_player_health(change: int) -> void:
var prev_health = current_health
var new_health = prev_health + change
current_health = new_health
$PlayerHealthBar.value += change
var current_health = $PlayerHealthBar.value
$PlayerHealthBar/PlayerHealthCurrent.text = str(current_health)
if current_health <= 0:
$PlayerHealthBar/PlayerHealthCurrent.text = str(0)
$PlayerHealthBar.value = 0
print("%s - You died." % Globals.elapsed_time_format(Globals.elapsed_time(PlayerState.zone_duration)))
# TODO: change to scene transition after slowing for a couple seconds
# Engine.time_scale = 0.0001
# get_tree().paused = true
get_tree().change_scene_to_file("res://scenes/main_menu.tscn")
elif current_health >= max_health:
$PlayerHealthBar/PlayerHealthCurrent.text = str(max_health)
$PlayerHealthBar.value = max_health
else:
$PlayerHealthBar/PlayerHealthCurrent.text = str(new_health)
$PlayerHealthBar.value = new_health
func _set_player_resource_display() -> void:
current_resource = max_resource
func _init_player_resource_display() -> void:
$PlayerResourceBar/PlayerResourceMax.text = str(max_resource)
$PlayerResourceBar/PlayerResourceCurrent.text = str(current_resource)
$PlayerResourceBar.value = current_resource
$PlayerResourceBar/PlayerResourceCurrent.text = str(max_resource)
$PlayerResourceBar.value = max_resource
func _update_player_resource(change: int) -> void:
var prev_resource = current_resource
var new_resource = prev_resource + change
current_resource = new_resource
# PlayerState.current_resource = current_resource
if current_resource <= 0:
$PlayerResourceBar/PlayerResourceCurrent.text = str(0)
$PlayerResourceBar.value = 0
elif current_resource >= max_resource:
$PlayerResourceBar/PlayerResourceCurrent.text = str(max_resource)
$PlayerResourceBar.value = max_resource
else:
$PlayerResourceBar/PlayerResourceCurrent.text = str(new_resource)
$PlayerResourceBar.value = new_resource
$PlayerResourceBar.value += change
var current_resource = $PlayerResourceBar.value
PlayerState.current_resource = current_resource
$PlayerResourceBar/PlayerResourceCurrent.text = str(current_resource)
func _on_enemy_damaged_player(damage: int) -> void:
var damage_received = damage
_update_player_health(-damage_received)
func _on_player_used_ability(ability_cost: int) -> void:
_update_player_resource(-ability_cost)
func _calculate_player_level() -> float:

View File

@ -10,6 +10,7 @@ var experience := 0.0
var level := 1.0
var base_health := 100
var base_resource := 100
var current_resource := 100
var weapon_type: Globals.Weapon.WeaponType
var zone_duration := 0
var world_tier := Globals.World.Tier.I

View File

@ -9,6 +9,7 @@ signal enemy_died(
)
signal enemy_damaged_player(damage: int)
signal player_leveled_up()
signal player_used_ability(ability_cost: int)
signal quest_generated(quest: Quest)
signal quest_completed
signal area_continue_pressed()
@ -19,6 +20,7 @@ func _dummy_func() -> void:
enemy_died.emit()
enemy_damaged_player.emit()
player_leveled_up.emit()
player_used_ability.emit()
quest_generated.emit()
quest_completed.emit()
area_continue_pressed.emit()