I use codeblock and I tried many things to only show on the screen a sprite from a class. If I only use the main it works but I plan a bigger project so I need to be able to draw those sprites.
What I copy-paste here is the last try I did to make it work. The error is : undefined reference to Snake::Snake()' wich is my class
Theres nothing in the map.cpp for the moment so its not important.
main#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "snake.h"
#include "map.h"
#include <list>
#include <iostream>
#include <vector>
int main()
{
int h = 45;
int l = 45;
sf::RenderWindow App(sf::VideoMode(20*h, 20*l, 32), "Snake O Tron");
App.SetFramerateLimit(60);
Snake test;
std::vector<sf::Sprite> serpent;
std::vector<std::vector<int> > map(h, std::vector<int> (l,0));
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();
for(int i = 0; i<serpent.size(); i++)
{
App.Draw(serpent[i]);
}
App.Display();
}
return EXIT_SUCCESS;
}
snake.cpp#include "snake.h"
using namespace std;
using namespace sf;
Snake::Snake()
{
tete.Create(20, 20, Color(200,0,0));
head.SetImage()(tete);
head.setPosition(200.f, 200.f);
affiche.push_back(head);
}
vector<Sprite> Snake::get_aff() const
{
return affiche;
}
snake.h#ifndef SNAKE_H_INCLUDED
#define SNAKE_H_INCLUDED
#include <SFML/Graphics.hpp>
#include <list>
#include <iostream>
#include <vector>
class Snake
{
public:
Snake();//constructeur
std::vector<sf::Sprite>get_aff() const;
std::vector<sf::Sprite> affiche;
protected:
private:
sf::Image tete;
sf::Sprite head;
};
#endif // SNAKE_H_INCLUDED