Class not seeing its avaliable attributes
Hi again
one of my classes operations keeps throwing up errors saying it can't find data it should be able too.
the operation is AISnake::check_collision( ); and it is a friend of the food class
prepare for masses of code
AI Class
Code:
// Class: AISnake Implementation
AISnake::AISnake(int x = 0, int y = 0)
{
//Image main_image(20, 20);
ImageFile("../Assets/node2.tga").load(nodeimage2);
AIsegments.push_front(Position(20,40));
AIsegments.push_front(Position(40,40));
AIsegments.push_front(Position(60,40));
direction_ = 'n';
}
void AISnake::AIupdate()
{
AIsegments.pop_back();
Position AI_p = AIsegments.front();
// depends upon direction_
switch(direction_)
{
case 'w':
AI_p.x_ -= 20;
break;
case 's':
AI_p.y_ -= 20;
break;
case 'e':
AI_p.x_ += 20;
break;
case 'n':
AI_p.y_ += 20;
break;
}
AIsegments.push_front(AI_p);
if (AI_p.x_ <= 0 || AI_p.x_ >= 800)
{
aFont.print((Image.background, 400, 300, Colour(0, 0, 0)), "You WIN!");
}
else if (AI_p.y_ <= 0 || AI_p.y_ >= 600)
{
aFont.print((Image.background, 400, 300, Colour(0, 0, 0)), "You WIN!");
}
}
void AISnake::AIcheck_collision(int foodx, int foody, int snakex, int snakey)
{
int index = 0;
while (index <= 6)
{
int foodx = foodpositions_[index].x_;
int foody = foodpositions_[index].y_;
int snakex = AI_p.x_;
int snakey = AI_p.y_;
if(snakex == foodx)
{
if(snakey == foody)
{
AIsegments.push_front((AI_p.x_ );
for(int i= 0; i< 5 ; i++)
{
foodpositions_[index] = foodpositions_[index+1];
}
}
}
}
}
food class attribuites
Code:
class food {
//Attributes
protected:
int type_;
Image foodImage_;
int foodcount_;
Position foodpositions_[5];
friend void Snake::check_collision();
friend void AISnake::AIcheck_collision();
// int foodpossiblepos[39];
the complier says that foodpositions_ is not declared in scope and niether is AI_p.x_ and AI_p.y_
why can't it find these?
thanks
ES