Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Godot project #1

Merged
merged 14 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions #Scenes/TestingScene.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[gd_scene load_steps=11 format=3 uid="uid://87fedoq257xg"]

[ext_resource type="Script" path="res://Cards/CardContainer.gd" id="1_cwemj"]
[ext_resource type="PackedScene" uid="uid://caxbd2ppk3ans" path="res://Cards/Card.tscn" id="2_tx1h0"]
[ext_resource type="PackedScene" uid="uid://clmg3l3n28x38" path="res://Entity/Player/Player.tscn" id="3_4psp7"]
[ext_resource type="Resource" uid="uid://dxgoopi1roxu4" path="res://Cards/Resource/Card_Damage.tres" id="3_6uosf"]
[ext_resource type="Resource" uid="uid://5yn4t13kwwoo" path="res://Cards/Resource/Card_DamageHealth.tres" id="4_nsiy1"]
[ext_resource type="Resource" uid="uid://d12g33rc6c3u5" path="res://Cards/Resource/Card_Heal.tres" id="5_4b2q2"]
[ext_resource type="Resource" uid="uid://ctx8jsvac84so" path="res://Cards/Resource/Card_Poison.tres" id="6_bferu"]
[ext_resource type="Resource" uid="uid://0x385c3nuq8f" path="res://Cards/Resource/Card_DamageAll.tres" id="7_7bwak"]
[ext_resource type="PackedScene" uid="uid://bcpmrmofcilbn" path="res://Core/Battler.tscn" id="8_qtw1k"]
[ext_resource type="Script" path="res://UI/EndTurnButton.gd" id="11_6xwul"]

[node name="TestingScene" type="Node2D"]

[node name="CardContainer" type="Node2D" parent="."]
script = ExtResource("1_cwemj")
card_scene = ExtResource("2_tx1h0")
total_hand_width = 500.0
card_queued_offset = 200.0
default_hand = Array[Resource("res://Cards/CardBase.gd")]([ExtResource("3_6uosf"), ExtResource("4_nsiy1"), ExtResource("5_4b2q2"), ExtResource("6_bferu"), ExtResource("7_7bwak")])

[node name="Battler" parent="." instance=ExtResource("8_qtw1k")]

[node name="Player" parent="." instance=ExtResource("3_4psp7")]
position = Vector2(595, 284)

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

[node name="UIControl" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2

[node name="EndTurnButton" type="Button" parent="CanvasLayer/UIControl"]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -110.0
offset_top = -32.0
grow_horizontal = 0
grow_vertical = 0
text = "end turn"
script = ExtResource("11_6xwul")

[connection signal="pressed" from="CanvasLayer/UIControl/EndTurnButton" to="CanvasLayer/UIControl/EndTurnButton" method="_on_pressed"]
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Godot 4+ specific ignores
.godot/
45 changes: 45 additions & 0 deletions .gut_editor_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"background_color": "262626ff",
"compact_mode": false,
"config_file": "res://.gutconfig.json",
"dirs": [
"res://Tests"
],
"disable_colors": false,
"double_strategy": 1,
"errors_do_not_cause_failure": false,
"font_color": "ccccccff",
"font_name": "CourierPrime",
"font_size": 16,
"gut_on_top": true,
"hide_orphans": false,
"ignore_pause": false,
"include_subdirs": false,
"inner_class": null,
"junit_xml_file": "",
"junit_xml_timestamp": false,
"log_level": 1,
"opacity": 100,
"paint_after": 0.1,
"panel_options": {
"font_name": "CourierPrime",
"font_size": 30,
"hide_output_text": false,
"hide_result_tree": false,
"hide_settings": false,
"output_font_name": "CourierPrime",
"output_font_size": 30,
"use_colors": false
},
"post_run_script": "",
"pre_run_script": "",
"prefix": "test_",
"selected": null,
"should_exit": false,
"should_exit_on_success": false,
"should_maximize": false,
"show_help": false,
"suffix": ".gd",
"tests": [],
"unit_test_name": null
}
Empty file added ArtSource/.gdignore
Empty file.
Binary file added ArtSource/Card/card.aseprite
Binary file not shown.
Binary file added ArtSource/Card/card_image.aseprite
Binary file not shown.
Binary file added ArtSource/Entity/fauna.aseprite
Binary file not shown.
Binary file added ArtSource/Entity/sapling2.aseprite
Binary file not shown.
37 changes: 37 additions & 0 deletions Buffs/BuffBase.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
extends Resource
class_name BuffBase
## Base buff resource
##
## If you want to make a new buff, create a child of this.
## If the buff applies some sort of instant effect (eg poison), you can use an
## event function like on_turn_end.
## If the buff applies persistent changes to the Entity's stats (eg strength), make changes to
## the stats in get_modified_stats.


