Question
PLEASE SHOW FULL CODE IN ANSWER INCLUDING GIVEN CODE!!!! PLEASE SHOW FULL CODE IN ANSWER INCLUDING GIVEN CODE!!!! PLEASE SHOW FULL CODE IN ANSWER INCLUDING
PLEASE SHOW FULL CODE IN ANSWER INCLUDING GIVEN CODE!!!!
PLEASE SHOW FULL CODE IN ANSWER INCLUDING GIVEN CODE!!!!
PLEASE SHOW FULL CODE IN ANSWER INCLUDING GIVEN CODE!!!!
Alter the state of the circles upon collision. When a circle collides with another circle, you will need to code for an event to occur. This means updating the code to alter the state of the circles upon collision. Some options you may wish to use for your work are as follows, but you do not need to complete all of these. You can also try an idea of your own instead.
The two circles combine to become one larger circle.
The circles change their color or texture.
Both circles disappear once hit.
The circles spawn multiple smaller circles.
PLEASE USE GIVEN CODE BELOW WITH NO ADDITIONAL LIBRARIES
#include
using namespace std;
const float DEG2RAD = 3.14159 / 180;
void processInput(GLFWwindow* window);
enum BRICKTYPE { REFLECTIVE, DESTRUCTABLE }; enum ONOFF { ON, OFF };
class Brick { public: float red, green, blue; float x, y, width; 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; };
void drawBrick() { if (onoff == ON) { double halfside = width / 6;
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(); } } };
class Circle { public: float red, green, blue; float radius; float x; float y; float speed = 0.01; //speed of circles int direction; // 1=up 2=right 3=down 4=left 5 = up right 6 = up left 7 = down right 8= down left
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; }
void CheckCollision(Brick* brk) { if (brk->brick_type == REFLECTIVE) { if ((x > brk->x - brk->width && x <= brk->x + brk->width) && (y > brk->y - brk->width && y <= brk->y + brk->width)) { direction = GetDirection(); x = x + 0.01; y = y + 0.02; } } else if (brk->brick_type == DESTRUCTABLE) { if ((x > brk->x - brk->width && x <= brk->x + brk->width) && (y > brk->y - brk->width && y <= brk->y + brk->width)) { brk->onoff = OFF; } } }
int GetDirection() { return (rand() % 8) + 1; }
void MoveOneStep() { if (direction == 1 || direction == 5 || direction == 6) // up { if (y > -1 + radius) { y -= speed; } else { direction = GetDirection(); } }
if (direction == 2 || direction == 5 || direction == 7) // right { if (x < 1 - radius) { x += speed; } else { direction = GetDirection(); } }
if (direction == 3 || direction == 7 || direction == 8) // down { if (y < 1 - radius) { y += speed; } else { direction = GetDirection(); } }
if (direction == 4 || direction == 6 || direction == 8) // left { if (x > -1 + radius) { x -= speed; } else { direction = GetDirection(); } } }
void DrawCircle() { 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
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, "Shingy Chiremba Week 8 Assignment", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); glfwSwapInterval(1);
Brick brick(REFLECTIVE, 0.5, -0.33, 0.2, 1, 1, 0); Brick brick2(DESTRUCTABLE, -0.5, 0.33, 0.2, 0, 1, 0); Brick brick3(DESTRUCTABLE, -0.5, -0.33, 0.2, 0, 1, 1); Brick brick4(DESTRUCTABLE, 1, 1, 0.5, 0, 0.5, 0.5); Brick brick5(REFLECTIVE, 0.3, 0.3, 0.2, 1, 0.5, 0.5); Brick brick6(DESTRUCTABLE, 0.2, 0.2, 0.2, 0.8, 0.3, 0.3);
while (!glfwWindowShouldClose(window)) { //Setup View float ratio; int width, height; glfwGetFramebufferSize(window, &width, &height); ratio = width / (float)height; glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT);
processInput(window);
//Movement for (int i = 0; i < world.size(); i++) { world[i].CheckCollision(&brick); world[i].CheckCollision(&brick2); world[i].CheckCollision(&brick3); world[i].CheckCollision(&brick4); world[i].CheckCollision(&brick5); world[i].CheckCollision(&brick6); world[i].MoveOneStep(); world[i].DrawCircle();
}
brick.drawBrick(); brick2.drawBrick(); brick3.drawBrick(); brick4.drawBrick(); brick5.drawBrick(); brick6.drawBrick();
glfwSwapBuffers(window); glfwPollEvents(); }
glfwDestroyWindow(window); glfwTerminate; exit(EXIT_SUCCESS); }
void processInput(GLFWwindow* window) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { double r, g, b; r = rand() / 10000; g = rand() / 10000; b = rand() / 10000; Circle B(0, 0, 02, 2, 0.05, r, g, b); world.push_back(B); } }
PLEASE SHOW FULL CODE INCLUDING GIVEN CODE IN RESPONSE
DO NOT SHOW CHECKCOLLISION ONLY, PLEASE SHOW ENTIRE CODE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started