Hi all,
I am writing a simple little shooter game (similar to asteroids). I am currently working on the upgrades for my space ship and one of these is a laser. I ave successfully implemented a laser which works nicely. However, the collision detection has not been working.
Below is the code:
Initialized as
Code:GameObject *laser; InitD3DX::d3dspt->Draw(laser->sprite, NULL, laser->centre, laser->position, D3DCOLOR_ARGB(255, 255,255,255));The laser displays but the the enemy ships do not get destroyed when the laser touches them. I get no error messages and am sure I am close but it just doesn't want to work! object1 should refer to the enemy ships as this code is the collision detection for the torpedoes hitting the enemy ships.Code:if (myXBox360Controller->IsButtonPressed(XINPUT_GAMEPAD_X)&& saucer->alive) { this->laser->position->x = saucer->position->x + saucer->spriteWidth - 8; this->laser->position->y = saucer->position->y + saucer->spriteHeight/2; } else { this->laser->position->x = 2000; this->laser->position->y = 2000; } for (std::vector<GameObject*>::iterator it = myEnemys.begin(); it!=myEnemys.end(); it++) { object1 = *it; // If enemy is hit register hit and play sound. if (this->laser->CollisionDetection(this->laser,object1) && this->laser->alive && object1->alive) { object1->alive = false; gameScore+=(level+1)*5; enemysDestroyed++; this->explosionSound->Reset(); this->explosionSound->Play(); object1->count = 0; } }
Any ideas? Thanks
Chris



LinkBack URL
About LinkBacks


