snake_2024/include/Snake.hpp

49 lines
722 B
C++
Raw Normal View History

2024-07-22 21:22:52 +03:00
#pragma once
#include <deque>
#include "Canvas.hpp"
namespace canvas {
2024-07-25 22:42:54 +03:00
struct SnakeObject : public Object {
2024-07-22 21:22:52 +03:00
size_t length;
int radius;
};
} // namespace canvas
2024-07-25 22:42:54 +03:00
class Snake : protected canvas::SnakeObject {
2024-07-22 21:22:52 +03:00
public:
2024-07-25 22:42:54 +03:00
Snake(canvas::SnakeObject obj) : SnakeObject(obj), track_{pos} {}
2024-07-22 21:22:52 +03:00
void add(Veci pos);
void draw(Veci offset = {}) const;
//
Veci get_pos() { return pos; }
//
2024-07-22 21:22:52 +03:00
size_t get_length() { return length; }
void set_length(size_t length) { this->length = length; }
void inc_length(int inc) {
if (-inc > static_cast<int>(length)) {
length = 0;
} else {
length += inc;
}
}
//
2024-07-25 22:42:54 +03:00
bool touches(const Snake &other);
2024-07-22 21:22:52 +03:00
protected:
std::deque<Veci> track_;
};