This commit is contained in:
RafayAhmad7548 2024-06-16 18:53:25 +05:00
parent 37776af5db
commit ab03d5f10c
4045 changed files with 286212 additions and 3 deletions

View file

@ -0,0 +1,24 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY()-ball.getRadius() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,39 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int vx, vy;
switch(rand()%3){
case 0: vx = 0; vy = 5; break;
case 1: vx = 5; vy = 5; break;
case 4: vx = 5/2 * sqrt(3); vy = 5/2; break;
}
vx *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(y);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(x);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,28 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){
// delete color;
}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int vx, vy;
switch(rand()%3){
case 0: vx = 0; vy = 5; break;
case 1: vx = 5; vy = 5; break;
case 2: vx = 5/2 * sqrt(3); vy = 5/2; break;
}
vx *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(vy);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(vx);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,24 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int vx, vy;
switch(rand()%3){
case 0: vx = 0; vy = 5; break;
case 1: vx = 5; vy = 5; break;
case 2: vx = 5/2 * sqrt(3); vy = 5/2; break;
}
vx *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(y);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(x);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
// int vx, vy;
// switch(rand()%3){
// case 0: vx = 0; vy = 5; break;
// case 1: vx = 5; vy = 5; break;
// case 2: vx = 5/2 * sqrt(3); vy = 5/2; break;
// }
// vx *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,35 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int x, y;
switch(rand()%3){
case 0: x = 0; y = 5; break;
case 1: x = 5; y = 5; break;
case 2: x = 5/2 * sqrt(3); y = 5/2; break;
}
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1-random);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
// int vx, vy;
// switch(rand()%3){
// case 0: vx = 0; vy = 5; break;
// case 1: vx = 5; vy = 5; break;
// case 2: vx = 5/2 * sqrt(3); vy = 5/2; break;
// }
// vx *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1020 - width/2) this->x = 1020 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int vx, vy;
switch(rand()%3){
case 0: vx = 0; vy = 5; break;
case 1: vx = 5; vy = 5; break;
// case 4: vx = 5/2 * sqrt(3); vy = 5/2; break;
}
vx *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(y);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(x);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int x, y;
switch(rand()%3){
case 0: x = 0; y = 5; break;
case 1: x = 5; y = 5; break;
case 2: x = 5/2 * sqrt(3); y = 5/2; break;
}
x *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1-random);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,60 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, int y, float *color) : height(20), y(y), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getX() >= x && ball.getX() <= x+width){
if(ball.getY()+ball.getRadius() >= y && ball.getY()+ball.getRadius() <= y+4){
}
else if(ball.getY()-ball.getRadius() <= y+height && ball.getY()+ball.getRadius() <= y-4){
}
}
// if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
// ball.setVY(ball.getVY()*-1);
// color = ball.getColor()
// }
// if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
// //TODO: game over screen
// if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
// if(x < width/2) this->x = 0;
// else if(x > 1050 - width/2) this->x = 1050 - width;
// else this->x = x - width/2;
this->x = x;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,55 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, int y, float *color) : height(20), y(y), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getX() >= x && ball.getX() <= x+width){
}
// if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
// ball.setVY(ball.getVY()*-1);
// color = ball.getColor();
// }
// if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
// //TODO: game over screen
// if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
// if(x < width/2) this->x = 0;
// else if(x > 1050 - width/2) this->x = 1050 - width;
// else this->x = x - width/2;
this->x = x;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,60 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, int y, float *color) : height(20), y(y), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getX() >= x && ball.getX() <= x+width){
if(ball.getY()+ball.getRadius() >= y && ball.getY()+ball.getRadius() <= y+4){
}
else if(ball.getY()-ball.getRadius() <= y+height && ball.getY()+ball.getRadius() <= y-4){
}
}
// if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
// ball.setVY(ball.getVY()*-1);
// color = ball.getColor()
// }
// if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
// //TODO: game over screen
// if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
// if(x < width/2) this->x = 0;
// else if(x > 1050 - width/2) this->x = 1050 - width;
// else this->x = x - width/2;
this->x = x;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int vx, vy;
switch(rand()%3){
case 0: x = 0; y = 5; break;
case 1: x = 5; y = 5; break;
case 2: x = 5/2 * sqrt(3); y = 5/2; break;
}
x *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,24 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int x, y;
switch(rand()%3){
case 0: x = 0; y = 5; break;
case 1: x = 5; y = 5; break;
case 2: x = 5/2 * sqrt(3); y = 5/2; break;
}
x *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,58 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, int y, float *color) : height(20), y(y), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getX() >= x && ball.getX() <= x+width){
if(ball.getY()+ball.getRadius() >= y && ball.getY()+ball.getRadius() <= y+4){
}
else if(ball.getY())
}
// if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
// ball.setVY(ball.getVY()*-1);
// color = ball.getColor()
// }
// if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
// //TODO: game over screen
// if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
// if(x < width/2) this->x = 0;
// else if(x > 1050 - width/2) this->x = 1050 - width;
// else this->x = x - width/2;
this->x = x;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,46 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
ball.setVY(ball.getVY()*-1);
}
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,43 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,47 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
ball.setVY(ball.getVY()*-1);
color
}
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int x, y;
switch(rand()%3){
case 0: x = 0; y = 5; break;
case 1: x = 5; y = 5; break;
case 2: x = 5/2 * sqrt(3); y = 5/2; break;
}
x *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(y);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(x);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,43 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,24 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,44 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,47 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, int y, float *color) : height(20), y(y), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
ball.setVY(ball.getVY()*-1);
color = ball.getColor();
}
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,27 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,42 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int x, y;
switch(rand()%3){
case 0: x = 0; y = 5; break;
case 1: x = 5; y = 5; break;
case 2: x = 5/2 * sqrt(3); y = 5/2; break;
}
x *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(-1 * y);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(x);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,28 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
// Paddle::~Paddle(){
// delete color;
// }

