Description:
Fix debouncing and only apply to certain keys.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -1,4 +1,5 | |||
|
1 | 1 | using System; |
|
2 | using System.Linq; | |
|
2 | 3 | using Microsoft.Xna.Framework; |
|
3 | 4 | using Microsoft.Xna.Framework.Graphics; |
|
4 | 5 | |
@@ -10,6 +11,7 | |||
|
10 | 11 | public Vector2 position; |
|
11 | 12 | |
|
12 | 13 | float _zoom; |
|
14 | float[] zoom_levels; | |
|
13 | 15 | |
|
14 | 16 | |
|
15 | 17 | public static int world_width { get; set; } |
@@ -29,6 +31,13 | |||
|
29 | 31 | position = Vector2.Zero; |
|
30 | 32 | } |
|
31 | 33 | |
|
34 | public Camera(float[] zoomLevels) | |
|
35 | { | |
|
36 | this.zoom = 1.0f; | |
|
37 | position = Vector2.Zero; | |
|
38 | this.zoom_levels = zoomLevels; | |
|
39 | } | |
|
40 | ||
|
32 | 41 | public void Move(Vector2 change) |
|
33 | 42 | { |
|
34 | 43 | this.position += change; |
@@ -56,5 +65,41 | |||
|
56 | 65 | { |
|
57 | 66 | return screenPosition + this.position - Camera.display_offset; |
|
58 | 67 | } |
|
68 | ||
|
69 | public float ZoomIn() | |
|
70 | { | |
|
71 | float next_level; | |
|
72 | ||
|
73 | foreach (float level in this.zoom_levels) | |
|
74 | { | |
|
75 | if(level > this.zoom) | |
|
76 | { | |
|
77 | next_level = level; | |
|
78 | this.zoom = next_level; | |
|
79 | return next_level; | |
|
80 | } | |
|
81 | } | |
|
82 | ||
|
83 | return this.zoom; | |
|
84 | ||
|
85 | } | |
|
86 | ||
|
87 | public float ZoomOut() | |
|
88 | { | |
|
89 | float next_level; | |
|
90 | ||
|
91 | foreach (float level in this.zoom_levels.Reverse()) | |
|
92 | { | |
|
93 | if (level < this.zoom) | |
|
94 | { | |
|
95 | next_level = level; | |
|
96 | this.zoom = next_level; | |
|
97 | return next_level; | |
|
98 | } | |
|
99 | } | |
|
100 | ||
|
101 | return this.zoom; | |
|
102 | ||
|
103 | } | |
|
59 | 104 | } |
|
60 | 105 | } |
@@ -23,7 +23,7 | |||
|
23 | 23 | private Song music; |
|
24 | 24 | private SpriteFont font; |
|
25 | 25 | |
|
26 | private Camera camera = new Camera(); | |
|
26 | private Camera camera = new Camera(new float[] {0.25f, 0.5f, 1.0f, 2.0f, 4.0f }); | |
|
27 | 27 | |
|
28 | 28 | Random random_generator = new Random(); |
|
29 | 29 | |
@@ -156,34 +156,33 | |||
|
156 | 156 | } |
|
157 | 157 | |
|
158 | 158 | |
|
159 |
if (keyboardCur.IsKeyDown(Keys.Down) |
|
|
159 | if (keyboardCur.IsKeyDown(Keys.Down) ) | |
|
160 | 160 | { |
|
161 | 161 | this.camera.Move(new Vector2(0, -2)); |
|
162 | 162 | } |
|
163 |
else if (keyboardCur.IsKeyDown(Keys.Up) |
|
|
163 | else if (keyboardCur.IsKeyDown(Keys.Up) ) | |
|
164 | 164 | { |
|
165 | 165 | this.camera.Move(new Vector2(0, 2)); |
|
166 | 166 | |
|
167 | 167 | } |
|
168 |
else if (keyboardCur.IsKeyDown(Keys.Left) |
|
|
168 | else if (keyboardCur.IsKeyDown(Keys.Left) ) | |
|
169 | 169 | { |
|
170 | 170 | this.camera.Move(new Vector2(-2, 0)); |
|
171 | 171 | |
|
172 | 172 | } |
|
173 |
else if (keyboardCur.IsKeyDown(Keys.Right) |
|
|
173 | else if (keyboardCur.IsKeyDown(Keys.Right) ) | |
|
174 | 174 | { |
|
175 | 175 | this.camera.Move(new Vector2(2, 0)); |
|
176 | 176 | |
|
177 | 177 | } |
|
178 | 178 | else if (keyboardCur.IsKeyDown(Keys.Subtract) && keyboardPrev.IsKeyUp(Keys.Subtract)) |
|
179 | 179 | { |
|
180 |
this.camera. |
|
|
181 | ||
|
180 | this.camera.ZoomOut(); | |
|
182 | 181 | } |
|
183 | 182 | else if (keyboardCur.IsKeyDown(Keys.Add) && keyboardPrev.IsKeyUp(Keys.Add)) |
|
184 | 183 | { |
|
185 | this.camera.zoom *= 1.25f; | |
|
186 | 184 | |
|
185 | this.camera.ZoomIn(); | |
|
187 | 186 | } |
|
188 | 187 | |
|
189 | 188 | |
@@ -232,6 +231,8 | |||
|
232 | 231 | frameCounter = 0; |
|
233 | 232 | } |
|
234 | 233 | |
|
234 | this.keyboardPrev = keyboardCur; | |
|
235 | ||
|
235 | 236 | base.Update(gameTime); |
|
236 | 237 | |
|
237 | 238 | |
@@ -364,8 +365,7 | |||
|
364 | 365 | drawTileAt(0, 0, 22, 1); |
|
365 | 366 | |
|
366 | 367 | |
|
367 | //Warning: creates a flashing effect because tree positions update every 1/60th of a second | |
|
368 | /* | |
|
368 | //* | |
|
369 | 369 | |
|
370 | 370 | |
|
371 | 371 | |
@@ -373,12 +373,19 | |||
|
373 | 373 | { |
|
374 | 374 | for (int j = 0; j < 50; j += 1) |
|
375 | 375 | { |
|
376 | //Warning: creates a flashing effect because tree positions update every 1/60th of a second | |
|
377 | ||
|
378 | /* | |
|
376 | 379 | if (this.random_generator.NextDouble() > 0.75) |
|
377 | 380 | { |
|
378 | 381 | drawTileAt(i, j, 142, 2); |
|
382 | }//*/ | |
|
383 | ||
|
384 | if ((i + j) % 3 == 0) | |
|
385 | { | |
|
386 | drawTileAt(i, j, 142, 2); | |
|
379 | 387 | } |
|
380 | ||
|
381 | ||
|
388 | ||
|
382 | 389 | } |
|
383 | 390 |
|
|
384 | 391 |
You need to be logged in to leave comments.
Login now