wip
This commit is contained in:
@@ -36,14 +36,15 @@ struct Ball {
|
|||||||
Point* m_origin;
|
Point* m_origin;
|
||||||
int vx;
|
int vx;
|
||||||
int vy;
|
int vy;
|
||||||
void determine_new_position();
|
void determine_new_position(int &paddle_lives, int reset_ball_x, int reset_ball_y);
|
||||||
void change_velocity(char d);
|
void change_velocity(char d);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Paddle {
|
struct Paddle {
|
||||||
Paddle(int size) : _size(size) {};
|
Paddle(int size) : _size(size), m_hearts(3) {};
|
||||||
~Paddle();
|
~Paddle();
|
||||||
int _size;
|
int _size;
|
||||||
|
int m_hearts;
|
||||||
Point** m_nodes;
|
Point** m_nodes;
|
||||||
enum Direction m_direction;
|
enum Direction m_direction;
|
||||||
void determine_new_position(Point* (*board)[COL]);
|
void determine_new_position(Point* (*board)[COL]);
|
||||||
|
|||||||
+4
-2
@@ -119,11 +119,13 @@ void Ball::change_velocity(char d) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ball::determine_new_position() {
|
void Ball::determine_new_position(int &paddle_lives, int reset_ball_x, int reset_ball_y) {
|
||||||
if(m_origin->m_row <= 0) {
|
if(m_origin->m_row <= 0) {
|
||||||
vy = 1;
|
vy = 1;
|
||||||
} else if(m_origin->m_row >= ROW - 1) {
|
} else if(m_origin->m_row >= ROW - 1) {
|
||||||
vy = -1;
|
paddle_lives--;
|
||||||
|
m_origin->m_row = reset_ball_y;
|
||||||
|
m_origin->m_col = reset_ball_x;
|
||||||
}
|
}
|
||||||
if(m_origin->m_col <= 0) {
|
if(m_origin->m_col <= 0) {
|
||||||
vx = 1;
|
vx = 1;
|
||||||
|
|||||||
+9
-5
@@ -6,7 +6,7 @@
|
|||||||
#include "elements.hpp"
|
#include "elements.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int buffer_size = 50, buffer_block_size = 15;
|
int buffer_size = 50, block_buffer_size = 15;
|
||||||
bool running = true;
|
bool running = true;
|
||||||
Point* buffer[50] = {};
|
Point* buffer[50] = {};
|
||||||
Input input;
|
Input input;
|
||||||
@@ -22,14 +22,18 @@ int main() {
|
|||||||
while (running) {
|
while (running) {
|
||||||
paddle.determine_new_position(window.m_board);
|
paddle.determine_new_position(window.m_board);
|
||||||
paddle.check_collision(ball);
|
paddle.check_collision(ball);
|
||||||
trim_block_buffer_on_collision(buffer, buffer_size, block_buffer, buffer_block_size, ball);
|
trim_block_buffer_on_collision(buffer, buffer_size, block_buffer, block_buffer_size, ball);
|
||||||
ball.determine_new_position();
|
ball.determine_new_position(paddle.m_hearts, (ROW - 5), (COL / 2));
|
||||||
window.clear_display();
|
window.clear_display();
|
||||||
window.update_board(buffer, 50);
|
window.update_board(buffer, buffer_size);
|
||||||
window.draw_display(FPMS);
|
window.draw_display(FPMS);
|
||||||
|
// Create a clause that closes game on lives = 0
|
||||||
|
std::cout << "Hearts left: " << paddle.m_hearts << "\n";
|
||||||
}
|
}
|
||||||
input_thread.join();
|
input_thread.join();
|
||||||
for(int i = 0; i < buffer_block_size; i++) {
|
// TODO
|
||||||
|
// move below to a cleanup function instead
|
||||||
|
for(int i = 0; i < block_buffer_size; i++) {
|
||||||
delete block_buffer[i];
|
delete block_buffer[i];
|
||||||
}
|
}
|
||||||
delete[] block_buffer;
|
delete[] block_buffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user