Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
oerc0122 committed Mar 6, 2021
1 parent 4595b56 commit b043b1d
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 39 deletions.
Binary file added BoardTile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions BoardTile.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/BoardTile.png-5335550af8d33ed13a9955d4b1e71850.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://BoardTile.png"
dest_files=[ "res://.import/BoardTile.png-5335550af8d33ed13a9955d4b1e71850.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
Binary file added ChessSprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions ChessSprite.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/ChessSprite.png-d12a7d76daa82fda428962c2f90c77d7.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://ChessSprite.png"
dest_files=[ "res://.import/ChessSprite.png-d12a7d76daa82fda428962c2f90c77d7.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
1 change: 1 addition & 0 deletions FileParser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func read(path):
var currTurn
if not "setup" in data:
currTurn = Turn.new().standard_start()
currTurn.raw = "0. Start game"
turns.push_back(currTurn)

for turn in turnRE.search_all(content):
Expand Down
19 changes: 19 additions & 0 deletions MainGame.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extends Node

var piece = load("res://Piece.tscn")

func _ready():
load_turn(0)


func load_turn(turn: int):
var currTurn = $FileParser.turns[turn]
for pos in currTurn.positions:
var currPiece = piece.instance()
var loc = $Board.map_to_world(currTurn.positions[pos])
currPiece.frame = "KQBNRP".find(pos[1])
currPiece.name = pos
if pos[0] == "B":
currPiece.frame+=6
currPiece.position = loc
add_child(currPiece)
50 changes: 50 additions & 0 deletions MainGame.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[gd_scene load_steps=5 format=2]

[ext_resource path="res://FileParser.tscn" type="PackedScene" id=1]
[ext_resource path="res://BoardTile.png" type="Texture" id=2]
[ext_resource path="res://MainGame.gd" type="Script" id=3]

[sub_resource type="TileSet" id=1]
0/name = "BoardTile.png 0"
0/texture = ExtResource( 2 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 0, 64, 64 )
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 = "BoardTile.png 1"
1/texture = ExtResource( 2 )
1/tex_offset = Vector2( 0, 0 )
1/modulate = Color( 1, 1, 1, 1 )
1/region = Rect2( 64, 0, 64, 64 )
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="MainGame" type="Node"]
script = ExtResource( 3 )

[node name="Board" type="TileMap" parent="."]
tile_set = SubResource( 1 )
format = 1
tile_data = PoolIntArray( -524287, 0, 0, -524286, 1, 0, -524285, 0, 0, -524284, 1, 0, -524283, 0, 0, -524282, 1, 0, -524281, 0, 0, -524280, 1, 0, -458751, 1, 0, -458750, 0, 0, -458749, 1, 0, -458748, 0, 0, -458747, 1, 0, -458746, 0, 0, -458745, 1, 0, -458744, 0, 0, -393215, 0, 0, -393214, 1, 0, -393213, 0, 0, -393212, 1, 0, -393211, 0, 0, -393210, 1, 0, -393209, 0, 0, -393208, 1, 0, -327679, 1, 0, -327678, 0, 0, -327677, 1, 0, -327676, 0, 0, -327675, 1, 0, -327674, 0, 0, -327673, 1, 0, -327672, 0, 0, -262143, 0, 0, -262142, 1, 0, -262141, 0, 0, -262140, 1, 0, -262139, 0, 0, -262138, 1, 0, -262137, 0, 0, -262136, 1, 0, -196607, 1, 0, -196606, 0, 0, -196605, 1, 0, -196604, 0, 0, -196603, 1, 0, -196602, 0, 0, -196601, 1, 0, -196600, 0, 0, -131071, 0, 0, -131070, 1, 0, -131069, 0, 0, -131068, 1, 0, -131067, 0, 0, -131066, 1, 0, -131065, 0, 0, -131064, 1, 0, -65535, 1, 0, -65534, 0, 0, -65533, 1, 0, -65532, 0, 0, -65531, 1, 0, -65530, 0, 0, -65529, 1, 0, -65528, 0, 0 )

[node name="FileParser" parent="." instance=ExtResource( 1 )]

[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2( 322.424, -255 )
current = true
zoom = Vector2( 0.9, 0.9 )
16 changes: 16 additions & 0 deletions Piece.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends Label


# Declare member variables here. Examples:
# var a: int = 2
# var b: String = "text"


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
# pass
9 changes: 9 additions & 0 deletions Piece.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://ChessSprite.png" type="Texture" id=1]

[node name="Piece" type="Sprite"]
texture = ExtResource( 1 )
vframes = 2
hframes = 6
frame = 4
41 changes: 26 additions & 15 deletions Turn.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var player : int
var comment : String = ""
var positions : Dictionary
var capture : bool = false
var captureLocation = null
var check : int = 0
var promote : String
var promotions : int = 0
Expand Down Expand Up @@ -59,10 +60,13 @@ func standard_start():

func which_piece(colour, label, disamb, pos) -> String:
var check : String
if colour == COLOUR.WHITE:
check = "W"
else:
check = "B"
match colour:
COLOUR.WHITE:
check = "W"
COLOUR.BLACK:
check = "B"
_:
return "Not found"

if not label:
label = "P"
Expand All @@ -87,7 +91,8 @@ func which_piece(colour, label, disamb, pos) -> String:
var grid_pos = to_grid(pos)

for poss in possibles:
var ref = (grid_pos - positions[poss]).abs()
var raw = (grid_pos - positions[poss]) # Raw useful for checking pawns moving in right dir.
var ref = raw.abs()
match label:
"Q":
if ref.x == 0 or ref.y == 0 or ref.x == ref.y:
Expand All @@ -105,20 +110,22 @@ func which_piece(colour, label, disamb, pos) -> String:
if ref.x == ref.y:
return poss
"P":
if self.capture:
if ref.y == colour and abs(ref.x) == 1:
return poss
if ((self.colour == COLOUR.WHITE and positions[poss].y == 2) or # Initial move of two
(self.colour == COLOUR.BLACK and positions[poss].y == 7)):
if ref.y in [self.colour, 2*self.colour]:
if ((colour == COLOUR.WHITE and positions[poss].y == 2) or # Initial move of two
(colour == COLOUR.BLACK and positions[poss].y == 7)):
if raw.y in [colour, 2*colour]:
return poss
# En passant
# En passant?
if self.capture:
pass

if ref.x == 1 and raw.y in [colour, 2*colour]:
self.captureLocation = positions[poss] + Vector2(1,1)
return poss
else:
if ref.y == colour:
if self.capture:
if raw.y == colour and ref.x == 1:
return poss
if raw.y == colour:
return poss
print(piece, colour, label)
return "Not found"

func to_grid(pos: String) -> Vector2:
Expand All @@ -133,9 +140,13 @@ func move(piece, location):
piece = self.get_colour() + self.promote + char(65+self.promotions)
self.promotions += 1


self.positions[piece] = self.to_grid(location)

if self.capture:
if self.captureLocation != null:
location = self.captureLocation

for capturedPiece in self.positions:
if self.positions[capturedPiece] == location:
self.positions.erase(capturedPiece)
Expand Down
Loading

0 comments on commit b043b1d

Please sign in to comment.