-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathCharacter.cs
65 lines (64 loc) · 1.92 KB
/
Character.cs
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
namespace Role_Playing_Game;
public class Character
{
public int Level { get; set; } = 1;
public int Experience { get; set; }
public int ExperienceToNextLevel { get; set; } = 10;
public int Health { get; set; } = 5;
public int MaxHealth => Level * 5;
public int Gold { get; set; }
public int Damage { get; set; } = 1;
// I & J represent the character's position in pixel coordinates
// relative to the current map
public int I { get; set; }
public int J { get; set; }
// TileI and TileJ represent the character's position in tile coordinates
// relative to the current map
public int TileI => I < 0 ? (I - 6) / 7 : I / 7;
public int TileJ => J < 0 ? (J - 3) / 4 : J / 4;
private string[]? _mapAnaimation;
public string[]? MapAnimation
{
get => _mapAnaimation;
set
{
_mapAnaimation = value;
_mapAnimationFrame = 0;
}
}
private int _mapAnimationFrame;
public int MapAnimationFrame
{
get => _mapAnimationFrame;
set
{
_mapAnimationFrame = value;
Moved = false;
if (_mapAnimationFrame >= MapAnimation!.Length)
{
if (MapAnimation == Sprites.RunUp) { Moved = true; MapAnimation = Sprites.IdleUp; }
if (MapAnimation == Sprites.RunDown) { Moved = true; MapAnimation = Sprites.IdleDown; }
if (MapAnimation == Sprites.RunLeft) { Moved = true; MapAnimation = Sprites.IdleLeft; }
if (MapAnimation == Sprites.RunRight) { Moved = true; MapAnimation = Sprites.IdleRight; }
_mapAnimationFrame = 0;
}
}
}
public bool IsIdle
{
get =>
_mapAnaimation == Sprites.IdleDown ||
_mapAnaimation == Sprites.IdleUp ||
_mapAnaimation == Sprites.IdleLeft ||
_mapAnaimation == Sprites.IdleRight;
}
public string Render =>
_mapAnaimation is not null && _mapAnimationFrame < _mapAnaimation.Length
? _mapAnaimation[_mapAnimationFrame]
: // "T" pose :D
@" __O__ " + '\n' +
@" | " + '\n' +
@" | " + '\n' +
@" | | ";
public bool Moved { get; set; } = false;
}