@@ -42,12 +42,12 @@ public double CalculateFPS()
42
42
}
43
43
44
44
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.
48
48
private void ArraySetup ( )
49
49
{
50
- for ( int i = 0 ; i < 5 ; i ++ )
50
+ for ( int i = 0 ; i < prevPos . Length ; i ++ )
51
51
{
52
52
prevPos [ i ] = gameObject . Position ;
53
53
curPosDif [ i ] . X = 0 ;
@@ -83,13 +83,7 @@ public void UpdatePositions(double framesPerSecond)
83
83
// Calculate avg of total differences between movement in array.
84
84
// Then move gameobject based on that to simulate velocity/physics.
85
85
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 ) ;
93
87
}
94
88
95
89
@@ -153,6 +147,7 @@ Point SumAvg(Point[] points)
153
147
}
154
148
155
149
150
+
156
151
/// <summary>
157
152
/// Apply physics forces on gameobject.
158
153
/// </summary>
@@ -197,24 +192,50 @@ private void ClampSpeed(Point prevPosition, float moveDistPerSecond)
197
192
// Render target image.
198
193
public void RenderActorFrame ( Graphics gfx )
199
194
{
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 ) ;
202
197
gameObject . Dimension . Width = img . Width ;
203
198
gameObject . Dimension . Height = img . Height ;
204
199
205
200
gfx . SmoothingMode = SmoothingMode . AntiAlias ;
206
201
gfx . CompositingQuality = CompositingQuality . HighQuality ;
202
+
203
+
207
204
gfx . DrawImage ( img , gameObject . Position . X , gameObject . Position . Y ) ;
208
205
}
209
206
210
- // Return current animation state name based on gameobject.
211
-
207
+
212
208
213
- void PlayAnimation ( int frameLength )
214
- {
209
+
210
+
211
+ string GetAnimState ( )
212
+ {
213
+ string [ ] animFrames = anims . Idle ;
214
+ Point velocity = SumAvg ( curPosDif ) ;
215
215
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 ] ;
216
235
}
217
236
237
+
238
+
218
239
219
240
// Return target image.
220
241
private Image FromFileImage ( string filePath )
0 commit comments