wip
This commit is contained in:
@@ -1 +0,0 @@
|
||||
compile_commands.json
|
||||
@@ -1,11 +1,13 @@
|
||||
#ifndef ELEMENTS_HPP
|
||||
#define ELEMENTS_HPP
|
||||
|
||||
#include "globals.hpp"
|
||||
|
||||
struct Point;
|
||||
struct Paddle;
|
||||
struct Block;
|
||||
struct Ball;
|
||||
Paddle create_new_paddle(int size);
|
||||
Paddle create_new_paddle(Point** segments, int index, int size, int row, char symbol);
|
||||
|
||||
enum Direction {
|
||||
LEFT = -1,
|
||||
@@ -20,6 +22,7 @@ struct Point {
|
||||
int m_col;
|
||||
char m_symbol;
|
||||
void assign(int row, int col);
|
||||
void to_string();
|
||||
};
|
||||
|
||||
struct Ball {
|
||||
@@ -34,11 +37,12 @@ struct Ball {
|
||||
};
|
||||
|
||||
struct Paddle {
|
||||
Paddle();
|
||||
Paddle(int size) : _size(size) {};
|
||||
~Paddle();
|
||||
int _size;
|
||||
Point m_nodes[3];
|
||||
Point** m_nodes;
|
||||
enum Direction m_direction;
|
||||
void get_new_pos();
|
||||
void determine_new_position(Point* (*board)[COL]);
|
||||
void check_collision(Ball &ball);
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -2,6 +2,6 @@
|
||||
#define GLOBALS_HPP
|
||||
#define ROW 15
|
||||
#define COL 15
|
||||
#define FPMS 300
|
||||
#define FPMS 100
|
||||
|
||||
#endif
|
||||
|
||||
+38
-19
@@ -1,3 +1,4 @@
|
||||
#include <iostream>
|
||||
#include "elements.hpp"
|
||||
#include "globals.hpp"
|
||||
|
||||
@@ -6,39 +7,57 @@ Point::Point() {
|
||||
m_col = 0;
|
||||
}
|
||||
|
||||
void Point::to_string() {
|
||||
std::cout << "(" << m_row << ", " << m_col << ")\n";
|
||||
}
|
||||
|
||||
void Point::assign(int row, int col) {
|
||||
m_row = row;
|
||||
m_col = col;
|
||||
}
|
||||
|
||||
Paddle create_new_paddle(int size) {
|
||||
Paddle paddle {};
|
||||
Paddle create_new_paddle(Point** segments, int index, int size, int row, char symbol) {
|
||||
Paddle paddle { size };
|
||||
paddle._size = size;
|
||||
paddle.m_nodes = new Point*[size];
|
||||
for(int i = 0; i < size; i++) {
|
||||
paddle.m_nodes[i] = new Point { row, ((COL / 2) - (size / 2)) + i, symbol };
|
||||
// paddle.m_nodes[i] = new Point { row, ((COL / 2) - (size / 2) - 1) + i, symbol };
|
||||
segments[i + index] = paddle.m_nodes[i];
|
||||
}
|
||||
|
||||
return paddle;
|
||||
}
|
||||
|
||||
Paddle::Paddle() {
|
||||
_size = 3;
|
||||
m_nodes[0].m_col = 6;
|
||||
for(int i = 0; i < _size; i++) {
|
||||
m_nodes[i].m_row = ROW - 2;
|
||||
}
|
||||
Paddle::~Paddle() {
|
||||
delete[] m_nodes;
|
||||
}
|
||||
|
||||
void Paddle::get_new_pos() {
|
||||
void Paddle::determine_new_position(Point* (*board)[COL]) {
|
||||
if(m_direction == LEFT && m_nodes[0]->m_col - 1 >= 0) {
|
||||
m_nodes[0]->m_col--;
|
||||
for(int i = 1; i < _size; i++) {
|
||||
m_nodes[i].m_col = m_nodes[0].m_col + i;
|
||||
m_nodes[i]->m_col = m_nodes[0]->m_col + i;
|
||||
}
|
||||
}
|
||||
else if(m_direction == RIGHT && m_nodes[_size - 1]->m_col + 1 < ROW) {
|
||||
m_nodes[_size - 1]->m_col++;
|
||||
for(int i = 1; i < _size; i++) {
|
||||
m_nodes[_size - (i + 1)]->m_col = m_nodes[_size - 1]->m_col - i;
|
||||
}
|
||||
}
|
||||
m_direction = NONE;
|
||||
}
|
||||
|
||||
void Paddle::check_collision(Ball &ball) {
|
||||
for(int i = 0; i < _size; i++) {
|
||||
if(ball.m_origin.m_row == m_nodes[i].m_row) {
|
||||
if(ball.m_origin.m_col == m_nodes[i].m_col) {
|
||||
ball.change_velocity('y');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// void Paddle::check_collision(Ball &ball) {
|
||||
// for(int i = 0; i < _size; i++) {
|
||||
// if(ball.m_origin.m_row == m_nodes[i].m_row) {
|
||||
// if(ball.m_origin.m_col == m_nodes[i].m_col) {
|
||||
// ball.change_velocity('y');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Ball::Ball() {
|
||||
m_origin.assign(ROW - 5, (COL / 2));
|
||||
|
||||
+15
-5
@@ -1,17 +1,19 @@
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
#include "globals.hpp"
|
||||
#include "input.hpp"
|
||||
#include "window.hpp"
|
||||
#include "elements.hpp"
|
||||
|
||||
int main() {
|
||||
int main(int argc, char **argv) {
|
||||
Input input;
|
||||
Window window;
|
||||
Paddle paddle;
|
||||
Ball ball;
|
||||
// Ball ball;
|
||||
|
||||
Point* segments[50] = {};
|
||||
segments[1] = new Point { 2, 5, '*' };
|
||||
// segments[1] = new Point { 2, 5, '*' };
|
||||
Paddle paddle = create_new_paddle(segments, 0, 3, ROW - 2, '*');
|
||||
|
||||
// Block block_list[15] = {
|
||||
// Block('3', 1, 0), Block('3', 1, 3), Block('3', 1, 6), Block('3', 1, 9), Block('3', 1, 12),
|
||||
// Block('2', 2, 0), Block('2', 2, 3), Block('2', 2, 6), Block('2', 2, 9), Block('2', 2, 12),
|
||||
@@ -23,7 +25,14 @@ int main() {
|
||||
|
||||
while (running) {
|
||||
// window.update_display(paddle, ball, block_list);
|
||||
paddle.get_new_pos();
|
||||
// paddle.m_direction = RIGHT;
|
||||
// for(int i = 0; i < 8; i++) {
|
||||
// paddle.m_direction = RIGHT;
|
||||
// }
|
||||
// for(int i = 0; i < 10; i++) {
|
||||
// if(segments[i] == nullptr) continue;
|
||||
// segments[i]->to_string();
|
||||
// }
|
||||
// ball.check_collision();
|
||||
// for(int i = 0; i < 15; i++) {
|
||||
// if(block_list[i]._deleted) {
|
||||
@@ -43,6 +52,7 @@ int main() {
|
||||
// paddle.check_collision(ball);
|
||||
// ball.get_new_pos();
|
||||
// window.terminate(ball, running);
|
||||
paddle.determine_new_position(window.m_board);
|
||||
window.clear_display();
|
||||
window.update_display(segments, 50);
|
||||
window.draw_display(FPMS);
|
||||
|
||||
Reference in New Issue
Block a user