@export var infinite_duration: bool = false
@export var buff_turn_duration: int = 3
@export var buff_power: float = 1.0
cheesefrycook marked this conversation as resolved.
Show resolved Hide resolved


var buff_owner: Entity = null
var buff_applier: Entity = null


func init_buff(in_owner: Entity, in_applier: Entity) -> void:
buff_owner = in_owner
buff_applier = in_applier


func get_modified_stats(stats: EntityStats) -> EntityStats:
return stats


func on_turn_start() -> void:
pass


# other event examples:
# on_take_damage (eg: thorns effect)
# on_application (eg: shield)
# on_card_drawn
13 changes: 13 additions & 0 deletions Buffs/Buff_Poison.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends BuffBase
class_name Buff_Poison
## Poison deals damage to the owning Entity at the start of their turn


func on_turn_start() -> void:
var damage_data: DealDamageData = DealDamageData.new()
damage_data.damage = buff_power
damage_data.caster = buff_applier
damage_data.ignore_caster_buffs = true
damage_data.ignore_target_buffs = true

buff_owner.get_health_component().deal_damage(damage_data)
8 changes: 8 additions & 0 deletions Buffs/Buff_Strength.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends BuffBase
class_name Buff_Strength
## Strength buff increases an Entity's damage stat


func get_modified_stats(stats: EntityStats) -> EntityStats:
stats.damage_dealt_increase += buff_power
return stats
8 changes: 8 additions & 0 deletions Buffs/Buff_Vulnerability.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends BuffBase
class_name Buff_Vulnerability
## Vulnerability buff increases the amount of damage an Entity takes from attacks


func get_modified_stats(stats: EntityStats) -> EntityStats:
stats.damage_taken_increase += buff_power
return stats
8 changes: 8 additions & 0 deletions Buffs/Buff_Weakness.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends BuffBase
class_name Buff_Weakness
## Vulnerability buff decreases the amount of damage that an Entity deals


func get_modified_stats(stats: EntityStats) -> EntityStats:
stats.damage_dealt_increase -= buff_power
return stats
90 changes: 90 additions & 0 deletions Cards/Card.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[gd_scene load_steps=8 format=3 uid="uid://caxbd2ppk3ans"]

[ext_resource type="Script" path="res://Cards/CardWorld.gd" id="1_4el5m"]
[ext_resource type="Texture2D" uid="uid://nheutko3fha3" path="res://Cards/card.png" id="2_k6rq5"]
[ext_resource type="Script" path="res://Input/ClickHandler.gd" id="3_du4nn"]
[ext_resource type="Script" path="res://Helpers/LerpComponent.gd" id="4_ujyje"]
[ext_resource type="Script" path="res://UI/CardUISetter.gd" id="5_hkyxd"]
[ext_resource type="Texture2D" uid="uid://bdc5r0w6lyh34" path="res://Cards/card_image.png" id="6_p357x"]

[sub_resource type="LabelSettings" id="LabelSettings_ooxvf"]
font_color = Color(0, 0, 0, 1)

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

[node name="ClickHandler" type="Node2D" parent="."]
script = ExtResource("3_du4nn")

[node name="LerpComponent" type="Node2D" parent="."]
script = ExtResource("4_ujyje")
lerp_speed = 7.0

[node name="CardUI" type="Control" parent="." node_paths=PackedStringArray("title_label", "description_label", "key_art")]
layout_mode = 3
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -94.0
offset_top = -134.0
offset_right = 94.0
offset_bottom = 134.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
script = ExtResource("5_hkyxd")
title_label = NodePath("VerticalLayout/Title")
description_label = NodePath("VerticalLayout/Description")
key_art = NodePath("VerticalLayout/KeyArt")

