mostly working, need netcode, en passant, and castling
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Normalize EOL for all files that Git considers text files.
|
||||
* text=auto eol=lf
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
25
Bishop.gd
Normal file
25
Bishop.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends "res://Piece.gd"
|
||||
|
||||
|
||||
func setup():
|
||||
kind = KIND.BISHOP
|
||||
var sprite2d = get_node("Sprite2D")
|
||||
if team == TEAM.WHITE:
|
||||
sprite2d.region_rect = Rect2(95, 4, 35, 36)
|
||||
elif team == TEAM.BLACK:
|
||||
sprite2d.region_rect = Rect2(95, 49, 35, 36)
|
||||
|
||||
func check_move(destination: Vector2i) -> bool:
|
||||
var board_state = get_board_state()
|
||||
if board_state.has(destination):
|
||||
if board_state[destination].team == team:
|
||||
return false
|
||||
|
||||
if !path_empty(destination):
|
||||
return false
|
||||
|
||||
var dx = abs(destination.x - grid_pos.x)
|
||||
var dy = abs(destination.y - grid_pos.y)
|
||||
|
||||
return dx == dy and dx > 0
|
||||
|
||||
12
Bishop.tscn
Normal file
12
Bishop.tscn
Normal file
@@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cmj0gtmfsdblb"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dyw0vra6it4f6" path="res://Piece.tscn" id="1_7mdde"]
|
||||
[ext_resource type="Script" path="res://Bishop.gd" id="2_bajhn"]
|
||||
[ext_resource type="Texture2D" uid="uid://cgwutjks35c7e" path="res://Chess_Pieces_Sprite.svg" id="3_m3vdx"]
|
||||
|
||||
[node name="Area2D" instance=ExtResource("1_7mdde")]
|
||||
script = ExtResource("2_bajhn")
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("3_m3vdx")
|
||||
region_rect = Rect2(95, 4, 35, 36)
|
||||
129
Board.gd
Normal file
129
Board.gd
Normal file
@@ -0,0 +1,129 @@
|
||||
extends TileMap
|
||||
|
||||
@export var board_state: Dictionary = Dictionary()
|
||||
|
||||
@onready var king = preload("res://King.tscn")
|
||||
@onready var knight = preload("res://Knight.tscn")
|
||||
@onready var rook = preload("res://Rook.tscn")
|
||||
@onready var queen = preload("res://Queen.tscn")
|
||||
@onready var bishop = preload("res://Bishop.tscn")
|
||||
@onready var pawn = preload("res://Pawn.tscn")
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
setup_board()
|
||||
|
||||
var children = get_children()
|
||||
for child in children:
|
||||
if child.has_signal("moved"):
|
||||
child.moved.connect(_on_piece_moved)
|
||||
board_state[child.grid_pos] = child
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func _on_piece_moved(piece, old_pos, new_pos):
|
||||
if board_state.has(new_pos):
|
||||
var destroyed = board_state[new_pos]
|
||||
if destroyed.is_king():
|
||||
get_tree().paused = true
|
||||
board_state.erase(new_pos)
|
||||
destroyed.queue_free()
|
||||
board_state.erase(old_pos)
|
||||
|
||||
var new_piece = piece
|
||||
if piece.is_pawn():
|
||||
if piece.is_white() and new_pos.y == 0:
|
||||
new_piece = queen.instantiate()
|
||||
new_piece.grid_size = tile_set.tile_size
|
||||
new_piece.make_white()
|
||||
new_piece.grid_pos = new_pos
|
||||
add_child(new_piece)
|
||||
piece.queue_free()
|
||||
elif piece.is_black() and new_pos.y == 7:
|
||||
new_piece = queen.instantiate()
|
||||
new_piece.grid_size = tile_set.tile_size
|
||||
new_piece.make_black()
|
||||
new_piece.grid_pos = new_pos
|
||||
add_child(new_piece)
|
||||
piece.queue_free()
|
||||
board_state[new_pos] = new_piece
|
||||
|
||||
func setup_board():
|
||||
var king_instance = king.instantiate()
|
||||
king_instance.grid_size = tile_set.tile_size
|
||||
king_instance.make_white()
|
||||
king_instance.grid_pos = Vector2i(4,7)
|
||||
add_child(king_instance)
|
||||
|
||||
var bking_instance = king.instantiate()
|
||||
bking_instance.grid_size = tile_set.tile_size
|
||||
bking_instance.make_black()
|
||||
bking_instance.grid_pos = Vector2i(4,0)
|
||||
add_child(bking_instance)
|
||||
|
||||
var queen_instance = queen.instantiate()
|
||||
queen_instance.grid_size = tile_set.tile_size
|
||||
queen_instance.make_white()
|
||||
queen_instance.grid_pos = Vector2i(3,7)
|
||||
add_child(queen_instance)
|
||||
|
||||
var bqueen_instance = queen.instantiate()
|
||||
bqueen_instance.grid_size = tile_set.tile_size
|
||||
bqueen_instance.make_black()
|
||||
bqueen_instance.grid_pos = Vector2i(3,0)
|
||||
add_child(bqueen_instance)
|
||||
|
||||
for x in [1, 6]:
|
||||
var knight_instance = knight.instantiate()
|
||||
knight_instance.grid_size = tile_set.tile_size
|
||||
knight_instance.make_white()
|
||||
knight_instance.grid_pos = Vector2i(x,7)
|
||||
add_child(knight_instance)
|
||||
|
||||
var bknight_instance = knight.instantiate()
|
||||
bknight_instance.grid_size = tile_set.tile_size
|
||||
bknight_instance.make_black()
|
||||
bknight_instance.grid_pos = Vector2i(x,0)
|
||||
add_child(bknight_instance)
|
||||
|
||||
for x in [0, 7]:
|
||||
var rook_instance = rook.instantiate()
|
||||
rook_instance.grid_size = tile_set.tile_size
|
||||
rook_instance.make_white()
|
||||
rook_instance.grid_pos = Vector2i(x,7)
|
||||
add_child(rook_instance)
|
||||
|
||||
var brook_instance = rook.instantiate()
|
||||
brook_instance.grid_size = tile_set.tile_size
|
||||
brook_instance.make_black()
|
||||
brook_instance.grid_pos = Vector2i(x,0)
|
||||
add_child(brook_instance)
|
||||
|
||||
for x in [2, 5]:
|
||||
var bishop_instance = bishop.instantiate()
|
||||
bishop_instance.grid_size = tile_set.tile_size
|
||||
bishop_instance.make_white()
|
||||
bishop_instance.grid_pos = Vector2i(x,7)
|
||||
add_child(bishop_instance)
|
||||
|
||||
var bbishop_instance = bishop.instantiate()
|
||||
bbishop_instance.grid_size = tile_set.tile_size
|
||||
bbishop_instance.make_black()
|
||||
bbishop_instance.grid_pos = Vector2i(x,0)
|
||||
add_child(bbishop_instance)
|
||||
|
||||
for x in range(0, 8):
|
||||
var pawn_instance = pawn.instantiate()
|
||||
pawn_instance.grid_size = tile_set.tile_size
|
||||
pawn_instance.make_white()
|
||||
pawn_instance.grid_pos = Vector2i(x,6)
|
||||
add_child(pawn_instance)
|
||||
|
||||
var bpawn_instance = pawn.instantiate()
|
||||
bpawn_instance.grid_size = tile_set.tile_size
|
||||
bpawn_instance.make_black()
|
||||
bpawn_instance.grid_pos = Vector2i(x,1)
|
||||
add_child(bpawn_instance)
|
||||
|
||||
21
Board.tscn
Normal file
21
Board.tscn
Normal file
@@ -0,0 +1,21 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://biklwr66hudpd"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dirue6kbvxdat" path="res://Tiles.svg" id="1_heb2f"]
|
||||
[ext_resource type="Script" path="res://Board.gd" id="2_kd5g1"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_8ren2"]
|
||||
texture = ExtResource("1_heb2f")
|
||||
texture_region_size = Vector2i(38, 38)
|
||||
use_texture_padding = false
|
||||
0:0/0 = 0
|
||||
1:0/0 = 0
|
||||
|
||||
[sub_resource type="TileSet" id="TileSet_qi5mr"]
|
||||
tile_size = Vector2i(38, 38)
|
||||
sources/0 = SubResource("TileSetAtlasSource_8ren2")
|
||||
|
||||
[node name="TileMap" type="TileMap"]
|
||||
tile_set = SubResource("TileSet_qi5mr")
|
||||
format = 2
|
||||
layer_0/tile_data = PackedInt32Array(1, 0, 0, 65536, 0, 0, 131073, 0, 0, 65538, 0, 0, 3, 0, 0, 196608, 0, 0, 5, 0, 0, 65540, 0, 0, 131075, 0, 0, 196610, 0, 0, 262145, 0, 0, 327680, 0, 0, 7, 0, 0, 65542, 0, 0, 131077, 0, 0, 196612, 0, 0, 262147, 0, 0, 327682, 0, 0, 393217, 0, 0, 458752, 0, 0, 458754, 0, 0, 393219, 0, 0, 327684, 0, 0, 262149, 0, 0, 196614, 0, 0, 131079, 0, 0, 262151, 0, 0, 327686, 0, 0, 393221, 0, 0, 458756, 0, 0, 458758, 0, 0, 393223, 0, 0, 458753, 65536, 0, 393216, 65536, 0, 262144, 65536, 0, 131072, 65536, 0, 0, 65536, 0, 2, 65536, 0, 65537, 65536, 0, 131074, 65536, 0, 196609, 65536, 0, 327681, 65536, 0, 262146, 65536, 0, 393218, 65536, 0, 458755, 65536, 0, 458757, 65536, 0, 458759, 65536, 0, 393222, 65536, 0, 327687, 65536, 0, 327685, 65536, 0, 393220, 65536, 0, 262150, 65536, 0, 196615, 65536, 0, 196613, 65536, 0, 262148, 65536, 0, 327683, 65536, 0, 196611, 65536, 0, 131076, 65536, 0, 131078, 65536, 0, 65543, 65536, 0, 6, 65536, 0, 65541, 65536, 0, 4, 65536, 0, 65539, 65536, 0)
|
||||
script = ExtResource("2_kd5g1")
|
||||
254
Chess_Pieces_Sprite.svg
Normal file
254
Chess_Pieces_Sprite.svg
Normal file
@@ -0,0 +1,254 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="270" height="90">
|
||||
<!-- white king //-->
|
||||
<g style="fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,0)">
|
||||
<path
|
||||
d="M 22.5,11.63 L 22.5,6"
|
||||
style="fill:none; stroke:#000000; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 20,8 L 25,8"
|
||||
style="fill:none; stroke:#000000; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25"
|
||||
style="fill:#ffffff; stroke:#000000; stroke-linecap:butt; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 11.5,37 C 17,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 19,16 9.5,13 6.5,19.5 C 3.5,25.5 11.5,29.5 11.5,29.5 L 11.5,37 z "
|
||||
style="fill:#ffffff; stroke:#000000;" />
|
||||
<path
|
||||
d="M 11.5,30 C 17,27 27,27 32.5,30"
|
||||
style="fill:none; stroke:#000000;" />
|
||||
<path
|
||||
d="M 11.5,33.5 C 17,30.5 27,30.5 32.5,33.5"
|
||||
style="fill:none; stroke:#000000;" />
|
||||
<path
|
||||
d="M 11.5,37 C 17,34 27,34 32.5,37"
|
||||
style="fill:none; stroke:#000000;" />
|
||||
</g>
|
||||
|
||||
<!-- white queen //-->
|
||||
<g style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(45,0)">
|
||||
<path
|
||||
d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z"
|
||||
transform="translate(-1,-1)" />
|
||||
<path
|
||||
d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z"
|
||||
transform="translate(15.5,-5.5)" />
|
||||
<path
|
||||
d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z"
|
||||
transform="translate(32,-1)" />
|
||||
<path
|
||||
d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z"
|
||||
transform="translate(7,-4.5)" />
|
||||
<path
|
||||
d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z"
|
||||
transform="translate(24,-4)" />
|
||||
<path
|
||||
d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38,14 L 31,25 L 31,11 L 25.5,24.5 L 22.5,9.5 L 19.5,24.5 L 14,10.5 L 14,25 L 7,14 L 9,26 z "
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 10.5,36 10.5,36 C 9,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z "
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 11.5,30 C 15,29 30,29 33.5,30"
|
||||
style="fill:none;" />
|
||||
<path
|
||||
d="M 12,33.5 C 18,32.5 27,32.5 33,33.5"
|
||||
style="fill:none;" />
|
||||
</g>
|
||||
|
||||
<!-- white bishop //-->
|
||||
<g style="opacity:1; fill:none; fill-rule:evenodd; fill-opacity:1; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(90,0)">
|
||||
<g style="fill:#ffffff; stroke:#000000; stroke-linecap:butt;">
|
||||
<path
|
||||
d="M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.646,38.99 6.677,38.97 6,38 C 7.354,36.06 9,36 9,36 z" />
|
||||
<path
|
||||
d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z" />
|
||||
<path
|
||||
d="M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z" />
|
||||
</g>
|
||||
<path
|
||||
d="M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18"
|
||||
style="fill:none; stroke:#000000; stroke-linejoin:miter;" />
|
||||
</g>
|
||||
|
||||
<!-- white knight //-->
|
||||
<g style="opacity:1; fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(135,0)">
|
||||
<path
|
||||
d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18"
|
||||
style="fill:#ffffff; stroke:#000000;" />
|
||||
<path
|
||||
d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10"
|
||||
style="fill:#ffffff; stroke:#000000;" />
|
||||
<path
|
||||
d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z"
|
||||
style="fill:#000000; stroke:#000000;" />
|
||||
<path
|
||||
d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z"
|
||||
transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)"
|
||||
style="fill:#000000; stroke:#000000;" />
|
||||
</g>
|
||||
|
||||
<!-- white rook //-->
|
||||
<g style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(180,0)">
|
||||
<path
|
||||
d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z "
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z "
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14"
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 34,14 L 31,17 L 14,17 L 11,14" />
|
||||
<path
|
||||
d="M 31,17 L 31,29.5 L 14,29.5 L 14,17"
|
||||
style="stroke-linecap:butt; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 31,29.5 L 32.5,32 L 12.5,32 L 14,29.5" />
|
||||
<path
|
||||
d="M 11,14 L 34,14"
|
||||
style="fill:none; stroke:#000000; stroke-linejoin:miter;" />
|
||||
</g>
|
||||
|
||||
<!-- white pawn //-->
|
||||
<g transform="translate(225,0)">
|
||||
<path
|
||||
d="M 22,9 C 19.79,9 18,10.79 18,13 C 18,13.89 18.29,14.71 18.78,15.38 C 16.83,16.5 15.5,18.59 15.5,21 C 15.5,23.03 16.44,24.84 17.91,26.03 C 14.91,27.09 10.5,31.58 10.5,39.5 L 33.5,39.5 C 33.5,31.58 29.09,27.09 26.09,26.03 C 27.56,24.84 28.5,23.03 28.5,21 C 28.5,18.59 27.17,16.5 25.22,15.38 C 25.71,14.71 26,13.89 26,13 C 26,10.79 24.21,9 22,9 z "
|
||||
style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:nonzero; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:miter; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" />
|
||||
</g>
|
||||
|
||||
<!-- black king //-->
|
||||
<g style="fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(0,45)">
|
||||
<path
|
||||
d="M 22.5,11.63 L 22.5,6"
|
||||
style="fill:none; stroke:#000000; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25"
|
||||
style="fill:#000000;fill-opacity:1; stroke-linecap:butt; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 11.5,37 C 17,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 19,16 9.5,13 6.5,19.5 C 3.5,25.5 11.5,29.5 11.5,29.5 L 11.5,37 z "
|
||||
style="fill:#000000; stroke:#000000;" />
|
||||
<path
|
||||
d="M 20,8 L 25,8"
|
||||
style="fill:none; stroke:#000000; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 32,29.5 C 32,29.5 40.5,25.5 38.03,19.85 C 34.15,14 25,18 22.5,24.5 L 22.51,26.6 L 22.5,24.5 C 20,18 9.906,14 6.997,19.85 C 4.5,25.5 11.85,28.85 11.85,28.85"
|
||||
style="fill:none; stroke:#ffffff;" />
|
||||
<path
|
||||
d="M 11.5,30 C 17,27 27,27 32.5,30 M 11.5,33.5 C 17,30.5 27,30.5 32.5,33.5 M 11.5,37 C 17,34 27,34 32.5,37"
|
||||
style="fill:none; stroke:#ffffff;" />
|
||||
</g>
|
||||
|
||||
<!-- black queen //-->
|
||||
<g style="opacity:1; fill:000000; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(45,45)">
|
||||
<g style="fill:#000000; stroke:none;">
|
||||
<circle cx="6" cy="12" r="2.75" />
|
||||
<circle cx="14" cy="9" r="2.75" />
|
||||
<circle cx="22.5" cy="8" r="2.75" />
|
||||
<circle cx="31" cy="9" r="2.75" />
|
||||
<circle cx="39" cy="12" r="2.75" />
|
||||
</g>
|
||||
<path
|
||||
d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z"
|
||||
style="stroke-linecap:butt; stroke:#000000;" />
|
||||
<path
|
||||
d="M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 10.5,36 10.5,36 C 9,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z"
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 11,38.5 A 35,35 1 0 0 34,38.5"
|
||||
style="fill:none; stroke:#000000; stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 11,29 A 35,35 1 0 1 34,29"
|
||||
style="fill:none; stroke:#ffffff;" />
|
||||
<path
|
||||
d="M 12.5,31.5 L 32.5,31.5"
|
||||
style="fill:none; stroke:#ffffff;" />
|
||||
<path
|
||||
d="M 11.5,34.5 A 35,35 1 0 0 33.5,34.5"
|
||||
style="fill:none; stroke:#ffffff;" />
|
||||
<path
|
||||
d="M 10.5,37.5 A 35,35 1 0 0 34.5,37.5"
|
||||
style="fill:none; stroke:#ffffff;" />
|
||||
</g>
|
||||
|
||||
<!-- black bishop //-->
|
||||
<g style="opacity:1; fill:none; fill-rule:evenodd; fill-opacity:1; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(90,45)">
|
||||
<g style="fill:#000000; stroke:#000000; stroke-linecap:butt;">
|
||||
<path
|
||||
d="M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.646,38.99 6.677,38.97 6,38 C 7.354,36.06 9,36 9,36 z" />
|
||||
<path
|
||||
d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z" />
|
||||
<path
|
||||
d="M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z" />
|
||||
</g>
|
||||
<path
|
||||
d="M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18"
|
||||
style="fill:none; stroke:#ffffff; stroke-linejoin:miter;" />
|
||||
</g>
|
||||
|
||||
<!-- black knight //-->
|
||||
<g style="opacity:1; fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(135,45)">
|
||||
<path
|
||||
d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18"
|
||||
style="fill:#000000; stroke:#000000;" />
|
||||
<path
|
||||
d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10"
|
||||
style="fill:#000000; stroke:#000000;" />
|
||||
<path
|
||||
d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z"
|
||||
style="fill:#ffffff; stroke:#ffffff;" />
|
||||
<path
|
||||
d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z"
|
||||
transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)"
|
||||
style="fill:#ffffff; stroke:#ffffff;" />
|
||||
<path
|
||||
d="M 24.55,10.4 L 24.1,11.85 L 24.6,12 C 27.75,13 30.25,14.49 32.5,18.75 C 34.75,23.01 35.75,29.06 35.25,39 L 35.2,39.5 L 37.45,39.5 L 37.5,39 C 38,28.94 36.62,22.15 34.25,17.66 C 31.88,13.17 28.46,11.02 25.06,10.5 L 24.55,10.4 z "
|
||||
style="fill:#ffffff; stroke:none;" />
|
||||
</g>
|
||||
|
||||
<!-- black rook //-->
|
||||
<g style="opacity:1; fill:000000; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" transform="translate(180,45)">
|
||||
<path
|
||||
d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z "
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 12.5,32 L 14,29.5 L 31,29.5 L 32.5,32 L 12.5,32 z "
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z "
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 14,29.5 L 14,16.5 L 31,16.5 L 31,29.5 L 14,29.5 z "
|
||||
style="stroke-linecap:butt;stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 14,16.5 L 11,14 L 34,14 L 31,16.5 L 14,16.5 z "
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14 L 11,14 z "
|
||||
style="stroke-linecap:butt;" />
|
||||
<path
|
||||
d="M 12,35.5 L 33,35.5 L 33,35.5"
|
||||
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 13,31.5 L 32,31.5"
|
||||
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 14,29.5 L 31,29.5"
|
||||
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 14,16.5 L 31,16.5"
|
||||
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />
|
||||
<path
|
||||
d="M 11,14 L 34,14"
|
||||
style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" />
|
||||
</g>
|
||||
|
||||
<!-- black pawn //-->
|
||||
<g transform="translate(225,45)">
|
||||
<path
|
||||
d="M 22,9 C 19.79,9 18,10.79 18,13 C 18,13.89 18.29,14.71 18.78,15.38 C 16.83,16.5 15.5,18.59 15.5,21 C 15.5,23.03 16.44,24.84 17.91,26.03 C 14.91,27.09 10.5,31.58 10.5,39.5 L 33.5,39.5 C 33.5,31.58 29.09,27.09 26.09,26.03 C 27.56,24.84 28.5,23.03 28.5,21 C 28.5,18.59 27.17,16.5 25.22,15.38 C 25.71,14.71 26,13.89 26,13 C 26,10.79 24.21,9 22,9 z "
|
||||
style="opacity:1; fill:#000000; fill-opacity:1; fill-rule:nonzero; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:miter; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 15 KiB |
37
Chess_Pieces_Sprite.svg.import
Normal file
37
Chess_Pieces_Sprite.svg.import
Normal file
@@ -0,0 +1,37 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cgwutjks35c7e"
|
||||
path="res://.godot/imported/Chess_Pieces_Sprite.svg-1ff6d13f4fe62b001920763db3338bd7.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Chess_Pieces_Sprite.svg"
|
||||
dest_files=["res://.godot/imported/Chess_Pieces_Sprite.svg-1ff6d13f4fe62b001920763db3338bd7.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
18
King.gd
Normal file
18
King.gd
Normal file
@@ -0,0 +1,18 @@
|
||||
extends "res://Piece.gd"
|
||||
|
||||
func setup():
|
||||
kind = KIND.KING
|
||||
var sprite2d = get_node("Sprite2D")
|
||||
if team == TEAM.WHITE:
|
||||
sprite2d.region_rect = Rect2(5, 5, 35, 36)
|
||||
elif team == TEAM.BLACK:
|
||||
sprite2d.region_rect = Rect2(5, 50, 35, 36)
|
||||
|
||||
func check_move(destination: Vector2i) -> bool:
|
||||
var board_state = get_board_state()
|
||||
if board_state.has(destination):
|
||||
if board_state[destination].team == team:
|
||||
return false
|
||||
# TODO castling
|
||||
|
||||
return abs(destination.x - grid_pos.x) + abs(destination.y - grid_pos.y) == 1
|
||||
11
King.tscn
Normal file
11
King.tscn
Normal file
@@ -0,0 +1,11 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cph4rivrfduvx"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dyw0vra6it4f6" path="res://Piece.tscn" id="1_dkrxf"]
|
||||
[ext_resource type="Script" path="res://King.gd" id="2_1gvdw"]
|
||||
[ext_resource type="Texture2D" uid="uid://cgwutjks35c7e" path="res://Chess_Pieces_Sprite.svg" id="2_x3kym"]
|
||||
|
||||
[node name="Area2D" instance=ExtResource("1_dkrxf")]
|
||||
script = ExtResource("2_1gvdw")
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("2_x3kym")
|
||||
19
Knight.gd
Normal file
19
Knight.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
extends "res://Piece.gd"
|
||||
|
||||
func setup():
|
||||
kind = KIND.KNIGHT
|
||||
var sprite2d = get_node("Sprite2D")
|
||||
if team == TEAM.WHITE:
|
||||
sprite2d.region_rect = Rect2(140, 6, 34, 34)
|
||||
elif team == TEAM.BLACK:
|
||||
sprite2d.region_rect = Rect2(140, 51, 34, 34)
|
||||
|
||||
func check_move(destination: Vector2i) -> bool:
|
||||
var board_state = get_board_state()
|
||||
if board_state.has(destination):
|
||||
if board_state[destination].team == team:
|
||||
return false
|
||||
|
||||
var dx = abs(destination.x - grid_pos.x)
|
||||
var dy = abs(destination.y - grid_pos.y)
|
||||
return min(dx, dy) == 1 and max(dx, dy) == 2
|
||||
12
Knight.tscn
Normal file
12
Knight.tscn
Normal file
@@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://twc6lel7yco"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dyw0vra6it4f6" path="res://Piece.tscn" id="1_um2nk"]
|
||||
[ext_resource type="Script" path="res://Knight.gd" id="2_as8oi"]
|
||||
[ext_resource type="Texture2D" uid="uid://cgwutjks35c7e" path="res://Chess_Pieces_Sprite.svg" id="3_qgq37"]
|
||||
|
||||
[node name="Area2D" instance=ExtResource("1_um2nk")]
|
||||
script = ExtResource("2_as8oi")
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("3_qgq37")
|
||||
region_rect = Rect2(140, 6, 34, 34)
|
||||
38
Pawn.gd
Normal file
38
Pawn.gd
Normal file
@@ -0,0 +1,38 @@
|
||||
extends "res://Piece.gd"
|
||||
|
||||
#TODO en passant
|
||||
|
||||
func setup():
|
||||
kind = KIND.PAWN
|
||||
var sprite2d = get_node("Sprite2D")
|
||||
if team == TEAM.WHITE:
|
||||
sprite2d.region_rect = Rect2(234, 8, 26, 34)
|
||||
elif team == TEAM.BLACK:
|
||||
sprite2d.region_rect = Rect2(234, 53, 26, 33)
|
||||
|
||||
func check_move(destination: Vector2i) -> bool:
|
||||
var enemy_exists = false
|
||||
var board_state = get_board_state()
|
||||
if board_state.has(destination):
|
||||
if board_state[destination].team == team:
|
||||
return false
|
||||
else:
|
||||
enemy_exists = true
|
||||
|
||||
var dx = abs(destination.x - grid_pos.x)
|
||||
var dy = abs(destination.y - grid_pos.y)
|
||||
|
||||
var forward = dx == 0 and dy == 1 and not enemy_exists
|
||||
var diag = dx == 1 and dy == 1 and enemy_exists
|
||||
var correct_direction = false
|
||||
if team == TEAM.WHITE:
|
||||
correct_direction = destination.y - grid_pos.y < 0
|
||||
elif team == TEAM.BLACK:
|
||||
correct_direction = destination.y - grid_pos.y > 0
|
||||
|
||||
if not enemy_exists and correct_direction and dy == 2:
|
||||
var white_row = team == TEAM.WHITE and grid_pos.y == 6
|
||||
var black_row = team == TEAM.BLACK and grid_pos.y == 1
|
||||
return path_empty(destination) and (white_row or black_row)
|
||||
|
||||
return correct_direction and (forward or diag)
|
||||
12
Pawn.tscn
Normal file
12
Pawn.tscn
Normal file
@@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cpf00usfgjyve"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dyw0vra6it4f6" path="res://Piece.tscn" id="1_ye55b"]
|
||||
[ext_resource type="Script" path="res://Pawn.gd" id="2_eq4j4"]
|
||||
[ext_resource type="Texture2D" uid="uid://cgwutjks35c7e" path="res://Chess_Pieces_Sprite.svg" id="3_trr1t"]
|
||||
|
||||
[node name="Area2D" instance=ExtResource("1_ye55b")]
|
||||
script = ExtResource("2_eq4j4")
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("3_trr1t")
|
||||
region_rect = Rect2(234, 8, 26, 33)
|
||||
140
Piece.gd
Normal file
140
Piece.gd
Normal file
@@ -0,0 +1,140 @@
|
||||
extends Area2D
|
||||
|
||||
enum TEAM {WHITE, BLACK, NEUTRAL}
|
||||
enum KIND {KING, QUEEN, ROOK, BISHOP, KNIGHT, PAWN}
|
||||
|
||||
@export var dragging: bool = false
|
||||
@export var grid_size: Vector2i = Vector2i(1, 1)
|
||||
@export var grid_pos: Vector2i = Vector2i(0, 0)
|
||||
@export var kind: KIND = KIND.PAWN
|
||||
@export var team: TEAM = TEAM.NEUTRAL
|
||||
|
||||
signal moved(piece: Area2D, old_pos: Vector2i, new_pos: Vector2i)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
position = grid_to_pos(grid_pos)
|
||||
setup()
|
||||
|
||||
func setup():
|
||||
pass
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func _on_input_event(viewport, event, shape_idx):
|
||||
if event.is_pressed():
|
||||
dragging = true
|
||||
position = viewport.get_mouse_position();
|
||||
|
||||
func _unhandled_input(event):
|
||||
if dragging and event is InputEventMouseButton and not event.pressed:
|
||||
dragging = false
|
||||
|
||||
var grid_x = floor(position.x / grid_size.x)
|
||||
var grid_y = floor(position.y / grid_size.y)
|
||||
|
||||
if check_move(Vector2i(grid_x, grid_y)):
|
||||
moved.emit(self, grid_pos, Vector2i(grid_x, grid_y))
|
||||
grid_pos = Vector2i(grid_x, grid_y)
|
||||
|
||||
position = grid_to_pos(grid_pos)
|
||||
|
||||
if self.dragging and event is InputEventMouseMotion:
|
||||
position += event.relative
|
||||
|
||||
func make_black():
|
||||
team = TEAM.BLACK
|
||||
|
||||
func make_white():
|
||||
team = TEAM.WHITE
|
||||
|
||||
func make_neutral():
|
||||
team = TEAM.NEUTRAL
|
||||
|
||||
func is_black() -> bool:
|
||||
return team == TEAM.BLACK
|
||||
|
||||
func is_white() -> bool:
|
||||
return team == TEAM.WHITE
|
||||
|
||||
func is_pawn() -> bool:
|
||||
return kind == KIND.PAWN
|
||||
|
||||
func is_king() -> bool:
|
||||
return kind == KIND.KING
|
||||
|
||||
func grid_to_pos(grid_p: Vector2i) -> Vector2:
|
||||
var new_x = grid_p.x * grid_size.x + grid_size.x / 2
|
||||
var new_y = grid_p.y * grid_size.y + grid_size.y / 2
|
||||
return Vector2(new_x, new_y)
|
||||
|
||||
func get_board_state() -> Dictionary:
|
||||
return get_parent().board_state
|
||||
|
||||
func path_empty(destination: Vector2i) -> bool:
|
||||
var board_state = get_board_state()
|
||||
|
||||
var dx = destination.x - grid_pos.x
|
||||
var dy = destination.y - grid_pos.y
|
||||
|
||||
if dx == 0:
|
||||
if dy < 0:
|
||||
for y in range(destination.y + 1, grid_pos.y):
|
||||
if board_state.has(Vector2i(grid_pos.x, y)):
|
||||
return false
|
||||
elif dy > 0:
|
||||
for y in range(grid_pos.y + 1, destination.y):
|
||||
if board_state.has(Vector2i(grid_pos.x, y)):
|
||||
return false
|
||||
else:
|
||||
# no movement
|
||||
return false
|
||||
elif dy == 0:
|
||||
if dx < 0:
|
||||
for x in range(destination.x + 1, grid_pos.x):
|
||||
if board_state.has(Vector2i(x, grid_pos.y)):
|
||||
return false
|
||||
elif dx > 0:
|
||||
for x in range(grid_pos.x + 1, destination.x):
|
||||
if board_state.has(Vector2i(x, grid_pos.y)):
|
||||
return false
|
||||
else:
|
||||
# impossible
|
||||
return false
|
||||
elif abs(dx) == abs(dy):
|
||||
if dx < 0:
|
||||
if dy < 0:
|
||||
for d in range(1, abs(dx)):
|
||||
if board_state.has(Vector2i(grid_pos.x - d, grid_pos.y - d)):
|
||||
return false
|
||||
elif dy > 0:
|
||||
for d in range(1, abs(dx)):
|
||||
if board_state.has(Vector2i(grid_pos.x - d, grid_pos.y + d)):
|
||||
return false
|
||||
else:
|
||||
# impossible
|
||||
return false
|
||||
elif dx > 0:
|
||||
if dy < 0:
|
||||
for d in range(1, abs(dx)):
|
||||
if board_state.has(Vector2i(grid_pos.x + d, grid_pos.y - d)):
|
||||
return false
|
||||
elif dy > 0:
|
||||
for d in range(1, abs(dx)):
|
||||
if board_state.has(Vector2i(grid_pos.x + d, grid_pos.y + d)):
|
||||
return false
|
||||
else:
|
||||
# impossible
|
||||
return false
|
||||
else:
|
||||
# impossible
|
||||
return false
|
||||
else:
|
||||
# not a legal move
|
||||
return false
|
||||
return true
|
||||
|
||||
func check_move(destination: Vector2i) -> bool:
|
||||
return true
|
||||
21
Piece.tscn
Normal file
21
Piece.tscn
Normal file
@@ -0,0 +1,21 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://dyw0vra6it4f6"]
|
||||
|
||||
[ext_resource type="Script" path="res://Piece.gd" id="1_f1vk3"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_v20n7"]
|
||||
size = Vector2(34, 34)
|
||||
|
||||
[node name="Area2D" type="Area2D"]
|
||||
script = ExtResource("1_f1vk3")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture_repeat = 1
|
||||
region_enabled = true
|
||||
region_rect = Rect2(5, 5, 35, 36)
|
||||
metadata/dragging = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_v20n7")
|
||||
|
||||
[connection signal="input_event" from="." to="." method="_on_input_event"]
|
||||
25
Queen.gd
Normal file
25
Queen.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends "res://Piece.gd"
|
||||
|
||||
|
||||
func setup():
|
||||
kind = KIND.QUEEN
|
||||
var sprite2d = get_node("Sprite2D")
|
||||
if team == TEAM.WHITE:
|
||||
sprite2d.region_rect = Rect2(48, 4, 39, 36)
|
||||
elif team == TEAM.BLACK:
|
||||
sprite2d.region_rect = Rect2(48, 50, 39, 37)
|
||||
|
||||
func check_move(destination: Vector2i) -> bool:
|
||||
var board_state = get_board_state()
|
||||
if board_state.has(destination):
|
||||
if board_state[destination].team == team:
|
||||
return false
|
||||
|
||||
if !path_empty(destination):
|
||||
return false
|
||||
|
||||
var dx = abs(destination.x - grid_pos.x)
|
||||
var dy = abs(destination.y - grid_pos.y)
|
||||
var straight = min(dx, dy) == 0 and max(dx, dy) > 0
|
||||
var diagonal = dx == dy and dx > 0
|
||||
return straight or diagonal
|
||||
12
Queen.tscn
Normal file
12
Queen.tscn
Normal file
@@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dgrj5mn0ccidx"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dyw0vra6it4f6" path="res://Piece.tscn" id="1_hf7p0"]
|
||||
[ext_resource type="Script" path="res://Queen.gd" id="2_k32bp"]
|
||||
[ext_resource type="Texture2D" uid="uid://cgwutjks35c7e" path="res://Chess_Pieces_Sprite.svg" id="3_2kcbn"]
|
||||
|
||||
[node name="Area2D" instance=ExtResource("1_hf7p0")]
|
||||
script = ExtResource("2_k32bp")
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("3_2kcbn")
|
||||
region_rect = Rect2(48, 4, 39, 36)
|
||||
24
Rook.gd
Normal file
24
Rook.gd
Normal file
@@ -0,0 +1,24 @@
|
||||
extends "res://Piece.gd"
|
||||
|
||||
# todo castling
|
||||
|
||||
func setup():
|
||||
kind = KIND.ROOK
|
||||
var sprite2d = get_node("Sprite2D")
|
||||
if team == TEAM.WHITE:
|
||||
sprite2d.region_rect = Rect2(188, 8, 29, 32)
|
||||
elif team == TEAM.BLACK:
|
||||
sprite2d.region_rect = Rect2(188, 53, 29, 32)
|
||||
|
||||
func check_move(destination: Vector2i) -> bool:
|
||||
var board_state = get_board_state()
|
||||
if board_state.has(destination):
|
||||
if board_state[destination].team == team:
|
||||
return false
|
||||
|
||||
if !path_empty(destination):
|
||||
return false
|
||||
|
||||
var dx = abs(destination.x - grid_pos.x)
|
||||
var dy = abs(destination.y - grid_pos.y)
|
||||
return min(dx, dy) == 0 and max(dx, dy) > 0
|
||||
12
Rook.tscn
Normal file
12
Rook.tscn
Normal file
@@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bovak7x6gtvcm"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dyw0vra6it4f6" path="res://Piece.tscn" id="1_ppb41"]
|
||||
[ext_resource type="Script" path="res://Rook.gd" id="2_op1wo"]
|
||||
[ext_resource type="Texture2D" uid="uid://cgwutjks35c7e" path="res://Chess_Pieces_Sprite.svg" id="3_dm10o"]
|
||||
|
||||
[node name="Area2D" instance=ExtResource("1_ppb41")]
|
||||
script = ExtResource("2_op1wo")
|
||||
|
||||
[node name="Sprite2D" parent="." index="0"]
|
||||
texture = ExtResource("3_dm10o")
|
||||
region_rect = Rect2(188, 8, 29, 32)
|
||||
51
Tiles.svg
Normal file
51
Tiles.svg
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="19.998245mm"
|
||||
height="9.9985943mm"
|
||||
viewBox="0 0 19.998245 9.9985943"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
inkscape:version="1.3.2 (091e20ef0f, 2023-11-25)"
|
||||
sodipodi:docname="Tiles.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="6.1149726"
|
||||
inkscape:cx="21.422827"
|
||||
inkscape:cy="18.888065"
|
||||
inkscape:window-width="1099"
|
||||
inkscape:window-height="1426"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs1" />
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0.0032863,-4.8043041e-4)">
|
||||
<path
|
||||
style="fill:#a05a2c;stroke-width:0.264583"
|
||||
d="M 1.4937719e-4,4.8043041e-4 9.9972055,0.00122731 9.9972216,9.9968824 -0.0032863,9.9974909 Z"
|
||||
id="path1" />
|
||||
<path
|
||||
style="fill:#e9c6af;stroke-width:0.264583"
|
||||
d="M 9.9962523,9.7895175e-4 19.993309,0.00172583 19.993325,9.9973811 9.9928163,9.9979891 Z"
|
||||
id="path3" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
37
Tiles.svg.import
Normal file
37
Tiles.svg.import
Normal file
@@ -0,0 +1,37 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dirue6kbvxdat"
|
||||
path="res://.godot/imported/Tiles.svg-51ddde98b14ff2c3eaebe057a37f7697.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Tiles.svg"
|
||||
dest_files=["res://.godot/imported/Tiles.svg-51ddde98b14ff2c3eaebe057a37f7697.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
1
icon.svg
Normal file
1
icon.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 813 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H447l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c3 34 55 34 58 0v-86c-3-34-55-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 950 B |
37
icon.svg.import
Normal file
37
icon.svg.import
Normal file
@@ -0,0 +1,37 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cyjglc47bn6gy"
|
||||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
22
project.godot
Normal file
22
project.godot
Normal file
@@ -0,0 +1,22 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="CrazyChess"
|
||||
run/main_scene="res://Board.tscn"
|
||||
config/features=PackedStringArray("4.1", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=304
|
||||
window/size/viewport_height=304
|
||||
window/stretch/mode="canvas_items"
|
||||
Reference in New Issue
Block a user