e có class tilemap như vậy mọi ng cho e hỏi làm sao để khi pacman va chạm với gold thì gold k xuất hiện nữa ạ?
#include "tilemap.h"
#include "player.h"
////////////tile.map/////////////
void generateMap(sf::RenderWindow &appWindow, sf::Sprite &pacSprite, direction &nextDirection, direction &key)
{
sf::Texture tileTexture_block;
sf::Texture tileTexture_gold;
tileTexture_block.loadFromFile("tile.png");
tileTexture_gold.loadFromFile("gold.png");
sf::Sprite tile_block;
sf::Sprite tile_gold;
tile_gold.setTexture(tileTexture_gold);
tile_block.setTexture(tileTexture_block);
std::vector < std::vector<int> > tilemap;
tilemap.resize(100, std::vector<int>(100, 0));
int speed = 4;
std::ifstream openfile("Map2.txt");
if (openfile.is_open())
{
std::string line;
int lineCount = 0;
while (std::getline(openfile, line))
{
for (int column = 0; column < line.length(); column++)
{
if (line[column] == '1')
{
tilemap[lineCount][column] = 1;
}
if (line[column] == '2')
{
tilemap[lineCount][column] = 2;
}
lineCount++;
}
}
}
//MAP DRAWING AND COLLISION
for (int i = 0; i<tilemap.size(); i++)
{
for (int j = 0; j < tilemap[0].size(); j++)
{
if (tilemap[j][i] == 1)
{
tile_block.setPosition(i * 32, j * 32);
appWindow.draw(tile_block);
if (tile_block.getGlobalBounds().intersects(pacSprite.getGlobalBounds()))
{
if (nextDirection == none)
{
switch (key)
{
case up:
pacSprite.move(0, speed);
break;
case left:
pacSprite.move(speed, 0);
break;
case right:
pacSprite.move(-speed, 0);
break;
case down:
pacSprite.move(0, -speed);
break;
default:
break;
}
}
else
{
switch (key)
{
case up:
pacSprite.move(0, speed);
break;
case left:
pacSprite.move(speed, 0);
break;
case right:
pacSprite.move(-speed, 0);
break;
case down:
pacSprite.move(0, -speed);
break;
default:
break;
}
key = nextDirection;
nextDirection = none;
}
}
}
if (tilemap[j][i] == 2)
{
tile_gold.setPosition(i * 32, j * 32);
appWindow.draw(tile_gold);
if (tile_gold.getGlobalBounds().intersects(pacSprite.getGlobalBounds()))
{
///////????????????????????????////
}
}
}
}
}