View file

@ -0,0 +1,24 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1 @@
{"version":1,"resource":"file:///home/rafayahmad/Stuff/OOP/Project/Paddle.cpp","entries":[{"id":"5WyT.cpp","timestamp":1714539275035},{"id":"7Qai.cpp","timestamp":1714539344292},{"id":"qqmp.cpp","timestamp":1714539360759},{"id":"YpU9.cpp","timestamp":1714539402620},{"id":"NNgM.cpp","timestamp":1714539427683},{"id":"ifvi.cpp","timestamp":1714539504094},{"id":"F9Q0.cpp","timestamp":1714539526401},{"id":"D3xr.cpp","timestamp":1714539555301},{"id":"3A4q.cpp","timestamp":1714539597397},{"id":"0xWD.cpp","timestamp":1714539735465},{"id":"7K7X.cpp","timestamp":1714539762397},{"id":"vdFJ.cpp","timestamp":1714539781990},{"id":"2adX.cpp","timestamp":1714540647029},{"id":"lAkT.cpp","timestamp":1714540752445},{"id":"mbeH.cpp","timestamp":1714540763618},{"id":"5q1D.cpp","timestamp":1714541559216},{"id":"5MJC.cpp","timestamp":1714616120206},{"id":"Ugos.cpp","timestamp":1714617314903},{"id":"DFtM.cpp","timestamp":1714617336150},{"id":"bXxD.cpp","timestamp":1714654800035},{"id":"Odpa.cpp","timestamp":1714654885176},{"id":"04sU.cpp","timestamp":1714657128644},{"id":"kPIl.cpp","timestamp":1714657148654},{"id":"taDs.cpp","timestamp":1714657227115},{"id":"tVWW.cpp","timestamp":1714657300310},{"id":"2jXH.cpp","timestamp":1714657585803},{"id":"gUv1.cpp","timestamp":1714700175605},{"id":"aMJd.cpp","timestamp":1714700273269},{"id":"1VNp.cpp","timestamp":1714700409175},{"id":"zuPC.cpp","timestamp":1714700638702},{"id":"xZ39.cpp","timestamp":1714822774685},{"id":"0S68.cpp","timestamp":1714822853819},{"id":"XsFa.cpp","timestamp":1714889006956},{"id":"O0Js.cpp","timestamp":1714889464396},{"id":"lxQw.cpp","timestamp":1714890149716},{"id":"KPLX.cpp","timestamp":1715093187632},{"id":"Q4Ur.cpp","timestamp":1715093979719},{"id":"KLQU.cpp","timestamp":1715145793197},{"id":"NBMe.cpp","timestamp":1715145804796},{"id":"uJGn.cpp","timestamp":1715145819288},{"id":"THu2.cpp","timestamp":1715160430725},{"id":"lmcp.cpp","timestamp":1715162788677},{"id":"B0DW.cpp","timestamp":1715178753175},{"id":"fHa3.cpp","timestamp":1715178802042},{"id":"zrg3.cpp","timestamp":1715178825751},{"id":"G3YE.cpp","timestamp":1715178848224},{"id":"CXIf.cpp","timestamp":1715178885685},{"id":"8iMb.cpp","timestamp":1715178913102},{"id":"vEKv.cpp","timestamp":1715178951750},{"id":"lDIq.cpp","timestamp":1715179670593}]}

