void moveTankBullet(){ if(tankBullet.type != INACTIVE_BULLET){ //bullet is active tankBullet.y -= TANK_BULLET_PIXELS_PER_MOVE; undrawTankBullet(); ScreenPoint hitCoord = tankBulletCollision(); if(tankBullet.y <= TOP_OF_PLAYABLE_AREA ){ tankBullet.type = INACTIVE_BULLET; //bullet has gone offscreen so deactivate the bullet clearTankBullet(); } else if(hitCoord.xcoord >= 0 && hitCoord.ycoord >= 0){ if(DB_ON1) xil_printf("This is oops: %d, %d\n\r",hitCoord.xcoord, hitCoord.ycoord); clearTankBullet(); tankBullet.type = INACTIVE_BULLET; //bullet has hit something deactiveFireTankBulletSound(); if(allAliensDead()){ drawAliens(); alienArray[lastAlienKilled] = NO_ALIEN; drawAliens(); runGameOver(1); } //chooseBunkerBlockToDamage(hitCoord); } drawTankBullet(); } }
void updateAllBullets() { if (getBulletStatus()) { point_t tank_bullet; tank_bullet.x = getTankBulletPosition().x; tank_bullet.y = getTankBulletPosition().y-BULLET_INCREMENT; setTankBulletPosition(tank_bullet); drawTankBullet(true); checkHits(); } updateBullets(); }
void debounceButtons() { int rightVal = MOVE_TANK_RIGHT; int leftVal = MOVE_TANK_LEFT; int fire = TANK_FIRE; if (currentButtonState == 0) { volFlag = false; } // Control volume of sounds in the game if (debounce_timer_count >= BUTTON_DEBOUNCE_WAIT && !volFlag){ if (currentButtonState == VOL_UP){ setVolLevel(getVolLevel() + 1); } else if (currentButtonState == VOL_DOWN){ setVolLevel(getVolLevel() - 1); } volFlag = true; debounce_timer_count = 0; // Reset the debouncing timer } // This waits the given amount of time, so that button presses can be properly debounced. if (debounce_timer_count >= BUTTON_DEBOUNCE_WAIT && !isTankHit()) { if ((currentButtonState == leftVal || currentButtonState == leftVal + fire) && getTankPositionGlobal() >= TANK_BORDER_LEFT){ setTankPositionGlobal(getTankPositionGlobal() - TANK_INCREMENT); drawTank(false, 0, 0); } else if ((currentButtonState == rightVal || currentButtonState == rightVal + fire) && getTankPositionGlobal() <= TANK_BORDER_RIGHT){ setTankPositionGlobal(getTankPositionGlobal() + TANK_INCREMENT); drawTank(false, 0, 0); } if (!getBulletStatus() && (currentButtonState == fire || currentButtonState == rightVal + fire || currentButtonState == leftVal + fire)){ setBulletStatus(true); // Let globals know that there's a tank bullet in the air point_t bullet; // Create a new bullet for the tank bullet.x = getTankPositionGlobal() + (TANK_WIDTH/SCALING_FACTOR); // Assign the bullet's x-val to the middle of the tank bullet.y = TANK_ROW_START; // Assign the bullets' y-val to the top of the tank setTankBulletPosition(bullet); // Set the bullet in globals drawTankBullet(false); // Draw this new bullet setPingFlag(1); } debounce_timer_count = 0; // Reset the debouncing timer } }