cleaning up
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#ifndef ELEMENT_HPP
|
||||
#define ELEMENT_HPP
|
||||
|
||||
#include <vector>
|
||||
|
||||
constexpr int ROW = 11;
|
||||
constexpr int COL = 11;
|
||||
|
||||
enum class Direction {
|
||||
UP, DOWN, LEFT, RIGHT
|
||||
};
|
||||
|
||||
struct vec2 {
|
||||
int x, y;
|
||||
vec2(int x, int y) : x(x), y(y) {}
|
||||
void set(int _x, int _y) { x = _x; y = _y; }
|
||||
auto operator <=> (const vec2&) const = default;
|
||||
};
|
||||
|
||||
struct Window {
|
||||
std::array<std::array<char, COL>, ROW> view;
|
||||
void draw_display();
|
||||
void update_display(vec2 &head, vec2 &fruit, std::vector<vec2> &buf);
|
||||
};
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
Engine();
|
||||
~Engine();
|
||||
void run();
|
||||
|
||||
private:
|
||||
Window win;
|
||||
std::vector<vec2> buf;
|
||||
vec2 head { COL / 2, ROW / 2 };
|
||||
vec2 fruit { rand() % COL, rand() % ROW };
|
||||
vec2 prev_head { head.x, head.y };
|
||||
Direction dir = Direction::RIGHT;
|
||||
unsigned int m_score = 0;
|
||||
bool process_input();
|
||||
void determine_index_zero_pos();
|
||||
void move_tail_indicies();
|
||||
void add_tail_and_respawn_fruit();
|
||||
bool exit_summary();
|
||||
};
|
||||
|
||||
#endif // ELEMENT_HPP
|
||||
Reference in New Issue
Block a user