Skip to content

Commit 7f26ca3

Browse files
authored
Merge pull request #6 from pb-413/feature/BDH-7/reorg-for-opponent
Feature/bdh 7/reorg for opponent
2 parents fa51e46 + 6a82404 commit 7f26ca3

File tree

11 files changed

+197
-25
lines changed

11 files changed

+197
-25
lines changed

project/Resources/CardDatabase.tres

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
data = {
55
"Archer": {
66
"Attack": 1.0,
7-
"Health": 1.0
7+
"Health": 1.0,
8+
"Type": "Monster"
89
},
910
"Demon": {
1011
"Attack": 5.0,
11-
"Health": 7.0
12+
"Health": 7.0,
13+
"Type": "Monster"
1214
},
1315
"Knight": {
1416
"Attack": 2.0,
15-
"Health": 3.0
17+
"Health": 3.0,
18+
"Type": "Monster"
1619
}
1720
}

project/Scenes/Card.tscn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ _data = {
165165
}
166166

167167
[node name="Card" type="Node2D"]
168-
position = Vector2(150, 890)
168+
position = Vector2(140, 955)
169+
scale = Vector2(0.6, 0.6)
169170
script = ExtResource("1_wsc5r")
170171

171172
[node name="CardBackImage" type="Sprite2D" parent="."]

project/Scenes/EnemyCardSlot.tscn

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[gd_scene load_steps=3 format=3 uid="uid://gdxppdo86l20"]
2+
3+
[ext_resource type="Script" path="res://Scripts/CardSlot.gd" id="1_rryry"]
4+
[ext_resource type="Texture2D" uid="uid://dbvdok451yk65" path="res://Assets/Slot.png" id="2_v38kf"]
5+
6+
[node name="CardSlot" type="Node2D"]
7+
script = ExtResource("1_rryry")
8+
9+
[node name="CardSlotImage" type="Sprite2D" parent="."]
10+
texture = ExtResource("2_v38kf")

project/Scenes/Main.tscn

Lines changed: 121 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
[gd_scene load_steps=8 format=3 uid="uid://dct70tba5rujv"]
1+
[gd_scene load_steps=11 format=3 uid="uid://dct70tba5rujv"]
22

33
[ext_resource type="Script" path="res://Scripts/CardManager.gd" id="1_5kc25"]
44
[ext_resource type="Script" path="res://Scripts/PlayerHand.gd" id="2_7tv27"]
55
[ext_resource type="PackedScene" uid="uid://cmc8cw3l15t6n" path="res://Scenes/CardSlot.tscn" id="3_vek35"]
66
[ext_resource type="Script" path="res://Scripts/Deck.gd" id="4_0mr2l"]
77
[ext_resource type="Texture2D" uid="uid://goc4ty4ti1m5" path="res://Assets/Deck.png" id="5_novla"]
88
[ext_resource type="Script" path="res://Scripts/InputManager.gd" id="6_t7lv7"]
9+
[ext_resource type="Script" path="res://Scripts/CardSlotOfMonster.gd" id="7_ydkw1"]
10+
[ext_resource type="Script" path="res://Scripts/CardSlotOfMagic.gd" id="8_s06at"]
11+
[ext_resource type="PackedScene" uid="uid://gdxppdo86l20" path="res://Scenes/EnemyCardSlot.tscn" id="9_qt82k"]
912

1013
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4th8u"]
1114
size = Vector2(249, 350)
@@ -19,7 +22,8 @@ script = ExtResource("1_5kc25")
1922
script = ExtResource("2_7tv27")
2023

2124
[node name="Deck" type="Node2D" parent="."]
22-
position = Vector2(150, 890)
25+
position = Vector2(140, 955)
26+
scale = Vector2(0.6, 0.6)
2327
script = ExtResource("4_0mr2l")
2428

2529
[node name="Sprite2D" type="Sprite2D" parent="Deck"]
@@ -47,8 +51,119 @@ text = "0"
4751
[node name="InputManager" type="Node2D" parent="."]
4852
script = ExtResource("6_t7lv7")
4953

50-
[node name="CardSlot" parent="." instance=ExtResource("3_vek35")]
51-
position = Vector2(200, 265)
54+
[node name="CardSlots" type="Node2D" parent="."]
5255

