-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjuhuligan.html
More file actions
498 lines (449 loc) · 20.2 KB
/
juhuligan.html
File metadata and controls
498 lines (449 loc) · 20.2 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Juhuligan | Priyank Jain </title>
<script src="https://use.fontawesome.com/21d3028b6a.js"></script>
<link href="https://fonts.googleapis.com/css?family=Arvo:400,700" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,300,600,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="resources/css/normalize.min.css">
<link rel="stylesheet" href="resources/css/base.css">
<link rel="stylesheet" href="resources/css/layout.css">
<link rel="stylesheet" href="resources/css/skeleton.css">
<link rel="stylesheet" href="resources/css/screen.css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body>
<header>
<div class="container">
<div class="navigation-inner clearfix">
<div class="seven columns">
<a href="index.html">
<div id="name"> Priyank Jain </div>
<div id="title"> Bringing Ideas to life </div>
</a>
</div>
<div class="nine columns">
<ul class="menu primary-menu clearfix">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
</ul>
</div>
</div>
</div>
</header>
<div class="container">
<div class="page clearfix">
<div class="sixteen columns">
<h2> Juhuligan </h2>
<!-- <img class="cover-photo" src="resources/imgs/wordsAway/wordsAway.png"> -->
</div>
<div class="eight columns">
<p> Juhuligan is my first big game where my objective was to get a better understanding of how the game-elements work together, especially from a programmer's perspective. Being a side-scroller, there are a lot of different type of game entities interacting in their own ways. Thus, as my previous games have done, this game had exposed me to all sorts of challenges, and now, I have a much better understanding of game programming. Also, I learnt about some of the bad programming practises, the hard way! </p>
</div>
<div class="six columns">
<iframe src="https://player.vimeo.com/video/10739073?portrait=0" width="100%" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
<div class="twelve columns">
<p>
I have broken down my journey in these parts:
</p>
<ul>
<li><a href="#Programming_challenges" rel="me">
Programming Challenges</a></li>
<li><a rel="me" href="#Lessons_Learnt">Lessons Learnt</a></li>
<li><a href="#Reusable_Components" rel="tag">Reusable components as a byproduct of this game</a></li>
</ul>
<hr>
<p><a name="Programming_challenges"></a>Programming
challenges:<br>
When I started out making this game, I just wanted to improve my game
programming skills. I wanted to understand things better than what I
already did. Without a vision, I decided that the game would be
something between mario and contra. This was my biggest flaw! (<a href="#Lessons_Learnt">Lessons
Learnt(LL) #1</a>). I'll walk you through my development journey.
</p><a href="#Phase_I">
Phase 1</a>:
Objectives:
<ol type="a">
<li>Draw World from data</li>
<li>Character can move around and jump, perfecting the collision</li>
</ol><a href="#Phase_2">
Phase 2</a>:
Objectives:
<ol type="a">
<li>Side-scrolling screen</li>
<li>Enemy player and different types of AI enemies</li>
</ol><a href="#Phase_3">
Phase 3</a>:
Objectives:
<ol type="a">
<li>Player has a gun and can shoot anywhere</li>
<li>Player-Enemy has health & bullet damage in effect</li>
</ol><a href="#Phase_4">
Phase 4:</a>
Objectives:
<ol type="a">
<li>Player can do powerups: Ammo pack/ Health Pack/ Shield</li>
<li> Player has Lives and Checkpoint system </li>
<li> Everyone
needs a HUD</li>
</ol><a href="#Phase_5">
Phase 5</a>:
Objectives:
<ol type="a">
<li> Game State Management</li>
<li> Sound effects</li>
<li> Critique</li>
</ol>
<div class="Top"><a href="#Top" rel="me">Top</a> <br> <br> <hr>
</div>
<hr><strong><a name="Phase_I"></a>Phase I</strong>
<ol type="a">
<li> Draw World from data: <br>
<p> I recently came to know what I was doing here is data
driven programming. I populate a world array with a tile number which
represents which tile to draw from the world tilesheet. At this stage,
I just populated the array manually. </p>
</li>
<li>Character movement:
<p>This was my first hurdle. I would say that this was my
biggest hurdle for I tried myriad approaches and it was unsolved for a
long long time (<a href="#Lessons_Learnt">LL #2</a>). But, now I know
the problem with all the
approaches that I tried, and it feels good to know them! The solution
that finally worked for me was what I had thought at the beginning.(<a href="#Lessons_Learnt">LL
#3</a>) This is what I used in the end: <br>
<img style="border: 1px solid ; width: 400px; height: 300px;" alt="Collision resolution" src="resources/imgs/juhuligan/collision.png" hspace="2" vspace="10">
<br>To check for collision, we need the following: </p>
<ul type="circle">
<li>Starting Position to be checked (collPos)</li>
<li>Size or Area which needs to be queried for collision
(collSize)</li>
<li>Direction in which the entity is required to move
(direction)</li>
<li>Final Position: what would be its final position in
either case Collision/not (newpos)</li>
<li> Returns true if a collision takes place, else returns
false</li>
<li>private bool Collide(Vector2 collPos, Vector2 collSize,
Direction direction, out float newpos)</li>
<ul>
<li>We then iterate from minX, minY to maxX,maxY;
checking if there is a tile at either of these locations.</li>
<li> If there is a collision: return true and set newPos
to the last x or y depending on "direction".</li>
<li>Else; set newPos to the extreme X/Y accordingly and
return false.</li>
</ul>
This method is wrapped in another function called Move <br>
<li>protected virtual Direction Move()</li>
<ul>
<li>It assumes that the velocity of the object is setup
already and takes that into account to determine if it Collides with
anything in the world. </li>
<li>Either ways, it moves the object by newPos along X/Y
depending on the velocity.</li>
<li>If there is a collision, it is indicated by the
Direction flag which is returned by the function. Direction is a
hexadecimal value from 0,1,2,4,8 indicating None, Up, Right, Down, Left.</li>
</ul>
</ul>
</li>
</ol>
<a href="#Top" rel="me">Top</a> <br> <br> <hr>
<strong><a name="Phase_2"></a>Phase 2:</strong>
<ol type="a">
<li>Side-scrolling screen
<p>This was my second biggest hurdle. And it was hard to go
on with one big problem followed by another equally painful problem,
especially after all the head-banging for the character's movement.</p>
<p>Side-scrolling was not hard to do. I got it going
relatively easily. What was hard to do was smooth side scrolling. The
way I coded earlier, it used to move one tile per scrolling. This just
dint cut through, since I had a some people try it and all of them
complaint of this one thing. Thus, I needed a way to make it smooth.
After some crazy nights, I ended up using the concept of World space
and Screen space, something that I had just learnt in my graphics class
at school. I had to implement these two functions to transform anything
from World to Screen space or vice versa, & voila, it worked! I
had everything happening in the world space. Whatever entity needed to
draw itself, it would call upon WorldToScreen(Position) to draw in the
Screen space. The code snippet: </p>
<ul>
<li> <code> <strong>public Vector2
WorldToScreen(Vector2 worldPosn)</strong> { Vector2 screenPosn =
Vector2.Zero; screenPosn.X = worldPosn.X - viewPort.X; screenPosn.X *=
Constants.TileWidth; screenPosn.Y = worldPosn.Y - viewPort.Y;
screenPosn.Y *= Constants.TileHeight; return screenPosn; } </code>
</li>
<li> <strong>public Vector2 ScreenToWorld(Vector2
screenPosn)</strong> { Vector2 worldPosn = Vector2.Zero;
screenPosn.X /= Constants.TileWidth; worldPosn.X = viewPort.X +
screenPosn.X; screenPosn.Y /= Constants.TileHeight; worldPosn.Y =
viewPort.Y + screenPosn.Y; return worldPosn; }</li>
</ul>
</li>
<li>Enemies
<ol type="i">
<li>Enemy player
<p> This part of the code really was not too hard to do,
especially with all the ground work done. Though, this required to put
my OO skills to test. It finally led me to develop, what I call as,
<a href="#MoM_Architecture">Manager of Manager (MoM) architecture</a>.
I used EnemyManager and the
minions as the enemies themselves.</p>
<img style="border: 0px solid ; width: 427px; height: 197px;" alt="Enemy Mgr and Enemy Relation" src="resources/imgs/juhuligan/UML_Enemy-Mgr.png" vspace="10"><br>
<br></li>
<li> Different types of AI enemies
<p> Also, I wanted to make it efficient, so that I dont
update/draw enemies that are not anywhere even near the player. (It
made no sense to update/draw an enemy that is to be found at the end of
the level, when the player is on the first screen). Thus, I had a bool
'active' flag which denoted when to activate/deactivate enemy (using
ActivateEnemies()). Only active enemies were updated/drawn. For
different types of enemies, I first identified the enemy behaviours and
used simple 1 level of inheritance. </p>
<br>
<img style="width: 713px; height: 443px;" alt="Enemy Hierarchy" src="resources/imgs/juhuligan/UML_Enemy_Hierarchy.png" vspace="10">
<br>
The generic enemy class made it
very easy to add any other type of enemy. I just had to override update
for the specific behavior. </li>
</ol>
</li>
</ol>
<a href="#Top" rel="me">Top</a> <br> <br> <hr>
<strong><a name="Phase_3"></a>Phase 3:</strong>
<ol>
<li>Player has a gun and can shoot anywhere
<p>My weapon class had two
variants of update function: one for its parent ResourceManager and the
other for player. Nothing much to say here, since it conforms to the
<a href="#MoM_Architecture">MoM architecture</a>. Also, Weapon Class
takes care of the input mouse
click and pointing the bullets in the right direction.
One thing to note here is, both the enemies and player use the same
bullet class. For different trajectories of the bullet, they are
identified using enumerator. Since, the distinction between different
bullets' trajectory is more data oriented, thus I chose not to go in
for inheritance.
I would also like to mention about my approach to getting the curved
trajectory for bullets. I did not use sin and cosine functions!! When I
started writing code for this, I realized I was making too many calls
to sine and cosine. With these being called every frame, I just couldnt
go ahead with it. My first trajectory that I had to try out was a sine
curve for the Frogger.
</p>
<img style="width: 634px; height: 336px;" alt="Approximate bullet Sine curve" src="resources/imgs/juhuligan/SineBullet.png"><br>
<br>
I realised if I increase/decrease the Y with X always increasing, it
would work for me!! I played around with some variables for some time
and voila, it works beautifully. All I had to do was:
if (velocity.Y > 0.4f) signY = -1;
else if (velocity.Y < -0.4f) signY = 1;
velocity.Y += (signY * 0.025f);
<p> Here, as soon as I hit the
threshold of 0.4 as height, I reverse the direction of Y and update the
velocity accordingly. Its a simple, yet a very effective solution to my
problem of calling sine to calculate the final velocity.
The other type of trajectory was the boomerang type. I was not shooting
for a perfect circular trajectory, but an approximate elliptical
trajectory. Again, I decided to use the rate of change of X with
respect to Y. It took me some time to get the proportions right,
otherwise, if X and Y are not changing in the right proportions; the
final trajectory would go haywire and I had all sorts of wierd(yet
beautiful :-) ) paths!
<br>
<img style="border: 1px solid ; width: 800px; height: 500px;" alt="Approximate boomerang trajectory" src="resources/imgs/juhuligan/boomerang.png" vspace="10"><br>
After a while, I thought I'll try to write generic equations in terms
of X and Y to yield me the curve that I wanted. After spending a lot of
time and reading around, I was enlightened to read about Bezier curves.
This is exactly what I was trying to invent! I was doing the same thing
as the equation did, but I was working on the data. Anyways, I feel
really proud of discovering<a href="#Bezier_Curve_Library"> Bezier
curves </a>the way I did. </p>
</li>
<li> Player-Enemy has health & bullet damage in effect
<p> With all the code around, this was fairly easy to do. I
had a OO design
issue when I was dealing with this. This part of the code really
puzzled me for some time since it wanted me to tightly couple the enemy
and player together. I finally ended up putting all the enemy and their
bullet interaction with the player in the EnemyManager class. I realize
this is a really bad way to do things but I look forward to improving
my OO skills to get around this. I needed some arbitrator to resolve
the outcome of collisions.
</p>
</li>
</ol>
<a href="#Top" rel="me">Top</a> <br> <br> <hr>
<strong><a name="Phase_4"></a>Phase 4:</strong>
<ol>
<li> Player can do powerups: Ammo pack/ Health Pack/ Armor
<p>This was implemented as yet another <a href="#MoM_Architecture">MoM architecture</a>. This
suffers from tight coupling between the player and ResourceManager.
Here, I implemented a <a href="#Timer_functionality">timer functionality</a> with multiple modes which
allowed resources to be spawned in places only for a specific time
duration. This was again based on the trigger set in the world.
</p>
</li>
<li> Player has Lives and Checkpoint system
<p>Influenced by mario, 100 coins yield a life to the player.
Also, there are checkpoints embedded within the world. If a player
crosses a certain checkpoint and dies after that, the player is
re-spawned at the last checkpoint he crossed. Also, this strips the
player of any weapon/ammo he was carrying on him.
</p>
</li>
<li> Everyone needs a HUD </li>
<p>
I wanted to make HUD more interesting than the usual HUD we have. I
also wanted to keep it simple, else it would be too much for the player
to handle. For one thing in particular, I needed a way to represent the
player's health. After trying out different ideas, this one thing stuck
with me. I finally decided to have a face which would give an idea of
Player's health. Now, my concern was; the face expression would have to
be changing dynamically, as the player takes a hit or a health pack. I
pin-pointed the eye-brows and smiley feat to give the player an idea of
its mood! My knowledge of <a href="#Bezier_Curve_Library">Bezier curves</a> really came in handy here and
thus came about; my own generic <a href="#Bezier_Curve_Library">Bezier curve library</a> functions. To
these functions, I simply provided the weighted points and it would
return a list of points along the curve:
</p>
<ul>
<li>public static List <Vector2>
Quadratic(Vector2
p0, Vector2 p1,Vector2 p2) </li>
<li>public static List < Vector2>
Linear(Vector2 p0,
Vector2 p1) </li>
</ul>
</ol><img style="width: 210px; height: 200px;" alt="HUD using bezier curves" src="resources/imgs/juhuligan/HUD.png" align="left" hspace="5">Red Dots are the weight points for smiley<br>
All of these update dynamically based on the health of the player<br>
<ol>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
I now intend to write a generic function where the degree of the curve
can be specified and requisite points.<br>
</ol>
<a href="#Top" rel="me">Top</a> <br> <br> <hr>
<strong><a name="Phase_5"></a>Phase 5:</strong>
<ol>
<li> Game State Management
<p>Having used Microsoft's Game State Management, I just had
a strong urge to write my own. I also wanted to learn to write my own
state/menu manager. I tried to search something useful, but all that I
came across was the State Design Pattern. Well, this is what I used to
make my own! It basically breaks down into two parts:
</p>
<ul>
<li>Game States: Introduction/Menu Display/Game End</li>
<li>GamePlayer state: Gameplay/Pause/Win or Loss state</li>
</ul>
I used a combination of List and Stacks to manipulate/draw different
states.
</li>
<li> Sound effects
<p>A <a href="#Sound_utility">generic sound component</a> in sync with XACT came in real
handy. This component takes care of running background song and sound
effects during the game.
</p>
</li>
<li> Critique
<p>Throughout the course of the game, I often asked my
friends for feedback about the feats which has helped me to improve them.
</p>
</li>
</ol>
<a href="#Top" rel="me">Top</a> <br> <br> <hr>
<strong><a name="Lessons_Learnt"></a>Lessons
Learnt:</strong>
<ol>
<li>
<p>Have a game design and translate that design to technical
design wherein, we translate each requirement to a programming module.
DO NOT WORK THE OTHER WAY ROUND. I just ended up spending more time
developing each feature, since I had not frozen my goal beforehand. I
ended up perfectly programming all the gameplay elements without a
game! </p>
</li>
<li>
<p>Do not move on till a high priority bug is solved. It
becomes impossible to debug multiple issues at the same time and might
lead to restart from scratch. Also, it results into massive hair loss! </p>
</li>
<li>
<p>Formulate the problem and solution on paper first. I had
all the steps written down for a given solution, but I dint write them
elaborately which made all the difference. Be convinced that the
solution works and then move on. </p>
</li>
</ol>
<a href="#Top" rel="me">Top</a> <br> <br> <hr>
<strong><a name="Reusable_Components"></a>Reusable
Components from this game </strong>
<ul>
<li><strong><a name="MoM_Architecture"></a>
Manager of Manager (MoM) software architecture</strong>:
<p> In this setup, I have a manager whose objective is to
keep a track of its minion or constituent workers. It allows new
entities to be added/deleted. Also, it takes care of
initializing/loading/updating/drawing the minions. I often use List<t>
as the data structure since objects keep adding/deleting thereby making
the size required to be dynamic. This architecture forces minions to
return an enum UpdateAction on invoking Update() method; to indicate if
the given object needs to be removed from the manager. Also, with my
newly found knowledge, I think this closely follows the Observer Design
Pattern (but I was not aware of this when I wrote this game :( ).
</t></p>
</li>
<li><a name="Bezier_Curve_Library"></a>
Bezier Curve Library
</li>
<li><a name="Timer_functionality"></a>
Timer functionality
</li>
<li><a name="Sound_utility"></a>
Sound utility</li>
</ul>
</div>
</div> <!-- page clearfix -->
</div>
<footer>
<div class="container">
<div class="footer-inner">
<div class="icons">
<span class="icon"> <a href="https://twitter.com/brainydexter"> <i class="fa fa-twitter"></i> </a> </span>
<span class="icon"> <a href="https://www.linkedin.com/in/brainydexter"> <i class="fa fa-linkedin"></i> </a></span>
<span class="icon"> <a href="https://github.com/brainydexter"> <i class="fa fa-github"></i> </a></span>
<span class="icon"> <a href="mailto:fly2priyank@gmail.com"> <i class="fa fa-envelope"></i> </a></span>
</div>
<div class="copyright">© Priyank Jain</div>
</div>
</div>
</footer>
<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=5744193;
var sc_invisible=1;
var sc_security="6e56ab81";
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
document.write("<sc"+"ript type='text/javascript' src='" +
scJsHost+
"statcounter.com/counter/counter.js'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="shopify stats"
href="http://statcounter.com/shopify/" target="_blank"><img
class="statcounter"
src="//c.statcounter.com/5744193/0/6e56ab81/1/" alt="shopify
stats"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->
</body>
</html>