#pragma once #include "globals.hpp" #include #include struct vec2; struct Paddle; struct Block; struct Ball; Paddle create_new_paddle(vec2** buffer, int starting_array_index, int size, int row, char symbol); Ball create_new_ball(vec2** buffer, int buffer_index, int default_vx, int default_vy, int row, int col, char symbol); Block** create_block_buffer(int starting_symbol, int rows, int cols, int length); void rasterize_buffer(vec2** buffer, Block** block_buffer, int offset); void trim_block_buffer_on_collision(vec2** buffer, const int buffer_size, Block** block_buffer, const int block_buffer_size, Ball &ball); void cleanup(Block** block_buffer, int block_buffer_size); bool is_block_buffer_empty(Block** block_buffer, int block_buffer_size); enum Direction { LEFT, RIGHT, NONE }; struct Window { char view[ROW][COL] = {}; void clear_display(); void draw_display(int fps) const; void update_board(Paddle paddle, Ball ball, std::vector); }; struct vec2 { vec2() : x(0), y(0) {}; vec2(int x, int y) : x(x), y(y) {}; vec2(int x, int y, char symbol) : x(x), y(y), m_symbol(symbol) {}; int x, y; char m_symbol; void set(int _x, int _y) { x = _x; y = _y; }; auto operator <=> (const vec2&) const = default; }; struct Ball { vec2 m_origin { COL / 2, ROW - 5, '*' }; vec2 vel { 1, -1 }; void determine_new_position(int &paddle_lives, int reset_ball_x, int reset_ball_y); void change_velocity(char d); }; struct Paddle { Paddle(); int _size; int m_hearts { 3 }; std::array m_nodes; enum Direction dir; void determine_new_position(char (*board)[COL]); void check_collision(Ball &ball); }; struct Block { Block(); Block(vec2 pos, char symbol); std::array m_nodes = {}; bool check_collision(Ball &ball); }; class Engine { public: Engine(); ~Engine(); void run(); private: Window win; Paddle paddle; Ball ball; std::vector block_buffer; bool process_input(); bool quit_if(); void create_block_buffer(int starting_symbol, int rows, int cols, int length); };