collision detection for template
Posted: Thu Aug 18, 2011 2:04 pm
Hi,
i'm referring to Patater's manual to learn nds programming,
and I need to implement a little collision detection.
I have a ship whose position is given by a template as following:
template <class T>
struct MathVector2D {
T x;
T y;
};
Ship::Ship(SpriteInfo * _spriteInfo) {
................
MathVector2D<float> position;
/* Place the ship in an interesting part of the screen. */
position.x = SCREEN_WIDTH / 2 - spriteInfo->width * 2 +
spriteInfo->width / 2;
position.y = SCREEN_HEIGHT / 2 - spriteInfo->height;
....
}
I need to make something happen once the ship reaches a certain area of the screen,
using conditionals like this, for example:
if((ship->position.x>SCREEN_WIDTH / 3)&&(ship->position.x<SCREEN_WIDTH / 2 )&&(ship->position.y>SCREEN_HEIGHT / 3)&&(ship->position.y<SCREEN_HEIGHT / 2)){...}
but then since the positions are template, its number are in different scheme, and are not stable.
Thus, the conditions don't work...
Is there anyway I could read the sprite's ACTUAL position info on the screen?
Please help me out.
And thanks in advance.
i'm referring to Patater's manual to learn nds programming,
and I need to implement a little collision detection.
I have a ship whose position is given by a template as following:
template <class T>
struct MathVector2D {
T x;
T y;
};
Ship::Ship(SpriteInfo * _spriteInfo) {
................
MathVector2D<float> position;
/* Place the ship in an interesting part of the screen. */
position.x = SCREEN_WIDTH / 2 - spriteInfo->width * 2 +
spriteInfo->width / 2;
position.y = SCREEN_HEIGHT / 2 - spriteInfo->height;
....
}
I need to make something happen once the ship reaches a certain area of the screen,
using conditionals like this, for example:
if((ship->position.x>SCREEN_WIDTH / 3)&&(ship->position.x<SCREEN_WIDTH / 2 )&&(ship->position.y>SCREEN_HEIGHT / 3)&&(ship->position.y<SCREEN_HEIGHT / 2)){...}
but then since the positions are template, its number are in different scheme, and are not stable.
Thus, the conditions don't work...
Is there anyway I could read the sprite's ACTUAL position info on the screen?
Please help me out.
And thanks in advance.