wip
This commit is contained in:
+12
-14
@@ -4,7 +4,7 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "globals.hpp"
|
||||
#include <globals.hpp>
|
||||
|
||||
class Window;
|
||||
|
||||
@@ -12,12 +12,12 @@ enum class Direction {
|
||||
UP, DOWN, LEFT, RIGHT
|
||||
};
|
||||
|
||||
struct vec {
|
||||
struct vec2 {
|
||||
int x, y;
|
||||
vec() : x(0), y(0) {}
|
||||
vec(int x, int y) : x(x), y(y) {}
|
||||
vec2() : x(0), y(0) {}
|
||||
vec2(int x, int y) : x(x), y(y) {}
|
||||
void set(int _x, int _y) { x = _x; y = _y; }
|
||||
auto operator <=> (const vec&) const = default;
|
||||
auto operator <=> (const vec2&) const = default;
|
||||
};
|
||||
|
||||
class SnakeGame {
|
||||
@@ -28,20 +28,18 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<Window> win;
|
||||
std::vector<vec> buf;
|
||||
vec head { COL / 2, ROW / 2 };
|
||||
vec fruit { rand() % COL, rand() % ROW };
|
||||
vec prev_head { head.x, head.y };
|
||||
std::vector<vec2> buf;
|
||||
vec2 head { COL / 2, ROW / 2 };
|
||||
vec2 fruit { rand() % COL, rand() % ROW };
|
||||
vec2 prev_head { head.x, head.y };
|
||||
struct {
|
||||
bool running = true;
|
||||
Direction m_dir = Direction::RIGHT;
|
||||
Direction dir = Direction::RIGHT;
|
||||
uint8_t m_score = 0;
|
||||
} state;
|
||||
void process_input();
|
||||
bool process_input();
|
||||
void determine_index_zero_pos();
|
||||
void move_tail_indicies();
|
||||
void add_tail_and_respawn_fruit(std::array<std::array<char, COL>, ROW> board);
|
||||
bool segment_overlap();
|
||||
void add_tail_and_respawn_fruit(std::array<std::array<char, COL>, ROW> view);
|
||||
bool exit_summary();
|
||||
};
|
||||
|
||||
|
||||
+4
-4
@@ -1,14 +1,14 @@
|
||||
#ifndef WINDOW_HPP
|
||||
#define WINDOW_HPP
|
||||
|
||||
#include "globals.hpp"
|
||||
#include "element.hpp"
|
||||
#include <globals.hpp>
|
||||
#include <element.hpp>
|
||||
#include <array>
|
||||
|
||||
struct Window {
|
||||
std::array<std::array<char, COL>, ROW> board;
|
||||
std::array<std::array<char, COL>, ROW> view;
|
||||
void draw_display();
|
||||
void update_display(vec &head, vec &fruit, std::vector<vec> &buf);
|
||||
void update_display(vec2 &head, vec2 &fruit, std::vector<vec2> &buf);
|
||||
};
|
||||
|
||||
#endif // WINDOW_HPP
|
||||
|
||||
Reference in New Issue
Block a user