使用oslib与PSPSDK工具链Im和出于某种原因,这并不工作,我想办法

它会

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();
  }
}
有帮助吗?

解决方案

有一两件事你可以做的,是不是具有字符“向后移动”的时候,他打布什,你可以有自己的位置而改变。

我的意思是这样的:(只使用了为例子)

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

这样一来,每当精灵发生碰撞时,它只是设置的位置,而不是得到它向后移动。

有其他的方法做碰撞检测,但我现在这样太累了,拉过一个智能的,更可读,回答现在...在谷歌的搜索将变成了许多成果。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top