Description:
Refactor and cleanup.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,47 | |||||
|
|
1 | using System; | ||
|
|
2 | namespace isometricparkfna | ||
|
|
3 | { | ||
|
|
4 | public class MathUtils | ||
|
|
5 | { | ||
|
|
6 | public MathUtils() | ||
|
|
7 | { | ||
|
|
8 | } | ||
|
|
9 | |||
|
|
10 | public static bool Between(float val, float x, float y) | ||
|
|
11 | { | ||
|
|
12 | return ((x < val && val < y) || (y < val && val < x)); | ||
|
|
13 | |||
|
|
14 | } | ||
|
|
15 | |||
|
|
16 | public static bool Between(int val, int x, int y) | ||
|
|
17 | { | ||
|
|
18 | return ((x < val && val < y) || (y < val && val < x)); | ||
|
|
19 | |||
|
|
20 | } | ||
|
|
21 | |||
|
|
22 | protected float Decrement(float value, float delta) | ||
|
|
23 | { | ||
|
|
24 | float magnitude = Math.Abs(value); | ||
|
|
25 | |||
|
|
26 | //If distance from zero is less than our delta, | ||
|
|
27 | //go to zero to prevent overshooting: | ||
|
|
28 | if (magnitude < delta) | ||
|
|
29 | { | ||
|
|
30 | return 0.0f; | ||
|
|
31 | } | ||
|
|
32 | else if (value > 0) | ||
|
|
33 | { | ||
|
|
34 | return value - delta; | ||
|
|
35 | } | ||
|
|
36 | else if (value < 0) | ||
|
|
37 | { | ||
|
|
38 | return value + delta; | ||
|
|
39 | } | ||
|
|
40 | else | ||
|
|
41 | { | ||
|
|
42 | return 0.0f; | ||
|
|
43 | } | ||
|
|
44 | } | ||
|
|
45 | |||
|
|
46 | } | ||
|
|
47 | } |
@@ -11,45 +11,6 | |||||
|
11 | using System.Diagnostics; |
|
11 | using System.Diagnostics; |
|
12 |
|
12 | ||
|
13 |
|
13 | ||
|
14 | struct Entity |
|
||
|
15 | { |
|
||
|
16 | public Vector2 loc; |
|
||
|
17 | public Vector2 velocity; |
|
||
|
18 |
|
|||
|
19 | private Rectangle _boundingBox; |
|
||
|
20 |
|
|||
|
21 | public Rectangle BoundingBox |
|
||
|
22 | { |
|
||
|
23 |
|
|||
|
24 | get |
|
||
|
25 | { |
|
||
|
26 | Rectangle calculatedRectangle = _boundingBox; |
|
||
|
27 | calculatedRectangle.Location += new Point((int)loc.X, (int)loc.Y); |
|
||
|
28 | return calculatedRectangle; |
|
||
|
29 | } |
|
||
|
30 | set { _boundingBox = value; } |
|
||
|
31 | } |
|
||
|
32 |
|
|||
|
33 | public Entity(Vector2 loc, Vector2 velocity) |
|
||
|
34 | { |
|
||
|
35 | this.loc = loc; |
|
||
|
36 | this.velocity = velocity; |
|
||
|
37 | this._boundingBox = Rectangle.Empty; |
|
||
|
38 | } |
|
||
|
39 |
|
|||
|
40 | public Entity(Vector2 loc, Vector2 velocity, Rectangle boundingBox) |
|
||
|
41 | { |
|
||
|
42 | this.loc = loc; |
|
||
|
43 | this.velocity = velocity; |
|
||
|
44 | this._boundingBox = boundingBox; |
|
||
|
45 | } |
|
||
|
46 | } |
|
||
|
47 |
|
|||
|
48 | //static class Camera |
|
||
|
49 | //{ |
|
||
|
50 | // static public Vector2 Location = Vector2.Zero; |
|
||
|
51 | //} |
|
||
|
52 |
|
|||
|
53 | class FNAGame : Game |
|
14 | class FNAGame : Game |
|
54 | { |
|
15 | { |
|
55 | private KeyboardState keyboardPrev = new KeyboardState(); |
|
16 | private KeyboardState keyboardPrev = new KeyboardState(); |
@@ -75,14 +36,6 | |||||
|
75 | private const int height = 640; |
|
36 | private const int height = 640; |
|
76 |
|
37 | ||
|
77 |
|
38 | ||
|
78 | private Entity paddleEntity = new Entity(Vector2.Zero, Vector2.Zero, |
|
||
|
79 | new Rectangle(36, 0, 20, 100)); |
|
||
|
80 | private Entity ballEntity = new Entity(new Vector2(height, 360), |
|
||
|
81 | new Vector2(2.0f, 2.0f), |
|
||
|
82 | new Rectangle(36, 36, 20, 20)); |
|
||
|
83 | private Entity aiPaddleEntity = new Entity(new Vector2(width - 100, 0), Vector2.Zero, |
|
||
|
84 | new Rectangle(36, 0, 20, 100)); |
|
||
|
85 |
|
|||
|
86 | private const float friction = 0.1f; |
|
39 | private const float friction = 0.1f; |
|
87 | private const float inputVelocityDelta = friction + 0.1f; |
|
40 | private const float inputVelocityDelta = friction + 0.1f; |
|
88 |
|
41 | ||
@@ -106,50 +59,6 | |||||
|
106 | g.Run(); |
|
59 | g.Run(); |
|
107 | } |
|
60 | } |
|
108 |
|
61 | ||
|
109 | public static bool Between(float val, float x, float y) |
|
||
|
110 | { |
|
||
|
111 | return ((x < val && val < y) || (y < val && val < x)); |
|
||
|
112 |
|
|||
|
113 | } |
|
||
|
114 |
|
|||
|
115 | public Entity Move(ref Entity orig, bool score) |
|
||
|
116 | { |
|
||
|
117 | orig.loc += orig.velocity; |
|
||
|
118 |
|
|||
|
119 | if (orig.loc.Y <= 0 && orig.velocity.Y < 0) |
|
||
|
120 | { |
|
||
|
121 | orig.velocity.Y *= -1; |
|
||
|
122 | orig.loc.Y = 0; |
|
||
|
123 | } |
|
||
|
124 | else if (orig.loc.Y >= (height) && orig.velocity.Y > 0) |
|
||
|
125 | { |
|
||
|
126 | orig.velocity.Y *= -1; |
|
||
|
127 | orig.loc.Y = (720 - 100); |
|
||
|
128 | } |
|
||
|
129 |
|
|||
|
130 | if (orig.loc.X <= 0 && orig.velocity.X < 0) |
|
||
|
131 | { |
|
||
|
132 | orig.velocity.X *= -1; |
|
||
|
133 | orig.loc.X = 0; |
|
||
|
134 |
|
|||
|
135 | if (score) |
|
||
|
136 | { |
|
||
|
137 | playerScore += 1; |
|
||
|
138 | } |
|
||
|
139 | } |
|
||
|
140 | else if (orig.loc.X >= width && orig.velocity.X > 0) |
|
||
|
141 | { |
|
||
|
142 | orig.velocity.X *= -1; |
|
||
|
143 | orig.loc.X = width; |
|
||
|
144 |
|
|||
|
145 | if (score) |
|
||
|
146 | { |
|
||
|
147 | aiScore += 1; |
|
||
|
148 | } |
|
||
|
149 | } |
|
||
|
150 |
|
|||
|
151 | return orig; |
|
||
|
152 | } |
|
||
|
153 |
|
62 | ||
|
154 |
|
63 | ||
|
155 |
|
64 | ||
@@ -230,29 +139,6 | |||||
|
230 | } |
|
139 | } |
|
231 |
|
140 | ||
|
232 |
|
141 | ||
|
233 | protected float Decrement(float value, float delta) |
|
||
|
234 | { |
|
||
|
235 | float magnitude = Math.Abs(value); |
|
||
|
236 |
|
|||
|
237 | //If distance from zero is less than our delta, |
|
||
|
238 | //go to zero to prevent overshooting: |
|
||
|
239 | if (magnitude < delta) |
|
||
|
240 | { |
|
||
|
241 | return 0.0f; |
|
||
|
242 | } |
|
||
|
243 | else if (value > 0) |
|
||
|
244 | { |
|
||
|
245 | return value - delta; |
|
||
|
246 | } |
|
||
|
247 | else if (value < 0) |
|
||
|
248 | { |
|
||
|
249 | return value + delta; |
|
||
|
250 | } |
|
||
|
251 | else |
|
||
|
252 | { |
|
||
|
253 | return 0.0f; |
|
||
|
254 | } |
|
||
|
255 | } |
|
||
|
256 |
|
142 | ||
|
257 | protected override void Update(GameTime gameTime) |
|
143 | protected override void Update(GameTime gameTime) |
|
258 | { |
|
144 | { |
@@ -291,12 +177,12 | |||||
|
291 | } |
|
177 | } |
|
292 | else if (keyboardCur.IsKeyDown(Keys.Subtract) && keyboardPrev.IsKeyUp(Keys.Subtract)) |
|
178 | else if (keyboardCur.IsKeyDown(Keys.Subtract) && keyboardPrev.IsKeyUp(Keys.Subtract)) |
|
293 | { |
|
179 | { |
|
294 |
this.camera.zoom |
|
180 | this.camera.zoom *= 0.75f; |
|
295 |
|
181 | ||
|
296 | } |
|
182 | } |
|
297 | else if (keyboardCur.IsKeyDown(Keys.Add) && keyboardPrev.IsKeyUp(Keys.Add)) |
|
183 | else if (keyboardCur.IsKeyDown(Keys.Add) && keyboardPrev.IsKeyUp(Keys.Add)) |
|
298 | { |
|
184 | { |
|
299 |
this.camera.zoom |
|
185 | this.camera.zoom *= 1.25f; |
|
300 |
|
186 | ||
|
301 | } |
|
187 | } |
|
302 |
|
188 | ||
@@ -319,21 +205,20 | |||||
|
319 |
|
205 | ||
|
320 | MouseState mouseCur = Mouse.GetState(); |
|
206 | MouseState mouseCur = Mouse.GetState(); |
|
321 |
|
207 | ||
|
322 | if ((mouseCur.X < 50) && (mouseCur.X > 0)) |
|
208 | if (MathUtils.Between(mouseCur.X, 0, 50)) |
|
323 |
|
|||
|
324 | { |
|
209 | { |
|
325 | this.camera.Move(new Vector2(-4, 0)); |
|
210 | this.camera.Move(new Vector2(-4, 0)); |
|
326 | } |
|
211 | } |
|
327 |
else if ((mouseCur.X |
|
212 | else if (MathUtils.Between(mouseCur.X, (FNAGame.width - 50), FNAGame.width)) |
|
328 | { |
|
213 | { |
|
329 | this.camera.Move(new Vector2(4, 0)); |
|
214 | this.camera.Move(new Vector2(4, 0)); |
|
330 | } |
|
215 | } |
|
331 |
|
216 | ||
|
332 | if ((mouseCur.Y < 50) && (mouseCur.Y > 0)) |
|
217 | if (MathUtils.Between(mouseCur.Y, 0, 50)) |
|
333 | { |
|
218 | { |
|
334 | this.camera.Move(new Vector2(0, -4)); |
|
219 | this.camera.Move(new Vector2(0, -4)); |
|
335 | } |
|
220 | } |
|
336 |
else if ((mouseCur.Y |
|
221 | else if (MathUtils.Between(mouseCur.Y , (FNAGame.height - 50), FNAGame.height)) |
|
337 | { |
|
222 | { |
|
338 | this.camera.Move(new Vector2(0, 4)); |
|
223 | this.camera.Move(new Vector2(0, 4)); |
|
339 | } |
|
224 | } |
@@ -347,9 +232,6 | |||||
|
347 | frameCounter = 0; |
|
232 | frameCounter = 0; |
|
348 | } |
|
233 | } |
|
349 |
|
234 | ||
|
350 |
|
|||
|
351 |
|
|||
|
352 |
|
|||
|
353 | base.Update(gameTime); |
|
235 | base.Update(gameTime); |
|
354 |
|
236 | ||
|
355 |
|
237 | ||
@@ -515,7 +397,6 | |||||
|
515 | batch.DrawString(font, this.drawTime.TotalMilliseconds.ToString(), new Vector2(120, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); |
|
397 | batch.DrawString(font, this.drawTime.TotalMilliseconds.ToString(), new Vector2(120, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); |
|
516 | batch.DrawString(font, this.drawTime.TotalMilliseconds.ToString(), new Vector2(119, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); |
|
398 | batch.DrawString(font, this.drawTime.TotalMilliseconds.ToString(), new Vector2(119, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); |
|
517 |
|
399 | ||
|
518 |
|
|||
|
519 | batch.DrawString(font, camera.position.ToString(), new Vector2(190, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); |
|
400 | batch.DrawString(font, camera.position.ToString(), new Vector2(190, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); |
|
520 | batch.DrawString(font, camera.position.ToString(), new Vector2(189, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); |
|
401 | batch.DrawString(font, camera.position.ToString(), new Vector2(189, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); |
|
521 |
|
402 |
@@ -33,6 +33,7 | |||||
|
33 | <Compile Include="TileMap.cs" /> |
|
33 | <Compile Include="TileMap.cs" /> |
|
34 | <Compile Include="Line.cs" /> |
|
34 | <Compile Include="Line.cs" /> |
|
35 | <Compile Include="Camera.cs" /> |
|
35 | <Compile Include="Camera.cs" /> |
|
|
36 | <Compile Include="MathUtils.cs" /> | ||
|
36 | </ItemGroup> |
|
37 | </ItemGroup> |
|
37 | <ItemGroup> |
|
38 | <ItemGroup> |
|
38 | <ProjectReference Include="..\FNA\FNA.csproj"> |
|
39 | <ProjectReference Include="..\FNA\FNA.csproj"> |
You need to be logged in to leave comments.
Login now