////////////////////////////////////////////////////////////////////////// // GaGameComponent //virtual void GaGameComponent::update( BcReal Tick ) { BcU32 Param = FontMaterial_->findParameter( "aAlphaTestStep" ); FontMaterial_->setParameter( Param, BcVec2d( 0.4f, 0.5f ) ); if( GameState_ == GS_PLAYING ) { pSimulator_->tick( Tick ); if( pSimulator_->getTimeOut() > 5.0f ) { GameState_ = GS_TIMEOUT; } if( pSimulator_->getUnitCount( TeamID_ ) == 0 || pSimulator_->getUnitCount( 1 - TeamID_ ) == 0 ) { GameState_ = GS_OVER; } if( !Networked_ ) { AITickTime_ -= Tick; if( AITickTime_ < 0.0f ) { pSimulator_->runAI( 1 - TeamID_ ); AITickTime_ = AITickMaxTime_; } } } //if( TeamID_ == 0 ) { if( CanvasComponent_.isValid() ) { OsClient* pClient = OsCore::pImpl()->getClient( 0 ); BcReal HW = static_cast< BcReal >( pClient->getWidth() ) / 2.0f; BcReal HH = static_cast< BcReal >( pClient->getHeight() ) / 2.0f; BcReal AspectRatio = HW / HH; BcMat4d Ortho; Ortho.orthoProjection( -HW, HW, HH, -HH, -1.0f, 1.0f ); // Clear canvas and push projection matrix. CanvasComponent_->clear(); CanvasComponent_->pushMatrix( Ortho ); CanvasComponent_->setMaterialComponent( BackgroundMaterial_ ); CanvasComponent_->drawSpriteCentered( BcVec2d( 0.0f, 0.0f ), BcVec2d( 1280.0f, 720.0f ), 0, RsColour( 1.0f, 1.0f, 1.0f, 1.0f ), 0 ); CanvasComponent_->setMaterialComponent( SpriteSheetMaterials_[ 0 ] ); pSimulator_->render( CanvasComponent_, 0 ); CanvasComponent_->setMaterialComponent( SpriteSheetMaterials_[ 1 ] ); pSimulator_->render( CanvasComponent_, 1 ); // Find unit over mouse. GaGameUnitIDList SelectionList; if( MouseDown_ ) { if( BoxSelection_ ) { pSimulator_->findUnits( SelectionList, StartGameCursorPosition_, EndGameCursorPosition_, BcErrorCode, BcErrorCode ); } } else { pSimulator_->findUnits( SelectionList, GameCursorPosition_, 0.8f, BcErrorCode, BcErrorCode ); while( SelectionList.size() > 1 ) { SelectionList.pop_back(); } } for( BcU32 Idx = 0; Idx < UnitSelection_.size(); ++Idx ) { SelectionList.push_back( UnitSelection_[ Idx ] ); } CanvasComponent_->setMaterialComponent( HUDMaterial_ ); pSimulator_->renderHUD( CanvasComponent_, SelectionList, TeamID_ ); } switch( GameState_ ) { case GS_PLAYING: { // Draw cursor. CanvasComponent_->setMaterialComponent( HUDMaterial_ ); CanvasComponent_->drawSpriteCentered( BcVec2d( CursorPosition_.x(), CursorPosition_.y() ), BcVec2d( 64.0f, 64.0f ), 1, AttackMove_ ? RsColour::RED : RsColour::WHITE, 10 ); // Draw selection box. if( MouseDown_ && BoxSelection_ ) { BcVec2d Min = BcVec2d( StartGameCursorPosition_.x(), StartGameCursorPosition_.y() ) * 32.0f; BcVec2d Max = BcVec2d( GameCursorPosition_.x(), GameCursorPosition_.y() ) * 32.0f; CanvasComponent_->drawSprite( Min, Max - Min, 0, RsColour::GREEN * RsColour( 1.0f, 1.0f, 1.0f, 0.1f ), 11 ); } std::string Text0 = TeamID_ == 0 ? "YOU ARE RED!" : "YOU ARE BLUE!"; BcVec2d TextSize0 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text0, RsColour::WHITE, BcTrue ); Font_->draw( CanvasComponent_, ( -TextSize0 / 2.0f ) + BcVec2d( 0.0f, -350.0f ), Text0, TeamID_ == 0 ? RsColour::RED : RsColour::BLUE, BcFalse ); } break; case GS_TIMEOUT: { std::string Text0 = "Connection timed out :("; std::string Text1 = "Press ESC to Quit."; BcVec2d TextSize0 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text0, RsColour::WHITE, BcTrue ); Font_->draw( CanvasComponent_, ( -TextSize0 / 2.0f ) + BcVec2d( 0.0f, -64.0f ), Text0, RsColour::WHITE, BcFalse ); BcVec2d TextSize1 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text1, RsColour::WHITE, BcTrue ); Font_->draw( CanvasComponent_, ( -TextSize1 / 2.0f ) + BcVec2d( 0.0f, 64.0f ), Text1, RsColour::WHITE, BcFalse ); } break; case GS_OVER: { if( pSimulator_->getUnitCount( TeamID_ ) > 0 ) { std::string Text0 = "You Won! :D"; std::string Text1 = "Press ESC to Quit."; BcVec2d TextSize0 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text0, RsColour::WHITE, BcTrue ); Font_->draw( CanvasComponent_, ( -TextSize0 / 2.0f ) + BcVec2d( 0.0f, -64.0f ), Text0, RsColour::WHITE, BcFalse ); BcVec2d TextSize1 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text1, RsColour::WHITE, BcTrue ); Font_->draw( CanvasComponent_, ( -TextSize1 / 2.0f ) + BcVec2d( 0.0f, 64.0f ), Text1, RsColour::WHITE, BcFalse ); } else { std::string Text0 = "You Lost! :<"; std::string Text1 = "Press ESC to Quit."; BcVec2d TextSize0 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text0, RsColour::WHITE, BcTrue ); Font_->draw( CanvasComponent_, ( -TextSize0 / 2.0f ) + BcVec2d( 0.0f, -64.0f ), Text0, RsColour::WHITE, BcFalse ); BcVec2d TextSize1 = Font_->draw( CanvasComponent_, BcVec2d( 0.0f, 0.0f ), Text1, RsColour::WHITE, BcTrue ); Font_->draw( CanvasComponent_, ( -TextSize1 / 2.0f ) + BcVec2d( 0.0f, 64.0f ), Text1, RsColour::WHITE, BcFalse ); } } break; } } }