Skip to content

Commit 4a63e37

Browse files
committed
Finished core features.
1 parent 047e8fe commit 4a63e37

20 files changed

+53
-87
lines changed

Anims.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

Desktop-Mascot/Desktop Actor/Animator.cs renamed to Desktop-Actor Code/Desktop Actor/Animator.cs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public double CalculateFPS()
4242
}
4343

4444
Point velocity; // Calculate velocity based on average distance per sec.
45-
int n = 0, d = 4; // Array overflows at length 5, d is n-1.
46-
Point[] prevPos = new Point[5]; // Save previous positions to get distance moved.
47-
Point[] curPosDif = new Point[5]; // Save distances between previous positions.
45+
int n = 0, d = 6; // Array overflows at length 5, d is n-1.
46+
Point[] prevPos = new Point[7]; // Save previous positions to get distance moved.
47+
Point[] curPosDif = new Point[7]; // Save distances between previous positions.
4848
private void ArraySetup()
4949
{
50-
for(int i = 0; i < 5; i++)
50+
for(int i = 0; i < prevPos.Length; i++)
5151
{
5252
prevPos[i] = gameObject.Position;
5353
curPosDif[i].X = 0;
@@ -83,13 +83,7 @@ public void UpdatePositions(double framesPerSecond)
8383
// Calculate avg of total differences between movement in array.
8484
// Then move gameobject based on that to simulate velocity/physics.
8585
velocity = SumAvg(curPosDif);
86-
PhysicsMovement(moveDistPerSecond);
87-
// Console.WriteLine("L"+anims.Carry_left);
88-
// --- DEBUG ---
89-
if (d == 4)
90-
{
91-
// Console.WriteLine("X::{0}, Y::{1}",velocity.X, velocity.Y);
92-
}
86+
PhysicsMovement(moveDistPerSecond);
9387
}
9488

9589

@@ -153,6 +147,7 @@ Point SumAvg(Point[] points)
153147
}
154148

155149

150+
156151
/// <summary>
157152
/// Apply physics forces on gameobject.
158153
/// </summary>
@@ -197,24 +192,50 @@ private void ClampSpeed(Point prevPosition, float moveDistPerSecond)
197192
// Render target image.
198193
public void RenderActorFrame(Graphics gfx)
199194
{
200-
201-
var img = FromFileImage("C:\\Users\\CautiousDev\\Pictures\\Game Dev\\Sprites\\Red Cloak\\use\\idle.gif");
195+
string path = Directory.GetCurrentDirectory() + "\\Data\\Frames\\"+ GetAnimState();
196+
var img = FromFileImage(path);
202197
gameObject.Dimension.Width = img.Width;
203198
gameObject.Dimension.Height = img.Height;
204199

205200
gfx.SmoothingMode = SmoothingMode.AntiAlias;
206201
gfx.CompositingQuality = CompositingQuality.HighQuality;
202+
203+
207204
gfx.DrawImage(img, gameObject.Position.X, gameObject.Position.Y);
208205
}
209206

210-
// Return current animation state name based on gameobject.
211-
207+
212208

213-
void PlayAnimation(int frameLength)
214-
{
209+
210+
211+
string GetAnimState()
212+
{
213+
string[] animFrames = anims.Idle;
214+
Point velocity = SumAvg(curPosDif);
215215

216+
if (velocity.Y < 0) // UP
217+
{
218+
animFrames = anims.Idle;
219+
}
220+
else if (velocity.Y > 0) // Down.
221+
{
222+
animFrames = anims.Air_vertical;
223+
}
224+
225+
if (velocity.X < 0) // Left.
226+
{
227+
animFrames = anims.Carry_left;
228+
}
229+
else if (velocity.X > 0) // Right.
230+
{
231+
animFrames = anims.Carry_right;
232+
}
233+
234+
return animFrames[0];
216235
}
217236

237+
238+
218239

219240
// Return target image.
220241
private Image FromFileImage(string filePath)

0 commit comments

Comments
 (0)