summaryrefslogtreecommitdiff
path: root/Sprite.gd
blob: 61ccf06717836793d43cec4b8e2d5f00f51f4161 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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()