-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDirectionalGuard.cs
162 lines (132 loc) · 4.36 KB
/
DirectionalGuard.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
namespace Nitemare3D
{
public class DirectionalGuard : Entity, ISprite
{
public GuardType type;
byte angle; //8 possible angles;
public int spriteIndex {get; set;}
public Vec2 spritePosition{get;set;} = new Vec2();
public bool visible{get;set;} = true;
public float yOffset{get;set;}
Vec2 velocity = new Vec2();
Direction direction;
float speed = 1f;
public DirectionalGuard(GuardType type, Direction dir)
{
switch (type)
{
case GuardType.HumanGreen:
texOffset = 482;
break;
case GuardType.HumanBlue:
texOffset = 434;
break;
case GuardType.Witch:
break;
case GuardType.Robot:
break;
case GuardType.Penelope:
break;
case GuardType.DRHammerstein:
break;
}
this.direction = dir;
Game.player.AddSprite(this);
}
int texOffset;
GuardState state = GuardState.patrol;
/*
Nitemare 3D has certain tiles used to guide the patrol state of certain guards,
pretty clever I think
*/
Vec2 MoveInCompassDirection()
{
switch (direction)
{
case Direction.NorthWest:
return new Vec2(-1, -1);
case Direction.North:
return new Vec2(0, -1);
case Direction.NorthEast:
return new Vec2(1, -1);
case Direction.East:
return new Vec2(1, 0);
case Direction.SouthEast:
return new Vec2(1, 1);
case Direction.South:
return new Vec2(0, 1);
case Direction.SouthWest:
return new Vec2(-1, 1);
case Direction.West:
return new Vec2(-1, 0);
default:
return new Vec2();
}
}
void UpdatePatrol()
{
var x = MathF.Round(position.X);
var y = MathF.Round(position.Y);
var tile = Level.tilemap[(int)x, (int)y];
//never eat soggy waffles
switch(tile.type)
{
case WallType.turningpointN:
direction = Direction.North;
break;
case WallType.turningpointNE:
direction = Direction.NorthEast;
break;
case WallType.turningpointNW:
direction = Direction.NorthWest;
break;
case WallType.turningpointE:
direction = Direction.East;
break;
case WallType.turningpointS:
direction = Direction.South;
break;
case WallType.turningpointSE:
direction = Direction.SouthEast;
break;
case WallType.turningpointSW:
direction = Direction.SouthWest;
break;
case WallType.turningpointW:
direction = Direction.West;
break;
}
velocity = MoveInCompassDirection();
}
void UpdateGuard()
{
switch (state)
{
case GuardState.idle:
break;
case GuardState.chasing:
break;
case GuardState.attacking:
break;
case GuardState.dead:
break;
case GuardState.patrol:
UpdatePatrol();
break;
}
}
void HandleAnimation()
{
}
public override void Update()
{
//todo calculate direction from velocity
HandleAnimation();
UpdateGuard();
position += velocity * speed * Time.dt;
spritePosition = position;
spriteIndex = texOffset + (int)direction * 4;
}
}
}