00001 #include "global.h"
00002 #include "ScreenHelloWorld.h"
00003 #include "MercuryTheme.h"
00004 #include "MercuryLog.h"
00005 #include "MercuryUtil.h"
00006 #include "MercuryDisplay.h"
00007 #include "MercuryInput.h"
00008
00009 #define MC_INPUTMAPPED 1 //convention: MESSAGE CODE
00010 #define MC_INPUTUNMAPPED 2
00011
00012 KeyMappingWithCode( button_a, "0-97" );
00013
00014 KeyMappingWithCode( button_b, "0-98" );
00015 KeyMappingWithCode( button_c, "0-99" );
00016 KeyMappingWithCode( button_d, "0-100" );
00017
00018 #include "MercuryObjectFactory.h"
00019 REGISTER_SCREEN_CLASS( ScreenHelloWorld )
00020
00021 void ScreenHelloWorld::Init()
00022 {
00023 MercuryScreen::Init();
00024
00025 m_held = false;
00026
00027 m_sprHello.SetName( "HelloSprite" );
00028 m_sprHello.Init();
00029 m_sprHello.LoadImage( THEME.GetMetricS( GetName(), "HelloImage" ) );
00030 m_sprHello.Tweening.AddCommand(THEME.GetMetricS( GetName(), m_sprHello.GetName()+"OnCommand" ) );
00031 m_sprHello.SetRotX(180);
00032 m_sprHello.SetScale( MercuryPoint(0.3, 0.3, 1) );
00033 AddPerspObject( &m_sprHello );
00034 m_timeElasped = 0;
00035
00036 Tweening.AddCommand(THEME.GetMetricS( GetName(), "GenericParticle" ) , MercuryTweenState::GLOBAL, "GenericParticle" ) ;
00037 Tweening.AddCommand(THEME.GetMetricS( GetName(), "Firework" ), MercuryTweenState::GLOBAL, "Firework" );
00038
00039 m_camera.Init();
00040 AddObject(&m_camera);
00041
00042 LOG.Info( THEME.GetMetricS( GetName(), "InfoComment" ) );
00043
00044
00045 m_light.Init();
00046 m_light.SetY(100);
00047 m_light.SetX(-100);
00048 m_light.SetZ(110);
00049 m_light.SetAttenuation(0.001f, Attenuation::LINEAR);
00050
00051 DISPLAY->AddLight(&m_light);
00052
00053 unsigned int numImg = THEME.GetMetricI( GetName(), "NumberImages" );
00054 m_imagePaths.resize( numImg );
00055 for (unsigned int i = 0; i < numImg; ++i)
00056 m_imagePaths[i] = THEME.GetMetricS( GetName(), ssprintf("Image%d",i) );
00057
00058 m_delay = THEME.GetMetricF( GetName(), "ShellDelay" );
00059 m_maxPoints = THEME.GetMetricI( GetName(), "MaxPointsInShell" );
00060 m_minPoints = THEME.GetMetricI( GetName(), "MinPointsInShell" );
00061
00062 this->RegisterMessage( MC_INPUTMAPPED, "mappedinput" );
00063 }
00064
00065 void ScreenHelloWorld::Update( const float dTime )
00066 {
00067 m_timeElasped += dTime;
00068 if (m_timeElasped >= m_delay)
00069 {
00070 m_timeElasped = 0;
00071 float fCenterX = float( rand()%640 );
00072 float fCenterY = float( rand()%480 );
00073
00074 float fRadius = float( rand()%100 )+100.0f;
00075
00076 bool bMulticolor = false;
00077
00078 if ( ( rand() % 3 ) == 0 )
00079 bMulticolor = true;
00080
00081 int iParticles = (rand()%(m_maxPoints-m_minPoints))+m_minPoints;
00082
00083 float ColorR = float(rand()%100)/100.0f;
00084 float ColorB = float(rand()%100)/100.0f;
00085 float ColorG = float(rand()%100)/100.0f;
00086
00087 int ModType = rand()%m_imagePaths.size();
00088 float RandScale = (50 + (rand()%100))/150.0f;
00089
00090 MercuryParticleField* seed = (MercuryParticleField*)Spawn( "MercuryParticleField", "Firework", ORTHOGRAPHIC );
00091 seed->Tweening.AddCommand( THEME.GetMetricS( GetName(), "Firework" ) );
00092
00093 seed->LoadImage( m_imagePaths[ModType] );
00094
00095 for ( int i = 0; i < iParticles; i++ )
00096 {
00097 float fLifetime = float( rand()%100 )/100.0f+0.3f;
00098 MercuryObject* c = seed->SpawnParticle();
00099
00100 c->SetScale( MercuryPoint(RandScale, RandScale, 1.0) );
00101
00102 c->SetZ(0);
00103 c->SetY( fCenterY );
00104 c->SetX( fCenterX );
00105
00106 if ( bMulticolor )
00107 {
00108 ColorR = float(rand()%100)/100.0f;
00109 ColorG = float(rand()%100)/100.0f;
00110 ColorB = float(rand()%100)/100.0f;
00111 }
00112
00113 float fAngle = float(rand()%200)/200.0f*6.283f;
00114 float fActRadius = powf((float(rand()%200)/200.0f),0.25);
00115 float fNewX = fActRadius*fRadius * COS( fAngle )+fCenterX;
00116 float fNewY = fActRadius*fRadius * SIN( fAngle )+fCenterY;
00117
00118
00119 PStack KArgs;
00120 KArgs.PushItemBack( PSElement( ColorR ) );
00121 KArgs.PushItemBack( PSElement( ColorG ) );
00122 KArgs.PushItemBack( PSElement( ColorB ) );
00123 KArgs.PushItemBack( PSElement( fLifetime ) );
00124 KArgs.PushItemBack( PSElement( fNewX ) );
00125 KArgs.PushItemBack( PSElement( fNewY ) );
00126 int rotz = (rand()%1000) - 500;
00127 KArgs.PushItemBack( PSElement( rotz ) );
00128 c->Tweening.ExecuteCommand( "GenericParticle", KArgs );
00129
00130 }
00131 }
00132
00133 if (m_held)
00134 {
00135 int x,y;
00136 INPUTMAN->GetCursorPosition( x, y );
00137
00138
00139 m_x = x;
00140 m_y = y;
00141 }
00142
00143
00144 {
00145 if (INPUTMAN->IsButtonDown(button_b))
00146 m_camera.MoveX(-.1f);
00147
00148 if (INPUTMAN->IsButtonDown(button_c))
00149 m_camera.MoveX(.1f);
00150 }
00151
00152 MercuryScreen::Update( dTime );
00153 }
00154
00155 void ScreenHelloWorld::Message( int Message, PStack & data, const MString & name )
00156 {
00157 switch ( Message )
00158 {
00159 case MC_INPUTMAPPED:
00160 {
00161 InputMessageStruct c(data);
00162 if ( c.code == button_a )
00163 {
00164 if ( c.type == IET_DOWN )
00165 {
00166 m_held = true;
00167 INPUTMAN->GetCursorPosition( m_x, m_y );
00168 }
00169 if ( c.type == IET_RELEASE )
00170 {
00171 m_held = false;
00172 }
00173 }
00174 if ( c.code == button_d )
00175 {
00176
00177
00178 }
00179 }
00180 }
00181 }
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209