# Assignment On Atari Video Game Asteroids

Added on - 25 Sep 2019

5

pages

2383

Words

79

Views

0

Downloads

1. Problem DescriptionThis assignment hearkens back to the classic Atari video gameAsteroids, although the basicproblem it addresses, collision detection among moving objects, is common to many games.It is common to represent objects as polygons. If this seems a bit crude, that is because theexample shown here uses very fewvertices(“corner” points). With enough points, quitesophisticated shapes can be rendered. Filling in the shape with colors, textures, or picturebitmaps often disguises the fact that the outer edges are actually quite simple. (Even 3-Dmodels of game objects are often formed by stitching together polygonal plates.)In this assignment, you will be given most of a simulation that moves two such shapes acrossa simulated screen. We will refer to the shapes as “asteroids,” though they could just aseasily represent the rocket, flying saucer, or even the bullets fired by the rocket in this game.

You are being given the driver (main program) for the simulation (collision.cpp) andtheLineSegmentandPointADTs. Your task is to design and implement theAsteroidADTso that it works with the provided code.An asteroid will be represented as a polygon, so your ADT implementation will need to storeeither the vertices of the polygon or the line segments that make up the perimeter of thepolygon. You will be provided with ADTs for both Points and LineSegments and areexpected to make use of them in your code.To simplify the problem a bit, we will restrict this simulation toconvexpolygons - polygonsin which all the corners point “out” away from the center. (The asteroids and rocket in thepicture are all concave polygons.) We will also not permit polygons thataredegenerate(polygons with no internal area because the edges lie directly on top of oneanother, e.g., a rectangle of widthw > 0but zero height ).The major operations you must support with your Asteroid ADT are:Construction: you will need a constructor that builds a newAsteroidobject, given anarray of Points representing its vertices and an integer counter indicating how manyvertices are in the array.Moving: you will need a function to move your asteroid. This function will be giventhe amount to move in the x and the y directions as parameters.To move a polygon without altering its shape, you add the same value to the xcoordinates and/or to the y coordinates of each vertex.Center: you will need a function to compute the center (technically the “center ofgravity”) of your asteroid.You can find this location(cx,cy)by computingcxas the average ofthexcoordinates of all vertices andcyas the average of theycoordinates of allvertices.Detecting collisions: you will need a function to determine if your asteroid is collidingwith another.Two asteroids are colliding if any vertex ofeitherasteroid is inside the polygon of theother asteroid. (This is also a bit of an over-simplification. For example, tworectangles forming a cross or “+” shape would not be judged as colliding by thisdefinition. But if we use a small enough time step compared to the speed at which theobjects are moving, we should never see those kinds of exceptions unless we havefirst seen at least one vertex inside the other polygon.)

**You’re reading a preview**

To View Complete Document

Become a Desklib Library Member.

Subscribe to our plans