Skip to: Site menu | Main content


Welcome to PSP-Programming.com, a place for developers to get together.

Welcome to the forums. Here you can find other user tutorials as well as homebrew releases and the source code repository. You can also ask for help with your code here and post your own homebrew!

PSP-Programming.com Forums
February 11, 2012, 01:08:54 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

News: Welcome to PSP-Programming.com
Home Help Search Shop Login Register
Digg This!
Pages: [1]
Print
Author Topic: Problems with collision  (Read 523 times)
PopPooB
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 9
621.77 points

View Inventory
Send Money to PopPooB

View Profile
« on: May 12, 2009, 10:25:21 AM »

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


Code:
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
Logged


PopPooB
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 9
621.77 points

View Inventory
Send Money to PopPooB

View Profile
« Reply #1 on: May 13, 2009, 09:06:02 AM »

I just started programming and im practicing with the basics

Quote from: Furypaw;1179397
Keep the four sides of collision seperate, e.g. have functions for collision being 2,3 and 4 as well. Also, rather than making your own variables for the width of something, just use sprite->stretchX. Also works with Y

I tried something like that and it didnt work the dude just flew aroud the map till he hit the corner

Im thinking of scraping the whole bush idea for now

 

i even tried this for each button and still no luck

Code:
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();

    }

}
Logged
Pages: [1]
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.306 seconds with 26 queries.
Sister Sites: Guitar Hero 4   BrokeniTouch.com