fuck this shit
This commit is contained in:
@@ -8,7 +8,6 @@ include_directories(include)
|
|||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/input.cpp
|
src/input.cpp
|
||||||
src/window.cpp
|
|
||||||
src/engine.cpp
|
src/engine.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+11
-10
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct vec2;
|
struct vec2;
|
||||||
struct Paddle;
|
struct Paddle;
|
||||||
@@ -20,8 +21,8 @@ enum Direction { LEFT, RIGHT, NONE };
|
|||||||
struct Window {
|
struct Window {
|
||||||
char view[ROW][COL] = {};
|
char view[ROW][COL] = {};
|
||||||
void clear_display();
|
void clear_display();
|
||||||
void draw_display(int fps);
|
void draw_display(int fps) const;
|
||||||
void update_board(Paddle paddle, Ball ball);
|
void update_board(Paddle paddle, Ball ball, std::vector<Block>);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vec2 {
|
struct vec2 {
|
||||||
@@ -51,13 +52,12 @@ struct Paddle {
|
|||||||
void check_collision(Ball &ball);
|
void check_collision(Ball &ball);
|
||||||
};
|
};
|
||||||
|
|
||||||
// struct Block {
|
struct Block {
|
||||||
// Block();
|
Block();
|
||||||
// Block(vec2 pos, char symbol);
|
Block(vec2 pos, char symbol);
|
||||||
// ~Block();
|
std::array<vec2, 3> m_nodes = {};
|
||||||
// std::array<vec2, 3> m_nodes = {};
|
bool check_collision(Ball &ball);
|
||||||
// bool check_collision(Ball &ball);
|
};
|
||||||
// };
|
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
public:
|
public:
|
||||||
@@ -69,7 +69,8 @@ private:
|
|||||||
Window win;
|
Window win;
|
||||||
Paddle paddle;
|
Paddle paddle;
|
||||||
Ball ball;
|
Ball ball;
|
||||||
|
std::vector<Block> block_buffer;
|
||||||
bool process_input();
|
bool process_input();
|
||||||
bool quit_if();
|
bool quit_if();
|
||||||
|
void create_block_buffer(int starting_symbol, int rows, int cols, int length);
|
||||||
};
|
};
|
||||||
|
|||||||
+46
-43
@@ -4,6 +4,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
void Window::clear_display() {
|
void Window::clear_display() {
|
||||||
for(int i = 0; i < ROW; i++) {
|
for(int i = 0; i < ROW; i++) {
|
||||||
@@ -13,14 +14,14 @@ void Window::clear_display() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::update_board(Paddle paddle, Ball ball) {
|
void Window::update_board(Paddle paddle, Ball ball, std::vector<Block>) {
|
||||||
for(int i = 0; i < paddle.m_nodes.size(); i++) {
|
for(int i = 0; i < paddle.m_nodes.size(); i++) {
|
||||||
view[paddle.m_nodes[i].y][paddle.m_nodes[i].x] = paddle.m_nodes[i].m_symbol;
|
view[paddle.m_nodes[i].y][paddle.m_nodes[i].x] = paddle.m_nodes[i].m_symbol;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
view[ball.m_origin.y][ball.m_origin.x] = ball.m_origin.m_symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::draw_display(int fps) {
|
void Window::draw_display(int fps) const {
|
||||||
std::cout << "\033[H" << std::flush;
|
std::cout << "\033[H" << std::flush;
|
||||||
for(int i = 0; i < ROW; i++) {
|
for(int i = 0; i < ROW; i++) {
|
||||||
for(int j = 0; j < COL; j++) {
|
for(int j = 0; j < COL; j++) {
|
||||||
@@ -37,6 +38,17 @@ Engine::Engine() {
|
|||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
nodelay(stdscr, true);
|
nodelay(stdscr, true);
|
||||||
|
vec2 block_size = { 5, 3 };
|
||||||
|
int row, int_symbol, col;
|
||||||
|
char char_symbol;
|
||||||
|
for(int index = 0; index < block_size.y * block_size.x; index++) {
|
||||||
|
row = index / 5;
|
||||||
|
int_symbol = ('3' - '0') - row;
|
||||||
|
char_symbol = '0' + int_symbol;
|
||||||
|
col = (index % 5) * 3;
|
||||||
|
Block new_block = { { col, row }, char_symbol };
|
||||||
|
block_buffer.push_back(new_block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine::~Engine() {
|
Engine::~Engine() {
|
||||||
@@ -52,46 +64,37 @@ void Engine::run() {
|
|||||||
// Block** block_buffer = create_block_buffer('3', 3, 5, 3);
|
// Block** block_buffer = create_block_buffer('3', 3, 5, 3);
|
||||||
// rasterize_buffer(buffer, block_buffer, 4);
|
// rasterize_buffer(buffer, block_buffer, 4);
|
||||||
|
|
||||||
std::thread input_thread([&] { input.get_input(running, paddle.m_direction); } );
|
// while (process_input() && quit_if()) {
|
||||||
|
while (process_input()) {
|
||||||
while (process_input() && quit_if()) {
|
|
||||||
paddle.determine_new_position(win.view);
|
paddle.determine_new_position(win.view);
|
||||||
paddle.check_collision(ball);
|
paddle.check_collision(ball);
|
||||||
// trim_block_buffer_on_collision(buffer, buffer_size, block_buffer, block_buffer_size, ball);
|
// trim_block_buffer_on_collision(buffer, buffer_size, block_buffer, block_buffer_size, ball);
|
||||||
ball.determine_new_position(paddle.m_hearts, (ROW - 5), (COL / 2));
|
ball.determine_new_position(paddle.m_hearts, (ROW - 5), (COL / 2));
|
||||||
win.clear_display();
|
win.clear_display();
|
||||||
win.update_board(paddle, ball);
|
win.update_board(paddle, ball, block_buffer);
|
||||||
win.draw_display(FPMS);
|
win.draw_display(FPMS);
|
||||||
if(paddle.m_hearts <= 0) {
|
// if(paddle.m_hearts <= 0) {
|
||||||
running = false;
|
// running = false;
|
||||||
std::cout << "No Hearts left! You lose!\n";
|
// std::cout << "No Hearts left! You lose!\n";
|
||||||
}
|
// }
|
||||||
// if(is_block_buffer_empty(block_buffer, block_buffer_size)) {
|
// if(is_block_buffer_empty(block_buffer, block_buffer_size)) {
|
||||||
// running = false;
|
// running = false;
|
||||||
// std::cout << "No Blocks left! You win!\n";
|
// std::cout << "No Blocks left! You win!\n";
|
||||||
// }
|
// }
|
||||||
std::cout << "Hearts left: " << paddle.m_hearts << "\n";
|
std::cout << "Hearts left: " << paddle.m_hearts << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
input_thread.join();
|
|
||||||
// cleanup(block_buffer, block_buffer_size);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block** create_block_buffer(int starting_symbol, int rows, int cols, int length) {
|
bool Engine::process_input() {
|
||||||
// Block** block_buffer = new Block*[rows * cols];
|
int ch;
|
||||||
// int row, int_symbol, col;
|
while((ch = getch()) != ERR) {
|
||||||
// char char_symbol;
|
if(ch == 'd') paddle.dir = Direction::RIGHT;
|
||||||
// for(int index = 0; index < rows * cols; index++) {
|
if(ch == 'a') paddle.dir = Direction::LEFT;
|
||||||
// row = index / 5;
|
if(ch == 'q') return false;
|
||||||
// int_symbol = (starting_symbol - '0') - row;
|
}
|
||||||
// char_symbol = '0' + int_symbol;
|
return true;
|
||||||
// col = (index % 5) * 3;
|
}
|
||||||
// block_buffer[index] = new Block(length, row, col, char_symbol);
|
|
||||||
// }
|
|
||||||
// return block_buffer;
|
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
// bool is_block_buffer_empty(Block** block_buffer, int block_buffer_size) {
|
// bool is_block_buffer_empty(Block** block_buffer, int block_buffer_size) {
|
||||||
// int total_clear_blocks = 0;
|
// int total_clear_blocks = 0;
|
||||||
@@ -191,17 +194,17 @@ void Ball::determine_new_position(int &paddle_lives, int reset_ball_x, int reset
|
|||||||
m_origin.y += vel.y;
|
m_origin.y += vel.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block::Block(vec2 pos, char symbol) {
|
Block::Block(vec2 pos, char symbol) {
|
||||||
// for(int i = 0; i < m_nodes.size(); i++) {
|
for(int i = 0; i < m_nodes.size(); i++) {
|
||||||
// m_nodes[i].set(pos.x + i, pos.y);
|
m_nodes[i].set(pos.x + i, pos.y);
|
||||||
// m_nodes[i].m_symbol = symbol;
|
m_nodes[i].m_symbol = symbol;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// bool Block::check_collision(Ball &ball) {
|
bool Block::check_collision(Ball &ball) {
|
||||||
// for(int i = 0; i < m_nodes.size(); i++) {
|
for(int i = 0; i < m_nodes.size(); i++) {
|
||||||
// if(m_nodes[i] != ball.m_origin) continue;
|
if(m_nodes[i] != ball.m_origin) continue;
|
||||||
// return true;
|
return true;
|
||||||
// }
|
}
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
|
|||||||
+2
-38
@@ -3,45 +3,9 @@
|
|||||||
#include <engine.hpp>
|
#include <engine.hpp>
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
#include <input.hpp>
|
#include <input.hpp>
|
||||||
#include <window.hpp>
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// const int buffer_size = 50, block_buffer_size = 15;
|
Engine engine;
|
||||||
bool running = true;
|
engine.run();
|
||||||
// vec2* buffer[buffer_size] = {};
|
|
||||||
Input input;
|
|
||||||
Window window;
|
|
||||||
|
|
||||||
// Ball ball = create_new_ball(buffer, 0, 1, -1, (ROW - 5), (COL / 2), '*' );
|
|
||||||
// Paddle paddle = create_new_paddle(buffer, 1, 3, ROW - 2, '-');
|
|
||||||
// Block** block_buffer = create_block_buffer('3', 3, 5, 3);
|
|
||||||
// rasterize_buffer(buffer, block_buffer, 4);
|
|
||||||
Paddle paddle;
|
|
||||||
Ball ball;
|
|
||||||
|
|
||||||
std::thread input_thread([&] { input.get_input(running, paddle.m_direction); } );
|
|
||||||
|
|
||||||
while (running) {
|
|
||||||
paddle.determine_new_position(window.view);
|
|
||||||
paddle.check_collision(ball);
|
|
||||||
// trim_block_buffer_on_collision(buffer, buffer_size, block_buffer, block_buffer_size, ball);
|
|
||||||
ball.determine_new_position(paddle.m_hearts, (ROW - 5), (COL / 2));
|
|
||||||
window.clear_display();
|
|
||||||
window.update_board(paddle, ball);
|
|
||||||
window.draw_display(FPMS);
|
|
||||||
if(paddle.m_hearts <= 0) {
|
|
||||||
running = false;
|
|
||||||
std::cout << "No Hearts left! You lose!\n";
|
|
||||||
}
|
|
||||||
// if(is_block_buffer_empty(block_buffer, block_buffer_size)) {
|
|
||||||
// running = false;
|
|
||||||
// std::cout << "No Blocks left! You win!\n";
|
|
||||||
// }
|
|
||||||
std::cout << "Hearts left: " << paddle.m_hearts << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
input_thread.join();
|
|
||||||
// cleanup(block_buffer, block_buffer_size);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user