53-
[node name="CardSlot2" parent="." instance=ExtResource("3_vek35")]
54-
position = Vector2(538, 270)
56+
[node name="CardSlot" parent="CardSlots" instance=ExtResource("3_vek35")]
57+
z_index = -2
58+
position = Vector2(960, 570)
59+
scale = Vector2(0.5, 0.5)
60+
script = ExtResource("7_ydkw1")
61+
62+
[node name="CardSlot2" parent="CardSlots" instance=ExtResource("3_vek35")]
63+
z_index = -2
64+
position = Vector2(1100, 570)
65+
scale = Vector2(0.5, 0.5)
66+
script = ExtResource("7_ydkw1")
67+
68+
[node name="CardSlot3" parent="CardSlots" instance=ExtResource("3_vek35")]
69+
z_index = -2
70+
position = Vector2(1240, 570)
71+
scale = Vector2(0.5, 0.5)
72+
script = ExtResource("7_ydkw1")
73+
74+
[node name="CardSlot4" parent="CardSlots" instance=ExtResource("3_vek35")]
75+
z_index = -2
76+
position = Vector2(820, 570)
77+
scale = Vector2(0.5, 0.5)
78+
script = ExtResource("7_ydkw1")
79+
80+
[node name="CardSlot5" parent="CardSlots" instance=ExtResource("3_vek35")]
81+
z_index = -2
82+
position = Vector2(680, 570)
83+
scale = Vector2(0.5, 0.5)
84+
script = ExtResource("7_ydkw1")
85+
86+
[node name="CardSlot6" parent="CardSlots" instance=ExtResource("3_vek35")]
87+
z_index = -2
88+
position = Vector2(960, 750)
89+
scale = Vector2(0.5, 0.5)
90+
script = ExtResource("8_s06at")
91+
92+
[node name="CardSlot7" parent="CardSlots" instance=ExtResource("3_vek35")]
93+
z_index = -2
94+
position = Vector2(1100, 750)
95+
scale = Vector2(0.5, 0.5)
96+
script = ExtResource("8_s06at")
97+
98+
[node name="CardSlot8" parent="CardSlots" instance=ExtResource("3_vek35")]
99+
z_index = -2
100+
position = Vector2(1240, 750)
101+
scale = Vector2(0.5, 0.5)
102+
script = ExtResource("8_s06at")
103+
104+
[node name="CardSlot9" parent="CardSlots" instance=ExtResource("3_vek35")]
105+
z_index = -2
106+
position = Vector2(820, 750)
107+
scale = Vector2(0.5, 0.5)
108+
script = ExtResource("8_s06at")
109+
110+
[node name="CardSlot10" parent="CardSlots" instance=ExtResource("3_vek35")]
111+
z_index = -2
112+
position = Vector2(680, 750)
113+
scale = Vector2(0.5, 0.5)
114+
script = ExtResource("8_s06at")
115+
116+
[node name="EnemyCardSlot" parent="CardSlots" instance=ExtResource("9_qt82k")]
117+
position = Vector2(960, 360)
118+
scale = Vector2(0.5, 0.5)
119+
120+
[node name="EnemyCardSlot2" parent="CardSlots" instance=ExtResource("9_qt82k")]
121+
position = Vector2(1100, 360)
122+
scale = Vector2(0.5, 0.5)
123+
124+
[node name="EnemyCardSlot3" parent="CardSlots" instance=ExtResource("9_qt82k")]
125+
position = Vector2(1240, 360)
126+
scale = Vector2(0.5, 0.5)
127+
128+
[node name="EnemyCardSlot4" parent="CardSlots" instance=ExtResource("9_qt82k")]
129+
position = Vector2(820, 360)
130+
scale = Vector2(0.5, 0.5)
131+
132+
[node name="EnemyCardSlot5" parent="CardSlots" instance=ExtResource("9_qt82k")]
133+
position = Vector2(680, 360)
134+
scale = Vector2(0.5, 0.5)
135+
136+
[node name="EnemyCardSlot6" parent="CardSlots" instance=ExtResource("9_qt82k")]
137+
position = Vector2(960, 180)
138+
scale = Vector2(0.5, 0.5)
139+
140+
[node name="EnemyCardSlot7" parent="CardSlots" instance=ExtResource("9_qt82k")]
141+
position = Vector2(1100, 180)
142+
scale = Vector2(0.5, 0.5)
143+
144+
[node name="EnemyCardSlot8" parent="CardSlots" instance=ExtResource("9_qt82k")]
145+
position = Vector2(1240, 180)
146+
scale = Vector2(0.5, 0.5)
147+
148+
[node name="EnemyCardSlot9" parent="CardSlots" instance=ExtResource("9_qt82k")]
149+
position = Vector2(820, 180)
150+
scale = Vector2(0.5, 0.5)
151+
152+
[node name="EnemyCardSlot10" parent="CardSlots" instance=ExtResource("9_qt82k")]
153+
position = Vector2(680, 180)
154+
scale = Vector2(0.5, 0.5)
155+
156+
[node name="EndTurnButton" type="Button" parent="."]
157+
offset_left = 300.0
158+
offset_top = 570.0
159+
offset_right = 378.0
160+
offset_bottom = 601.0
161+
text = "End Turn"
162+
163+
[node name="OpponentDeck" type="Node2D" parent="."]
164+
position = Vector2(1780, 125)
165+
scale = Vector2(0.6, 0.6)
166+
167+
[node name="Sprite2D" type="Sprite2D" parent="OpponentDeck"]
168+
z_index = -2
169+
texture = ExtResource("5_novla")

