As I hope you’ve seen in my previous post, I participated in the MIX 10K Challenge (see here for the entry). HitEmUp features a classic idea, hitting enemies with your mouse as fast as you can! Hit 'Em hard and quickly to gain more points and more ranks!
HitEmUp Instructions: Click on the purple targets before their timer expires and get +1 Score or you lose a life. Don't click an empty nest, or you lose a life. Lose all lives and it's game over! Click on the yellow targets before their timer expires to get +1 Life. The more points you get, the more ranks you achieve and the more harder it gets!
At the end it shows you a Game Over image taken randomly from the Bing services. It also features short sounds dynamically downloaded from the internet. The game gets really interesting and harder when you reach 175 score, about to get the Lieutenant rank.
I developed HitEmUp in Silverlight 3.0. It was a bit challenging trying to get the source code smaller and smaller in order to pack it into 10 kilobytes. That’s the main reason this contest is interesting. Not only for the pieces of software, but for techniques on making the code smaller. Even if it really doesn’t matter much, because C# gets compiled in IL :)
You must have Silverlight 3.0 installed on your machine. Download this file, and extract it to your desktop. Open view.html with your favorite browser to play the game. Note: Internet resources may not play if run locally.
The source code is made up of two solutions. Download this file. The big one is the main project, right before getting minified and is about ~20K (only the .cs and .xaml files are counted against the size limit). The smaller one is the minified one and is about ~8K. [Note: The minified one is more updated than the big one, because I made some changes after minifying my entry.]
To understand what’s being done, start by examining the big project before going to the minified one. The first thing to check out is the Nest usercontrol which represents each of the 16 nests of the game. It has methods on how to activate a nest, either with a purple or yellow target, how much time it will be activated and an event when the timer expires etc. Next thing to check out is the main page. First examine the XAML code for the layout and the objects. Then, check out how the timer works.
The main variables that control the gameplay are: The maximum score which is set to 800 (the scores and the ranks are defined in the main page’s constructor). The spidersSpawnInterval which is the milliseconds between the random activation of nests. The badProbability which determines if the nest will be populated (randomly) with a purple or yellow target. The spidersTimeToSmash which sets the duration of a nest’s activation (yellow targets get half time).
Also, when the score increases, depending on the score value, the game progressively changes the above variables to create a harder gameplay. When Lives deplete, the game ends and shows a random “congratulations” image from the Bing web search services.
Next read on, on how the code got minified into more than the half of its size.
Let’s tell many of the tricks used (or could be used) to minify the code:
Powered by Zimbra