Compare commits

..

16 Commits

Author SHA1 Message Date
69e00d25a3 Fix damage being dealt 2022-07-19 08:25:02 +01:00
c7ee498435 Fix sending uneeded damage and movement signals 2022-07-17 19:19:32 +01:00
2b92579dc3 Add support for "Placing" the dice and cleanup 2022-07-17 19:15:22 +01:00
78bfa30e0e Fix no default health 2022-07-17 19:08:13 +01:00
57ca632630 Show specific dice reqirements 2022-07-17 19:06:43 +01:00
8abb393949 Fix player reverting back to default position upon first move 2022-07-17 18:48:34 +01:00
c6d26f9b77 Use decimals instead of % 1 to find if int or float 2022-07-17 18:35:33 +01:00
b4e2f071df Fix card data lot loading visually 2022-07-17 18:30:28 +01:00
1e5fb13615 Implement taking damage 2022-07-17 18:30:05 +01:00
f2fad3bb0e Make a new Character class which both the enemy and player share 2022-07-17 18:23:41 +01:00
3ad8e574dd Fix starting positions for characters, add some groups, add enermies to battlescene 2022-07-17 17:37:01 +01:00
d0e99788fb Add a very basic enemy 2022-07-17 17:23:21 +01:00
6ec76a2988 Fix a few crashes to do with logic ordering 2022-07-17 17:11:43 +01:00
3df809aa9d Fix current_cards list not be updated upon card removal 2022-07-17 17:05:43 +01:00
6b2007ee1a Fix the movement amount calculation 2022-07-17 17:01:38 +01:00
a0ddbdae43 Fix Accepted Dice enum not corrisponding with actual dice numbers 2022-07-17 16:50:23 +01:00
14 changed files with 165 additions and 47 deletions

View File

@ -8,9 +8,9 @@ name = "Broadsword"
type = 0 type = 0
effect_damage_range = 2 effect_damage_range = 2
move_amount_addition = 0 move_amount_addition = 0
move_dice_multiplyer = 1 move_dice_multiplyer = 0
damage_amount_addition = 0 damage_amount_addition = 0
damage_dice_multiplyer = 0 damage_dice_multiplyer = 1
effects = [ ] effects = [ ]
accepted_dice = [ ] accepted_dice = [ ]
number_of_dice = 2 number_of_dice = 2

View File

@ -10,12 +10,12 @@ enum TYPE {
} }
enum ACCEPTED_DICE { enum ACCEPTED_DICE {
DICE_1 DICE_1 = 1
DICE_2 DICE_2 = 2
DICE_3 DICE_3 = 3
DICE_4 DICE_4 = 4
DICE_5 DICE_5 = 5
DICE_6 DICE_6 = 6
} }
export (String) var name = "" export (String) var name = ""

View File

@ -12,7 +12,7 @@ move_dice_multiplyer = 0
damage_amount_addition = 0 damage_amount_addition = 0
damage_dice_multiplyer = 0 damage_dice_multiplyer = 0
effects = [ 0, 9 ] effects = [ 0, 9 ]
accepted_dice = [ 0, 1 ] accepted_dice = [ 1, 2, 3 ]
number_of_dice = 1 number_of_dice = 1
same_dice_requirement = false same_dice_requirement = false
addition_dice = false addition_dice = false

37
Characters/Character.gd Normal file
View File

@ -0,0 +1,37 @@
extends Node2D
class_name Character
export var base_max_health : int = 20
export (int, 1, 5) var level : int = 1 setget level_change
var health = base_max_health
var map_position : Vector2 = Vector2.ZERO
onready var target_position : Vector2 = position
var moving : bool = false
func level_change(new_level):
# when leveing up restore health
health = base_max_health * pow(level, 1.5)
func _physics_process(delta):
# If the 2 positions are close enough, then not moving
moving = false if target_position.round() == position.round() else true
if not moving: return
#TODO: Replace with tween magic
position += (target_position - position)/2.5
func take_damage(damage):
health -= damage
if health <= 0:
die()
func die():
#Animation here
queue_free()

