Skip to content
Snippets Groups Projects
Commit 16fe7e12 authored by Alan's avatar Alan
Browse files

Added base rook movements

parent 16367bd8
No related branches found
No related tags found
1 merge request!1Refactoring game.gd to split up move validation to individual pieces, added...
......@@ -27,7 +27,7 @@ dock_5="Inspector,Node,History"
open_scenes=PackedStringArray("res://scenes/game.tscn", "res://scenes/explosion.tscn", "res://scenes/Pawn.tscn", "res://scenes/Rook.tscn")
current_scene="res://scenes/Pawn.tscn"
center_split_offset=-288
center_split_offset=-320
selected_default_debugger_tab_idx=0
selected_main_editor_idx=2
selected_bottom_panel_item=0
......@@ -35,7 +35,7 @@ selected_bottom_panel_item=0
[ScriptEditor]
open_scripts=["res://scripts/game.gd", "res://scripts/Pawn.gd", "res://scripts/Piece.gd", "res://scripts/Rook.gd"]
selected_script="res://scripts/game.gd"
selected_script="res://scripts/Rook.gd"
open_help=[]
script_split_offset=70
list_split_offset=0
......
......@@ -7,7 +7,7 @@ state={
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 122,
"scroll_position": 107.0,
"scroll_position": 95.0,
"selection": false,
"syntax_highlighter": "GDScript"
}
......@@ -31,7 +31,7 @@ state={
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 14,
"column": 0,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 10,
......@@ -45,11 +45,11 @@ state={
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 0,
"column": 36,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 16,
"scroll_position": 6.0,
"row": 52,
"scroll_position": 39.0,
"selection": false,
"syntax_highlighter": "GDScript"
}
......@@ -2,19 +2,23 @@ extends Piece
class_name Rook
enum Upgrade {
DIAGONAL_MOVE_ONE,
}
func _init(is_white: bool, position: Vector2):
super._init(is_white, position)
func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
var valid_moves = []
var valid_moves: Array[Vector2] = []
var x = pos.x
var y = pos.y
# Check moves to the right
for i in range(x + 1, 8):
if board_state[i][y] == 0:
if board_state[i][y] == null:
valid_moves.append(Vector2(i, y))
elif board_state[i][y].is_white != is_white:
elif board_state[i][y] != null and not board_state[i][y].is_white:
valid_moves.append(Vector2(i, y))
break
else:
......@@ -22,9 +26,9 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
# Check moves to the left
for i in range(x - 1, -1, -1):
if board_state[i][y] == 0:
if board_state[i][y] == null:
valid_moves.append(Vector2(i, y))
elif board_state[i][y].is_white != is_white:
elif board_state[i][y] != null and not board_state[i][y].is_white:
valid_moves.append(Vector2(i, y))
break
else:
......@@ -32,9 +36,11 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
# Check moves upwards
for i in range(y - 1, -1, -1):
if board_state[x][i] == 0:
# Check if the square is empty
if board_state[x][i] == null:
valid_moves.append(Vector2(x, i))
elif board_state[x][i].is_white != is_white:
# Check if the square has an enemy piece
elif board_state[x][i] != null and not board_state[x][i].is_white:
valid_moves.append(Vector2(x, i))
break
else:
......@@ -42,9 +48,11 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
# Check moves downwards
for i in range(y + 1, 8):
if board_state[x][i] == 0:
# Check if the square is empty
if board_state[x][i] == null:
valid_moves.append(Vector2(x, i))
elif board_state[x][i].is_white != is_white:
# Check if the square has an enemy piece
elif board_state[x][i] != null and not board_state[x][i].is_white:
valid_moves.append(Vector2(x, i))
break
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment