Split 'Ball' class into header and implementation files
This commit is contained in:
		
							
								
								
									
										34
									
								
								ball.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								ball.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
#include "includes/raylib-cpp/raylib-cpp.hpp"
 | 
			
		||||
#include "includes/ball.hpp"
 | 
			
		||||
 | 
			
		||||
Ball::Ball(int pos_x, int pos_y, int radius, int vel_x = 0, int vel_y = 0) {
 | 
			
		||||
	this->pos = raylib::Vector2(pos_x, pos_y);
 | 
			
		||||
	this->initial_pos = this->pos; // Create a copy of the position vector
 | 
			
		||||
	this->radius = radius;
 | 
			
		||||
	this->color = raylib::Color::White();
 | 
			
		||||
	this->vel = raylib::Vector2(vel_x, vel_y);
 | 
			
		||||
	this->initial_vel = this->vel; // Create a copy of the velocity vector
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Ball::setPosition(Vector2 pos) {
 | 
			
		||||
	this->pos = pos;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Ball::reset() {
 | 
			
		||||
	this->pos = this->initial_pos;
 | 
			
		||||
	this->vel = this->initial_vel;
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Ball::updatePosition() {
 | 
			
		||||
	this->pos.x += this->vel.x;
 | 
			
		||||
	this->pos.y += this->vel.y;
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Ball::draw() {
 | 
			
		||||
	DrawCircle(this->pos.x, this->pos.y, this->radius, this->color);  // This is a raylib function, not a raylib-cpp function
 | 
			
		||||
	return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -3,7 +3,6 @@
 | 
			
		||||
 | 
			
		||||
class Ball {
 | 
			
		||||
public:
 | 
			
		||||
	/* Variables */
 | 
			
		||||
	raylib::Vector2 pos;
 | 
			
		||||
	raylib::Vector2 initial_pos;
 | 
			
		||||
	raylib::Vector2 vel;
 | 
			
		||||
@@ -11,37 +10,20 @@ public:
 | 
			
		||||
	int radius;
 | 
			
		||||
	raylib::Color color;
 | 
			
		||||
 | 
			
		||||
	/* Functions */
 | 
			
		||||
	Ball(int pos_x, int pos_y, int radius, int vel_x = 0, int vel_y = 0) {
 | 
			
		||||
		this->pos = raylib::Vector2(pos_x, pos_y);
 | 
			
		||||
		this->initial_pos = this->pos; // Create a copy of the position vector
 | 
			
		||||
		this->radius = radius;
 | 
			
		||||
		this->color = raylib::Color::White();
 | 
			
		||||
		this->vel = raylib::Vector2(vel_x, vel_y);
 | 
			
		||||
		this->initial_vel = this->vel; // Create a copy of the velocity vector
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	/* Constructor */
 | 
			
		||||
	Ball(int pos_x, int pos_y, int radius, int vel_x, int vel_y);
 | 
			
		||||
 | 
			
		||||
	void setPosition(Vector2 pos) {
 | 
			
		||||
		this->pos = pos;
 | 
			
		||||
	}
 | 
			
		||||
	/* Set the position of the ball */
 | 
			
		||||
	void setPosition(Vector2 pos);
 | 
			
		||||
 | 
			
		||||
	void reset() {
 | 
			
		||||
		this->pos = this->initial_pos;
 | 
			
		||||
		this->vel = this->initial_vel;
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	/* Reset the position and velocity of the ball */
 | 
			
		||||
	void reset();
 | 
			
		||||
 | 
			
		||||
	void updatePosition() {
 | 
			
		||||
		this->pos.x += this->vel.x;
 | 
			
		||||
		this->pos.y += this->vel.y;
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	/* Update the position of the ball based on its velocity */
 | 
			
		||||
	void updatePosition();
 | 
			
		||||
 | 
			
		||||
	void draw() {
 | 
			
		||||
		DrawCircle(this->pos.x, this->pos.y, this->radius, this->color);  // This is a raylib function, not a raylib-cpp function
 | 
			
		||||
		return;
 | 
			
		||||
		}
 | 
			
		||||
	/* Draw the ball onto the screen */
 | 
			
		||||
	void draw();
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user