Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Explain the changes you made to the code. Discuss the work you completed by focusing on the different tactics you used to create a fully

Explain the changes you made to the code. Discuss the work you completed by focusing on the different tactics you used to create a fully realized 2D animation. What were the changes you chose to make? What was your intent behind them? How did you approach coding to successfully create this outcome?
using namespace std;
const float DEG2RAD =3.14159/180;
void processInput(GLFWwindow* window);
enum BRICKTYPE { REFLECTIVE, DESTRUCTABLE, PADDLE };
enum ONOFF { ON, OFF };
class Brick{
public:
float red, green, blue;
float x, y, width;
int health; // track the brick's health
BRICKTYPE brick_type;
ONOFF onoff;
Brick(BRICKTYPE bt, float xx, float yy, float ww, float rr, float gg, float bb){
brick_type = bt; x = xx; y = yy, width = ww; red = rr, green = gg, blue = bb;
onoff = ON;
health =10;};
void drawBrick(){
if (onoff == ON){
double halfside = width /1;
glColor3d(red, green, blue);
glBegin(GL_POLYGON);
glVertex2d(x + halfside, y + halfside);
glVertex2d(x + halfside, y - halfside);
glVertex2d(x - halfside, y - halfside);
glVertex2d(x - halfside, y + halfside);
glEnd();}}};
Brick paddle(PADDLE,-0.0,-1.0,0.1,1,0,1);
class Circle{
public:
float red, green, blue;
float radius;
float x;
float y;
float speed =0.03;
int direction; //1=up 2=right 3=down 4=left 5= up right 6= up left 7= down right 8= down left
ONOFF onoff;
Circle(double xx, double yy, double rr, int dir, float rad, float r, float g, float b){
x = xx;
y = yy;
radius = rr;
red = r;
green = g;
blue = b;
radius = rad;
direction = dir;
onoff = ON;}
void CheckCollision(Brick* brk){
if (brk->brick_type == REFLECTIVE && onoff == ON){
if ((x > brk->x - brk->width && x <= brk->x + brk->width) && (y > brk->y - brk->width && y <= brk->y + brk->width)){
direction = GetRandomDirection();
x = x +0.03;
y = y +0.04;}}
// make a brick into a paddle that reflects balls and can move
else if (brk->brick_type == PADDLE && onoff == ON){
if ((x > brk->x - brk->width && x <= brk->x + brk->width) && (y > brk->y - brk->width && y <= brk->y + brk->width)){
direction = GetRandomDirection();
x = x +0.03;
y = y +0.04;}}
else if (brk->brick_type == DESTRUCTABLE && brk->onoff == ON
&& brk->health >0 && onoff == ON)// added check for "ON" to prevent destroyed bricks causing collisions {
if ((x > brk->x - brk->width && x <= brk->x + brk->width) && (y > brk->y - brk->width && y <= brk->y + brk->width)){
brk->health--;
if (brk->health <=0)// check brk health, if 0 or less, turn brick off{
brk->onoff = OFF;}
brk->green =1.0;// brk was hit but still has health, change color
direction = GetRandomDirection();
x = x +0.03;
y = y +0.04;}}}
int GetRandomDirection(){
return (rand()%8)+1;}
void MoveOneStep(){
if (y <=-1+ radius){
onoff = OFF;}
if (direction ==1|| direction ==5|| direction ==6)// up{
if (y >-1+ radius){
y -= speed;}
else{
direction = GetRandomDirection(); }}
if (direction ==2|| direction ==5|| direction ==7)// right{
if (x <1- radius){
x += speed;}
else{
direction = GetRandomDirection();}}
if (direction ==3|| direction ==7|| direction ==8)// down{
if (y <1- radius){
y += speed;}
else{
direction = GetRandomDirection();}}
if (direction ==4|| direction ==6|| direction ==8)// left{
if (x >-1+ radius){
x -= speed;}
else{
direction = GetRandomDirection();}}}
void DrawCircle(){
if (onoff == ON){
glColor3f(red, green, blue);
glBegin(GL_POLYGON);
for (int i =0; i <360; i++){
float degInRad = i * DEG2RAD;
glVertex2f((cos(degInRad)* radius)+ x,(sin(degInRad)* radius)+ y);}
glEnd();}}};
vector world;
int main(void){
srand(time(NULL));
if (!glfwInit()){
exit(EXIT_FAILURE);}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
GLFWwindow* window = glfwCreateWindow(480,480, "Random World of Circles", NULL, NULL);
if (!window){
glfwTerminate();
exit(EXIT_FAILURE);}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
// row of brick accross the middle
Brick brick2(DESTRUCTABLE,-1.0,0.33,0.2,1,0,1);
Brick brick3(DESTRUCTABLE,-0.8,0.33,0.2,1,0,1);
Brick brick4(DESTRUCTABLE,-0.6,0.33,0.2,1,0,1);
Brick brick5(DESTRUCTABLE,-0.4,0.33,0.2,1,0,1);
Brick brick6(DESTRUCTABLE,-0.2,0.33,0.2,1,0,1);
Brick brick7(DESTRUCTABLE,-0.0,0.33,0.2,1,0,1);
Brick brick8(DESTRUCTABLE,0.2,0.33,0.2,1,0,1);
Brick brick9(DESTRUCTABLE,0.4,0.33,0.2,1,0,1);
Brick brick10(DESTRUCTABLE,0.6,0.33,0.2,1,0,1);
Brick brick11(DESTRUCTABLE,0.8,0.33,0.2,1,0,

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

What is involved in the administration of a labor agreement?

Answered: 1 week ago

Question

What are topics included in virtually all labor agreements?

Answered: 1 week ago