online multiplayer chess game (note server currently down)
basic turn switching
bendn 2022-04-26
parent 553e4e3 · commit 4f1b5d4
-rw-r--r--Globals.gd5
-rw-r--r--Grid.gd6
-rw-r--r--Piece.gd27
3 files changed, 17 insertions, 21 deletions
diff --git a/Globals.gd b/Globals.gd
index 1c609fa..ea34f25 100644
--- a/Globals.gd
+++ b/Globals.gd
@@ -1,3 +1,6 @@
extends Node
-var grid
+var grid: Grid = null
+var turns := 0
+var turn := true # true for white, false for black
+# true cuz white goes first
diff --git a/Grid.gd b/Grid.gd
index cc14f55..57a456a 100644
--- a/Grid.gd
+++ b/Grid.gd
@@ -3,8 +3,8 @@ class_name Grid
export var PIECE_SET = "california"
-export(Color) var board_color1 = Color.white
-export(Color) var board_color2 = Color.black
+export(Color) var board_color1 = Color(0.870588, 0.890196, 0.901961)
+export(Color) var board_color2 = Color(0.54902, 0.635294, 0.678431)
export(Color) var overlay_color = Color(0.2, 0.345098, 0.188235, 0.592157)
onready var background = $Background
@@ -145,7 +145,7 @@ func check_for_frame(position: Vector2):
func square_clicked(position: Vector2):
var spot = matrix[position.y][position.x]
- if !spot or !spot.white: # spot is not a tile or spot is not white
+ if !spot or spot.white != Globals.turn: # spot is not a tile or spot is not turn color
if !last_clicked: # last clicked is null, so this is pointless
return
if check_for_circle(position): # see if theres a circle at the position
diff --git a/Piece.gd b/Piece.gd
index e80f189..6b7e6ac 100644
--- a/Piece.gd
+++ b/Piece.gd
@@ -42,6 +42,8 @@ func moveto(position):
Globals.grid.matrix[position.y][position.x] = self
real_position = position
move(position)
+ Globals.turn = not Globals.turn
+ Globals.turns += 1
func pos_around(around_vector):
@@ -49,31 +51,22 @@ func pos_around(around_vector):
func all_dirs():
- return [
- Vector2.UP,
- Vector2.DOWN,
- Vector2.LEFT,
- Vector2.RIGHT,
- Vector2(1, 1),
- Vector2(1, -1),
- Vector2(-1, 1),
- Vector2(-1, -1)
- ]
+ return [Vector2.UP, Vector2.DOWN, Vector2.LEFT, Vector2.RIGHT, Vector2(1, 1), Vector2(1, -1), Vector2(-1, 1), Vector2(-1, -1)]
func create_circles():
# for motion
match realname:
"pawn":
- var carry = (
- [pos_around(Vector2.UP)]
- if has_moved
- else [pos_around(Vector2.UP), pos_around(Vector2.UP * 2)]
- )
+ var carry = [pos_around(Vector2.UP)] if has_moved else [pos_around(Vector2.UP), pos_around(Vector2.UP * 2)]
+ if !white:
+ carry = ([pos_around(Vector2.DOWN)] if has_moved else [pos_around(Vector2.DOWN), pos_around(Vector2.DOWN * 2)])
set_circle(carry)
# deal with the take logic
carry = []
var takes = [pos_around(Vector2(-1, -1)), pos_around(Vector2(1, -1))]
+ if !white:
+ takes = [pos_around(Vector2(-1, 1)), pos_around(Vector2(1, 1))]
for i in takes:
i = clamp_vector(i)
if i == null:
@@ -140,7 +133,7 @@ func traverse_helper(pos):
return null
pos = at_pos(pos)
if pos:
- if !pos.white and !black_holder:
+ if pos.white != Globals.turn and !black_holder:
black_holder = true
return true
return null
@@ -162,7 +155,7 @@ func set_circle(positions: Array, type := "move"):
continue
Globals.grid.background_matrix[pos.x][pos.y].set_circle(true)
elif type == "take":
- if spot and !spot.white:
+ if spot and spot.white != Globals.turn:
spot.set_frame(true)