1
General / SFML Linker error vs 2010
« on: January 11, 2012, 07:51:17 pm »
Could you explain how you fix it?
thanks
thanks
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
SFML 1.6 I guess :Code: [Select]pac.SetCenter(pac.GetSize().x / 2 , pac.GetSize().y / 2);
pac.GetPosition().x + pac.GetCenter().x?
pac.SetCenter(BLOCKSIZE/2, BLOCKSIZE/2);
pac.TransformToGlobal(pac.GetCenter()).x;
pac.TransformToGlobal(pac.GetCenter()).y;
The code ought to be:Code: [Select]PacPosX = pac.TransformToGlobal(pac.GetCenter()).x/BLOCKSIZE;
PacPosY = pac.TransformToGlobal(pac.GetCenter()).y/BLOCKSIZE;
The code would be pac.TransformToGlobal(pac.GetCenter()).x or y. And you should do pac.SetCenter(halfOfPacMan'sWidth, halfOfPacMan'sHeight). It should also be possible to just offset PacMan.GetPosition().x and y by adding the values here as well.
pac.SetCenter(BLOCKSIZE/2, BLOCKSIZE/2);
pac.TransformToGlobal(pac.GetCenter()).x;
pac.TransformToGlobal(pac.GetCenter()).y;
//then i should get the position on the screen and convert to the correct position on the gameboard.
PacPosX = pac.GetCenter().x/BLOCKSIZE;
PacPosY = pac.GetCenter().x/BLOCKSIZE;
// this should give me the position of the center of the pacman on the screen right?
//after this i checked for it on the gameboard.
if ((tabuleiro[PacPosX+1][PacPosY]!=WALL))
pac.Move(MAX_SPEED, 0);
Casting to int ought to merely truncate the number, not round it up or down. But I think my mistake is that pac.GetPosition gets the top-left x/y coordinate of the sprite by default, when you really need the sprite's center. You would have to use pac.GetCenter().x/y (which you would first need to transform to global coordinates).
Quote from: "gl0w"Quote from: "Vit"Pac-Man is tile-based; your array should be the size of your tile grid. For example, if each of your tiles was 20x20 pixels, and your screen size was 640x480, your tile grid would be 32x24 tiles. Each element in your array would then represent a 20x20 square on the screen.
When you want to move Pac-Man on the screen, you'll need to find out which tile he'll be moving to first. For example, assuming your tile array starts from the top-left, to move right you'll need to check board[pacman.x + 1][pacman.y]. If the element is passable, you can start moving him into the tile; otherwise, do nothing (as he's trying to move into a wall).
Hello,
Could you please tell me what do you mean by "board[pacman.x + 1][pacman.y]" is the position X and Y on the screen? if yes, how can i compare a float number with a integer on the board? I'm not understanding.
Could you kindly explain?
thank you.
Hello:
You would do something like this:Code: [Select]if (board[int(PacMan.GetPosition().x/tileWidth) + 1][int(PacMan.GetPosition().y/tileHeight)] == 0) // Where 0 denotes a passable tile
// Code for moving PacMan to the right;
As you can see, by wrapping the PacMan.GetPostion().x/y values with int( ), you can cast the floats as int. The formula will allow you to get the square Pac-Man is on. For example, on a 640x480 screen with a grid of 32x24 tiles and PacMan's x/y at 100,78, PacMan is at square board[3][3]. The code will check if board[4][3] is a passable square, and if it is, allow PacMan to move there. I hope that helps!
Pac-Man is tile-based; your array should be the size of your tile grid. For example, if each of your tiles was 20x20 pixels, and your screen size was 640x480, your tile grid would be 32x24 tiles. Each element in your array would then represent a 20x20 square on the screen.
When you want to move Pac-Man on the screen, you'll need to find out which tile he'll be moving to first. For example, assuming your tile array starts from the top-left, to move right you'll need to check board[pacman.x + 1][pacman.y]. If the element is passable, you can start moving him into the tile; otherwise, do nothing (as he's trying to move into a wall).
Hi guys I've been making a simple game of pacman. Currently I have the map, Pac-pills, Pac-man, Movement and Powerpills in the game all working as intended.
I'm trying to implement my first ghost and get him fully working before worrying about the others
I really need help making my ghost chase Pacman, After some research I'd like to use Dijkstra's algorithm and nodes but I cant figure out how to implement these into pacman.
I've found several tutorials that show how to use the algorithm, finding a path between 3 or 4 nodes.
The main things I'm having problems with is giving a node a position in my map, how to make the ghost move according to the nodes positions and how to detect which node is closest to the player.
Any help would be appreciated.
void loadMap(int number)
{
int x=0;
int y=0;
string line;
ifstream map;
switch(number)
{
case 1:
map.open("mapa1.txt");
while(map && y<MATRIX_HEIGHT)
{
getline(map,line);
while(x<MATRIX_WIDTH)
{
tabuleiro[x][y]=line[x]-'0';
x++;
}
y++;
x=0;
}
}
map.close();
}
for(int x=0;x<MATRIX_WIDTH;x++)
for(int y=0;y<MATRIX_HEIGHT;y++)
if(tabuleiro[x][y] == 1)
{
Wall.SetPosition((float)(x*BLOCKSIZE),(float)(y*BLOCKSIZE));
App.Draw(Wall);
}
void movePac(int direction, float ElapsedTime)
{
// Desenhar image pac correspondente no ecrã
setImage(direction);
int x= (int)(pac.GetPosition().x/BLOCKSIZE +1);
int y= (int)(pac.GetPosition().y/BLOCKSIZE +1);
float x_x= (pac.GetPosition().x/BLOCKSIZE);
float y_y= (pac.GetPosition().y/BLOCKSIZE);
std::stringstream stream;
stream << "x:" << x_x << "-y:" << y_y << "Wall: " << tabuleiro[x][y];
string st;
stream>>st;
textoPontos.SetText(st);
textoPontos.SetPosition(300, 400);
switch (direction)
{
case UP:
if ((tabuleiro[x][y-1]!=WALL)) //
pac.Move(0, -MAX_SPEED * ElapsedTime);
break;
case DOWN:
if ((tabuleiro[x+1][y]!=WALL))
{
pac.Move(0, MAX_SPEED * ElapsedTime);
}
break;
case RIGHT:
if ((tabuleiro[x+1][y]!=WALL))
if (pac.GetPosition().x + 35 < 640)
pac.Move(MAX_SPEED * ElapsedTime, 0);
//pac.SetPosition(pac.GetPosition().x + 1, pac.GetPosition().y);
else
pac.SetPosition(0, pac.GetPosition().y);
break;
case LEFT:
if ((tabuleiro[x-1][y]!=WALL))
if (pac.GetPosition().x + 35 > 0)
pac.Move(-MAX_SPEED * ElapsedTime, 0);
else
pac.SetPosition(640, pac.GetPosition().y);
break;
}
}