void moveAlienBullets(){ int i; tankDeathOccurred = 0; for(i = 0; i < NUM_ALIEN_BULLETS; i++){ if(bulletArray[i].type != INACTIVE_BULLET){ //bullet is active bulletArray[i].y += ALIEN_BULLETS_PIXELS_PER_MOVE; bulletArray[i].state = (bulletArray[i].state + 1) % 3; undrawAlienBullet(); ScreenPoint hitCoord = alienBulletCollision(i); if(bulletArray[i].y >= BOTTOM_OF_PLAYABLE_AREA - BULLET_HEIGHT){ bulletArray[i].type = INACTIVE_BULLET; //bullet has gone offscreen so deactivate the bullet clearAlienBullet(i); bulletArray[i].y = -BULLET_HEIGHT; //make sure the tank isn't overwritten by a rogue bullet //schedule the next bullet fire if(tankDeathOccurred) tankDeath(); else insertDC(rand() % MAX_TICS_BETWEEN_ALIEN_FIRE, EVENT_ALIEN_FIRE); } else if(hitCoord.xcoord >= 0 && hitCoord.ycoord >= 0){ if(DB_ON1) xil_printf("These are the alien bullet hit coordiantes: %d, %d\n\r",hitCoord.xcoord, hitCoord.ycoord); if(DB_ON1) xil_printf("And these are the bullet's x,y coordinates: %d, %d\n\r",bulletArray[i].x, bulletArray[i].y); bulletArray[i].type = INACTIVE_BULLET; //deactive the bullet since it's hit either the bunker or the tank clearAlienBullet(i); if(tankDeathOccurred) tankDeath(); else insertDC(rand() % MAX_TICS_BETWEEN_ALIEN_FIRE, EVENT_ALIEN_FIRE); } } } drawAlienBullet(-1); }
// Update the locations of all alien bullets. // This generally means moving the bullets down by two pixels. // However, it also erases the bullets when they reach the bottom line. void updateBullets() { int i; for (i=0; i<BULLET_COUNT; i++) { if (getAlienBullet(i).is_in_flight) { //drawTBullet0(getAlienBullet(i), true); int isHit = checkAlienBulletHits(i); clearAlienBullet(false, getAlienBullet(i)); shiftAlienBullet(i); if (getAlienBullet(i).point.y < 430 && isHit) { incrementBulletStage(i); if (getAlienBullet(i).type == T_type) { switch(getAlienBullet(i).bullet_stage) { case (BULLET_STAGE_0): drawTBullet0(getAlienBullet(i), false); break; case (BULLET_STAGE_1): drawTBullet1(getAlienBullet(i), false); break; case (BULLET_STAGE_2): drawTBullet2(getAlienBullet(i), false); break; default: break; } } else { switch(getAlienBullet(i).bullet_stage) { case (BULLET_STAGE_0): drawSBullet0(getAlienBullet(i), false); break; case (BULLET_STAGE_1): drawSBullet1(getAlienBullet(i), false); break; case (BULLET_STAGE_2): drawSBullet2(getAlienBullet(i), false); break; case (BULLET_STAGE_3): drawSBullet3(getAlienBullet(i), false); break; default: break; } } } else { disableBullet(i); } } } }