C++ 中 psp 的 OSlib 的冲突问题

发布于 2024-07-20 22:27:33 字数 2090 浏览 10 评论 0原文

我将 oslib 与 pspsdk 工具链一起使用,由于某种原因,这并不像我想象的那样工作。

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;

 //Bush
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 == 0)
   {
     sprite->y += 4;
     sprite_position = DOWN;
     SpriteAnimate();
   }
   else
   { 
     sprite->y -= 6;
     bushcol = 0;
   }
 }

 if (osl_keys->held.up)    
 {
   if (bushcol == 0)
   {
     sprite->y -= 4;
     sprite_position = UP;
     SpriteAnimate();
   }
   else
   { 
     sprite->y += 6;
     bushcol = 0;
   }
 }

 if (osl_keys->held.right)
 {
   if (bushcol == 0)
   {
     sprite->x += 4;
     sprite_position = RIGHT;
     SpriteAnimate();
   }
   else
   { 
     sprite->x -= 6;
     bushcol = 0;
   }
 }

 if (osl_keys->held.left)
 {
   if (bushcol == 0)
   {
     sprite->x -= 4;
     sprite_position = LEFT;
     SpriteAnimate();
   }
   else
   { 
     sprite->x += 6;
     bushcol = 0;
   }
 }

当我试图离开时,精灵开始从灌木丛的相反方向移动,但最终会自由落体,

任何更好的碰撞方法或建议

我什至有 对每个按钮都尝试了这个,但仍然没有运气

if (osl_keys->held.down)
{
  if ( (sprite->x + spritewidth > bush->x) &&
       (sprite->x < bush->x + bushwidth) && 
       (sprite->y + spriteheight > bush->y) &&
       (sprite->y < bush->y + bushheight) ) 
  {
    sprite->y -= 4; 
  }
  else
  {
    sprite->y += 2;
    sprite_position = DOWN;
    SpriteAnimate();
  }
}

Im using oslib with the pspsdk toolchain and for some reason this doesnt work the way I think it would

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;

 //Bush
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 == 0)
   {
     sprite->y += 4;
     sprite_position = DOWN;
     SpriteAnimate();
   }
   else
   { 
     sprite->y -= 6;
     bushcol = 0;
   }
 }

 if (osl_keys->held.up)    
 {
   if (bushcol == 0)
   {
     sprite->y -= 4;
     sprite_position = UP;
     SpriteAnimate();
   }
   else
   { 
     sprite->y += 6;
     bushcol = 0;
   }
 }

 if (osl_keys->held.right)
 {
   if (bushcol == 0)
   {
     sprite->x += 4;
     sprite_position = RIGHT;
     SpriteAnimate();
   }
   else
   { 
     sprite->x -= 6;
     bushcol = 0;
   }
 }

 if (osl_keys->held.left)
 {
   if (bushcol == 0)
   {
     sprite->x -= 4;
     sprite_position = LEFT;
     SpriteAnimate();
   }
   else
   { 
     sprite->x += 6;
     bushcol = 0;
   }
 }

The sprite starts moving in the opposite direction from the bush when I try to move away but does fall free eventually

any better collision methods or suggestions

I even tried this for each button and still no luck

if (osl_keys->held.down)
{
  if ( (sprite->x + spritewidth > bush->x) &&
       (sprite->x < bush->x + bushwidth) && 
       (sprite->y + spriteheight > bush->y) &&
       (sprite->y < bush->y + bushheight) ) 
  {
    sprite->y -= 4; 
  }
  else
  {
    sprite->y += 2;
    sprite_position = DOWN;
    SpriteAnimate();
  }
}

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

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

发布评论

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

评论(1

剧终人散尽 2024-07-27 22:27:33

你可以做的一件事是,你可以改变他的位置,而不是让角色在撞到灌木丛时“向后移动”。

我的意思是这样的:(仅使用 up 作为示例)。

 if (osl_keys->held.up)    
 {
   if (bushcol == 0)
   {
     sprite->y -= 4;
     sprite_position = UP;
     SpriteAnimate();
   }
   else
   { 
     sprite->y = bush->y + 2;
     bushcol = 0;
   }
 }

这样,每当精灵碰撞时,它只是设置位置而不是让它向后移动。

还有其他方法可以进行碰撞检测,但我现在太累了,无法立即给出一个智能的、可读性更差的答案……在谷歌上搜索会出现很多结果。

One thing you can do, is instead of having the character "move backwards" when he hits the bush, you can have his position changed.

What I mean is something like this: (Using only up for the example).

 if (osl_keys->held.up)    
 {
   if (bushcol == 0)
   {
     sprite->y -= 4;
     sprite_position = UP;
     SpriteAnimate();
   }
   else
   { 
     sprite->y = bush->y + 2;
     bushcol = 0;
   }
 }

That way, whenever the sprite collides, it just sets the position instead getting it to move backwards.

There are other methods for doing collision detection, but I'm way too tired right now to pull off an intelligent, much less readable, answer right now... A search on google will turn up many results.

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