Files
breakout/include/engine.hpp
T
2025-11-18 23:53:53 -05:00

60 lines
1.6 KiB
C++

#pragma once
#include "globals.hpp"
#include <array>
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 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);
auto operator <=> (const vec2&) const = default;
};
struct Ball {
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) : _size(size), m_hearts(3) {};
~Paddle();
int _size;
int m_hearts;
vec2** m_nodes;
enum Direction m_direction;
void determine_new_position(vec2* (*board)[COL]);
void check_collision(Ball &ball);
};
struct Block {
Block();
Block(vec2 pos, char symbol);
~Block();
std::array<vec2, 3> m_nodes = {};
bool check_collision(Ball &ball);
};
// class Engine {
//
// };