This question was probably asked here a 1000 times, but I don't really know how would I implement it. I made a circleShape head and a vector of circleShape for a body. I don't understand how would I position them behind the head or how could they follow the head.
#ifndef SNAKE_HPP
#define SNAKE_HPP
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
using namespace std;
class Snake : public sf::Drawable {
public:
sf::CircleShape head;
vector<sf::CircleShape> body;
sf::Vector2f pos;
sf::Vector2f bodyPos;
Snake();
~Snake();
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
void drawSnake();
void move();
void grow();
};
#endif
#include "Snake.hpp"
Snake::Snake() {
pos = sf::Vector2f(0, 0);
}
Snake::~Snake() {
}
void Snake::drawSnake() {
head.setRadius(12);
head.setFillColor(sf::Color::Black);
head.setPosition(400, 300);
}
void Snake::draw(sf::RenderTarget& target, sf::RenderStates states) const {
target.draw(head);
}
void Snake::move() {
head.move(pos);
}
void Snake::grow() {
sf::CircleShape part;
}
If anyone has some advice I would appreciate it. This is my first time using SFML.