-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,46 @@ | ||
extends Label | ||
extends Sprite | ||
|
||
enum TYPES {KING, QUEEN, BISHOP, KNIGHT, ROOK, PAWN} | ||
enum COLOUR {WHITE=0, BLACK=1} | ||
const PAWN_DIR = [-1, 1] | ||
const KNIGHT_MOVES = [Vector2(1,2), | ||
Vector2(-1,2), | ||
Vector2(-1,-2), | ||
Vector2(1,-2), | ||
Vector2(2,1), | ||
Vector2(-2,1), | ||
Vector2(-2,-1), | ||
Vector2(2,-1)] | ||
|
||
# Declare member variables here. Examples: | ||
# var a: int = 2 | ||
# var b: String = "text" | ||
var gridPos : Vector2 | ||
var type : int | ||
var moved : bool = false | ||
var colour : int | ||
onready var board = get_parent() | ||
|
||
func init(colour: int, type: int) -> void: | ||
self.colour = colour | ||
self.type = type | ||
self.set_frame(colour*6 + type) | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready() -> void: | ||
pass # Replace with function body. | ||
func can_move(newLoc, capture=false) -> bool: | ||
var raw = newLoc - self.gridPos | ||
var ref = raw.abs() | ||
match type: | ||
TYPES.QUEEN: | ||
return ref.x == 0 or ref.y == 0 or ref.x == ref.y | ||
TYPES.KING: | ||
return ref.length_squared < 2 | ||
TYPES.KNIGHT: | ||
return ref in KNIGHT_MOVES | ||
TYPES.ROOK: | ||
return ref.x == 0 or ref.y == 0 | ||
TYPES.BISHOP: | ||
return ref.x == ref.y | ||
TYPES.PAWN: | ||
if not self.moved: | ||
return ref.x == int(capture) and raw in [PAWN_DIR[self.colour], PAWN_DIR[self.colour]*2] | ||
else: | ||
return ref.x == int(capture) and raw == PAWN_DIR[self.colour] | ||
return false | ||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
#func _process(delta: float) -> void: | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
[gd_scene load_steps=2 format=2] | ||
[gd_scene load_steps=4 format=2] | ||
|
||
[ext_resource path="res://ChessSprite.png" type="Texture" id=1] | ||
[ext_resource path="res://Piece.gd" type="Script" id=2] | ||
[ext_resource path="res://Draggable.tscn" type="PackedScene" id=3] | ||
|
||
[node name="Piece" type="Sprite"] | ||
scale = Vector2( 0.3, 0.3 ) | ||
texture = ExtResource( 1 ) | ||
vframes = 2 | ||
hframes = 6 | ||
frame = 4 | ||
frame = 11 | ||
script = ExtResource( 2 ) | ||
|
||
[node name="Draggable" parent="." instance=ExtResource( 3 )] |