Skip to content

Commit

Permalink
added multiple target buttons, added clear dot action
Browse files Browse the repository at this point in the history
  • Loading branch information
enrico committed Feb 13, 2022
1 parent b83a026 commit 6258417
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 126 deletions.
112 changes: 1 addition & 111 deletions src/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,118 +1,8 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=2 format=2]

[ext_resource path="res://src/Main.gd" type="Script" id=1]

[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;

const float PI = 3.14159265359;

uniform vec2 screen_size = vec2(320.0, 180.0);
uniform bool show_curvature = true;
uniform float curvature_x_amount : hint_range(3.0, 15.0, 0.01) = float(6.0);
uniform float curvature_y_amount : hint_range(3.0, 15.0, 0.01) = float(4.0);
uniform vec4 corner_color : hint_color = vec4(0.0, 0.0, 0.0, 1.0);
uniform bool show_vignette = true;
uniform float vignette_opacity : hint_range(0.0, 1.0, 0.01) = 0.2;
uniform bool show_horizontal_scan_lines = true;
uniform float horizontal_scan_lines_amount : hint_range(0.0, 180.0, 0.1) = 180.0;
uniform float horizontal_scan_lines_opacity : hint_range(0.0, 1.0, 0.01) = 1.0;
uniform bool show_vertical_scan_lines = false;
uniform float vertical_scan_lines_amount : hint_range(0.0, 320.0, 0.1) = 320.0;
uniform float vertical_scan_lines_opacity : hint_range(0.0, 1.0, 0.01) = 1.0;
uniform float boost : hint_range(1.0, 2.0, 0.01) = 1.2;
uniform float aberration_amount : hint_range(0.0, 10.0, 0.01) = 0.0;

vec2 uv_curve(vec2 uv) {
if (show_curvature) {
uv = uv * 2.0 - 1.0;
vec2 offset = abs(uv.yx) / vec2(curvature_x_amount, curvature_y_amount);
uv = uv + uv * offset * offset;
uv = uv * 0.5 + 0.5;
}

return uv;
}


void fragment() {
vec2 uv = uv_curve(UV);
vec2 screen_uv = uv_curve(SCREEN_UV);
vec3 color = texture(SCREEN_TEXTURE, screen_uv).rgb;

if (aberration_amount > 0.0) {
float adjusted_amount = aberration_amount / screen_size.x;
color.r = texture(SCREEN_TEXTURE, vec2(screen_uv.x + adjusted_amount, screen_uv.y)).r;
color.g = texture(SCREEN_TEXTURE, screen_uv).g;
color.b = texture(SCREEN_TEXTURE, vec2(screen_uv.x - adjusted_amount, screen_uv.y)).b;
}

if (show_vignette) {
float vignette = uv.x * uv.y * (1.0 - uv.x) * (1.0 - uv.y);
vignette = clamp(pow((screen_size.x / 4.0) * vignette, vignette_opacity), 0.0, 1.0);
color *= vignette;
}

if (show_horizontal_scan_lines) {
float s = sin(screen_uv.y * horizontal_scan_lines_amount * PI * 2.0);
s = (s * 0.5 + 0.5) * 0.9 + 0.1;
vec4 scan_line = vec4(vec3(pow(s, horizontal_scan_lines_opacity)), 1.0);
color *= scan_line.rgb;
}

if (show_vertical_scan_lines) {
float s = sin(screen_uv.x * vertical_scan_lines_amount * PI * 2.0);
s = (s * 0.5 + 0.5) * 0.9 + 0.1;
vec4 scan_line = vec4(vec3(pow(s, vertical_scan_lines_opacity)), 1.0);
color *= scan_line.rgb;
}

if (show_horizontal_scan_lines || show_vertical_scan_lines) {
color *= boost;
}

// Fill the blank space of the corners, left by the curvature, with black.
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
color = corner_color.rgb;
}

COLOR = vec4(color, 1.0);
}"

