Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func rook_move(object, start_square, new_square):
- var start_xy = Global.label_to_xy(start_square.label)
- var new_xy = Global.label_to_xy(new_square.label)
- if new_xy.x != start_xy.x and new_xy.y != start_xy.y:
- return false
- if new_xy.y == start_xy.y:
- if new_xy.x > start_xy.x:
- for i in range(start_xy.x + 1, new_xy.x, 1):
- var square = Global.xy_to_square(Vector2i(i, start_xy.y))
- if square.occupied:
- if square.guest.colour != colour:
- return true
- else:
- return false
- else:
- for i in range(new_xy.x - 1, start_xy.x, -1):
- var square = Global.xy_to_square(Vector2i(i, start_xy.y))
- if square.occupied:
- if square.guest.colour == colour:
- return false
- else:
- return true
- return true
- elif new_xy.x == start_xy.x:
- if new_xy.y > start_xy.y:
- for i in range(start_xy.y + 1, new_xy.y, 1):
- var square = Global.xy_to_square(Vector2i(start_xy.x, i))
- if square.occupied:
- if square.guest.colour != colour:
- return true
- else:
- return false
- else:
- for i in range(new_xy.y - 1, start_xy.y, -1):
- var square = Global.xy_to_square(Vector2i(start_xy.x, i))
- if square.occupied:
- if square.guest.colour == colour:
- return false
- else:
- return true
- return true
- else:
- return false
- ----
- # Global functions used above:
- func label_to_xy(label: String):
- var out: Vector2i
- var files = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6, "G": 7, "H": 8}
- var file = files[label[0]]
- var rank = int(label[1])
- out = Vector2i(file, rank)
- return out
- func xy_to_square(xy: Vector2i):
- var label = xy_to_label(xy)
- var square = label_squareobj[label]
- return square
- # The Squares class
- extends Node2D
- class_name squares
- signal broadcast(ID: Object, label: String, occupied: bool)
- @export var light: bool
- var label: String
- var occupied: bool
- var guest: Object
- var xy: Vector2i
- func _ready():
- $Sprite2D.scale = Vector2i(70,70)
- if light: $Sprite2D.self_modulate = Color(0.98, 0.647, 0.455)
- else: $Sprite2D.self_modulate = Color(0.321, 0.175, 0.029)
- var Label = Label.new()
- Label.text = label
- if light: Label.self_modulate.a = 0.9
- else: Label.self_modulate.a = 0.5
- Label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
- Label.vertical_alignment = VERTICAL_ALIGNMENT_BOTTOM
- Label.position.x += 10
- Label.position.y += 10
- add_child(Label)
- emit_signal("broadcast", self, label, null)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement