00001 #include "global.h"
00002 #include "ScreenSound.h"
00003 #include "MercuryScreenManager.h"
00004 #include "MercuryInput.h"
00005 #include "MercuryLog.h"
00006 #include "MercuryDisplay.h"
00007 #include "MercuryTheme.h"
00008 #include "MercurySoundManager.h"
00009
00010 KeyMappingWithCode( button_a, "0-97" );
00011 KeyMappingWithCode( button_s, "0-115" );
00012 KeyMappingWithCode( button_d, "0-100" );
00013 KeyMappingWithCode( button_w, "0-119" );
00014 KeyMappingWithCode( button_up, "0-273" );
00015 KeyMappingWithCode( button_down, "0-274" );
00016
00017 #include "MercuryObjectFactory.h"
00018 REGISTER_SCREEN_CLASS( ScreenSound )
00019
00020 #define MC_INPUTMAPPED 1 //convention: MESSAGE CODE
00021 #define MC_INPUTUNMAPPED 2
00022
00023 ScreenSound::~ScreenSound()
00024 {
00025 DISPLAY->RemoveLight(&m_light);
00026 SAFE_DELETE(m_sound);
00027 SAFE_DELETE(m_ball);
00028 }
00029
00030 void ScreenSound::Init()
00031 {
00032 MercuryScreen::Init();
00033
00034 m_sound = SOUNDMAN->Load(THEME.GetMetricS(GetName(), "Wav"));
00035
00036 AddObject( m_sound );
00037
00038 x = 0;
00039 y = 0;
00040
00041 totalTime = 0;
00042
00043 m_left = false;
00044 m_right = true;
00045 m_up = false;
00046 m_down = false;
00047
00048 m_paddle.SetName( "Paddle" );
00049 m_paddle.Init();
00050 m_paddle.LoadImage( GET_GRAPHIC_BY_NAME( "Paddle" ) );
00051 m_paddle.MoveX( -300 );
00052 m_paddle.MoveY( 39 );
00053 m_paddle.MoveZ( -500 );
00054 m_paddle.SetDrawOrder( -1 );
00055 AddObject( &m_paddle );
00056
00057
00058 m_bar1.SetName( "Bar" );
00059 m_bar1.Init();
00060 m_bar1.LoadImage( GET_GRAPHIC_BY_NAME( "Bar" ) );
00061 m_bar1.MoveX( 0 );
00062 m_bar1.MoveY( 39 );
00063 m_bar1.MoveZ( 5 );
00064 m_bar1.SetDrawOrder( -1 );
00065 AddObject( &m_bar1 );
00066
00067
00068 m_bar2.SetName( "Bar" );
00069 m_bar2.Init();
00070 m_bar2.LoadImage( GET_GRAPHIC_BY_NAME( "Bar" ) );
00071 m_bar2.MoveX( 0 );
00072 m_bar2.MoveY( -39 );
00073 m_bar2.MoveZ( 5 );
00074 m_bar2.SetDrawOrder( -1 );
00075 AddObject( &m_bar2 );
00076
00077
00078 m_bar3.SetName( "Bar" );
00079 m_bar3.Init();
00080 m_bar3.LoadImage( GET_GRAPHIC_BY_NAME( "Bar" ) );
00081 m_bar3.MoveX( 52 );
00082 m_bar3.MoveY( 0 );
00083 m_bar3.MoveZ( 5 );
00084 m_bar3.MoveRotZ( 90 );
00085 m_bar3.SetDrawOrder( -1 );
00086 AddObject( &m_bar3 );
00087
00088 m_ball = new MercuryLoadableModel;
00089 m_ball->SetName( "ball" );
00090 m_ball->Init();
00091 m_ball->Load(GET_MODEL_BY_NAME( "Model" ));
00092 m_ball->MoveX( 0 );
00093 m_ball->MoveY( 0 );
00094 m_ball->MoveZ( -500 );
00095 m_ball->SetDrawOrder( -2 );
00096 AddObject( m_ball );
00097
00098
00099
00100
00101 m_camera.SetName( "camera" );
00102 m_camera.Init();
00103 m_camera.SetEye( MercuryPoint( 0,0,100 ) );
00104 m_camera.SetTarget( m_ball->GetPosition() );
00105 this->AddObject( &m_camera );
00106
00107
00108 m_light.Init();
00109 m_light.SetY(100);
00110 m_light.SetX(-100);
00111 m_light.SetZ(110);
00112 m_light.SetAttenuation(0.001f, Attenuation::LINEAR);
00113
00114 DISPLAY->AddLight(&m_light);
00115
00116 this->RegisterMessage( MC_INPUTMAPPED, "mappedinput" );
00117 }
00118
00119 void ScreenSound::Message( int Message, PStack & data, const MString & name )
00120 {
00121 InputMessageStruct c(data);
00122 switch ( Message )
00123 {
00124 case MC_INPUTMAPPED:
00125 {
00126 if ( c.code == button_a )
00127 {
00128 if ( c.type == IET_DOWN )
00129 {
00130
00131 }
00132 if ( c.type == IET_RELEASE )
00133 {
00134
00135 }
00136 }
00137 }
00138 };
00139 }
00140
00141 void ScreenSound::Update( const float dTime )
00142 {
00143 totalTime += dTime;
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 if(m_ball->GetY() >= 213)
00160 {
00161 m_up = false;
00162 m_down = true;
00163 y = -y;
00164 m_sound->Play();
00165 }
00166
00167 else if(m_ball->GetY() <= -215)
00168 {
00169 m_down = false;
00170 m_up = true;
00171 y = -y;
00172 m_sound->Play();
00173 }
00174
00175 if(m_ball->GetX() >= 290)
00176 {
00177 m_right = false;
00178 m_left = true;
00179 x = -x;
00180 m_sound->Play();
00181 }
00182
00183 else if( m_ball->GetX() <= m_paddle.GetX() + 49
00184 && m_ball->GetX() >= m_paddle.GetX() - 49
00185 && m_ball->GetY() <= m_paddle.GetY() + 60
00186 && m_ball->GetY() >= m_paddle.GetY() - 60
00187 )
00188 {
00189
00190
00191
00192
00193 if( m_ball->GetX() <= m_paddle.GetX() + 49
00194 && m_ball->GetX() >= m_paddle.GetX() - 49
00195 && m_ball->GetY() <= m_paddle.GetY() + 60
00196 && m_ball->GetY() >= m_paddle.GetY() + 20 )
00197 {
00198 m_up = true;
00199 m_down = false;
00200 m_right = true;
00201 m_left = false;
00202
00203 x = -x;
00204 y = -y;
00205 }
00206 else if( m_ball->GetX() <= m_paddle.GetX() + 49
00207 && m_ball->GetX() >= m_paddle.GetX() - 49
00208 && m_ball->GetY() <= m_paddle.GetY() + 19
00209 && m_ball->GetY() >= m_paddle.GetY() - 21 )
00210 {
00211 m_up = false;
00212 m_down = false;
00213 m_right = true;
00214 m_left = false;
00215
00216 x = -x;
00217 y = -y;
00218 }
00219 else if( m_ball->GetX() <= m_paddle.GetX() + 49
00220 && m_ball->GetX() >= m_paddle.GetX() - 49
00221 && m_ball->GetY() <= m_paddle.GetY() - 22
00222 && m_ball->GetY() >= m_paddle.GetY() - 60 )
00223 {
00224 m_up = false;
00225 m_down = true;
00226 m_right = true;
00227 m_left = false;
00228
00229 x = -x;
00230 y = -y;
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 m_sound->Play();
00254 }
00255
00256 if(m_right == true)
00257 {
00258 x += ( float(.1) );
00259 }
00260 else if(m_left == true)
00261 {
00262 x -= ( float(.1) );
00263 }
00264
00265 if(m_up)
00266 {
00267 y += ( float(.1) );
00268 }
00269 else if(m_down)
00270 {
00271 y -= ( float(.1) );
00272 }
00273
00274 m_ball->MoveX( x * dTime);
00275 m_ball->MoveY( y * dTime);
00276
00277 if ( INPUTMAN->IsButtonDown( button_a ) )
00278 {
00279
00280
00281 }
00282 if ( INPUTMAN->IsButtonDown( button_d ) )
00283 {
00284
00285 }
00286 if ( INPUTMAN->IsButtonDown( button_w ) && (m_paddle.GetY() + 30) < 210 )
00287 {
00288
00289 m_paddle.MoveY(500 * dTime );
00290 }
00291 if ( INPUTMAN->IsButtonDown( button_s ) && (m_paddle.GetY() + 30) > -150 )
00292 {
00293
00294 m_paddle.MoveY(-500 * dTime );
00295 }
00296 if ( INPUTMAN->IsButtonDown( button_up ) )
00297 {
00298
00299 }
00300 if ( INPUTMAN->IsButtonDown( button_down ) )
00301 {
00302
00303 }
00304
00305
00306 if(m_ball->GetX() < -600)
00307 {
00308 x = 0;
00309 y = 0;
00310
00311 m_left = false;
00312 m_right = true;
00313 m_up = false;
00314 m_down = false;
00315
00316 m_ball->SetX( 0 );
00317 m_ball->SetY( 0 );
00318 }
00319
00320 MercuryScreen::Update( dTime );
00321 }
00322
00323 void ScreenSound::Draw()
00324 {
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 MercuryScreen::Draw();
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367