CS
010 - Introduction to Computer Science I
Assignment 7:
DUE: Thursday December 2nd before 5: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-(group letter) 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;
// Course: CS 10
//
// Lecture Section: ... 001 or 002
// Lab Section: ... 021, 022, etc)
//
// Assignment #: ... assignment 2, 3, etc.
//
// Last Name: Enter your LAST (family) name here (eg, Doe)
// First Name: Enter your FIRST (given) name here (eg, John)
//
// ID Number: Enter your ID number here (eg, 860-00-0000)
// lab login id: Enter your cs10 login here (eg, jdoe)
//
// Email address: Enter your UCR email address here (eg,
jdoe@cs.ucr.edu)
//
// Group: Enter your group here (eg, D4)
// Teammates: List the names of the teammates you worked with
// Meeting Time: Specify the next time your team plans to meet
//
//
=======================================================================
Problem Definition:
For this assignment you will impliment the final moon lander game
!
You will have to add some code to ccc_win_main, create a collision
detection function, add a function that draws a simple landscape, and
add a function that draws an explosion based on the position of the
ship.
You have already written some functions that draw a landscape and
draw an explosion. As in the previous assignments, the draw landscape
function is passed nothing, and returns void, the draw explosion
function is passed a point that represents the position of your ship,
and returns void. Keep your landscape simple, have no more than THREE
places to land as in the example main below! This means there should
be no more than 5 lines drawn in your landscape, and they should only
be horizontal, and vertical.
For the collision detection function, you will pass it a SINGLE
Point object that represents the position of the ship. The point that
represents your ship should be at the bottom-center of your ship. The
function will then check to see if that point is inside your landscape,
if it is, the function will return true,
otherwise it will return false.
The easiest way to do this is to break up your landscape into squares
(as mentioned 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 (0,3500), and the lower right point
of the square was at point (2000,0), to check if the point representing
your ship was inside the box you would use the statement:
if(x >= 0 && x <= 2000 && y <= 3500)
{
//inside the square
}
else
{
//outside the square
}
This would need to be done for each square, so you will need to use a
switch statement or an if-else if structure. Becuase this is a
relatively simple way to check for collisions, it is OK if your ship
*lands* on a wall (vertical line). Also, since the point representing
your ship will be in the at the ship's center, it is OK if half your
ship passes through a vertical line/wall before the collision is
detected.
You will then need to modify your ccc_win_main function. The
program should continue until the ship either lands, or explodes.
At the point in ccc_win_main where you were previously drawing the
ship, you will now need to call your
collision detection function to decide weither you will draw the ship,
or draw an explosion. If there is no collision you can just draw the
ship, otherwise you need to check the ship's current velocity. If the
ship is over some acceptable negative velocity, it has landed safely,
otherwise KABOOM! Using the code that was given for assignment 6, I
found that any velocity greater than or equal to -17.5 was acceptable
but difficult to land. For an easier game (and testing my code), a
velocity greater than or equal to -35 was reasonable.
After the ship lands safely or explodes, you will use a break
statement (page 137) to exit the main animation loop, this should cause
the program to end.
The ship should move as specified in assignment 6, using the set
postion, velocity, and acceleration functions you wrote. The controls for the
thrusters should be exactly as in as6.
Solution to as6
main.cpp
Example Program Download
main
Rubric: (10 pts total)
1.5 pt: Collision function detects collision with landscape and returns true
0.5 pt: Collision function returns false when there is no collision
0.5 pt: Landscape has no more than three landing pads
0.5 pt: Point that represents ship is located at the bottom center of ship drawing (don't draw this point though)
0.5 pt: Correctly breaks out of animation loop when ship lands or explodes
1 pt: On landing, draws ship when velocity is greater than or equal to -17.5
1 pt: Draws explosion when ship lands too fast
1 pt: Just draws ship when no collision is detected
1.5 pt: Program uses correct functions to draw ship, landscape, and explosion
2 pts: Style
- Good variable names
- Proper indentation and spacing
- Good comments
- No line wraps
- No magic numbers