[sub_resource type="ShaderMaterial" id=2]
render_priority = 3
shader = SubResource( 1 )
shader_param/screen_size = Vector2( 320, 180 )
shader_param/show_curvature = true
shader_param/curvature_x_amount = 4.65
shader_param/curvature_y_amount = 3.35
shader_param/corner_color = Color( 0, 0, 0, 1 )
shader_param/show_vignette = true
shader_param/vignette_opacity = 0.3
shader_param/show_horizontal_scan_lines = true
shader_param/horizontal_scan_lines_amount = 0.0
shader_param/horizontal_scan_lines_opacity = 0.4
shader_param/show_vertical_scan_lines = false
shader_param/vertical_scan_lines_amount = 260.5
shader_param/vertical_scan_lines_opacity = 0.31
shader_param/boost = 1.1
shader_param/aberration_amount = 0.0

[node name="Main" type="Node2D"]
script = ExtResource( 1 )

[node name="CurrentScene" type="Node2D" parent="."]

[node name="CanvasLayer" type="CanvasLayer" parent="."]
layer = 10

[node name="CRTShader" type="ColorRect" parent="CanvasLayer"]
visible = false
material = SubResource( 2 )
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -0.00012207
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
2 changes: 2 additions & 0 deletions src/autoloads/Constants.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const ActionTarget_Self = "self"
# Effect Types
const EffectType_Status = "status"
const EffectType_Heal = "heal"
const EffectType_ClearBleed = "clear_bleed"
const EffectType_ClearPoison = "clear_poison"

# Status Types

