ScreenTitle.cpp

Go to the documentation of this file.
00001 #include "global.h"
00002 #include "ScreenTitle.h"
00003 #include "MercuryScreenManager.h"
00004 #include "MercuryLoadableModel.h"
00005 #include "MercuryInput.h"
00006 #include "MercuryLog.h"
00007 #include "MercuryTheme.h"
00008 #include "MercuryDisplay.h"
00009 #include "MercuryLoadableModel.h"
00010 
00011 #if defined(_EE)
00012 #include "MercuryDisplayEE.h"
00013 #endif
00014 #include "MercuryTheme.h"
00015 
00016 KeyMappingWithCode( button_a, "0-97" );
00017 KeyMappingWithCode( button_b, "0-98" );
00018 KeyMappingWithCode( button_c, "0-99" );
00019 KeyMappingWithCode( button_t, "0-116" );
00020 KeyMappingWithCode( button_u, "0-117" );
00021 
00022 #include "MercuryObjectFactory.h"
00023 REGISTER_SCREEN_CLASS( ScreenHgTitle )
00024 
00025 #define     MC_INPUTMAPPED      1       //convention: MESSAGE CODE
00026 #define     MC_INPUTUNMAPPED    2   
00027 
00028 ScreenHgTitle::~ScreenHgTitle()
00029 {
00030     DISPLAY->RemoveLight(&m_light);
00031     SAFE_DELETE(m_mercury);
00032 }
00033 
00034 void ScreenHgTitle::Init()
00035 {
00036     MercuryScreen::Init();  
00037 
00038     m_mercury = new MercuryLoadableModel;
00039     m_mercury->SetName( "Mercury" );
00040     m_mercury->Init();
00041     m_mercury->Load(GET_MODEL_BY_NAME( "Mercury" ));
00042     m_mercury->Tweening.AddCommand( THEME.GetMetricS( m_name, "MercuryTween" ) );
00043     AddPerspObject(m_mercury);
00044 
00045     //The deleting of explosion will happen in metrics or when the screen is destroyed.
00046     MercuryModel* m_mercuryExplode = new MercuryLoadableModel;
00047     m_mercuryExplode->SetName( "MercuryExplode" );
00048     m_mercuryExplode->Init();
00049     m_mercuryExplode->Load(GET_MODEL_BY_NAME( "Mercury" ));
00050     m_mercuryExplode->Tweening.AddCommand( THEME.GetMetricS( m_name, "MercuryExplodeTween" ) );
00051     AddPerspObject(m_mercuryExplode, true);
00052 
00053 /*  MercurySprite* background = new MercurySprite;
00054     m_pBackground = background;
00055     background->SetName(m_name + " background");
00056     background->LoadImage( THEME.GetMetricS( m_name, "background" ));
00057     background->SetProjectionType(ORTHOGRAPHIC);
00058     background->MoveX(320);
00059     background->MoveY(240);*/
00060     //The ScreenObject will delete this when destructing
00061 
00062     m_logo.SetName("MercuryEngine");
00063     m_logo.Init();
00064     m_logo.LoadImage( THEME.GetMetricS( m_name, m_logo.GetName()+"Image") );
00065 //  m_logo.SetProjectionType(ORTHOGRAPHIC);
00066     m_logo.Tweening.AddCommand( THEME.GetMetricS( m_name, m_logo.GetName()+"OnCommand") );
00067     AddOrthoObject(&m_logo);
00068 
00069     m_iDirection = 0;
00070     fTotalTime = 0;
00071 
00072     //Setup a light
00073     m_light.Init();
00074     m_light.SetY(100);
00075     m_light.SetX(-100);
00076     m_light.SetZ(110);
00077     m_light.SetAttenuation(0.001f, Attenuation::LINEAR);
00078 //  m_light.SetStatic(true);
00079     DISPLAY->AddLight(&m_light);
00080 
00081 //  m_pCamera = new MercuryCamera;
00082 //  m_pCamera->Init();
00083 //  AddObject(m_pCamera);
00084 
00085     this->RegisterMessage( MC_INPUTMAPPED, "mappedinput" );
00086 }
00087 
00088 void ScreenHgTitle::Message( int Message, PStack & data, const MString & name )
00089 {
00090     switch ( Message ) 
00091     {
00092     case MC_INPUTMAPPED:
00093         {
00094             InputMessageStruct c(data);
00095             if ( c.code == button_c )
00096             {
00097                 if ( c.type == IET_DOWN )
00098                 {
00099                     m_logo.Tweening.StopTweening();
00100                     m_logo.Tweening.AddCommand( "hide,0;linear,2;rotationz,0;diffuse,1,1,1,1");
00101                 }
00102                 if ( c.type == IET_RELEASE )
00103                 {
00104                     m_logo.Tweening.StopTweening();
00105                     m_logo.Tweening.AddCommand( "hide,0;linear,2;rotationz,360;diffuse,1,1,1,1");
00106                 }
00107                 if ( m_mercury->GetName() == GET_MODEL_BY_NAME( "jupiter" )  )
00108                 {
00109                     if ( c.type == IET_DOWN )
00110                         ((MercuryLoadableModel*)m_mercury)->GetAnimationState( 3 ).Trigger();
00111                     else
00112                         ((MercuryLoadableModel*)m_mercury)->GetAnimationState( 2 ).Trigger();
00113                 }
00114             }
00115             if ( c.code == button_t )
00116             {
00117                 if ( c.type == IET_RELEASE )
00118                 {
00119                     RemoveObject(m_mercury);
00120                     SAFE_DELETE(m_mercury);
00121                     m_mercury = new MercuryLoadableModel;
00122                     m_mercury->SetName( "Jupiter" );
00123                     m_mercury->Init();
00124                     m_mercury->Load( GET_MODEL_BY_NAME( "jupiter" ) );
00125                     m_mercury->Tweening.StopTweening();
00126 
00127                     MVector< MercuryLoadableModel::LoadableModelAnimationInfo > pTweenCommands;
00128 
00129                     pTweenCommands.resize(4);
00130                     pTweenCommands[0].sAnimationName = "walk_lower";
00131                     pTweenCommands[0].fPercent = .5;
00132                     pTweenCommands[1].sAnimationName = "walk_upper";
00133                     pTweenCommands[1].fPercent = .25;
00134 
00135                     pTweenCommands[2].sAnimationName = "shootright_upper";
00136                     pTweenCommands[2].bLoop = pTweenCommands[2].bRunning = false;
00137                     pTweenCommands[3].sAnimationName = "shootleft_upper";
00138                     pTweenCommands[3].bLoop = pTweenCommands[3].bRunning = false;
00139                     ((MercuryLoadableModel*)m_mercury)->SetAnimationState( pTweenCommands );
00140 
00141                     this->AddPerspObject(m_mercury);
00142                     m_mercury->SetDrawOrder(-1);
00143                     m_mercury->SetZ(-400);
00144                     m_mercury->MoveY(-20);
00145                 }
00146             }
00147             if ( c.code == button_u )
00148             {
00149                 if ( c.type == IET_RELEASE )
00150                 {
00151                     m_logo.LoadImage( THEME.GetMetricS( GetName(), "DownloadImage" ) );
00152 
00153                     m_mercury->GetMaterial(0)->EditTexture(0)->Tweening.AddCommand( THEME.GetMetricS(m_name, "MercuryTextureTween"));
00154                 }
00155             }
00156         }
00157         break;
00158     };
00159 }
00160 
00161 void ScreenHgTitle::Update( const float dTime )
00162 {
00163     fTotalTime += dTime;
00164     if ( fTotalTime > THEME.GetMetricF( GetName(), "RestrainInput" ) )
00165     {
00166         int x,y;
00167         INPUTMAN->GetCursorPosition( x, y );
00168         m_mercury->SetRotX( float(y)/3.0f );
00169         m_mercury->SetRotY( float(x)/3.0f );
00170     }
00171     if ( INPUTMAN->IsButtonDown( button_a ) )
00172     {
00173         m_mercury->MoveX( -20*dTime );
00174     }
00175     if ( INPUTMAN->IsButtonDown( button_b ) )
00176     {
00177         m_mercury->MoveX( 20*dTime );
00178     }
00179 
00180     MercuryScreen::Update( dTime );
00181 }
00182 
00183 /* 
00184  * Copyright (c) 2005-2006, Joshua Allen
00185  * All rights reserved.
00186  *
00187  * Redistribution and use in source and binary forms, with or
00188  * without modification, are permitted provided that the following
00189  * conditions are met:
00190  *  -   Redistributions of source code must retain the above
00191  *      copyright notice, this list of conditions and the following disclaimer.
00192  *  -   Redistributions in binary form must reproduce the above copyright
00193  *      notice, this list of conditions and the following disclaimer in
00194  *      the documentation and/or other materials provided with the distribution.
00195  *  -   Neither the name of the Mercury Engine nor the names of its
00196  *      contributors may be used to endorse or promote products derived from
00197  *      this software without specific prior written permission.
00198  *
00199  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00200  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00201  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00202  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00203  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00204  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00205  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00206  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00207  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00208  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00209  */

Hosted by SourceForge.net Logo