Skip to content
Snippets Groups Projects
Commit 3b67f709 authored by Alan's avatar Alan
Browse files

deleted old file

parent a31cd9fb
No related branches found
No related tags found
No related merge requests found
......@@ -175,4 +175,4 @@ Anim={
"zfar": 4000.01,
"znear": 0.05
}
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/Node2D")])
selected_nodes=Array[NodePath]([])
......@@ -5,12 +5,6 @@ list=Array[Dictionary]([{
"language": &"GDScript",
"path": "res://scripts/Bishop.gd"
}, {
"base": &"Sprite2D",
"class": &"Board",
"icon": "",
"language": &"GDScript",
"path": "res://scripts/board.gd"
}, {
"base": &"Piece",
"class": &"King",
"icon": "",
......
......@@ -23,6 +23,7 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
Vector2(x + 1, y + 2), Vector2(x + 1, y - 2),
Vector2(x - 1, y + 2), Vector2(x - 1, y - 2)
]
# Check for LONGER_L_MOVE upgrade
if Upgrade.LONGER_L_MOVE in upgrades:
moves += [
......
......@@ -7,8 +7,8 @@ enum Upgrade { DOUBLE_MOVE, DIAGONAL_MOVE }
func _init(is_white: bool, position: Vector2):
super._init(is_white, position)
# Testing upgrades
# upgrades.append(Upgrade.DOUBLE_MOVE)
# upgrades.append(Upgrade.DIAGONAL_MOVE)
upgrades.append(Upgrade.DOUBLE_MOVE)
upgrades.append(Upgrade.DIAGONAL_MOVE)
func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
......@@ -16,6 +16,8 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
var x = pos.x
var y = pos.y
# TODO: Add En passant move
if is_white:
# Check if the pawn is at the starting position
if (y == 7 or Upgrade.DOUBLE_MOVE in upgrades) and board_state[x][y - 1] == null:
......
extends Sprite2D
class_name Board
const BOARD_SIZE = 8
const CELL_WIDTH = 18
# piece textures
const BLACK_BISHOP = preload("res://assets/temp_assets/black_bishop.png")
const BLACK_KING = preload("res://assets/temp_assets/black_king.png")
const BLACK_KNIGHT = preload("res://assets/temp_assets/black_knight.png")
const BLACK_PAWN = preload("res://assets/temp_assets/black_pawn.png")
const BLACK_QUEEN = preload("res://assets/temp_assets/black_queen.png")
const BLACK_ROOK = preload("res://assets/temp_assets/black_rook.png")
const WHITE_BISHOP = preload("res://assets/temp_assets/white_bishop.png")
const WHITE_KING = preload("res://assets/temp_assets/white_king.png")
const WHITE_KNIGHT = preload("res://assets/temp_assets/white_knight.png")
const WHITE_PAWN = preload("res://assets/temp_assets/white_pawn.png")
const WHITE_QUEEN = preload("res://assets/temp_assets/white_queen.png")
const WHITE_ROOK = preload("res://assets/temp_assets/white_rook.png")
const TEXTURE_HOLDER = preload("res://scenes/texture_holder.tscn")
@onready var pieces: Node2D = $Pieces
@onready var dots: Node2D = $Dots
# Variables
var board: Array
var white: bool
var state: bool
var moves = []
var selected_piece: Vector2
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
board.append([4,2,3,5,6,3,2,4])
board.append([1,1,1,1,1,1,1,1])
board.append([0,0,0,0,0,0,0,0])
board.append([0,0,0,0,0,0,0,0])
board.append([0,0,0,0,0,0,0,0])
board.append([0,0,0,0,0,0,0,0])
board.append([-1,-1,-1,-1,-1,-1,-1,-1])
board.append([-4,-2,-3,-5,-6,-3,-2,-4])
display_board()
func _input(event):
if (event is InputEventMouseButton && event.pressed):
if (event.button_index == MOUSE_BUTTON_LEFT):
if is_mouse_out():
return
var mouse_position: Vector2 = get_global_mouse_position()
var x_click = snapped(mouse_position.x, 0) / CELL_WIDTH
var y_click = abs(snapped(mouse_position.y, 0)) / CELL_WIDTH
print(x_click, y_click)
# Checks if mouse input is on the board
func is_mouse_out() -> bool:
var mouse_position: Vector2 = get_global_mouse_position()
if (mouse_position.x < 0 || mouse_position.x > 144 || mouse_position.y > 0 || mouse_position.y < -144):
return true
return false
# Displays board and instantiates "piece holders"
func display_board() -> void:
for i in BOARD_SIZE:
for j in BOARD_SIZE:
# Instantiate texture holders, scene that holds pieces
var holder = TEXTURE_HOLDER.instantiate()
pieces.add_child(holder)
holder.global_position = Vector2(j * CELL_WIDTH + (CELL_WIDTH / 2), -i * CELL_WIDTH - (CELL_WIDTH / 2))
# Looks at board array and matches pieces with its respective value
match board[i][j]:
-6: holder.texture = BLACK_KING
-5: holder.texture = BLACK_QUEEN
-4: holder.texture = BLACK_ROOK
-3: holder.texture = BLACK_BISHOP
-2: holder.texture = BLACK_KNIGHT
-1: holder.texture = BLACK_PAWN
0: holder.texture = null
6: holder.texture = WHITE_KING
5: holder.texture = WHITE_QUEEN
4: holder.texture = WHITE_ROOK
3: holder.texture = WHITE_BISHOP
2: holder.texture = WHITE_KNIGHT
1: holder.texture = WHITE_PAWN
......@@ -35,7 +35,7 @@ var sprite: Sprite2D
func _ready() -> void:
DisplayServer.window_set_min_size(Vector2(1152, 648)) # Set minimum window size
#creates 2D array for board, with empty ('0') spaces
#creates 2D array for board, with empty (null) spaces
for x in range(X):
board.append([])
for y in range(Y):
......@@ -126,8 +126,6 @@ func draw_pieces():
elif board[x][y] is Knight:
piece_scene = preload("res://scenes/Knight.tscn")
# Add other piece types here (e.g., Knight, Bishop, Queen, King)
if piece_scene:
var piece_instance = piece_scene.instantiate()
piece_instance.position = Vector2((x * tile_size) + tile_size/2, (y * tile_size) + tile_size/2)
......@@ -295,7 +293,7 @@ func remove_piece(x,y):
#iterate through the pieces in piece_container, if that piece is at location x,y, remove it
for child in piece_container.get_children():
#translate x,y index values to screen coordinates
if child.position == Vector2(x*tile_size+32, y*tile_size+32):
if child.position == Vector2(x*tile_size + 32, y*tile_size + 32):
explosion_effect.position = child.position + translate()
explosion_effect.restart()
piece_container.remove_child(child)
......@@ -374,5 +372,3 @@ func move_selected_piece(x,y):
remove_highlight()
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