-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComida.cpp
More file actions
61 lines (46 loc) · 1.27 KB
/
Comida.cpp
File metadata and controls
61 lines (46 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Comida.hpp"
#include "Jugador.hpp"
using namespace std;
Comida::Comida(const Nivel &n,const std::vector<sf::Sprite> &cola) : nivel(n),cola_jugador(cola)
{
// Prepara el sprite de la comida
sf::RectangleShape rec(sf::Vector2f(9.f,9.f));
rec.setFillColor(sf::Color::Yellow);
sf::RenderTexture render;
render.create(10,10);
render.clear();
render.draw(rec);
render.display();
textura_comida = render.getTexture();
comida = sf::Sprite(textura_comida);
ponerComida();
}
bool Comida::teComo(sf::Vector2f pos)
{
//int px=comida.getPosition().x-pos.x,py=comida.getPosition().y-pos.y;
if (comida.getPosition()!= pos)return false;//(px>3||px<-1) &&(py>3 || py <-1)) return false;
else
{
ponerComida();
return true;
}
}
void Comida::ponerComida()
{
do
{
comida.setPosition(Jugador::despl*(rand()%(Nivel::TAMX*10/Jugador::despl)),Jugador::despl*(rand()%(Nivel::TAMY*10/Jugador::despl)));
} while(colision());
}
bool Comida::colision()
{
sf::Vector2f pos = comida.getPosition();
if(nivel.colision(pos))
return true;
for(auto it = cola_jugador.cbegin(); it!=cola_jugador.cend();it++)
{
if(it->getPosition()==pos)
return true;
}
return false;
}