View file

@ -0,0 +1,55 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, int y, float *color) : height(20), y(y), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getX() >= x && ball.getX() <= x+width){
if(ball.getY()-ball.getRadius() >= y && ball.getY() <= y+4)
}
// if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
// ball.setVY(ball.getVY()*-1);
// color = ball.getColor()
// }
// if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
// //TODO: game over screen
// if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
// if(x < width/2) this->x = 0;
// else if(x > 1050 - width/2) this->x = 1050 - width;
// else this->x = x - width/2;
this->x = x;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,28 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){
delete color;
}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int x, y;
switch(rand()%3){
case 0: x = 0; y = 5; break;
case 1: x = 5; y = 5; break;
case 2: x = 5/2 * sqrt(3); y = 5/2; break;
}
x *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) {ball.setVY(y); cout<<111;}
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(x);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,24 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY()-ball.getRadius() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int vx, vy;
switch(rand()%3){
case 0: vx = 0; vy = 5; break;
case 1: vx = 5; vy = 5; break;
case 2: vx = 5/2 * sqrt(3); vy = 5/2; break;
}
vx *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(vy);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(vx);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,64 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, int y, float *color) : height(20), y(y), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getX() >= x && ball.getX() < x+width){
if(ball.getY() >= y && ball.getY() <= y+4){
ball.setVY(ball.getVY()>0 ? ball.getVY()*-1 : ball.getVY());
ball.setY(ball.getY()/10*10);
color = ball.getColor();
}
if(ball.getY() <= y+height && ball.getY() >= y+height-4){
ball.setVY(ball.getVY()>0 ? ball.getVY() : ball.getVY()*-1);
ball.setY(ball.getY()/10*10);
color = ball.getColor();
}
}
if(ball.getY() >= y && ball.getY() < y+height){
if(ball.getX() >= x && ball.getX() <= x+4){
ball.setVX(ball.getVX()>0 ? ball.getVX()*-1 : ball.getVX());
ball.setX(ball.getX()/10*10);
color = ball.getColor();
}
if(ball.getX() <= x+width && ball.getX() >= x+width-4){
ball.setVX(ball.getVX()>0 ? ball.getVX() : ball.getVX()*-1);
ball.setX(ball.getX()/10*10);
color = ball.getColor();
}
}
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
// if(x < width/2) this->x = 0;
// else if(x > 1050 - width/2) this->x = 1050 - width;
// else this->x = x - width/2;
this->x = x;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,48 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, int y, float *color) : height(20), y(y), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
ball.setVY(ball.getVY()*-1);
color = ball.getColor();
}
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
// if(x < width/2) this->x = 0;
// else if(x > 1050 - width/2) this->x = 1050 - width;
// else this->x = x - width/2;
this->x = x;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,43 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int vx, vy;
switch(rand()%3){
case 0: vx = 0; vy = 5; break;
case 1: vx = 5; vy = 5; break;
case 2: vx = 5/2 * sqrt(3); vy = 5/2; break;
}
vx *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(vy);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(vx);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1020 - width/2) this->x = 1020 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int x, y;
switch(rand()%3){
case 0: x = 0; y = 5; break;
case 1: x = 5; y = 5; break;
case 2: x = 5/2 * sqrt(3); y = 5/2; break;
}
x *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(y);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(x);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,24 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY()-ball.getRadius() < y+height && ball.getX()+ball.getRadius() >= x && ball.getX()-ball.getRadius() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,24 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY()-ball.getRadius() <= y+height && ball.getX()+ball.getRadius() >= x && ball.getX()-ball.getRadius() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,47 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
ball.setVY(ball.getVY()*-1);
color = ball.getColor();
}
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,79 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, int y, float *color) : height(20), y(y), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getX() >= x && ball.getX() < x+width){
if(ball.getY() >= y && ball.getY() <= y+4){
ball.setVY(ball.getVY()>0 ? ball.getVY()*-1 : ball.getVY());
ball.setY(ball.getY()/10*10);
}
if(ball.getY() <= y+height && ball.getY() >= y+height-4){
ball.setVY(ball.getVY()>0 ? ball.getVY() : ball.getVY()*-1);
ball.setY(ball.getY()/10*10);
}
}
if(ball.getY() >= y && ball.getY() < y+height){
if(ball.getX() >= x && ball.getX() <= x+4){
ball.setVX(ball.getVX()>0 ? ball.getVX()*-1 : ball.getVX());
ball.setX(ball.getX()/10*10);
}
if(ball.getX() <= x+width && ball.getX() >= x+width-4){
ball.setVX(ball.getVX()>0 ? ball.getVX() : ball.getVX()*-1);
ball.setX(ball.getX()/10*10);
}
}
// if(ball.getX() >= x && ball.getX() <= x+width){
// if(ball.getY()+ball.getRadius() >= y && ball.getY()+ball.getRadius() <= y+4){
// }
// else if(ball.getY()-ball.getRadius() <= y+height && ball.getY()+ball.getRadius() <= y-4){
// }
// }
// if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
// ball.setVY(ball.getVY()*-1);
// color = ball.getColor()
// }
// if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
// //TODO: game over screen
// if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
// if(x < width/2) this->x = 0;
// else if(x > 1050 - width/2) this->x = 1050 - width;
// else this->x = x - width/2;
this->x = x;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,36 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x){
// color = new float[3];
color = other.color;
}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
// y = 5, 5, 2.5
// x = 0, 5, 5/2 sqrt3
int vx, vy;
switch(rand()%3){
case 0: vx = 0; vy = 5; break;
case 1: vx = 5; vy = 5; break;
// case 4: vx = 5/2 * sqrt(3); vy = 5/2; break;
}
vx *= ball.getVX()>0 ? -1 : 1;
if(ball.getY() - ball.getRadius() <= y+height && ball.getX()-ball.getRadius() >= x && ball.getX()+ball.getRadius() < x+width) ball.setVY(vy);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(vx);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < 10 + width/2) this->x = 10;
else if(x > 1010 - width/2) this->x = 1010 - width;
else this->x = x - width/2;
return *this;
}

