72 lines
1.5 KiB
C++
72 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "raylibCpp.h"
|
|
#include <vector>
|
|
#include <list>
|
|
#include <string>
|
|
#include "Vec2.h"
|
|
#include "Settings.h"
|
|
|
|
class Snake {
|
|
public:
|
|
enum Direction {
|
|
Up,
|
|
Down,
|
|
Left,
|
|
Right,
|
|
None
|
|
};
|
|
|
|
private:
|
|
class Body {
|
|
public:
|
|
Body(Vec2<int> pos);
|
|
|
|
void draw(Color color = WHITE) const;
|
|
void move(Vec2<int> pos) { this->pos = pos; };
|
|
Vec2<int> getPos() const { return this->pos; }
|
|
static void setSize(Vec2<int> size) { Body::size = size; }
|
|
|
|
private:
|
|
Vec2<int> pos;
|
|
static Vec2<int> size;
|
|
Snake::Direction nextPart;
|
|
};
|
|
|
|
class Food {
|
|
public:
|
|
Food();
|
|
|
|
void draw() const;
|
|
void newPosition();
|
|
Vec2<int> getPosition() { return this->pos; }
|
|
|
|
private:
|
|
Vec2<int> pos;
|
|
Vec2<int> size;
|
|
};
|
|
|
|
public:
|
|
Snake();
|
|
|
|
void update();
|
|
void draw() const;
|
|
|
|
void setDirection(Direction dir);
|
|
private:
|
|
void move();
|
|
void eat();
|
|
|
|
Direction dir = Direction::None;
|
|
Food food;
|
|
|
|
bool hasEaten = false;
|
|
bool hasBitten = false;
|
|
|
|
int score = 0;
|
|
|
|
double lastMoveTime = 0;
|
|
double moveDelay = 0.15;
|
|
|
|
std::list<Snake::Body> bodyList;
|
|
}; |