February 26, 2010 – 2:30 pm

Your task is a bit different today and you may find it a bit more difficult. Anyway, fewer lines of code to write than the last week!
Pleased download the source code of the Cannons game.
Compile and run it. It is not a working version yet! For the full version check the Resources tab (subject to availability).
Your task is to finish the game. This time we will tell you what to do, but not how. In theMyGame.cpp file, OnUpdate function, you will find a series of comments starting with TODO. They mark the places where you have something to do, and also tell you what to do.
Your games already has a lot of functionality: you will not have to create sprites, they are all already in-place. The user interaction is all done: the player can move the cannon (right mouse button) and aim and shoot (left mouse button) but — there are no collisions checked, so the game never knows if you hit a wall, and if the game is over (a cannon destroyed). More importantly, there is no gravity, so your balls travel along straight lines, which is rather not very enjoyable.
A couple of hints for you, but only read this if you are lost:
- You can use ball.HitTest(p) to check for collisions. In case of cannons, use cannon[0] or cannon[1] for the left and the right one, or cannon[which] for your current turn, or cannon[1-which] for the opponent.
- To check the collisions with the castle, check the loop in OnDraw function used for drawing the castle. Your collision test loop will be pretty much similar.
- What to do when a cannon is hit? That’s simple – just call a function: GameOver();
- What do do when the castle is hit? Simply set the value bHit = true;
- How to model the gravitation? Think about a following call:
ball.SetMotion(ball.GetXVelocity(), ball.GetYVelocity());
This code will NOT change anything, but it gives you a lot of opportunities. The motion of ther ball is here decomposed into horizontal and vertical (or: X and Y) velocities, and then combine again to set the motion. Isn’t it exciting?
There is no separate workshop sheet.
If you have a working game, you can now award yourself with Paper Cannon XP, a nice heavily physics-based web game. Enjoy!
Posted in Workshops | Comments Off