project/Scripts/Card.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ signal hovered
44
signal hovered_off
55

66
var hand_position
7+
var in_slot : Node2D
8+
var card_type : String
79

810
# Called when the node enters the scene tree for the first time.
911
func _ready() -> void:

project/Scripts/CardManager.gd

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ extends Node2D
22

33
const COLLISION_MASK_CARD = 1
44
const COLLISION_MASK_CARD_SLOT = 2
5-
const INIT_CARD_SCALE = Vector2(1.0, 1.0)
6-
const HIGHLIGHT_CARD_SCALE = Vector2(1.05, 1.05)
5+
const INIT_CARD_SCALE = Vector2(.6, .6)
6+
const HIGHLIGHT_CARD_SCALE = Vector2(.65, .65)
7+
const SLOTTED_CARD_SCALE = Vector2(.5, .5)
78

89
var card_being_dragged : Node2D
910
var screen_size : Vector2
1011
var is_hovering_on_card
1112
var player_hand_reference
13+
var has_played_monster_card_per_turn : bool = false
1214

1315
# Called when the node enters the scene tree for the first time.
1416
func _ready() -> void:
@@ -36,13 +38,20 @@ func finish_drag():
3638
card_being_dragged.scale = HIGHLIGHT_CARD_SCALE
3739
var card_slot_found = raycast_check_for_card_slot()
3840
if card_slot_found and not card_slot_found.card_in_slot:
39-
player_hand_reference.remove_card_from_hand(card_being_dragged)
4041
# Card dropped in empty slot.
41-
card_being_dragged.position = card_slot_found.position
42-
card_being_dragged.get_node("Area2D/CollisionShape2D").disabled = true
43-
card_slot_found.card_in_slot = true
44-
else:
45-
player_hand_reference.add_card_to_hand(card_being_dragged)
42+
if card_being_dragged.card_type == card_slot_found.card_slot_type:
43+
if !has_played_monster_card_per_turn:
44+
card_being_dragged.scale = SLOTTED_CARD_SCALE
45+
card_being_dragged.in_slot = card_slot_found
46+
card_being_dragged.z_index = -1 # under cards in hand
47+
player_hand_reference.remove_card_from_hand(card_being_dragged)
48+
card_being_dragged.position = card_slot_found.position
49+
card_being_dragged.get_node("Area2D/CollisionShape2D").disabled = true
50+
card_slot_found.card_in_slot = true
51+
card_being_dragged = null
52+
is_hovering_on_card = false
53+
return
54+
player_hand_reference.add_card_to_hand(card_being_dragged)
4655
card_being_dragged = null
4756

4857

@@ -63,7 +72,7 @@ func on_hover_over_card(card):
6372

6473

