-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cs
More file actions
85 lines (67 loc) · 2 KB
/
Player.cs
File metadata and controls
85 lines (67 loc) · 2 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Godot;
public partial class Player : Node2D
{
public Team_Enum id { get; private set; }
public IPiece selected_piece;
Timer clock;
Label clock_label;
Node2D capture_list_node;
bool ignore_clock;
public IPiece checkmate_target;
public void Setup(Team_Enum player_id, int clock_length)
{
id = player_id;
clock = (Timer)GetNode("Clock");
clock_label = (Label)GetNode("Clock_Label");
if (clock_length == 0)
{
ignore_clock = true;
clock_label.Visible = false;
}
else
{
ignore_clock = false;
}
clock.WaitTime = clock_length;
capture_list_node = (Node2D)GetNode("Capture_List");
if (!ignore_clock)
{
clock.Start();
clock.Paused = true;
}
Game game = (Game)GetParent();
clock.Timeout += () => game.Checkmate(this, "timeout");
}
public override void _Process(double delta)
{
base._Process(delta);
clock_label.Text = String.Format("{0:D2}:{1:D2}", (int)(clock.TimeLeft / 60), (int)clock.TimeLeft % 60);
}
public void Record_Capture(IPiece new_capture)
{
Sprite2D new_sprite = new Sprite2D();
new_sprite.Texture = GD.Load<Texture2D>($"res://assets/{new_capture.GetType()}_{(1 - this.id).ToString()}.png");
new_sprite.ApplyScale(new Vector2((float)0.25, (float)0.25));
new_sprite.Position += new Vector2(capture_list_node.GetChildren().Count * 32,0);
capture_list_node.AddChild(new_sprite);
}
public void Toggle_Clock()
{
if (!ignore_clock)
{
clock.Paused = !clock.Paused;
}
}
public void Add_Time(int bonus_time)
{
if (!ignore_clock)
{
clock.Start(clock.TimeLeft + bonus_time);
}
}
}