From ece682cacbb4300897239cd03cc427161788626e Mon Sep 17 00:00:00 2001 From: jake Date: Fri, 17 Feb 2023 14:37:23 -0500 Subject: Initial Commit --- Sprite.gd | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Sprite.gd (limited to 'Sprite.gd') diff --git a/Sprite.gd b/Sprite.gd new file mode 100644 index 0000000..61ccf06 --- /dev/null +++ b/Sprite.gd @@ -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() -- cgit v1.2.3