1
Characters/Enemy.gd Normal file
View File

@ -0,0 +1 @@
extends Character

11
Characters/Enemy.tscn Normal file
View File

@ -0,0 +1,11 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Characters/Enemy.gd" type="Script" id=2]
[node name="Enemy" type="Node2D" groups=["Enemy", "OnMap"]]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
modulate = Color( 1, 0, 0, 1 )
texture = ExtResource( 1 )

View File

@ -1,17 +1 @@
extends Node2D extends Character
export var map_position : Vector2 = Vector2.ZERO
var target_position : Vector2 = Vector2.ZERO
var moving : bool = false
func _physics_process(delta):
# If the 2 positions are close enough, then not moving
moving = false if target_position.round() == position.round() else true
if not moving: return
#TODO: Replace with tween magic
position += (target_position - position)/2.5

View File

@ -3,7 +3,7 @@
[ext_resource path="res://icon.png" type="Texture" id=1] [ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Characters/Player.gd" type="Script" id=2] [ext_resource path="res://Characters/Player.gd" type="Script" id=2]
[node name="Player" type="Node2D"] [node name="Player" type="Node2D" groups=["OnMap"]]
script = ExtResource( 2 ) script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."] [node name="Sprite" type="Sprite" parent="."]

View File

@ -13,17 +13,33 @@ func _ready():
$UI/CardView.selected = false $UI/CardView.selected = false
self.player_to_move = false self.player_to_move = false
$UI/CardView.draw_card() $UI/CardView.draw_card("Broadsword")
$UI/CardView.draw_card() $UI/CardView.draw_card("Sprint")
$UI/CardView.draw_card() $UI/CardView.draw_card("Magic Carving Knife")
$UI/DiceView.roll_dice() $UI/DiceView.roll_dice()
$UI/DiceView.roll_dice() $UI/DiceView.roll_dice()
$UI/DiceView.roll_dice() $UI/DiceView.roll_dice()
# generate all of the OnTile nodes's tile positions
for child in get_children():
if child.is_in_group("OnMap"):
child.map_position = $TileMap.world_to_map(child.position)
child.target_position = $TileMap.map_to_world(child.map_position)
child.target_position += $TileMap.cell_size/2
func do_damage_around_player(damage, damage_range): func do_damage_around_player(damage, damage_range):
pass for enemy in get_children():
if not enemy.is_in_group("Enemy"):
continue
if ($Player.map_position - enemy.map_position).length() > damage_range:
continue
enemy.take_damage(damage)
func do_effect_around_player(effect, effect_range): func do_effect_around_player(effect, effect_range):
pass pass
@ -53,6 +69,13 @@ func _physics_process(delta):
yield(get_tree().create_timer(0.1), "timeout") #TODO BAD WORKAROUND yield(get_tree().create_timer(0.1), "timeout") #TODO BAD WORKAROUND
$UI/DiceView.selected = false $UI/DiceView.selected = false
$UI/CardView.selected = true $UI/CardView.selected = true
# if all 3 parts are done, select the DiceView again
if ($UI/DiceView.selected == false and
$UI/CardView.selected == false and
self.player_to_move == false):
$UI/DiceView.selected = true
func player_movement_input(): func player_movement_input():

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2] [gd_scene load_steps=9 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1] [ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Characters/Player.tscn" type="PackedScene" id=2] [ext_resource path="res://Characters/Player.tscn" type="PackedScene" id=2]
@ -6,6 +6,7 @@
[ext_resource path="res://UI/CardView.tscn" type="PackedScene" id=4] [ext_resource path="res://UI/CardView.tscn" type="PackedScene" id=4]
[ext_resource path="res://UI/DiceView.tscn" type="PackedScene" id=5] [ext_resource path="res://UI/DiceView.tscn" type="PackedScene" id=5]
[ext_resource path="res://Assets/TestTile.png" type="Texture" id=6] [ext_resource path="res://Assets/TestTile.png" type="Texture" id=6]
[ext_resource path="res://Characters/Enemy.tscn" type="PackedScene" id=7]
[sub_resource type="TileSet" id=1] [sub_resource type="TileSet" id=1]
0/name = "icon.png 0" 0/name = "icon.png 0"
@ -50,9 +51,9 @@ format = 1
tile_data = PoolIntArray( 65538, 1, 0, 65539, 1, 0, 65540, 1, 0, 65541, 1, 0, 131074, 1, 0, 131075, 1, 0, 131076, 1, 0, 131077, 1, 0, 131078, 0, 0, 196610, 1, 0, 196611, 1, 0, 196612, 1, 0, 196613, 1, 0, 196614, 0, 0, 262144, 0, 0, 262145, 0, 0, 262146, 1, 0, 262147, 1, 0, 262148, 1, 0, 262149, 0, 0, 262150, 0, 0, 327681, 0, 0, 327682, 0, 0, 327683, 0, 0, 327684, 0, 0, 327685, 0, 0, 327686, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 524291, 0, 0, 524292, 0, 0 ) tile_data = PoolIntArray( 65538, 1, 0, 65539, 1, 0, 65540, 1, 0, 65541, 1, 0, 131074, 1, 0, 131075, 1, 0, 131076, 1, 0, 131077, 1, 0, 131078, 0, 0, 196610, 1, 0, 196611, 1, 0, 196612, 1, 0, 196613, 1, 0, 196614, 0, 0, 262144, 0, 0, 262145, 0, 0, 262146, 1, 0, 262147, 1, 0, 262148, 1, 0, 262149, 0, 0, 262150, 0, 0, 327681, 0, 0, 327682, 0, 0, 327683, 0, 0, 327684, 0, 0, 327685, 0, 0, 327686, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 524291, 0, 0, 524292, 0, 0 )
[node name="Player" parent="." instance=ExtResource( 2 )] [node name="Player" parent="." instance=ExtResource( 2 )]
position = Vector2( 195, 283 )
[node name="Camera2D" type="Camera2D" parent="Player"] [node name="Camera2D" type="Camera2D" parent="Player"]
visible = false
offset = Vector2( 0, 200 ) offset = Vector2( 0, 200 )
current = true current = true
drag_margin_h_enabled = true drag_margin_h_enabled = true
@ -61,6 +62,15 @@ drag_margin_left = 0.3
drag_margin_top = 0.05 drag_margin_top = 0.05
drag_margin_right = 0.3 drag_margin_right = 0.3
[node name="Enemy" parent="." instance=ExtResource( 7 )]
position = Vector2( 565, 218 )
[node name="Enemy2" parent="." instance=ExtResource( 7 )]
position = Vector2( 916, 218 )
[node name="Enemy3" parent="." instance=ExtResource( 7 )]
position = Vector2( 1140, 630 )
[node name="UI" type="CanvasLayer" parent="."] [node name="UI" type="CanvasLayer" parent="."]
[node name="CardView" parent="UI" instance=ExtResource( 4 )] [node name="CardView" parent="UI" instance=ExtResource( 4 )]

View File

@ -5,6 +5,7 @@ signal return_dice(dice_number)
signal do_movement(movement_range) signal do_movement(movement_range)
signal do_damage(damage, damage_range) signal do_damage(damage, damage_range)
signal do_effect(effect, effect_range) signal do_effect(effect, effect_range)
signal card_removed(card_self)
const TYPE_COLORS = [ const TYPE_COLORS = [
Color("#db4758"), # DAMAGE Color("#db4758"), # DAMAGE
@ -15,6 +16,7 @@ const TYPE_COLORS = [
] ]
const dice_node = preload("res://UI/Dice.tscn") const dice_node = preload("res://UI/Dice.tscn")
const dice_texture_string : String = "res://Assets/Dice/Dice%s.png"
export (Resource) var card_info export (Resource) var card_info
@ -24,6 +26,8 @@ var hovering_dice setget _set_hovering_dice
func _set_hovering_dice(dice_value): func _set_hovering_dice(dice_value):
var input_dice0 = $VBox/AutoGrid.get_node_from_grid("InputDice0")
if hovering_dice == dice_value: if hovering_dice == dice_value:
return return
@ -31,16 +35,16 @@ func _set_hovering_dice(dice_value):
#remove the dice preview if not hovering #remove the dice preview if not hovering
if dice_value == null: if dice_value == null:
var input_dice_children = $VBox/AutoGrid.get_node_from_grid("InputDice0").get_children() var input_dice_children = input_dice0.get_children()
if len(input_dice_children) <= 1: if len(input_dice_children) <= 1:
return return
var old_dice = input_dice_children[1] var old_dice = input_dice_children[1]
$VBox/AutoGrid.get_node_from_grid("InputDice0").remove_child(old_dice) input_dice0.remove_child(old_dice)
return return
var new_dice = dice_node.instance() var new_dice = dice_node.instance()
new_dice.dice_value = dice_value new_dice.dice_value = dice_value
$VBox/AutoGrid.get_node_from_grid("InputDice0").add_child(new_dice) input_dice0.add_child(new_dice)
func _set_addition_dice(new_amount): func _set_addition_dice(new_amount):
@ -68,6 +72,18 @@ func _ready():
#maybe set the addition amount #maybe set the addition amount
if card_info.addition_dice: if card_info.addition_dice:
self.addition_dice_amount = card_info.addition_amount self.addition_dice_amount = card_info.addition_amount
# show the requirements for a dice
# TODO more difference from addition, smaller font, >, <, etc.
if len(card_info.accepted_dice) != 0:
var dice_string : String = ""
for num in card_info.accepted_dice:
dice_string += String(num)
dice_string += ","
dice_string = dice_string.trim_suffix(",")
$VBox/AutoGrid/InputDice0/Number.text = dice_string
func dice_inputted(dice_number): func dice_inputted(dice_number):
@ -105,6 +121,12 @@ func dice_inputted(dice_number):
emit_signal("return_dice", input_dice[0]) emit_signal("return_dice", input_dice[0])
input_dice.remove(0) input_dice.remove(0)
# Put the Dice in the slot
var input_dice0 = $VBox/AutoGrid.get_node_from_grid("InputDice0")
input_dice0.texture = load(dice_texture_string % dice_number)
# -- RUN DICE CHECKS -- # -- RUN DICE CHECKS --
if card_info.addition_dice: if card_info.addition_dice:
self.addition_dice_amount -= dice_number self.addition_dice_amount -= dice_number
@ -124,7 +146,17 @@ func run_card():
var damage = card_info.damage_amount_addition var damage = card_info.damage_amount_addition
for dice_number in input_dice: for dice_number in input_dice:
damage += card_info.damage_dice_multiplyer * dice_number damage += card_info.damage_dice_multiplyer * dice_number
emit_signal("do_damage", damage, card_info.effect_damage_range)
if damage != 0:
emit_signal("do_damage", damage, card_info.effect_damage_range)
# calculate the damage amount
var movement = card_info.move_amount_addition
for dice_number in input_dice:
movement += card_info.move_dice_multiplyer * dice_number
if movement != 0:
emit_signal("do_movement", movement)
# do any utility dice returns # do any utility dice returns
for dice_number in input_dice: for dice_number in input_dice:
@ -136,7 +168,7 @@ func run_card():
var new_dice2 = halfed_dice var new_dice2 = halfed_dice
#if decimal value, then minus half and add half #if decimal value, then minus half and add half
if halfed_dice % 1 != 0: if decimals(halfed_dice) != 0:
new_dice1 -= 0.5 new_dice1 -= 0.5
new_dice2 += 0.5 new_dice2 += 0.5
@ -159,7 +191,7 @@ func run_card():
var new_dice = float(dice_number)/2.0 var new_dice = float(dice_number)/2.0
#if decimal valued, add 0.5 or - 0.5 at random #if decimal valued, add 0.5 or - 0.5 at random
if new_dice % 1 != 0: if decimals(new_dice) != 0:
new_dice += round(randf()) - 0.5 new_dice += round(randf()) - 0.5
emit_signal("return_dice", new_dice) emit_signal("return_dice", new_dice)
@ -176,11 +208,11 @@ func run_card():
for effect in card_info.effects: for effect in card_info.effects:
emit_signal("do_effect", effect, card_info.effect_damage_range) emit_signal("do_effect", effect, card_info.effect_damage_range)
emit_signal("do_movement", card_info.movement)
#clear the input dice #clear the input dice
input_dice = [] input_dice = []
#card is used, disappear #card is used, disappear
emit_signal("card_removed", self)
queue_free() queue_free()

View File

@ -31,6 +31,11 @@ func set_currently_holding_dice(dice_number : int):
currently_holding_dice = dice_number currently_holding_dice = dice_number
func remove_card(card):
var card_index = current_cards.find(card)
current_cards.remove(card_index)
func _physics_process(delta): func _physics_process(delta):
# no keyboard input if not selected # no keyboard input if not selected
@ -66,32 +71,36 @@ func _physics_process(delta):
#if the enter key is pressed, input the dice into the card #if the enter key is pressed, input the dice into the card
if Input.is_action_just_pressed("ui_accept"): if Input.is_action_just_pressed("ui_accept"):
current_cards[hovering_card].dice_inputted(currently_holding_dice)
current_cards[hovering_card].hovering_dice = null current_cards[hovering_card].hovering_dice = null
current_cards[hovering_card].dice_inputted(currently_holding_dice)
hovering_card = 0
selected = false selected = false
func draw_card(specific_card : String = ""): func draw_card(specific_card : String = ""):
# make a new card instance and add it to the grid container # make a new card instance and add it to the grid container
var new_card = card.instance() var new_card = card.instance()
$Margin/HBox.add_child(new_card)
# check if a specific card data exists # check if a specific card data exists
var card_data_check = File.new() var card_data_check = File.new()
var card_data_exists : bool = card_data_check.file_exists(card_db_string % specific_card) var card_data_exists : bool = card_data_check.file_exists(card_db_string % specific_card)
# if a specifc card choosen, make new card that type # if a specifc card choosen, make new card that type
if card_data_exists: if card_data_exists:
new_card.card_info = load(card_db_string % specific_card) new_card.card_info = load(card_db_string % specific_card)
else: #no card choosen, pick default else: #no card choosen, pick default
new_card.card_info = load(card_db_string % "Default") new_card.card_info = load(card_db_string % "Default")
# connect new_card.return_dice signal to self.emit_return_dice $Margin/HBox.add_child(new_card)
# connect new_card.x signal to self.x
new_card.connect("return_dice", self, "emit_return_dice") new_card.connect("return_dice", self, "emit_return_dice")
new_card.connect("do_movement", self, "emit_do_movement") new_card.connect("do_movement", self, "emit_do_movement")
new_card.connect("do_damage", self, "emit_do_damage") new_card.connect("do_damage", self, "emit_do_damage")
new_card.connect("do_effect", self, "emit_do_effect") new_card.connect("do_effect", self, "emit_do_effect")
# connect the signal remove card signal
new_card.connect("card_removed", self, "remove_card")
# add the current card to the list of card # add the current card to the list of card
current_cards.append(new_card) current_cards.append(new_card)

View File

@ -17,6 +17,11 @@ func _physics_process(delta):
selected_dice = null selected_dice = null
return return
# skip turn if the list is empty
if len(current_dice) == 0:
selected = false
return
# if selected dice is null, add a value # if selected dice is null, add a value
if not selected_dice: if not selected_dice:
selected_dice = 0 selected_dice = 0

View File

@ -13,9 +13,15 @@ _global_script_classes=[ {
"class": "CardResource", "class": "CardResource",
"language": "GDScript", "language": "GDScript",
"path": "res://Assets/CardDB/CardBD.gd" "path": "res://Assets/CardDB/CardBD.gd"
}, {
"base": "Node2D",
"class": "Character",
"language": "GDScript",
"path": "res://Characters/Character.gd"
} ] } ]
_global_script_class_icons={ _global_script_class_icons={
"CardResource": "" "CardResource": "",
"Character": ""
} }
[application] [application]