Add opponent's hand
This commit is contained in:
parent
0feb249439
commit
384f6756fb
6 changed files with 85 additions and 25 deletions
|
@ -22,9 +22,12 @@ transform = Transform( 1, 0, 0, 0, 0.224381, 0.974502, 0, -0.974502, 0.224381, 0
|
||||||
fov = 50.0
|
fov = 50.0
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Hand" type="Spatial" parent="Camera"]
|
[node name="PlayerHand" type="Spatial" parent="Camera"]
|
||||||
transform = Transform( 0.4, 0, 0, 0, 2.98023e-008, -0.4, 0, 0.4, 2.98023e-008, 0, -0.6, -1.3 )
|
transform = Transform( 0.4, 0, 0, 0, 2.98023e-008, -0.4, 0, 0.4, 2.98023e-008, 0, -0.6, -1.3 )
|
||||||
|
|
||||||
|
[node name="OppHand" type="Spatial" parent="Camera"]
|
||||||
|
transform = Transform( 0.3, 0, 0, 0, -1.31134e-008, 0.3, 0, -0.3, -1.31134e-008, -2.48878e-016, 0.629771, -1.3 )
|
||||||
|
|
||||||
[node name="MeshInstance" type="MeshInstance" parent="."]
|
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.001, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.001, 0 )
|
||||||
mesh = SubResource( 2 )
|
mesh = SubResource( 2 )
|
||||||
|
@ -42,7 +45,7 @@ faceDown = true
|
||||||
|
|
||||||
[node name="P1Graveyard" parent="Cards" instance=ExtResource( 5 )]
|
[node name="P1Graveyard" parent="Cards" instance=ExtResource( 5 )]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 3.52858 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 3.52858 )
|
||||||
title = "Graveyard"
|
title = "Discard pile"
|
||||||
zoneName = "player1.graveyard"
|
zoneName = "player1.graveyard"
|
||||||
|
|
||||||
[node name="P1Banished" parent="Cards" instance=ExtResource( 5 )]
|
[node name="P1Banished" parent="Cards" instance=ExtResource( 5 )]
|
||||||
|
@ -50,17 +53,36 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 2.40401 )
|
||||||
title = "Banished"
|
title = "Banished"
|
||||||
zoneName = "player1.banished"
|
zoneName = "player1.banished"
|
||||||
|
|
||||||
|
[node name="P2Deck" parent="Cards" instance=ExtResource( 5 )]
|
||||||
|
transform = Transform( -1, 0, -8.74228e-008, 0, 1, 0, 8.74228e-008, 0, -1, 4.309, 0, -3.529 )
|
||||||
|
title = "Deck"
|
||||||
|
zoneName = "player2.deck"
|
||||||
|
faceDown = true
|
||||||
|
|
||||||
|
[node name="P2Graveyard" parent="Cards" instance=ExtResource( 5 )]
|
||||||
|
transform = Transform( -1, 0, -8.74228e-008, 0, 1, 0, 8.74228e-008, 0, -1, 5.234, 0, -3.529 )
|
||||||
|
title = "Discard pile"
|
||||||
|
zoneName = "player2.graveyard"
|
||||||
|
|
||||||
|
[node name="P2Banished" parent="Cards" instance=ExtResource( 5 )]
|
||||||
|
transform = Transform( -1, 0, -8.74228e-008, 0, 1, 0, 8.74228e-008, 0, -1, 5.234, 0, -2.404 )
|
||||||
|
title = "Banished"
|
||||||
|
zoneName = "player2.banished"
|
||||||
|
|
||||||
[node name="P1Problem" parent="Cards" instance=ExtResource( 5 )]
|
[node name="P1Problem" parent="Cards" instance=ExtResource( 5 )]
|
||||||
transform = Transform( -4.37114e-008, 0, -1, 0, 1, 0, 1, 0, -4.37114e-008, 2.5, 0, 0 )
|
transform = Transform( -6.55671e-008, 0, -1.5, 0, 1, 0, 1.5, 0, -6.55671e-008, 2.5, 0, 0 )
|
||||||
title = "Problem"
|
title = "Problem"
|
||||||
zoneName = "player1.problem"
|
zoneName = "player1.problem"
|
||||||
|
|
||||||
[node name="P2Problem" parent="Cards" instance=ExtResource( 5 )]
|
[node name="P2Problem" parent="Cards" instance=ExtResource( 5 )]
|
||||||
transform = Transform( -4.37114e-008, 0, 1, 0, 1, 0, -1, 0, -4.37114e-008, -2.5, 0, 0 )
|
transform = Transform( -6.55671e-008, 0, 1.5, 0, 1, 0, -1.5, 0, -6.55671e-008, -2.5, 0, 0 )
|
||||||
title = "Problem"
|
title = "Problem"
|
||||||
zoneName = "player2.problem"
|
zoneName = "player2.problem"
|
||||||
[connection signal="card_picked" from="Cards/P1Deck" to="." method="_card_picked_zone" binds= [ "player1.deck" ]]
|
[connection signal="card_picked" from="Cards/P1Deck" to="." method="_card_picked_zone" binds= [ "player1.deck" ]]
|
||||||
[connection signal="card_picked" from="Cards/P1Graveyard" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
[connection signal="card_picked" from="Cards/P1Graveyard" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
||||||
[connection signal="card_picked" from="Cards/P1Banished" to="." method="_card_picked_zone" binds= [ "player1.banished" ]]
|
[connection signal="card_picked" from="Cards/P1Banished" to="." method="_card_picked_zone" binds= [ "player1.banished" ]]
|
||||||
|
[connection signal="card_picked" from="Cards/P2Deck" to="." method="_card_picked_zone" binds= [ "player1.deck" ]]
|
||||||
|
[connection signal="card_picked" from="Cards/P2Graveyard" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
||||||
|
[connection signal="card_picked" from="Cards/P2Banished" to="." method="_card_picked_zone" binds= [ "player1.banished" ]]
|
||||||
[connection signal="card_picked" from="Cards/P1Problem" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
[connection signal="card_picked" from="Cards/P1Problem" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
||||||
[connection signal="card_picked" from="Cards/P2Problem" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
[connection signal="card_picked" from="Cards/P2Problem" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]]
|
||||||
|
|
|
@ -68,12 +68,18 @@ func _input_event(camera, event, click_position, click_normal, shape_idx):
|
||||||
var denom := Vector3.UP.dot(direction)
|
var denom := Vector3.UP.dot(direction)
|
||||||
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom;
|
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom;
|
||||||
translation = origin + direction * t
|
translation = origin + direction * t
|
||||||
|
# Rotate depending on what side of the board it is
|
||||||
|
if translation.z < 0:
|
||||||
|
rotation.y = PI
|
||||||
|
else:
|
||||||
|
rotation.y = 0
|
||||||
# Right click
|
# Right click
|
||||||
if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_RIGHT:
|
if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_RIGHT:
|
||||||
# Show menu
|
# Show menu
|
||||||
emit_signal("card_menu")
|
emit_signal("card_menu")
|
||||||
# Left click
|
# Left click
|
||||||
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
|
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and clickable():
|
||||||
|
|
||||||
# Update click status
|
# Update click status
|
||||||
clicked = event.pressed
|
clicked = event.pressed
|
||||||
|
|
||||||
|
@ -92,6 +98,12 @@ func _input_event(camera, event, click_position, click_normal, shape_idx):
|
||||||
animation.play("tap")
|
animation.play("tap")
|
||||||
exhausted = true
|
exhausted = true
|
||||||
|
|
||||||
|
func clickable() -> bool:
|
||||||
|
#TODO Better control over if a card can be taken or not
|
||||||
|
if playerID == 0:
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
func reset_transform():
|
func reset_transform():
|
||||||
$CardModel.translation = Vector3.ZERO
|
$CardModel.translation = Vector3.ZERO
|
||||||
$CardModel.rotation = Vector3.ZERO
|
$CardModel.rotation = Vector3.ZERO
|
||||||
|
@ -134,6 +146,7 @@ func _card_fetched(result: int, response_code: int, headers: PoolStringArray, bo
|
||||||
assert(result == HTTPRequest.RESULT_SUCCESS)
|
assert(result == HTTPRequest.RESULT_SUCCESS)
|
||||||
var img = Image.new()
|
var img = Image.new()
|
||||||
var err = img.load_jpg_from_buffer(body)
|
var err = img.load_jpg_from_buffer(body)
|
||||||
|
assert(err == OK)
|
||||||
# Depending if card pic is a problem or not, rotate the card image mesh
|
# Depending if card pic is a problem or not, rotate the card image mesh
|
||||||
if img.get_width() > img.get_height():
|
if img.get_width() > img.get_height():
|
||||||
cardImage.scale = Vector3(0.45,1,0.319)
|
cardImage.scale = Vector3(0.45,1,0.319)
|
||||||
|
@ -141,7 +154,6 @@ func _card_fetched(result: int, response_code: int, headers: PoolStringArray, bo
|
||||||
else:
|
else:
|
||||||
cardImage.scale = Vector3(0.319,1,0.45)
|
cardImage.scale = Vector3(0.319,1,0.45)
|
||||||
cardImage.rotation.y = 0
|
cardImage.rotation.y = 0
|
||||||
assert(err == OK)
|
|
||||||
var mat = cardMat.duplicate()
|
var mat = cardMat.duplicate()
|
||||||
texture = ImageTexture.new()
|
texture = ImageTexture.new()
|
||||||
texture.create_from_image(img)
|
texture.create_from_image(img)
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
[gd_scene load_steps=6 format=2]
|
[gd_scene load_steps=7 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Scenes/Components/Stack.gd" type="Script" id=1]
|
[ext_resource path="res://Scenes/Components/Stack.gd" type="Script" id=1]
|
||||||
|
|
||||||
[sub_resource type="BoxShape" id=1]
|
[sub_resource type="BoxShape" id=1]
|
||||||
extents = Vector3( 0.424389, 0.024053, 0.546632 )
|
extents = Vector3( 0.424389, 0.024053, 0.546632 )
|
||||||
|
|
||||||
|
[sub_resource type="SpatialMaterial" id=5]
|
||||||
|
flags_transparent = true
|
||||||
|
flags_unshaded = true
|
||||||
|
flags_vertex_lighting = true
|
||||||
|
flags_do_not_receive_shadows = true
|
||||||
|
flags_disable_ambient_light = true
|
||||||
|
albedo_color = Color( 1, 1, 1, 0.392157 )
|
||||||
|
|
||||||
[sub_resource type="DynamicFontData" id=2]
|
[sub_resource type="DynamicFontData" id=2]
|
||||||
font_path = "res://UIAssets/Fonts/Catamaran-Bold.ttf"
|
font_path = "res://UIAssets/Fonts/Catamaran-Bold.ttf"
|
||||||
|
|
||||||
|
@ -24,16 +32,18 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0239744, 0 )
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
[node name="CSGBox" type="CSGBox" parent="."]
|
[node name="CSGBox" type="CSGBox" parent="."]
|
||||||
transform = Transform( 0.85598, 0, 0, 0, 1, 0, 0, 0, 0.871019, 0, 0, 0 )
|
transform = Transform( 0.802373, 0, 0, 0, 1, 0, 0, 0, 0.81647, 0, 0, 0 )
|
||||||
width = 0.946586
|
width = 0.85
|
||||||
height = 0.002
|
height = 0.002
|
||||||
depth = 1.18809
|
depth = 1.15
|
||||||
|
material = SubResource( 5 )
|
||||||
|
|
||||||
[node name="CSGBox2" type="CSGBox" parent="CSGBox"]
|
[node name="CSGBox2" type="CSGBox" parent="CSGBox"]
|
||||||
|
transform = Transform( 1.00679, 0, 0, 0, 1.00679, 0, 0, 0, 1.00679, 0, 0, 0 )
|
||||||
operation = 2
|
operation = 2
|
||||||
width = 0.891339
|
width = 0.8
|
||||||
height = 0.102173
|
height = 0.102173
|
||||||
depth = 1.1406
|
depth = 1.1
|
||||||
|
|
||||||
[node name="CSGBox3" type="CSGBox" parent="CSGBox"]
|
[node name="CSGBox3" type="CSGBox" parent="CSGBox"]
|
||||||
operation = 2
|
operation = 2
|
||||||
|
|
|
@ -16,7 +16,6 @@ func fetch(url: String, cbObj: Object, cbFn: String):
|
||||||
var flen := file.get_len()
|
var flen := file.get_len()
|
||||||
var buf := file.get_buffer(flen)
|
var buf := file.get_buffer(flen)
|
||||||
cbObj.call(cbFn, HTTPRequest.RESULT_SUCCESS, 200, [], buf)
|
cbObj.call(cbFn, HTTPRequest.RESULT_SUCCESS, 200, [], buf)
|
||||||
print("CACHED")
|
|
||||||
return
|
return
|
||||||
var req := HTTPRequest.new()
|
var req := HTTPRequest.new()
|
||||||
add_child(req)
|
add_child(req)
|
||||||
|
@ -31,6 +30,5 @@ func _request_completed(result: int, response_code: int, headers: PoolStringArra
|
||||||
file.open(res_file_name(url), File.WRITE)
|
file.open(res_file_name(url), File.WRITE)
|
||||||
file.store_buffer(body)
|
file.store_buffer(body)
|
||||||
file.close()
|
file.close()
|
||||||
print("SAVED")
|
|
||||||
# Call callback
|
# Call callback
|
||||||
cbObj.call(cbFn, result, response_code, headers, body)
|
cbObj.call(cbFn, result, response_code, headers, body)
|
|
@ -5,7 +5,8 @@ class_name Board
|
||||||
onready var CardTemplate := preload("res://Scenes/Components/Card.tscn")
|
onready var CardTemplate := preload("res://Scenes/Components/Card.tscn")
|
||||||
|
|
||||||
onready var camera := $Camera
|
onready var camera := $Camera
|
||||||
onready var hand := $Camera/Hand
|
onready var hand := $Camera/PlayerHand
|
||||||
|
onready var oppHand := $Camera/OppHand
|
||||||
onready var ui := $BoardUI
|
onready var ui := $BoardUI
|
||||||
onready var cards := $Cards
|
onready var cards := $Cards
|
||||||
|
|
||||||
|
@ -19,10 +20,13 @@ var mouseOrigin: Vector2
|
||||||
var lastCameraTransform: Transform
|
var lastCameraTransform: Transform
|
||||||
|
|
||||||
onready var zones: Dictionary = {
|
onready var zones: Dictionary = {
|
||||||
"player1.deck": $Cards/Deck,
|
"player1.deck": $Cards/P1Deck,
|
||||||
"player1.banished": $Cards/Banished,
|
"player1.banished": $Cards/P1Banished,
|
||||||
"player1.graveyard": $Cards/Graveyard,
|
"player1.graveyard": $Cards/P1Graveyard,
|
||||||
"player1.problem": $Cards/P1Problem,
|
"player1.problem": $Cards/P1Problem,
|
||||||
|
"player2.deck": $Cards/P2Deck,
|
||||||
|
"player2.banished": $Cards/P2Banished,
|
||||||
|
"player2.graveyard": $Cards/P2Graveyard,
|
||||||
"player2.problem": $Cards/P2Problem
|
"player2.problem": $Cards/P2Problem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +38,13 @@ func _ready():
|
||||||
add_card("eo11", 0, true)
|
add_card("eo11", 0, true)
|
||||||
add_card("pr168", 0, true)
|
add_card("pr168", 0, true)
|
||||||
add_card("ad176", 0, true)
|
add_card("ad176", 0, true)
|
||||||
reorder_hand()
|
|
||||||
|
add_card("ff33", 1, true)
|
||||||
|
add_card("ff33", 1, true)
|
||||||
|
add_card("ff33", 1, true)
|
||||||
|
add_card("ff33", 1, true)
|
||||||
|
reorder_hand(0)
|
||||||
|
reorder_hand(1)
|
||||||
|
|
||||||
func _input(event: InputEvent):
|
func _input(event: InputEvent):
|
||||||
# Camera zoom
|
# Camera zoom
|
||||||
|
@ -139,7 +149,7 @@ func reparent(object: Node, from: Node, to: Node):
|
||||||
from.remove_child(object)
|
from.remove_child(object)
|
||||||
to.add_child(object)
|
to.add_child(object)
|
||||||
object.set_owner(to)
|
object.set_owner(to)
|
||||||
reorder_hand()
|
reorder_hand(0)
|
||||||
|
|
||||||
func add_card(cardID: String, playerID: int, inHand: bool):
|
func add_card(cardID: String, playerID: int, inHand: bool):
|
||||||
var card := CardTemplate.instance()
|
var card := CardTemplate.instance()
|
||||||
|
@ -155,8 +165,11 @@ func add_card(cardID: String, playerID: int, inHand: bool):
|
||||||
card.connect("card_dropped_anim", self, "check_hand_drop", [card])
|
card.connect("card_dropped_anim", self, "check_hand_drop", [card])
|
||||||
card.connect("card_menu", ui, "show_card_menu", [card])
|
card.connect("card_menu", ui, "show_card_menu", [card])
|
||||||
if inHand:
|
if inHand:
|
||||||
# TODO if player != me, put in opponent's hand
|
# TODO support for >2 players
|
||||||
|
if playerID == 0:
|
||||||
hand.add_child(card)
|
hand.add_child(card)
|
||||||
|
else:
|
||||||
|
oppHand.add_child(card)
|
||||||
else:
|
else:
|
||||||
cards.add_child(card)
|
cards.add_child(card)
|
||||||
|
|
||||||
|
@ -164,15 +177,19 @@ func check_hand_drop(card: Card):
|
||||||
# Re-order hand as soon as the animation is over
|
# Re-order hand as soon as the animation is over
|
||||||
if card.inHand:
|
if card.inHand:
|
||||||
card.reset_transform()
|
card.reset_transform()
|
||||||
reorder_hand()
|
reorder_hand(0)
|
||||||
|
|
||||||
const MAX_CARD_DISTANCE := 0.5
|
const MAX_CARD_DISTANCE := 0.5
|
||||||
const HAND_SCREEN_PERC := 0.6
|
const HAND_SCREEN_PERC := 0.6
|
||||||
const CARD_ROTATION := 0.03
|
const CARD_ROTATION := 0.03
|
||||||
const UNITSPERPX := 0.003
|
const UNITSPERPX := 0.003
|
||||||
|
|
||||||
func reorder_hand():
|
func reorder_hand(playerID: int):
|
||||||
var cardsInHand: Array = hand.get_children()
|
var cardsInHand: Array = []
|
||||||
|
if playerID == 0:
|
||||||
|
cardsInHand = hand.get_children()
|
||||||
|
else:
|
||||||
|
cardsInHand = oppHand.get_children()
|
||||||
cardsInHand.sort_custom(TransformSorter, "sort")
|
cardsInHand.sort_custom(TransformSorter, "sort")
|
||||||
var size := cardsInHand.size()
|
var size := cardsInHand.size()
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ onready var cardPic = $CardZoom
|
||||||
var menu: PopupMenu = null
|
var menu: PopupMenu = null
|
||||||
|
|
||||||
func _card_selected(card: Card):
|
func _card_selected(card: Card):
|
||||||
|
# TODO Hide card if it shouldn't be visible
|
||||||
cardPic.texture = card.texture
|
cardPic.texture = card.texture
|
||||||
animation.play("fade ui card")
|
animation.play("fade ui card")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue