20 lines
557 B
GDScript
20 lines
557 B
GDScript
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
|