概述 RPG 平铺空间

发布于 2024-07-19 17:46:19 字数 1598 浏览 4 评论 0原文

我试图将其置于角色在图块中的位置,当它们向上或向下移动时,它会移动到下一个图块,但我不知道该怎么做。 现在,我已将其设置为角色按像素移动,但我希望它移动 1 平方。

现在的代码是这样的,它可以工作,但在像素模式下有问题。 我相信如果按块划分可能会效果更好,但无论如何我可能会改变它。

float spritewidth  = sprite->stretchX;
float spriteheight = sprite->stretchY;
float bushwidth  = bush->stretchX;
float bushheight = bush->stretchY;
//Basic border collision
if (sprite->x <= 0)
 sprite->x = 0;

if (sprite->y <= 0)
 sprite->y = 0;

if (sprite->x >= 455)
 sprite->x = 455;

if (sprite->y >= 237)
 sprite->y = 237;

if ( (sprite->x + spritewidth > bush->x) && (sprite->x < bush->x + bushwidth) && (sprite->y + spriteheight > bush->y) && (sprite->y < bush->y + bushheight) ) 
{
         bushcol = 1;               
}
else
{
        bushcol = 0;      
}

if (osl_keys->held.down)
{
if (bushcol == 1) 
{
sprite->y = bush->y - spriteheight - 3;
        bushcol = 0; 
}
else
{
        bushcol = 0; 
        sprite->y += 3;
}
}
if (osl_keys->held.up)
{
 if (bushcol == 1) 
{
    sprite->y = bush->y + bushheight + 3;
    bushcol = 0;
}
    else
{ 
        bushcol = 0; 
        sprite->y -= 3;
}
}
if (osl_keys->held.right)
{
 if (bushcol == 1) 
{
    sprite->x = bush->x - spritewidth - 3;
    bushcol = 0;
}
    else
{ 
         bushcol = 0; 
    sprite->x += 3;}
}
if (osl_keys->held.left)
{
        if (bushcol == 1) 
{
    sprite->x = bush->x + bushwidth + 3;
    bushcol = 0; 
}
    else
{ 
        bushcol = 0; 
        sprite->x -= 3;
}
}

I'm trying to make it where the character is in a tile and when they move up or down it moves to the next tile but I'm not sure how to do that. Right now, I have it set up where the character moves by pixels but I want it to move by 1 square.

The code right now is this, and it works, but it's glitchy in pixel mode. I believe if it was by blocks it might work better but I might change it anyway.

float spritewidth  = sprite->stretchX;
float spriteheight = sprite->stretchY;
float bushwidth  = bush->stretchX;
float bushheight = bush->stretchY;
//Basic border collision
if (sprite->x <= 0)
 sprite->x = 0;

if (sprite->y <= 0)
 sprite->y = 0;

if (sprite->x >= 455)
 sprite->x = 455;

if (sprite->y >= 237)
 sprite->y = 237;

if ( (sprite->x + spritewidth > bush->x) && (sprite->x < bush->x + bushwidth) && (sprite->y + spriteheight > bush->y) && (sprite->y < bush->y + bushheight) ) 
{
         bushcol = 1;               
}
else
{
        bushcol = 0;      
}

if (osl_keys->held.down)
{
if (bushcol == 1) 
{
sprite->y = bush->y - spriteheight - 3;
        bushcol = 0; 
}
else
{
        bushcol = 0; 
        sprite->y += 3;
}
}
if (osl_keys->held.up)
{
 if (bushcol == 1) 
{
    sprite->y = bush->y + bushheight + 3;
    bushcol = 0;
}
    else
{ 
        bushcol = 0; 
        sprite->y -= 3;
}
}
if (osl_keys->held.right)
{
 if (bushcol == 1) 
{
    sprite->x = bush->x - spritewidth - 3;
    bushcol = 0;
}
    else
{ 
         bushcol = 0; 
    sprite->x += 3;}
}
if (osl_keys->held.left)
{
        if (bushcol == 1) 
{
    sprite->x = bush->x + bushwidth + 3;
    bushcol = 0; 
}
    else
{ 
        bushcol = 0; 
        sprite->x -= 3;
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耳根太软 2024-07-26 17:46:19

如果您希望角色一次移动一个图块/方块/块,只需将精灵移动图块宽(或高)的像素数即可。

const int tile_width = 32; // or something

// and then
sprite->x += tile_width;

If you want the character to move one tile/square/block at a time, just move the sprite the number of pixels the tile is wide (or tall).

const int tile_width = 32; // or something

// and then
sprite->x += tile_width;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文