void SiegeTank::blitToScreen() { SDL_Surface* pUnitGraphic = graphic[currentZoomlevel]; int imageW1 = pUnitGraphic->w/numImagesX; int x1 = screenborder->world2screenX(realX); int y1 = screenborder->world2screenY(realY); SDL_Rect source1 = { drawnAngle * imageW1, 0, imageW1, pUnitGraphic->h }; SDL_Rect dest1 = { x1 - imageW1/2, y1 - pUnitGraphic->h/2, imageW1, pUnitGraphic->h }; SDL_BlitSurface(pUnitGraphic, &source1, screen, &dest1); const Coord siegeTankTurretOffset[] = { Coord(8, -12), Coord(0, -20), Coord(0, -20), Coord(-4, -20), Coord(-8, -12), Coord(-8, -4), Coord(-4, -12), Coord(8, -4) }; SDL_Surface* pTurretGraphic = turretGraphic[currentZoomlevel]; int imageW2 = pTurretGraphic->w/NUM_ANGLES; int x2 = screenborder->world2screenX(realX + siegeTankTurretOffset[drawnTurretAngle].x); int y2 = screenborder->world2screenY(realY + siegeTankTurretOffset[drawnTurretAngle].y); SDL_Rect source2 = { drawnTurretAngle * imageW2, 0, imageW2, pTurretGraphic->h }; SDL_Rect dest2 = { x2 - imageW2/2, y2 - pTurretGraphic->h/2, imageW2, pTurretGraphic->h }; SDL_BlitSurface(pTurretGraphic, &source2, screen, &dest2); if(isBadlyDamaged()) { drawSmoke(x1, y1); } }
void UnitBase::blitToScreen() { SDL_Surface* pUnitGraphic = graphic[currentZoomlevel]; int imageW = pUnitGraphic->w/numImagesX; int imageH = pUnitGraphic->h/numImagesY; int x = screenborder->world2screenX(realX); int y = screenborder->world2screenY(realY); SDL_Rect source = { drawnAngle * imageW, drawnFrame * imageH, imageW, imageH }; SDL_Rect dest = { x - imageW/2, y - imageH/2, imageW, imageH }; SDL_BlitSurface(pUnitGraphic, &source, screen, &dest); if(isBadlyDamaged()) { drawSmoke(x, y); } }
void SiegeTankClass::blitToScreen() { SDL_Rect dest, source; dest.x = getDrawnX(); dest.y = getDrawnY(); dest.w = source.w = imageW; dest.h = source.h = imageH; source.y = 0; source.x = drawnAngle*imageW; SDL_BlitSurface(graphic, &source, screen, &dest); //blit base source.x = drawnTurretAngle*source.w; source.y = 0; dest.x = getDrawnX() + TurretOffset[drawnTurretAngle].x; dest.y = getDrawnY() + TurretOffset[drawnTurretAngle].y; SDL_BlitSurface(turretGraphic, &source, screen, &dest); //blit turret if(isBadlyDamaged()) drawSmoke(screenborder->world2screenX(realX), screenborder->world2screenY(realY)); }
void UnitBase::setSpeeds() { float speed = getMaxSpeed(); if(!isAFlyingUnit()) { speed += speed*(1.0f - getTerrainDifficulty((TERRAINTYPE) currentGameMap->getTile(location)->getType())); if(isBadlyDamaged()) { speed *= HEAVILYDAMAGEDSPEEDMULTIPLIER; } } switch(drawnAngle){ case LEFT: xSpeed = -speed; ySpeed = 0; break; case LEFTUP: xSpeed = -speed*DIAGONALSPEEDCONST; ySpeed = xSpeed; break; case UP: xSpeed = 0; ySpeed = -speed; break; case RIGHTUP: xSpeed = speed*DIAGONALSPEEDCONST; ySpeed = -xSpeed; break; case RIGHT: xSpeed = speed; ySpeed = 0; break; case RIGHTDOWN: xSpeed = speed*DIAGONALSPEEDCONST; ySpeed = xSpeed; break; case DOWN: xSpeed = 0; ySpeed = speed; break; case LEFTDOWN: xSpeed = -speed*DIAGONALSPEEDCONST; ySpeed = -xSpeed; break; } }
void UnitBase::move() { if(!moving && !justStoppedMoving && (isAFlyingUnit() == false) && currentGame->randomGen.rand(0,40) == 0 && itemID != Unit_Sandworm) { currentGameMap->viewMap(owner->getTeam(), location, getViewRange() ); } if(moving && !justStoppedMoving) { if((isBadlyDamaged() == false) || isAFlyingUnit()) { realX += xSpeed; realY += ySpeed; } else { realX += xSpeed/2; realY += ySpeed/2; } // check if vehicle is on the first half of the way float fromDistanceX; float fromDistanceY; float toDistanceX; float toDistanceY; if(location != nextSpot) { // check if vehicle is half way out of old tile fromDistanceX = strictmath::abs(location.x*TILESIZE - (realX-bumpyOffsetX) + TILESIZE/2); fromDistanceY = strictmath::abs(location.y*TILESIZE - (realY-bumpyOffsetY) + TILESIZE/2); toDistanceX = strictmath::abs(nextSpot.x*TILESIZE - (realX-bumpyOffsetX) + TILESIZE/2); toDistanceY = strictmath::abs(nextSpot.y*TILESIZE - (realY-bumpyOffsetY) + TILESIZE/2); if((fromDistanceX >= TILESIZE/2) || (fromDistanceY >= TILESIZE/2)) { // let something else go in unassignFromMap(location); oldLocation = location; location = nextSpot; if(isAFlyingUnit() == false && itemID != Unit_Sandworm) { currentGameMap->viewMap(owner->getTeam(), location, getViewRange()); } } } else { // if vehicle is out of old tile fromDistanceX = strictmath::abs(oldLocation.x*TILESIZE - (realX-bumpyOffsetX) + TILESIZE/2); fromDistanceY = strictmath::abs(oldLocation.y*TILESIZE - (realY-bumpyOffsetY) + TILESIZE/2); toDistanceX = strictmath::abs(location.x*TILESIZE - (realX-bumpyOffsetX) + TILESIZE/2); toDistanceY = strictmath::abs(location.y*TILESIZE - (realY-bumpyOffsetY) + TILESIZE/2); if ((fromDistanceX >= TILESIZE) || (fromDistanceY >= TILESIZE)) { if(forced && (location == destination) && !target) { setForced(false); } moving = false; justStoppedMoving = true; realX = location.x * TILESIZE + TILESIZE/2; realY = location.y * TILESIZE + TILESIZE/2; bumpyOffsetX = 0.0f; bumpyOffsetY = 0.0f; oldLocation.invalidate(); } } bumpyMovementOnRock(fromDistanceX, fromDistanceY, toDistanceX, toDistanceY); } else { justStoppedMoving = false; } checkPos(); }
void UnitBase::attack() { if(numWeapons) { Coord targetCenterPoint; Coord centerPoint = getCenterPoint(); bool bAirBullet; if(target.getObjPointer() != NULL) { targetCenterPoint = target.getObjPointer()->getClosestCenterPoint(location); bAirBullet = target.getObjPointer()->isAFlyingUnit(); } else { targetCenterPoint = currentGameMap->getTile(attackPos)->getCenterPoint(); bAirBullet = false; } int currentBulletType = bulletType; Sint32 currentWeaponDamage = currentGame->objectData.data[itemID][originalHouseID].weapondamage; if(getItemID() == Unit_Trooper) { // Troopers change weapon type depending on distance float distance = distanceFrom(centerPoint, targetCenterPoint); if(distance > 2*TILESIZE) { currentBulletType = Bullet_SmallRocket; } } if(primaryWeaponTimer == 0) { bulletList.push_back( new Bullet( objectID, ¢erPoint, &targetCenterPoint, currentBulletType, currentWeaponDamage, bAirBullet) ); playAttackSound(); primaryWeaponTimer = getWeaponReloadTime(); secondaryWeaponTimer = 15; if(attackPos && getItemID() != Unit_SonicTank && currentGameMap->getTile(attackPos)->isSpiceBloom()) { setDestination(location); forced = false; attackPos.invalidate(); } // shorten deviation time if(deviationTimer > 0) { deviationTimer = std::max(0,deviationTimer - MILLI2CYCLES(20*1000)); } } if((numWeapons == 2) && (secondaryWeaponTimer == 0) && (isBadlyDamaged() == false)) { bulletList.push_back( new Bullet( objectID, ¢erPoint, &targetCenterPoint, currentBulletType, currentWeaponDamage, bAirBullet) ); playAttackSound(); secondaryWeaponTimer = -1; if(attackPos && getItemID() != Unit_SonicTank && currentGameMap->getTile(attackPos)->isSpiceBloom()) { setDestination(location); forced = false; attackPos.invalidate(); } // shorten deviation time if(deviationTimer > 0) { deviationTimer = std::max(0,deviationTimer - MILLI2CYCLES(20*1000)); } } } }