[node name="SelectionButton" type="TextureButton" parent="CardUI"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture_normal = ExtResource("2_k6rq5")
texture_pressed = ExtResource("2_k6rq5")
texture_hover = ExtResource("2_k6rq5")
texture_disabled = ExtResource("2_k6rq5")
texture_focused = ExtResource("2_k6rq5")

[node name="VerticalLayout" type="VBoxContainer" parent="CardUI"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2

[node name="Title" type="Label" parent="CardUI/VerticalLayout"]
custom_minimum_size = Vector2(188, 23)
layout_mode = 2
text = "Card Title"
label_settings = SubResource("LabelSettings_ooxvf")
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 2

[node name="KeyArt" type="TextureRect" parent="CardUI/VerticalLayout"]
layout_mode = 2
mouse_filter = 2
texture = ExtResource("6_p357x")
stretch_mode = 3

[node name="Description" type="Label" parent="CardUI/VerticalLayout"]
custom_minimum_size = Vector2(188, 127)
layout_mode = 2
text = "This is a test description for a card. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam"
label_settings = SubResource("LabelSettings_ooxvf")
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 2

[connection signal="gui_input" from="CardUI/SelectionButton" to="ClickHandler" method="_on_gui_input_event"]
[connection signal="mouse_entered" from="CardUI/SelectionButton" to="ClickHandler" method="_on_mouse_entered"]
[connection signal="mouse_exited" from="CardUI/SelectionButton" to="ClickHandler" method="_on_mouse_exited"]
84 changes: 84 additions & 0 deletions Cards/CardBase.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
extends Resource
class_name CardBase
## Resource that holds data about a card and provides functions that all derived cards could
## use if they want.
##
## The intention with this is to provide functionality that is common to a lot of cards,
## like dealing damage, drawing cards, and restoring resources.
## If you want functionality that's unique to a certain card, then create a new child of this
## and override one of the functions below.
## This resource also has data that is used for displaying the card in the world, like
## description, title, and key art.
## This includes functionality for applying damage to both the target and caster. Casters may
## wish to take damage in some contexts.
## For example, consider the card: "Deal 10 damage to all enemies, but take 3 damage"


@export var damage_to_apply_to_target: float = 0.0
@export var damage_to_apply_to_caster: float = 0.0
@export var buffs_to_apply_to_target: Array[BuffBase]
@export var buffs_to_apply_to_caster: Array[BuffBase]
@export var affect_all_targets: bool = false
@export var affect_all_casters: bool = false
@export var application_type: Enums.ApplicationType = Enums.ApplicationType.ENEMY_ONLY
@export var card_title: String = "NULL"
@export var card_key_art: ImageTexture = null
@export var card_description: String = "NULL"


func try_play_card(caster: Entity, target: Entity) -> bool:
if caster.get_party_component().can_play_on_entity(application_type, target):
_on_card_play(caster, target)
return true
return false


func _on_card_play(caster: Entity, target: Entity) -> void:
_deal_damage(caster, target)
_apply_buffs(caster, target)
# TODO add other functionality that lots of cards may share (eg: restore AP, draw cards)


# override in child cards if you want to deal damage in a unique way
func _deal_damage(caster: Entity, target: Entity) -> void:
# damage target
if damage_to_apply_to_target != 0.0:
_damage_entity(caster, target, damage_to_apply_to_target, affect_all_targets)

#damage caster
if damage_to_apply_to_caster != 0.0:
_damage_entity(caster, caster, damage_to_apply_to_caster, affect_all_casters)


func _damage_entity(caster: Entity, target: Entity, damage_amount: float, damage_all: bool) -> void:
var target_damage_data: DealDamageData = DealDamageData.new()
target_damage_data.damage = damage_amount
target_damage_data.caster = caster

# If damage_all is set, try to damage all the party members set in the party component
if damage_all:
var party: Array[Entity] = target.get_party_component().party
assert(party.size() > 0, "Entity has an empty party. Make sure you added party members.")

for party_member: Entity in party:
party_member.get_health_component().deal_damage(target_damage_data)
else:
target.get_health_component().deal_damage(target_damage_data)


func _apply_buffs(caster: Entity, target: Entity) -> void:
# apply buffs to caster
for buff: BuffBase in buffs_to_apply_to_caster:
if affect_all_casters:
for party_member: Entity in caster.get_party_component().party:
party_member.get_buff_component().add_buff(buff, caster)
else:
caster.get_buff_component().add_buff(buff, caster)

# apply buffs to target
for buff: BuffBase in buffs_to_apply_to_target:
if affect_all_targets:
for party_member: Entity in target.get_party_component().party:
party_member.get_buff_component().add_buff(buff, caster)
else:
target.get_buff_component().add_buff(buff, caster)
Loading