6574
func on_hover_off_card(card):
66-
if !card_being_dragged:
75+
if !card_being_dragged and !card.in_slot:
6776
highlight_card(card, false)
6877
var new_card_hovered = raycast_check_for_card()
6978
if new_card_hovered:

project/Scripts/CardSlot.gd renamed to project/Scripts/CardSlotOfMagic.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ extends Node2D
22

33

44
var card_in_slot = false
5+
var card_slot_type = "Magic"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extends Node2D
2+
3+
4+
var card_in_slot = false
5+
var card_slot_type = "Monster"

project/Scripts/Deck.gd

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@ extends Node2D
22

33
const CARD_SCENE_PATH = "res://Scenes/Card.tscn"
44
const CARD_DRAW_SPEED = .3
5+
const STARTING_HAND_SIZE = 4
56

6-
var player_deck = ["Knight", "Archer", "Demon", "Knight"]
7+
var player_deck = [
8+
"Knight", "Archer", "Demon", "Knight", "Knight", "Knight", "Knight"
9+
]
710
var card_database_reference : Dictionary
11+
var has_drawn_for_turn : bool = false
12+
813

914
# Called when the node enters the scene tree for the first time.
1015
func _ready() -> void:
1116
player_deck.shuffle()
1217
$RichTextLabel.text = str(player_deck.size())
1318
card_database_reference = load("res://Resources/CardDatabase.tres").data
19+
for i in range(STARTING_HAND_SIZE):
20+
draw_card()
21+
has_drawn_for_turn = false
22+
has_drawn_for_turn = true
1423

1524

1625
func draw_card():
26+
if has_drawn_for_turn:
27+
return
28+
has_drawn_for_turn = true
1729
var card_drawn_name: String = player_deck[0]
1830
player_deck.erase(card_drawn_name)
1931

@@ -30,6 +42,7 @@ func draw_card():
3042
new_card.get_node("CardImage").texture = load(card_image_path)
3143
new_card.get_node("Attack").text = str(card_database_reference[card_drawn_name]["Attack"])
3244
new_card.get_node("Health").text = str(card_database_reference[card_drawn_name]["Health"])
45+
new_card.card_type = card_database_reference[card_drawn_name]["Type"]
3346
$"../CardManager".add_child(new_card)
3447
new_card.name = "card"
3548
$"../PlayerHand".add_card_to_hand(new_card, CARD_DRAW_SPEED)

project/Scripts/PlayerHand.gd

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
extends Node2D
22

3-
const CARD_WIDTH = 250
4-
const HAND_Y_POSITION = 890
3+
const CARD_WIDTH = 150
4+
const HAND_Y_POSITION = 955
55
const DEFAULT_CARD_MOVE_SPEED = 0.1
66
var player_hand = []
7-
var center_screen_x
7+
var CENTER_SCREEN_X = 960 # aka 1920 / 2
88

99
# Called when the node enters the scene tree for the first time.
1010
func _ready() -> void:
11-
center_screen_x = get_viewport().size.x / 2
11+
pass
12+
# CENTER_SCREEN_X = get_viewport().size.x / 2
13+
# print(CENTER_SCREEN_X)
14+
# On my Laptop (1366 x 768): 682 (half of my screen/resolution width)
15+
# On my Desktop (2560 x 1440): 1279 (almost half my screen/resolution width)
16+
# CENTER_SCREEN_X = 960
17+
# I had to hardcode this because I was using these settings:
18+
# - Window Stretch Mode "Viewport"
19+
# - Window Aspect "Expand"
20+
# get_viewport() must be tied to the real hardware / window resolution
21+
# rather than relative to the scaling I'm doing.
1222

1323

1424
func add_card_to_hand(card, speed=DEFAULT_CARD_MOVE_SPEED):
@@ -33,7 +43,7 @@ func calculate_card_position(index):
3343
var double_pad_propotion = 1.0 + (1.0/16)
3444
var fake_width = CARD_WIDTH * double_pad_propotion
3545
var x_offset = (player_hand.size() - 1) * fake_width
36-
var x_position = center_screen_x + index * fake_width - x_offset / 2
46+
var x_position = CENTER_SCREEN_X + index * fake_width - x_offset / 2
3747
return x_position
3848

3949

0 commit comments

Comments
 (0)