Expand Down
30 changes: 26 additions & 4 deletions src/autoloads/Database.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const combatant_data = {
"speed": 4,
"protection": 20,
"max_hp": 132,
"actions": ["basic_attack", "basic_heal", "basic_bleed", "basic_poison"],
"actions": ["basic_attack", "basic_heal", "basic_bleed", "basic_poison", "basic_group_heal", "clear_dot"],
"animations": preload("res://assets/animations/combatants/KnightAnim.tscn")
},
"butcher": {
Expand All @@ -18,7 +18,7 @@ const combatant_data = {
"speed": 2,
"protection": 5,
"max_hp": 136,
"actions": ["basic_attack", "basic_bleed", "basic_poison"],
"actions": ["basic_attack", "basic_bleed", "basic_poison", "basic_area_attack"],
"animations": preload("res://assets/animations/combatants/ButcherAnim.tscn")
},
"wax_slug": {
Expand All @@ -28,7 +28,7 @@ const combatant_data = {
"speed": 1,
"protection": 65,
"max_hp": 108,
"actions": ["basic_attack", "basic_bleed"],
"actions": ["basic_group_heal", "basic_bleed"],
"animations": preload("res://assets/animations/combatants/WaxSlugAnim.tscn")
},
"candle_priest": {
Expand Down Expand Up @@ -84,7 +84,15 @@ const action_data = {
"target": Constants.ActionTarget_AllySingle,
"effects": [{
"type": Constants.EffectType_Heal,
"amount": 10
"amount": 15
}]
},
"basic_group_heal": {
"name": "Basic Group Heal",
"target": Constants.ActionTarget_AllyMultiple,
"effects": [{
"type": Constants.EffectType_Heal,
"amount": 7
}]
},
"basic_bleed": {
Expand Down Expand Up @@ -112,5 +120,19 @@ const action_data = {
"turn_duration": 2,
"icon": preload("res://assets/ui/status_icons/poison.png")
}]
},
"clear_dot": {
"name": "Clear DoT",
"target": Constants.ActionTarget_AllySingle,
"effects": [{
"type": Constants.EffectType_ClearBleed,
}, {
"type": Constants.EffectType_ClearPoison,
}]
},
"basic_area_attack": {
"name": "Basic Area Attack",
"damage_percentage": 70,
"target": Constants.ActionTarget_EnemyMultiple
}
}
10 changes: 9 additions & 1 deletion src/entities/Combatant.gd
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ func inflict_damage(damage):
emit_signal("combatant_hp_changed", current_hp, max_hp)

func heal_hp(amount):
var was_ko = current_hp <= 0
current_hp = min(max_hp, current_hp + amount)
if current_hp > 0:
toggle_ko_sprite(false)
EventBus.emit_signal("combatant_revived", self)
if was_ko:
EventBus.emit_signal("combatant_revived", self)
EventBus.emit_signal("create_damage_label", amount, global_position + Vector2(0, -20), Color("2cb744"))
emit_signal("combatant_hp_changed", current_hp, max_hp)

Expand All @@ -97,6 +99,12 @@ func add_status(status_name, status_type, amount, turn_duration, icon):

emit_signal("status_changed")

func clear_status(status_type):
for status in $Status.get_children():
if status.status_type == status_type:
status.queue_free()
emit_signal("status_changed")

func die():
EventBus.emit_signal("remove_combatant_from_queue", self)
EventBus.emit_signal("remove_combatant_ui", self)
Expand Down
4 changes: 4 additions & 0 deletions src/entities/Effect.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ func apply_to_target(target):
target.heal_hp(amount)
Constants.EffectType_Status:
target.add_status(effect_name, status_type, amount, turn_duration, icon_texture)
Constants.EffectType_ClearBleed:
target.clear_status(Constants.StatusType_Bleed)
Constants.EffectType_ClearPoison:
target.clear_status(Constants.StatusType_Poison)
6 changes: 3 additions & 3 deletions src/entities/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func choose_action(current_combatant):
# Check all the available targets
var possible_targets = []
match chosen_action.target:
"ally_single", "ally_all":
Constants.ActionTarget_AllySingle, Constants.ActionTarget_AllyMultiple:
for c in combatants:
if !c.is_ko():
possible_targets.append(c)
"enemy_single", "enemy_all":
Constants.ActionTarget_EnemySingle, Constants.ActionTarget_EnemyMultiple:
for c in opponent_combatants:
if !c.is_ko():
possible_targets.append(c)
"self":
Constants.ActionTarget_Self:
possible_targets.append(current_combatant)

# Show the action text
Expand Down
28 changes: 26 additions & 2 deletions src/scenes/BattleScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var combatant_reference = load("res://src/entities/Combatant.tscn")

var enemy_target_button_reference = load("res://src/ui/EnemyTargetButton.tscn")
var ally_target_button_reference = load("res://src/ui/AllyTargetButton.tscn")
var multi_enemy_target_button_reference = load("res://src/ui/EnemyMultiTargetButton.tscn")
var multi_ally_target_button_reference = load("res://src/ui/AllyMultiTargetButton.tscn")
var health_bar_reference = load("res://src/ui/HealthBar.tscn")

var damage_label_reference = load("res://src/effects/DamageLabel.tscn")
Expand Down Expand Up @@ -37,7 +39,7 @@ func _ready():

# Create the enemy position references, delete the scene after retrieving the data
# (this function should be called externally)
var new_battle_data_scene = load("res://src/battle_data/battle_test_003.tscn").instance()
var new_battle_data_scene = load("res://src/battle_data/battle_test_001.tscn").instance()
add_child(new_battle_data_scene)
var enemy_data = new_battle_data_scene.get_battle_data()
new_battle_data_scene.queue_free()
Expand Down Expand Up @@ -279,6 +281,28 @@ func show_action_targets(acting_combatant, action):
new_target.connect("mouse_enter", self, "focus_target_hover", [new_target])
new_target.global_position = combatant.get_target_position()
$UI/Targets.add_child(new_target)
Constants.ActionTarget_EnemyMultiple:
var targets_positions = []
var targets = []
for combatant in $Combatants/Ysort.get_children():
if combatant.player_id != acting_combatant.player_id:
targets_positions.append(combatant.global_position)
targets.append(combatant)
var new_multi_target_button = multi_enemy_target_button_reference.instance()
new_multi_target_button.init(targets_positions)
new_multi_target_button.connect("pressed", self, "execute_action", [acting_combatant, action, targets])
$UI/Targets.add_child(new_multi_target_button)
Constants.ActionTarget_AllyMultiple:
var targets_positions = []
var targets = []
for combatant in $Combatants/Ysort.get_children():
if combatant.player_id == acting_combatant.player_id:
targets_positions.append(combatant.global_position)
targets.append(combatant)
var new_multi_target_button = multi_ally_target_button_reference.instance()
new_multi_target_button.init(targets_positions)
new_multi_target_button.connect("pressed", self, "execute_action", [acting_combatant, action, targets])
$UI/Targets.add_child(new_multi_target_button)

# Executes an action over an array of targets
func execute_action(acting_combatant, action, targets):
Expand Down Expand Up @@ -312,9 +336,9 @@ func execute_action(acting_combatant, action, targets):

# Check if the battle is over, otherwise go to the next combatant
if !is_battle_over():
yield(get_tree().create_timer(1.2), "timeout")
go_to_next_combatant()

yield(get_tree().create_timer(1.2), "timeout")

# Removes a Ko-ed combatant
func remove_combatant_from_queue(combatant):
Expand Down
8 changes: 8 additions & 0 deletions src/ui/AllyMultiTargetButton.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://src/ui/AllyTargetButton.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/ui/MultiTargetButton.gd" type="Script" id=2]

[node name="AllyMultiTargetButton" type="Node2D"]
script = ExtResource( 2 )
target_button_reference = ExtResource( 1 )
8 changes: 8 additions & 0 deletions src/ui/EnemyMultiTargetButton.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://src/ui/MultiTargetButton.gd" type="Script" id=1]
[ext_resource path="res://src/ui/EnemyTargetButton.tscn" type="PackedScene" id=2]

[node name="EnemyMultiTargetButton" type="Node2D"]
script = ExtResource( 1 )
target_button_reference = ExtResource( 2 )
1 change: 1 addition & 0 deletions src/ui/EnemyTargetButton.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ margin_right = 64.0
margin_bottom = 64.0
texture_normal = ExtResource( 2 )
texture_pressed = ExtResource( 3 )
texture_hover = ExtResource( 4 )
__meta__ = {
"_edit_use_anchors_": false
}
Expand Down
28 changes: 28 additions & 0 deletions src/ui/MultiTargetButton.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extends Node2D

export (PackedScene) var target_button_reference = load("res://src/ui/EnemyTargetButton.tscn")

signal pressed()

func _ready():
pass # Replace with function body.

# targets is a Array of Vector2
func init(targets):
for target in targets:
var new_target_button = target_button_reference.instance()
new_target_button.global_position = target
new_target_button.connect("pressed", self, "press")
new_target_button.connect("mouse_entered", self, "mouse_entered")
new_target_button.connect("mouse_exited", self, "mouse_exited")
add_child(new_target_button)

func press():
emit_signal("pressed")

func mouse_entered():
for child in get_children():
child.set_hover_sprite(true)
func mouse_exited():
for child in get_children():
child.set_hover_sprite(false)
9 changes: 4 additions & 5 deletions src/ui/TargetButton.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export (Texture) var normal_texture
export (Texture) var hover_texture

signal pressed()
signal mouse_enter()
signal mouse_exit()
signal mouse_entered()
signal mouse_exited()


var is_multiple = false
Expand All @@ -19,11 +19,10 @@ func _on_TextureButton_pressed():
emit_signal("pressed")

func _on_TextureButton_mouse_entered():
emit_signal("mouse_enter")
set_hover_sprite(true)
emit_signal("mouse_entered")

func _on_TextureButton_mouse_exited():
emit_signal("mouse_exit")
emit_signal("mouse_exited")

func set_hover_sprite(value):
if value:
Expand Down

0 comments on commit 6258417

Please sign in to comment.