CS
010 - Introduction to Computer Science I
Assignment 7:
DUE: Fri, July 23 before 11:00pm
Collaboration Policy
Collaboration is strongly ENCOURAGED.
You will be working in teams, but programs must represent YOUR OWN
original work. Teams should work on the algorithm together and help
debug/test each others code. However, copying code from ANY source (any
book, current or past students, past solutions, the web, etc.) is
STRICTLY FORBIDDEN. Code between teamates will be similar, but you are
not allowed to just copy a teamate's solution.
Code that is turned in, must be contained in a .cpp file named
main.cpp. Files of any other format will not be
graded (e.g. main.doc, main.txt, etc…).
You must turn your work in from a lab computer on campus.
Turn in online to as7 folder. If you turn
your assignment in to the wrong folder, your assignment may not be
graded. If it is graded, you will lose 2 pts
(out of 10).
Remember to include the following header
information at the top of your program;
// last
name, first name
// last 4 digits of SID
// UCR email address
// user name (log in name)
Problem Definition:
For this assignment you will impliment the final moon lander game
!
You have written most of the code that is required to impliment the
game, and now you must draw upon that code, make modifications as need
be, and add a collision detection function. The easiest way to complete
this assignment is to modify the code you have written for assignment
6. Just add to it the functions to draw the landscape, and draw the
explosion.
For the collision detection function, you will pass it a Point
object that represents the position of the ship. The function will then
check if that point is outside the window, or inside your landscape, if
either of these cases is true the function will return true, otherwise it will return false. The easiest way to do this,
is to break up your landscape into squares (only draw your landscape as
a sequance of horizontal lines, followed by vertical lines), the area
under each horizontal line would constitute a square. Then, all you
need to do, is check if your point lies within any of the squares. For
example; if the upper left corner of the square was at point (10,100),
and the lower right point of the square was at point (70,30), to check
if the point representing your ship was inside the box you would use the
statement:
if(x >= 10 && x <= 70 && y >= 30 && y
<= 100)
{
//inside the square
}
else
{
//outside the square
}
This would need to be done for each square (if else-if maybe...).
You will then need to modify your ccc_win_main function. You can
take out the code that asks the user if they want to play again. The
program should now assume that the person wants to continue until the
ship either lands, or explodes.
Inside your ccc_win_main function,
somewhere after each time step (calculation of the ship's new position
at time t), you will need to call the
collision function to decide wether you will draw the ship, or draw an
explosion. If there is no collision (meaning the ship is not under your
landscape, OR outside the window) you can just draw the ship, otherwise
you need to check the current velocity of the ship. If the ship is
under some acceptable velocity it has safely landed, otherwise KABOOM!
For my program, using the code that was given for assignment 6 I found
that any velocity greater than or equal to -35 was acceptable.
After the ship lands safely or explodes, you will use a break
statement to exit the main animation loop, and end your program.
In addition to the collision, your program should use code from
previous assignments to draw the ship, landscape, and explosion using
functions. The ship should move as specified in assignment 6, using the
set postion, velocity, and acceleration functions you wrote.
Example Program Download
Note that my program asks the person if they want to play
again. This will be extra credit. Also note that my program asks if
the user wants to set the rockets to High, Medium, Low, or None. You
only need to ask if they want to set them to High, Low, or None.
main
Rubric: (10 pts total)
2 pt: Collision function detects collision with landscape, and returns true
1 pt: Collision function detects ship has moved outside of window, and returns true
1 pt: Collision function returns false when appropriate
1 pt: Draws ship on ground when ship lands safely
1 pt: Draws explosion on ground when ship lands too fast
2 pt: Program uses functions to draw ship, landscape, and explosion
2 pts: Style (0.5 each)
- Good variable names
- Proper indentation
- Good comments
- No line wraps
Bonus + 1 Point
Create another function "play_again()" that is passed void, and returns true when the person wants to go again, and false otherwise. The function should reset the variables
to the value they had at the beginning of the game. So if the person chooses to play again, the game will reset itself as in the example program download above,
otherwise the program just ends. This function would have to be called after the ship lands or explodes, but NOWHERE else.