View file

@ -0,0 +1,33 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,57 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, int y, float *color) : height(20), y(y), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
//TODO: Redo Collisoin
if(ball.getX() >= x && ball.getX() <= x+width){
if(ball.getY()-ball.getRadius() >= y && ball.getY() <= y+4){
}
}
// if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width){
// ball.setVY(ball.getVY()*-1);
// color = ball.getColor()
// }
// if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
// //TODO: game over screen
// if(ball.getY() < 0) ball.setVY(ball.getVY()*-1);
}
int Paddle::getX(){
return x;
}
int Paddle::getY(){
return y;
}
int Paddle::getWidth(){
return width;
}
int Paddle::getHeight(){
return height;
}
Paddle& Paddle::setWidth(int width){
this->width = width;
return *this;
}
Paddle& Paddle::setX(int x){
// if(x < width/2) this->x = 0;
// else if(x > 1050 - width/2) this->x = 1050 - width;
// else this->x = x - width/2;
this->x = x;
return *this;
}
Paddle::~Paddle(){}

View file

@ -0,0 +1,26 @@
#include "Paddle.h"
#include "Ball.h"
#include "util.h"
Paddle::Paddle(int width, int x, float *color) : height(20), y(10), width(width), x(x), color(color){}
Paddle::Paddle(const Paddle& other) : height(other.height), y(other.y), width(other.width), x(other.x), color(other.color){}
void Paddle::draw(){
DrawRectangle(x, y, width, height, color);
}
void Paddle::checkCollision(Ball& ball){
if(ball.getY()-ball.getRadius() == y+height && ball.getX()-ball.getRadius() > x && ball.getX()+ball.getRadius() < x+width) ball.setVY(ball.getVY()*-1);
if(ball.getY() <= y+height && ball.getX() >= x && ball.getX() < x+width) ball.setVX(ball.getVX()*-1);
//TODO: game over screen
if(ball.getY() < 0) exit(1);
}
Paddle& Paddle::setX(int x){
if(x < width/2) this->x = 0;
else if(x > 1050 - width/2) this->x = 1050 - width;
else this->x = x - width/2;
return *this;
}
Paddle::~Paddle(){}