vg101 recitation 8
DESCRIPTION
VG101 RECITATION 8. By TAs. CONTENTS. Brief review of class Strategy for assignment 9 Questions about assignment 7, 8. BRIEF REVIEW OF CLASS. In header file: Base class Constructors Private/protected/public member Data/ function member Accessors/ Mutators In cpp file: - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/1.jpg)
VG101RECITATION 8By TAs
![Page 2: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/2.jpg)
CONTENTS
Brief review of class Strategy for assignment 9 Questions about assignment 7, 8
![Page 3: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/3.jpg)
BRIEF REVIEW OF CLASS
In header file: Base class Constructors Private/protected/public member Data/ function member Accessors/ Mutators
In cpp file: Implementation of class functions
![Page 4: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/4.jpg)
class RectangleT : public GObjectT{
PointT llp, urp;void drawRect ();
public:RectangleT (const double x0 = 0, const double y0 = 0,
const double x1 = 0, const double y1 = 0, const string clr = "Blue", const double fill = 0);
RectangleT (const PointT &p0, const PointT &p1, const string clr = "Blue", const double fill = 0);
const PointT &getLocation () {return llp;}double getWidth () const;double getHeight () const;double getArea () const;void setLocation (const double x, const double y);void setLocation (const PointT p);void setWidth (const double w);void setHeight (const double h);void draw ();void draw (const string clr, const double density = 0);
};
Base class
Private membe
r
Public membe
r
constructor
Get & Set
Data members
Function members
![Page 5: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/5.jpg)
BRIEF REVIEW OF CLASS
Base class Base class will be constructed first // BallT is a derived class from ArcT // A ball is an arc of 360 degree BallT (double r = 0) : ArcT (r, 0, 360, "Blue", 1)
{};
Constructors Always define a default constructor (suggested) One and only one of the constructors must be
called
![Page 6: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/6.jpg)
STRATEGY FOR ASSIGNMENT 9
Divide the project into several stages: 1. class design 2. initialization 3. get ball/paddle moving 4. handle collisions 5. end of game
One function for one simple purpose only Test your functions one by one Test your program after finishing each stage Have fun after finishing the whole project
![Page 7: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/7.jpg)
STAGE ONE: CLASS DESIGN
Game window: GwindowT Represent the application window
Brick wall Represent all the bricks Row, column, vector of bricks…
Brick: RectangleT Represent one brick Color, position(row, column), location( x, y)…
Paddle: RectangleT Location(x, y) …
![Page 8: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/8.jpg)
STAGE ONE: CLASS DESIGN
What need you to design: 1. constructors 2. data members and their accessors and mutators 3. special functions: Samples:
// let the paddle move when being selectedbool paddle::selected(…)void paddle::move(…)
// draw the brick wall, the main function in initialization
void brickWall::draw(…)
![Page 9: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/9.jpg)
STAGE TWO: INITIALIZATION
Initialize the game: 1. init brick wall, give color, location to each
brick 2. init paddle, give color, location to it 3. draw the window ,the wall and paddle
No movement in this stage Refer to the lecture note on drawing the brick
wall
![Page 10: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/10.jpg)
STAGE THREE: GET BALL/PADDLE MOVING
To move the ball Just as what you do in assignment 5-2 Consider the brick wall as a static border of the
window, don’t drop out the brick been clicked
To move the paddle Just as the movingBall program discussed in
lecture (page 46) Don’t let the paddle move out of the window
These are not difficult, but they are basis for the following stage
![Page 11: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/11.jpg)
STAGE FOUR: HANDLE COLLISIONS
Three kinds of collision 1. ball and brick 2. ball and paddle 3. ball and window
For kind 2 and 3, it’s similar to assignment5-2
Refer to the boundary check discussed in lecture (page 27)
Remember to check the position of the paddle to see whether the ball falls onto the paddle or falls out.
![Page 12: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/12.jpg)
STAGE FOUR: HANDLE COLLISIONS
For kind 1, divide it into two steps 1. how to determine whether a known brick
collides with the ball? 2. search among all the existing brick in the wall
to find the brick to be clicked Maybe you need a function
bool BrickT::isClicked(…) 3. do changes to the ball (direction), and do
changes to the brick (disappear)
You just need a for/while loop to do the searching and a if statement to handle the collision
![Page 13: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/13.jpg)
STAGE FIVE: END OF GAME
Taking care of some small details in the game: You’ve got to take care of the case when the ball
hits the bottom wall You need to check for the other terminating
condition, which is hitting the last brick You should experiment with the settings that
control the speed of your program Most importantly, you’ve got to test your
program to see that it works
![Page 14: VG101 RECITATION 8](https://reader033.vdocument.in/reader033/viewer/2022051116/56815044550346895dbe43f2/html5/thumbnails/14.jpg)
QUESTIONS ABOUT ASSIGNMENT 7, 8
Send your code to TA’s email box if you didn’t submit your assignment before deadline
Any questions?