mirror of
https://github.com/ProgramSnail/snake_2024.git
synced 2025-12-18 04:08:44 +00:00
initial game
This commit is contained in:
parent
4570d6e593
commit
adabb50a9e
10 changed files with 200 additions and 132 deletions
|
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
|
||||
#include "Canvas.hpp"
|
||||
|
||||
namespace canvas {
|
||||
|
||||
struct WormObject : public Object {
|
||||
size_t length;
|
||||
int radius;
|
||||
};
|
||||
|
||||
} // namespace canvas
|
||||
|
||||
class Worm : protected canvas::WormObject {
|
||||
public:
|
||||
Worm(canvas::WormObject obj) : WormObject(obj), track_{pos} {}
|
||||
|
||||
void add(Veci pos);
|
||||
|
||||
void draw(Veci offset = {}) const;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
std::deque<Veci> track_;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue