CSIS3700 Project1–SimpleArtilleryGame solved

$29.99

Original Work ?

Download Details:

  • Name: Project-1.zip
  • Type: zip
  • Size: 8.39 MB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (3 votes)

1 Introduction
In this project you will create a simple artillery game. In this game play will alternate between two players. Each playerhasatankwithamuzzle. Onaplayer’sturntheyselecttheangleoftheirmuzzle(upanddownarrowkeys)and the velocity of their shell (left and right arrow keys). Once the player is happy with the angle they press space to fire the shell which may or may not destroy the opponent’s tank. Below I will describe some of the considerations you will need to make asyoudesign your solution.
2 Images
I recommend starting with hand-drawn images of the following: • Tank base (without muzzle) around 50×50 pixels • Tank muzzle oriented horizontally…this should be a short and wide image around 50×5 pixels • Abackgroundimagewhichincludesarelativelyflat“ground”. Irecommendincreasingthesizeofyourwindow from 800×600 to 1024×768 (or choose something more appropriate for the aspect ratio and resolution of your monitor). The background image should have dimensions that correspond to your selected size. • A “missed” explosion image…the shell exploding when it hits the ground, missing the opponent’s tank • A “hit” explosion image…the shell exploding when it hits the opponents tank
3 Theworld
Spriteswillbecomingandgoingfromtheworld. Asasimpleexample,whenanexplosionisaddedtotheworlditwill want to remove itself after a certain time has passed (I used 2 seconds). The world needs to have methods to support this. In this particular example I added: • void begin explosion(float x, float y, bool hit) – creates the appropriate kind of explosionspriteatthespecifiedlocation. Updatestheworldstatetoreflectthatanexplosionisoccurring. (Seebelow for discussion of the world state.) • void end explosion(explosion sprite *) – remove the supplied explosion sprite. Update the world state so that it is the next player’s turn or the game is over.
1
You may have several messages like these to control sprites coming and going from the world. Do not allow sprites to add and remove arbitrary sprites from the world. Your game will become unmanageable. Finally, messages like those above complicate your loops in the world. Consider the world’s advance by time method. As it loops over the sprites: void world :: advance by time (double dt ) { for ( vector<sprite∗:: iterator it = sprites . begin (); it != sprites . end (); ++it ) (∗ it)−advance by time ( dt ); } the list of sprites may change. This will cause significant problems with the iterator. The solution is to modify this method so that it loops over acopyof the sprite list: void world :: advance by time (double dt ) { vector<sprite∗ copy ; copy = sprites ; for ( vector<sprite∗:: iterator it = copy . begin (); it != copy . end (); ++it ) (∗ it)−advance by time ( dt ); } In this game the world moves through a sequence of states in a predictable fashion. I recommend enumerating these states and explicitly checking the state during event handling. The states I used were: • aiming • shell in air • explosion animation • Game over (one of the tanks destroyed) Irecommendeitherdefininganenumtorepresentthestateorcreateastate-relatedclasses(moreadvancedapproach). The world will need to have an instance varibale, currentState, which it will use to make decisions during event handling. I also have an instance variable to track which player is taking their turn.2 Finally don’t be surprised if the world needs to treat some of the sprites in a special way. That is, it will still need to keep a list of sprites so that they animate properly etc. but it may also what to keep separate pointer variables to specific important sprites (the tanks, for example).
4 Sprites
You will need specialized sprite subclasses:
• tank sprite • shell sprite • missed explosion sprite • hit explosion sprite
2
Unlike your first animation, these sprites will need to interact with the world. For example, a shell sprite will need to know if it hit the other tank (just use the width and height of the shell and the tank and their positions to determine if a hit occurred). This means that these sprites will need to have a pointer to the world in an instance variable.
5 TankMuzzle
Astheplayeraims,theangleofthemuzzleshouldchange. Allegrosupportsdrawingarotatedbitmapviaal draw rotated bitmap. See the documentation of that function for details.
6 Motionoftheshell
At each time step the shell’s position after that time step (x(t + ∆t),y(t + ∆t)) depends on its position and velocity before that time step (x(t),y(t)) etc. Similarly for the velocities. They should be updated with the following:
x(t + ∆t) = x(t) + vx(t)∆t y(t + ∆t) = y(t) + vy(t)∆t vx(t + ∆t) = vx(t) + ax∆t vy(t + ∆t) = vy(t) + ay∆t
The accelerations should be constant:
ax = 0 ay = 300 Theinitialvelocities are determined by the angle θ and velocity v selected by the user:
vx(0) = v cosθ vy(0) = v sinθ
At each time step the shell sprite should check to see if it hit the ground or the enemy tank. In either case the sprite should ask the world to delete it and replace it by the appropriate explosion.
7 Text
During the aiming phase, the player needs some feedback about they direction and velocity of their shell. Display text showing them this information. In addition it is helpful to display text indicating the current active player (whose “turn” it is) and when the game ends to display “GAME OVER” in a large font. First select and download font files for the muzzle information and the GAME OVER display. To draw text you must make sure that you initialize the font add-on via al init font addon. If your font is a TrueType font, you will also need to call al init ttf font. Add these calls to main. Next, you’ll need to load the fonts from the files using al load font. This can be done in world who also should keep pointers to the return fonts. Finally, to display text on the screen use al draw text or al draw justified text. See the documentation for details.
3
8 Tohandin
Submit a zip file of your complete solution (all source code) on the submission system.