Tiling in C ++
that's what i'm working on now
if (osl_keys->held.down)
{
sprite_position = DOWN;
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->y += 16;
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->y += 16;
}
if (osl_keys->held.up)
{
sprite_position = UP;
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->y -= 16;
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->y -= 16;
}
if (osl_keys->held.right)
{
sprite_position = RIGHT;
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->x += 16;
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->x += 16;
}
if (osl_keys->held.left)
{
sprite_position = LEFT;
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->x -= 16;
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->x -= 16;
}
sceKernelDelayThread(750000);
and I figured each sprite would be 32x32 so collision could be easier.
from lokiare1 you still have to check for tile collision. The most thorough way to do a collision is to check to see the position of every visible pixel of the sprite against every other pixel every other sprite, then return a pointer to the sprite that is colliding with. It will be very slow. the method I describe should be slow and dirty working collisions detection. If I'm wrong, tell me how wrong I am.
This is the part I worry about (I want to make sure everything works in my head before I try it like this, I don't go for something random) I spent a few evenings sitting in the shower trying to think about it , or check what was there.
I'm thinking of something preset that the x, y tile is solid, so if a solid object is in front of it, don't move another movement Im working in my post>. >
if (osl_keys->held.down)
{
if (y+1 == bush=>y)
{
sprite_march = 4;
SpriteAnimate();
else
{
sprite_position = DOWN;
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->y += 16;
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->y += 16;
}
But then again, how could I reduce the amount of code by just asking (y + 1 == solid) im not sure how to do this
a source to share
This is not an answer, but a general style note. Have you noticed that your code is repetitive? Because it. Your first code post can be shortened:
int down_direction = 0, right_direction = 0;
if (osl_keys->held.down)
{
down_direction = 16;
sprite_position = DOWN;
}
else if (osl_keys->held.up)
{
down_direction = -16;
sprite_position = UP;
}
else if (osl_keys->held.right)
{
right_direction = 16;
sprite_position = RIGHT;
}
else if (osl_keys->held.left)
{
right_direction = -16;
sprite_position = LEFT;
}
for (int i = 0; i < 2; ++i)
{
SpriteAnimate();
sceKernelDelayThread(20000);
sprite->x += right_direction;
sprite->y += down_direction;
}
sceKernelDelayThread(750000);
There, isn't it better?
To answer your question, you don't want to track the pixel position of your sprite. You want to keep track of the position of the row and column. Then just check the side before moving if the target tile is solid.
a source to share