Initial Commit
This commit is contained in:
parent
93f5dbb7e1
commit
ece682cacb
27 changed files with 1877 additions and 0 deletions
17
.gitattributes
vendored
Normal file
17
.gitattributes
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Set the default behavior, in case people don't have core.autocrlf set.
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
# Explicitly declare text files you want to always be normalized and converted
|
||||||
|
# to native line endings on checkout.
|
||||||
|
*.cpp text
|
||||||
|
*.c text
|
||||||
|
*.h text
|
||||||
|
*.gd text
|
||||||
|
*.cs text
|
||||||
|
|
||||||
|
# Declare files that will always have CRLF line endings on checkout.
|
||||||
|
*.sln text eol=crlf
|
||||||
|
|
||||||
|
# Denote all files that are truly binary and should not be modified.
|
||||||
|
*.png binary
|
||||||
|
*.jpg binary
|
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Import cache
|
||||||
|
.import/
|
||||||
|
|
||||||
|
# Binaries
|
||||||
|
bin/
|
||||||
|
build/
|
||||||
|
lib/
|
324
Main.gd
Normal file
324
Main.gd
Normal file
|
@ -0,0 +1,324 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
export (PackedScene) var piece_scene
|
||||||
|
export (PackedScene) var movetile_scene
|
||||||
|
|
||||||
|
var board = new_board2()
|
||||||
|
var board_cell = 128
|
||||||
|
const BOARD_WIDTH = 7 # starting at 0..7
|
||||||
|
const BOARD_HEIGHT = 7
|
||||||
|
|
||||||
|
var movement_layer = false
|
||||||
|
var movement_layer_piece = null
|
||||||
|
|
||||||
|
var safely_handle_movement = false
|
||||||
|
|
||||||
|
var team1 = 1
|
||||||
|
var team2 = 2
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
make_player1("green")
|
||||||
|
make_player2("red")
|
||||||
|
print(OS.set_window_size(Vector2(700,700)))
|
||||||
|
|
||||||
|
# horrifying discovery: this occurs after the signal capturing functions
|
||||||
|
func _process(delta):
|
||||||
|
# hack to prevent 'clicking' on a killed piece
|
||||||
|
safely_handle_movement = false
|
||||||
|
|
||||||
|
func remove_movement_layer():
|
||||||
|
movement_layer = false
|
||||||
|
movement_layer_piece = null
|
||||||
|
var movement_tiles = get_tree().get_nodes_in_group("tile")
|
||||||
|
for e in movement_tiles:
|
||||||
|
e.queue_free()
|
||||||
|
|
||||||
|
func piece_clicked(piece):
|
||||||
|
if movement_layer:
|
||||||
|
print("I was clicked on, but the movement layer is toggled")
|
||||||
|
if movement_layer_piece == click_spot():
|
||||||
|
remove_movement_layer()
|
||||||
|
else:
|
||||||
|
if ! safely_handle_movement:
|
||||||
|
var piece_name = piece.get_piece()
|
||||||
|
print("You clicked on a %s, team %s" % [piece_name, piece.get_team()])
|
||||||
|
var location = click_spot()
|
||||||
|
print("Spot: %s " % location)
|
||||||
|
var pattern = get_move_pattern(piece, location)
|
||||||
|
if can_chess_move(pattern, location):
|
||||||
|
movement_layer = true
|
||||||
|
movement_layer_piece = location
|
||||||
|
|
||||||
|
func click_spot():
|
||||||
|
var square = get_viewport().get_mouse_position()
|
||||||
|
square[0] = floor(square[0] / board_cell)
|
||||||
|
square[1] = floor(square[1] / board_cell)
|
||||||
|
return square
|
||||||
|
|
||||||
|
func make_player2(color):
|
||||||
|
spawn_piece('rook', color, 0, 0, team2)
|
||||||
|
spawn_piece('knight', color, 1, 0, team2)
|
||||||
|
spawn_piece('bishop', color, 2, 0, team2)
|
||||||
|
spawn_piece('queen', color, 3, 0, team2)
|
||||||
|
spawn_piece('king', color, 4, 0, team2)
|
||||||
|
spawn_piece('bishop', color, 5, 0, team2)
|
||||||
|
spawn_piece('knight', color, 6, 0, team2)
|
||||||
|
spawn_piece('rook', color, 7, 0, team2)
|
||||||
|
for i in BOARD_WIDTH + 1:
|
||||||
|
spawn_piece('pawn', color, i , 1, team2)
|
||||||
|
|
||||||
|
func make_player1(color):
|
||||||
|
spawn_piece('rook', color, 0, 7, team1)
|
||||||
|
spawn_piece('knight', color, 1, 7, team1)
|
||||||
|
spawn_piece('bishop', color, 2, 7, team1)
|
||||||
|
spawn_piece('queen', color, 3, 7, team1)
|
||||||
|
spawn_piece('king', color, 4, 7, team1)
|
||||||
|
spawn_piece('bishop', color, 5, 7, team1)
|
||||||
|
spawn_piece('knight', color, 6, 7, team1)
|
||||||
|
spawn_piece('rook', color, 7, 7, team1)
|
||||||
|
for i in BOARD_WIDTH + 1:
|
||||||
|
spawn_piece('pawn', color, i , 6, team1)
|
||||||
|
|
||||||
|
func spawn_piece(piece_name, color, x=0, y=0, team=0):
|
||||||
|
var piece = piece_scene.instance()
|
||||||
|
piece.init(piece.piece_map.get(piece_name), piece.piece_color.get(color), team)
|
||||||
|
add_child(piece)
|
||||||
|
piece.connect("clicked", self, "piece_clicked", [piece])
|
||||||
|
board_add_piece(piece, x, y)
|
||||||
|
piece.position = in_square(Vector2(x * board_cell, y * board_cell))
|
||||||
|
return piece
|
||||||
|
|
||||||
|
func rand_pos():
|
||||||
|
return Vector2(rand_range(0, get_viewport().size.x),rand_range(0, get_viewport().size.y))
|
||||||
|
|
||||||
|
# needs to be Vector2 as that is what object.position takes
|
||||||
|
func in_square(vect2):
|
||||||
|
#print(vect2)
|
||||||
|
vect2.x = ceil(vect2.x / board_cell)
|
||||||
|
#print(vect2.x)
|
||||||
|
vect2.x *= board_cell
|
||||||
|
vect2.x += board_cell / 2
|
||||||
|
|
||||||
|
vect2.y = ceil(vect2.y / board_cell)
|
||||||
|
#print(vect2.y)
|
||||||
|
vect2.y *= board_cell
|
||||||
|
vect2.y += board_cell / 2
|
||||||
|
|
||||||
|
#print(vect2)
|
||||||
|
return vect2
|
||||||
|
|
||||||
|
func new_board2():
|
||||||
|
# x →
|
||||||
|
# y
|
||||||
|
# ↓
|
||||||
|
# [0][0] = top left, [0][7] = bottom left, [7][0] = top right, [7][7] = bottom right
|
||||||
|
var board = []
|
||||||
|
for i in BOARD_HEIGHT + 1:
|
||||||
|
board.append([])
|
||||||
|
board[i].resize(BOARD_WIDTH + 1)
|
||||||
|
for j in BOARD_WIDTH + 1:
|
||||||
|
board[i][j] = 0
|
||||||
|
return board
|
||||||
|
|
||||||
|
func new_board():
|
||||||
|
return [[0,0,0,0,0,0,0,0],
|
||||||
|
[0,0,0,0,0,0,0,0],
|
||||||
|
[0,0,0,0,0,0,0,0],
|
||||||
|
[0,0,0,0,0,0,0,0],
|
||||||
|
[0,0,0,0,0,0,0,0],
|
||||||
|
[0,0,0,0,0,0,0,0],
|
||||||
|
[0,0,0,0,0,0,0,0],
|
||||||
|
[0,0,0,0,0,0,0,0]]
|
||||||
|
|
||||||
|
func board_add_piece(piece, x, y):
|
||||||
|
board[x][y] = piece
|
||||||
|
|
||||||
|
enum {
|
||||||
|
move_2_up_pawn,
|
||||||
|
move_1_up_pawn,
|
||||||
|
attack_1_nw,
|
||||||
|
attack_1_ne,
|
||||||
|
|
||||||
|
move_2_down_pawn,
|
||||||
|
move_1_down_pawn,
|
||||||
|
attack_1_sw,
|
||||||
|
attack_1_se,
|
||||||
|
|
||||||
|
move_1_up,
|
||||||
|
move_1_down,
|
||||||
|
move_1_left,
|
||||||
|
move_1_right,
|
||||||
|
move_1_nw,
|
||||||
|
move_1_ne,
|
||||||
|
move_1_sw,
|
||||||
|
move_1_se,
|
||||||
|
|
||||||
|
move_up_inf,
|
||||||
|
move_down_inf,
|
||||||
|
move_left_inf,
|
||||||
|
move_right_inf,
|
||||||
|
|
||||||
|
move_nw_inf,
|
||||||
|
move_ne_inf,
|
||||||
|
move_sw_inf,
|
||||||
|
move_se_inf,
|
||||||
|
|
||||||
|
knight,
|
||||||
|
}
|
||||||
|
|
||||||
|
func get_move_pattern(piece, coords):
|
||||||
|
var piece_name = piece.get_piece()
|
||||||
|
match (piece_name):
|
||||||
|
"pawn":
|
||||||
|
if piece.get_team() == team1:
|
||||||
|
if coords[1] == 6:
|
||||||
|
print("This pawn piece hasn't moved!")
|
||||||
|
return [attack_1_nw, move_2_up_pawn, attack_1_ne]
|
||||||
|
else:
|
||||||
|
print("This pawn piece has moved and that is hecking brave!")
|
||||||
|
return [attack_1_nw, move_1_up_pawn, attack_1_ne]
|
||||||
|
else:
|
||||||
|
if coords[1] == 1:
|
||||||
|
return [attack_1_sw, move_2_down_pawn, attack_1_se]
|
||||||
|
else:
|
||||||
|
return [attack_1_sw, move_1_down_pawn, attack_1_se]
|
||||||
|
"rook":
|
||||||
|
return [move_up_inf, move_left_inf, move_right_inf, move_down_inf]
|
||||||
|
"knight":
|
||||||
|
return [knight]
|
||||||
|
"bishop":
|
||||||
|
return [move_ne_inf, move_nw_inf, move_sw_inf, move_se_inf]
|
||||||
|
"queen":
|
||||||
|
return [move_up_inf, move_down_inf, move_left_inf, move_right_inf, move_ne_inf, move_nw_inf, move_sw_inf, move_se_inf]
|
||||||
|
"king":
|
||||||
|
return [move_1_down, move_1_left, move_1_right, move_1_up, move_1_ne, move_1_nw, move_1_se, move_1_sw]
|
||||||
|
_:
|
||||||
|
print("no pattern for this one")
|
||||||
|
|
||||||
|
func can_chess_move(pattern, coords):
|
||||||
|
var can_move = false
|
||||||
|
var curr_team = board[coords[0]][coords[1]].get_team()
|
||||||
|
for e in pattern:
|
||||||
|
match (e):
|
||||||
|
move_1_down_pawn:
|
||||||
|
if make_tiles(coords, [0,1], 1, true, curr_team): can_move = true
|
||||||
|
move_2_down_pawn:
|
||||||
|
if make_tiles(coords, [0,1], 2, true, curr_team): can_move = true
|
||||||
|
attack_1_sw:
|
||||||
|
if make_tiles(coords, [-1,1], 1, false, curr_team, true): can_move = true
|
||||||
|
attack_1_se:
|
||||||
|
if make_tiles(coords, [1,1], 1, false, curr_team, true): can_move = true
|
||||||
|
|
||||||
|
move_1_up_pawn:
|
||||||
|
if make_tiles(coords, [0,-1], 1, true, curr_team): can_move = true
|
||||||
|
move_2_up_pawn:
|
||||||
|
if make_tiles(coords, [0,-1], 2, true, curr_team): can_move = true
|
||||||
|
attack_1_nw:
|
||||||
|
if make_tiles(coords, [-1,-1], 1, false, curr_team, true): can_move = true
|
||||||
|
attack_1_ne:
|
||||||
|
if make_tiles(coords, [1,-1], 1, false, curr_team, true): can_move = true
|
||||||
|
|
||||||
|
move_up_inf:
|
||||||
|
if make_tiles(coords, [0,-1], BOARD_HEIGHT, false, curr_team): can_move =true
|
||||||
|
move_down_inf:
|
||||||
|
if make_tiles(coords, [0,1], BOARD_HEIGHT, false, curr_team): can_move = true
|
||||||
|
move_left_inf:
|
||||||
|
if make_tiles(coords, [-1,0], BOARD_WIDTH, false, curr_team): can_move = true
|
||||||
|
move_right_inf:
|
||||||
|
if make_tiles(coords, [1,0], BOARD_WIDTH, false, curr_team): can_move = true
|
||||||
|
|
||||||
|
move_ne_inf:
|
||||||
|
if make_tiles(coords, [1,-1], 8, false, curr_team): can_move = true
|
||||||
|
move_nw_inf:
|
||||||
|
if make_tiles(coords, [-1,-1], 8, false, curr_team): can_move = true
|
||||||
|
move_sw_inf:
|
||||||
|
if make_tiles(coords, [-1,1], 8, false, curr_team): can_move = true
|
||||||
|
move_se_inf:
|
||||||
|
if make_tiles(coords, [1,1], 8, false, curr_team): can_move = true
|
||||||
|
|
||||||
|
knight:
|
||||||
|
if make_tiles(coords, [1,2], 1, false, curr_team): can_move = true
|
||||||
|
if make_tiles(coords, [1,-2], 1, false, curr_team): can_move = true
|
||||||
|
if make_tiles(coords, [-1,-2], 1, false, curr_team): can_move = true
|
||||||
|
if make_tiles(coords, [-1,2], 1, false, curr_team): can_move = true
|
||||||
|
if make_tiles(coords, [2,1], 1, false, curr_team): can_move = true
|
||||||
|
if make_tiles(coords, [2,-1], 1, false, curr_team): can_move = true
|
||||||
|
if make_tiles(coords, [-2,-1], 1, false, curr_team): can_move = true
|
||||||
|
if make_tiles(coords, [-2,1], 1, false, curr_team): can_move = true
|
||||||
|
|
||||||
|
move_1_down:
|
||||||
|
if make_tiles(coords, [0,1], 1, false, curr_team): can_move = true
|
||||||
|
move_1_up:
|
||||||
|
if make_tiles(coords, [0,-1], 1, false, curr_team): can_move = true
|
||||||
|
move_1_right:
|
||||||
|
if make_tiles(coords, [1,0], 1, false, curr_team): can_move = true
|
||||||
|
move_1_left:
|
||||||
|
if make_tiles(coords, [-1,0], 1, false, curr_team): can_move = true
|
||||||
|
move_1_ne:
|
||||||
|
if make_tiles(coords, [1,-1], 1, false, curr_team): can_move = true
|
||||||
|
move_1_nw:
|
||||||
|
if make_tiles(coords, [-1,-1], 1, false, curr_team): can_move = true
|
||||||
|
move_1_se:
|
||||||
|
if make_tiles(coords, [1,1], 1, false, curr_team): can_move = true
|
||||||
|
move_1_sw:
|
||||||
|
if make_tiles(coords, [-1,1], 1, false, curr_team): can_move = true
|
||||||
|
return can_move
|
||||||
|
|
||||||
|
func movetile_clicked(move_tile):
|
||||||
|
print("Yep, I was clicked")
|
||||||
|
var location = click_spot()
|
||||||
|
var check = board[location[0]][location[1]]
|
||||||
|
if ! check:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
check.kill()
|
||||||
|
|
||||||
|
board[location[0]][location[1]] = board[movement_layer_piece[0]][movement_layer_piece[1]]
|
||||||
|
board[movement_layer_piece[0]][movement_layer_piece[1]].position = \
|
||||||
|
in_square(Vector2(location[0] * board_cell, location[1] * board_cell))
|
||||||
|
board[movement_layer_piece[0]][movement_layer_piece[1]] = 0
|
||||||
|
remove_movement_layer()
|
||||||
|
safely_handle_movement = true
|
||||||
|
|
||||||
|
|
||||||
|
func spawn_move_tile(coords):
|
||||||
|
var move_tile = movetile_scene.instance()
|
||||||
|
add_child(move_tile)
|
||||||
|
move_tile.connect("move_clicked", self, "movetile_clicked", [move_tile])
|
||||||
|
move_tile.position = in_square(Vector2(coords[0] * board_cell, coords[1] * board_cell))
|
||||||
|
print(move_tile.position)
|
||||||
|
|
||||||
|
func make_tiles(coords, pattern, go_range, cant_attack, curr_team, must_attack = false):
|
||||||
|
var x = coords[0]
|
||||||
|
var y = coords[1]
|
||||||
|
var pattern0 = pattern[0]
|
||||||
|
var pattern1 = pattern[1]
|
||||||
|
var a = 0
|
||||||
|
var b = 0
|
||||||
|
var board_size_x = 7 # starting at 0
|
||||||
|
var board_size_y = 7
|
||||||
|
|
||||||
|
var made_tile = false
|
||||||
|
|
||||||
|
for i in range(1,go_range+1):
|
||||||
|
a += pattern0
|
||||||
|
b += pattern1
|
||||||
|
# dont go out of bounds: not bigger than board size but not smaller than 0
|
||||||
|
if (x + a) <= board_size_x and (y + b) <= board_size_y and (x + a) >= 0 and (y + b) >= 0 :
|
||||||
|
var check = board[x + a][y + b]
|
||||||
|
if ! check and ! must_attack:
|
||||||
|
spawn_move_tile([x + a, y + b])
|
||||||
|
made_tile = true
|
||||||
|
elif must_attack:
|
||||||
|
if ! check:
|
||||||
|
pass
|
||||||
|
elif check.get_team() != curr_team:
|
||||||
|
spawn_move_tile([x + a, y + b])
|
||||||
|
made_tile = true
|
||||||
|
elif ! cant_attack and check.get_team() != curr_team:
|
||||||
|
spawn_move_tile([x + a, y + b])
|
||||||
|
made_tile = true
|
||||||
|
break # rules of chess say pieces cant go past another
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
return made_tile
|
48
Main.tscn
Normal file
48
Main.tscn
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
[gd_scene load_steps=6 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://board.png" type="Texture" id=1]
|
||||||
|
[ext_resource path="res://Main.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://Piece.tscn" type="PackedScene" id=3]
|
||||||
|
[ext_resource path="res://MoveTile.tscn" type="PackedScene" id=4]
|
||||||
|
|
||||||
|
[sub_resource type="TileSet" id=1]
|
||||||
|
0/name = "board.png 0"
|
||||||
|
0/texture = ExtResource( 1 )
|
||||||
|
0/tex_offset = Vector2( 0, 0 )
|
||||||
|
0/modulate = Color( 1, 1, 1, 1 )
|
||||||
|
0/region = Rect2( 0, 0, 128, 128 )
|
||||||
|
0/tile_mode = 0
|
||||||
|
0/occluder_offset = Vector2( 0, 0 )
|
||||||
|
0/navigation_offset = Vector2( 0, 0 )
|
||||||
|
0/shape_offset = Vector2( 0, 0 )
|
||||||
|
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||||
|
0/shape_one_way = false
|
||||||
|
0/shape_one_way_margin = 0.0
|
||||||
|
0/shapes = [ ]
|
||||||
|
0/z_index = 0
|
||||||
|
1/name = "board.png 1"
|
||||||
|
1/texture = ExtResource( 1 )
|
||||||
|
1/tex_offset = Vector2( 0, 0 )
|
||||||
|
1/modulate = Color( 1, 1, 1, 1 )
|
||||||
|
1/region = Rect2( 128, 0, 128, 128 )
|
||||||
|
1/tile_mode = 0
|
||||||
|
1/occluder_offset = Vector2( 0, 0 )
|
||||||
|
1/navigation_offset = Vector2( 0, 0 )
|
||||||
|
1/shape_offset = Vector2( 0, 0 )
|
||||||
|
1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
|
||||||
|
1/shape_one_way = false
|
||||||
|
1/shape_one_way_margin = 0.0
|
||||||
|
1/shapes = [ ]
|
||||||
|
1/z_index = 0
|
||||||
|
|
||||||
|
[node name="Main" type="Node"]
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
piece_scene = ExtResource( 3 )
|
||||||
|
movetile_scene = ExtResource( 4 )
|
||||||
|
|
||||||
|
[node name="BoardMap" type="TileMap" parent="."]
|
||||||
|
z_index = -1
|
||||||
|
tile_set = SubResource( 1 )
|
||||||
|
cell_size = Vector2( 128, 128 )
|
||||||
|
format = 1
|
||||||
|
tile_data = PoolIntArray( 0, 1, 0, 1, 0, 0, 2, 1, 0, 3, 0, 0, 4, 1, 0, 5, 0, 0, 6, 1, 0, 7, 0, 0, 65536, 0, 0, 65537, 1, 0, 65538, 0, 0, 65539, 1, 0, 65540, 0, 0, 65541, 1, 0, 65542, 0, 0, 65543, 1, 0, 131072, 1, 0, 131073, 0, 0, 131074, 1, 0, 131075, 0, 0, 131076, 1, 0, 131077, 0, 0, 131078, 1, 0, 131079, 0, 0, 196608, 0, 0, 196609, 1, 0, 196610, 0, 0, 196611, 1, 0, 196612, 0, 0, 196613, 1, 0, 196614, 0, 0, 196615, 1, 0, 262144, 1, 0, 262145, 0, 0, 262146, 1, 0, 262147, 0, 0, 262148, 1, 0, 262149, 0, 0, 262150, 1, 0, 262151, 0, 0, 327680, 0, 0, 327681, 1, 0, 327682, 0, 0, 327683, 1, 0, 327684, 0, 0, 327685, 1, 0, 327686, 0, 0, 327687, 1, 0, 393216, 1, 0, 393217, 0, 0, 393218, 1, 0, 393219, 0, 0, 393220, 1, 0, 393221, 0, 0, 393222, 1, 0, 393223, 0, 0, 458752, 0, 0, 458753, 1, 0, 458754, 0, 0, 458755, 1, 0, 458756, 0, 0, 458757, 1, 0, 458758, 0, 0, 458759, 1, 0 )
|
16
MoveTile.gd
Normal file
16
MoveTile.gd
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
signal move_clicked
|
||||||
|
|
||||||
|
const blue = Color(0.30, 0.71, 0.96, 0.54)
|
||||||
|
const red = Color(1.00, 0.00, 0.00, 0.54)
|
||||||
|
|
||||||
|
func _on_Area2D_input_event(viewport, event, shape_idx):
|
||||||
|
if event.is_action_pressed("mouse1"):
|
||||||
|
emit_signal("move_clicked")
|
||||||
|
|
||||||
|
func set_color(color):
|
||||||
|
if color == "blue":
|
||||||
|
color = blue
|
||||||
|
elif color == "red":
|
||||||
|
color = red
|
30
MoveTile.tscn
Normal file
30
MoveTile.tscn
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://MoveTile.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id=1]
|
||||||
|
|
||||||
|
[node name="MoveTile" type="Node2D" groups=[
|
||||||
|
"tile",
|
||||||
|
]]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="Rect" type="ColorRect" parent="."]
|
||||||
|
margin_left = -64.0
|
||||||
|
margin_top = -64.0
|
||||||
|
margin_right = 64.0
|
||||||
|
margin_bottom = 64.0
|
||||||
|
mouse_filter = 2
|
||||||
|
color = Color( 0.301961, 0.717647, 0.964706, 0.54902 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D" parent="Rect"]
|
||||||
|
position = Vector2( 64, 64 )
|
||||||
|
scale = Vector2( 6.4, 6.4 )
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Rect/Area2D"]
|
||||||
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
|
[connection signal="input_event" from="Rect/Area2D" to="." method="_on_Area2D_input_event"]
|
24
Piece.tscn
Normal file
24
Piece.tscn
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://chess.png" type="Texture" id=1]
|
||||||
|
[ext_resource path="res://Sprite.gd" type="Script" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id=1]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
flags = 4
|
||||||
|
atlas = ExtResource( 1 )
|
||||||
|
region = Rect2( 0, 0, 128, 128 )
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id=2]
|
||||||
|
|
||||||
|
[node name="Piece" type="Sprite"]
|
||||||
|
texture = SubResource( 1 )
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||||
|
scale = Vector2( 4, 4 )
|
||||||
|
shape = SubResource( 2 )
|
||||||
|
|
||||||
|
[connection signal="input_event" from="Area2D" to="." method="_on_Area2D_input_event"]
|
86
Sprite.gd
Normal file
86
Sprite.gd
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
extends Sprite
|
||||||
|
|
||||||
|
signal clicked
|
||||||
|
|
||||||
|
var CELL_W = 128
|
||||||
|
var CELL_H = 128
|
||||||
|
|
||||||
|
export var piece = 'pawn'
|
||||||
|
export var team = 0
|
||||||
|
|
||||||
|
const move_patterns = {
|
||||||
|
pawn = [[0,0,0],[2,0,0],[0,0,0]]
|
||||||
|
}
|
||||||
|
|
||||||
|
func get_move_pattern():
|
||||||
|
return self.move_patterns.get(piece)
|
||||||
|
|
||||||
|
enum piece_color {
|
||||||
|
black = 0,
|
||||||
|
white = 128
|
||||||
|
grey = 256,
|
||||||
|
litegrey = 384,
|
||||||
|
pink = 512,
|
||||||
|
red = 640,
|
||||||
|
orange = 768,
|
||||||
|
yellow = 896,
|
||||||
|
green = 1024,
|
||||||
|
blue = 1152,
|
||||||
|
teal = 1280,
|
||||||
|
purple = 1408
|
||||||
|
}
|
||||||
|
|
||||||
|
enum piece_map {
|
||||||
|
pawn = 0,
|
||||||
|
knight = 128,
|
||||||
|
bishop = 256,
|
||||||
|
rook = 384,
|
||||||
|
queen = 512,
|
||||||
|
king = 640
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
#print("Trying Red Pawn... Color: %s, Piece: " % piece_color.red, piece_map.pawn)
|
||||||
|
#var atlas = get_texture()
|
||||||
|
#atlas.set_region(Rect2(piece_map.king, piece_color.red, CELL_W, CELL_H))
|
||||||
|
#print(atlas.get_region())
|
||||||
|
#get_texture().set_region(Rect2(piece_map.king, piece_color.red, CELL_W, CELL_H))
|
||||||
|
|
||||||
|
#position = Vector2(500,500)
|
||||||
|
pass
|
||||||
|
|
||||||
|
func init(piece, color, team = 0):
|
||||||
|
get_texture().set_region(Rect2(piece, color, CELL_W, CELL_H))
|
||||||
|
self.set_piece(self.get_piece_name_by_region())
|
||||||
|
self.set_team(team)
|
||||||
|
|
||||||
|
func _on_Area2D_input_event(viewport, event, shape_idx):
|
||||||
|
if event.is_action_pressed("mouse1"):
|
||||||
|
emit_signal("clicked")
|
||||||
|
|
||||||
|
func set_piece(new_piece):
|
||||||
|
piece = new_piece
|
||||||
|
|
||||||
|
func get_piece():
|
||||||
|
return piece
|
||||||
|
|
||||||
|
func get_team():
|
||||||
|
return team
|
||||||
|
|
||||||
|
func set_team(new_team):
|
||||||
|
team = new_team
|
||||||
|
|
||||||
|
func get_piece_name_by_region():
|
||||||
|
var region = get_texture().get_region()
|
||||||
|
for map in piece_map:
|
||||||
|
if piece_map.get(map) == region.position.x:
|
||||||
|
return map
|
||||||
|
|
||||||
|
func get_piece_color_by_region():
|
||||||
|
var region = get_texture().get_region()
|
||||||
|
for map in piece_color:
|
||||||
|
if piece_color.get(map) == region.position.y:
|
||||||
|
return map
|
||||||
|
|
||||||
|
func kill():
|
||||||
|
queue_free()
|
21
addons/godot-git-plugin/LICENSE
Normal file
21
addons/godot-git-plugin/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2016-2022 The Godot Engine community
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
1062
addons/godot-git-plugin/THIRDPARTY.md
Normal file
1062
addons/godot-git-plugin/THIRDPARTY.md
Normal file
File diff suppressed because it is too large
Load diff
18
addons/godot-git-plugin/git_api.gdnlib
Normal file
18
addons/godot-git-plugin/git_api.gdnlib
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
[general]
|
||||||
|
|
||||||
|
singleton=true
|
||||||
|
load_once=true
|
||||||
|
symbol_prefix="godot_"
|
||||||
|
reloadable=false
|
||||||
|
|
||||||
|
[entry]
|
||||||
|
|
||||||
|
OSX.64="res://addons/godot-git-plugin/osx/release/libgitapi.dylib"
|
||||||
|
Windows.64="res://addons/godot-git-plugin/win64/release/libgitapi.dll"
|
||||||
|
X11.64="res://addons/godot-git-plugin/x11/release/libgitapi.so"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
OSX.64=[ ]
|
||||||
|
Windows.64=[ ]
|
||||||
|
X11.64=[ ]
|
9
addons/godot-git-plugin/git_api.gdns
Normal file
9
addons/godot-git-plugin/git_api.gdns
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/godot-git-plugin/git_api.gdnlib" type="GDNativeLibrary" id=1]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
resource_name = "GitAPI"
|
||||||
|
class_name = "GitAPI"
|
||||||
|
library = ExtResource( 1 )
|
||||||
|
script_class_name = "GitAPI"
|
BIN
addons/godot-git-plugin/osx/release/libgitapi.dylib
Normal file
BIN
addons/godot-git-plugin/osx/release/libgitapi.dylib
Normal file
Binary file not shown.
7
addons/godot-git-plugin/plugin.cfg
Normal file
7
addons/godot-git-plugin/plugin.cfg
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[plugin]
|
||||||
|
|
||||||
|
name="Godot Git Plugin"
|
||||||
|
description="This plugin lets you interact with Git without leaving the Godot editor. More information can be found at https://github.com/godotengine/godot-git-plugin/wiki"
|
||||||
|
author="ChronicallySerious"
|
||||||
|
version="v1.2.3"
|
||||||
|
script="git_api.gdns"
|
BIN
addons/godot-git-plugin/win64/release/libgitapi.dll
Normal file
BIN
addons/godot-git-plugin/win64/release/libgitapi.dll
Normal file
Binary file not shown.
BIN
addons/godot-git-plugin/win64/release/libgitapi.exp
Normal file
BIN
addons/godot-git-plugin/win64/release/libgitapi.exp
Normal file
Binary file not shown.
BIN
addons/godot-git-plugin/win64/release/libgitapi.lib
Normal file
BIN
addons/godot-git-plugin/win64/release/libgitapi.lib
Normal file
Binary file not shown.
BIN
addons/godot-git-plugin/x11/release/libgitapi.so
Normal file
BIN
addons/godot-git-plugin/x11/release/libgitapi.so
Normal file
Binary file not shown.
BIN
board.png
Normal file
BIN
board.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
34
board.png.import
Normal file
34
board.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/board.png-aeeee8e2906231b92d271d02de0f6106.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://board.png"
|
||||||
|
dest_files=[ "res://.import/board.png-aeeee8e2906231b92d271d02de0f6106.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
BIN
chess.png
Normal file
BIN
chess.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 251 KiB |
34
chess.png.import
Normal file
34
chess.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/chess.png-13880741cf18e1df88857507e523d925.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://chess.png"
|
||||||
|
dest_files=[ "res://.import/chess.png-13880741cf18e1df88857507e523d925.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
6
default_env.tres
Normal file
6
default_env.tres
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[gd_resource type="Environment" load_steps=2 format=2]
|
||||||
|
|
||||||
|
[sub_resource type="ProceduralSky" id=1]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
background_sky = SubResource( 1 )
|
49
export_presets.cfg
Normal file
49
export_presets.cfg
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
[preset.0]
|
||||||
|
|
||||||
|
name="HTML5"
|
||||||
|
platform="HTML5"
|
||||||
|
runnable=true
|
||||||
|
custom_features=""
|
||||||
|
export_filter="all_resources"
|
||||||
|
include_filter=""
|
||||||
|
exclude_filter=""
|
||||||
|
export_path="html5/chessgame.html"
|
||||||
|
script_export_mode=1
|
||||||
|
script_encryption_key=""
|
||||||
|
|
||||||
|
[preset.0.options]
|
||||||
|
|
||||||
|
custom_template/debug=""
|
||||||
|
custom_template/release=""
|
||||||
|
variant/export_type=0
|
||||||
|
vram_texture_compression/for_desktop=true
|
||||||
|
vram_texture_compression/for_mobile=false
|
||||||
|
html/custom_html_shell=""
|
||||||
|
html/head_include=""
|
||||||
|
html/canvas_resize_policy=2
|
||||||
|
html/experimental_virtual_keyboard=false
|
||||||
|
|
||||||
|
[preset.1]
|
||||||
|
|
||||||
|
name="Linux/X11"
|
||||||
|
platform="Linux/X11"
|
||||||
|
runnable=true
|
||||||
|
custom_features=""
|
||||||
|
export_filter="all_resources"
|
||||||
|
include_filter=""
|
||||||
|
exclude_filter=""
|
||||||
|
export_path="./chessgame.x86_64"
|
||||||
|
script_export_mode=1
|
||||||
|
script_encryption_key=""
|
||||||
|
|
||||||
|
[preset.1.options]
|
||||||
|
|
||||||
|
custom_template/debug=""
|
||||||
|
custom_template/release=""
|
||||||
|
binary_format/64_bits=true
|
||||||
|
binary_format/embed_pck=false
|
||||||
|
texture_format/bptc=false
|
||||||
|
texture_format/s3tc=true
|
||||||
|
texture_format/etc=false
|
||||||
|
texture_format/etc2=false
|
||||||
|
texture_format/no_bptc_fallbacks=true
|
BIN
icon.png
Normal file
BIN
icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
34
icon.png.import
Normal file
34
icon.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="StreamTexture"
|
||||||
|
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://icon.png"
|
||||||
|
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_mode=0
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
compress/normal_map=0
|
||||||
|
flags/repeat=0
|
||||||
|
flags/filter=true
|
||||||
|
flags/mipmaps=false
|
||||||
|
flags/anisotropic=false
|
||||||
|
flags/srgb=2
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/HDR_as_SRGB=false
|
||||||
|
process/invert_color=false
|
||||||
|
stream=false
|
||||||
|
size_limit=0
|
||||||
|
detect_3d=true
|
||||||
|
svg/scale=1.0
|
51
project.godot
Normal file
51
project.godot
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
; 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=4
|
||||||
|
|
||||||
|
_global_script_classes=[ {
|
||||||
|
"base": "",
|
||||||
|
"class": "GitAPI",
|
||||||
|
"language": "NativeScript",
|
||||||
|
"path": "res://addons/godot-git-plugin/git_api.gdns"
|
||||||
|
} ]
|
||||||
|
_global_script_class_icons={
|
||||||
|
"GitAPI": ""
|
||||||
|
}
|
||||||
|
|
||||||
|
[application]
|
||||||
|
|
||||||
|
config/name="chessgame"
|
||||||
|
run/main_scene="res://Main.tscn"
|
||||||
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
|
[display]
|
||||||
|
|
||||||
|
window/size/height=1024
|
||||||
|
window/stretch/mode="2d"
|
||||||
|
window/stretch/aspect="expand"
|
||||||
|
|
||||||
|
[gdnative]
|
||||||
|
|
||||||
|
singletons=[ "res://addons/godot-git-plugin/git_api.gdnlib" ]
|
||||||
|
|
||||||
|
[input]
|
||||||
|
|
||||||
|
mouse1={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
[physics]
|
||||||
|
|
||||||
|
common/enable_pause_aware_picking=true
|
||||||
|
|
||||||
|
[rendering]
|
||||||
|
|
||||||
|
environment/default_environment="res://default_env.tres"
|
Loading…
Reference in a new issue