ScreenGameForBlind.cpp

Go to the documentation of this file.
00001 #include "MercuryScreen.h"
00002 #include "MercuryInput.h"
00003 #include "MercuryINI.h"
00004 #include "MercurySoundObject.h"
00005 #include "MercurySoundManager.h"
00006 #include "MercuryTheme.h"
00007 
00008 class ScreenGameForBlind : public MercuryScreen
00009 {
00010 public:
00011     ScreenGameForBlind() : MercuryScreen() { }
00012     ScreenGameForBlind( const MString & name ) : MercuryScreen( name ) { m_name = name; }
00013     virtual ~ScreenGameForBlind();
00014 
00015     virtual void Init();
00016     virtual void Update( const float dTime );
00017     virtual void Message( int Message, PStack & data, const MString & name );
00018     CLASS_RTTI( ScreenGameForBlind, MercuryScreen );
00019 private:
00020     MercurySprite sprGround;
00021     MercurySprite sprPerson;
00022     MercurySprite sprTarget;
00023 
00024     MercurySoundObject * sndTarget;
00025 
00026     MercuryPoint pPerson;
00027     MercuryPoint pTarget;
00028 
00029     float fRotation;
00030     int iLastMouseX;
00031 };
00032 
00033 #include "MercuryObjectFactory.h"
00034 REGISTER_SCREEN_CLASS( ScreenGameForBlind )
00035 
00036 KeyMappingWithCode( button_a, "0-97" );
00037 KeyMappingWithCode( button_s, "0-115" );
00038 KeyMappingWithCode( button_d, "0-100" );
00039 KeyMappingWithCode( button_w, "0-119" );
00040 
00041 ScreenGameForBlind::~ScreenGameForBlind()
00042 {
00043 //  SAFE_DELETE( sndTarget );
00044 }
00045 
00046 void ScreenGameForBlind::Init()
00047 {
00048     MercuryScreen::Init();
00049 
00050     sprGround.SetName( "Ground" );
00051     sprGround.Init();
00052     sprGround.LoadImage( GET_GRAPHIC_BY_NAME( "Ground" ) );
00053     AddOrthoObject( &sprGround );
00054 
00055     sprPerson.SetName( "Person" );
00056     sprPerson.Init();
00057     sprPerson.LoadImage( GET_GRAPHIC_BY_NAME( "Person" ) );
00058     AddOrthoObject( &sprPerson );
00059 
00060     sprTarget.SetName( "Target" );
00061     sprTarget.Init();
00062     sprTarget.LoadImage( GET_GRAPHIC_BY_NAME( "Target" ) );
00063     AddOrthoObject( &sprTarget );
00064     pTarget = MercuryPoint( 100,100,0 );
00065 
00066     sndTarget = SOUNDMAN->Load(THEME.GetMetricS(GetName(), "Wav"));
00067     sndTarget->SetLoop(true);
00068     sndTarget->Play();
00069     sndTarget->SetDoppler( 0.4f );
00070     AddObject( sndTarget, true );
00071 
00072     fRotation = 0;
00073     int x,y;
00074     INPUTMAN->GetCursorPosition( x, y );
00075     iLastMouseX = x;
00076 
00077     SetPosition( MercuryPoint( 320, 240, 0 ) );
00078 }
00079 
00080 void ScreenGameForBlind::Update( const float dTime )
00081 {
00082     int x = 0,y = 0;
00083 
00084     if ( INPUTMAN->IsButtonDown( button_a ) ) x = -1;
00085     if ( INPUTMAN->IsButtonDown( button_s ) ) y = 1;
00086     if ( INPUTMAN->IsButtonDown( button_d ) ) x = 1;
00087     if ( INPUTMAN->IsButtonDown( button_w ) ) y = -1;
00088 
00089     float AngleToGo=fRotation*DEGRAD;
00090 
00091     pPerson += Rotate2DPoint( AngleToGo, MercuryPoint( float(x)*dTime*30, float(y)*dTime*30, 0 ) );
00092 
00093     if( pPerson.x < -250 )
00094         pPerson.x = -250;
00095     if( pPerson.y < -250 )
00096         pPerson.y = -250;
00097     if( pPerson.x > 250 )
00098         pPerson.x = 250;
00099     if( pPerson.y > 250 )
00100         pPerson.y = 250;
00101 
00102     INPUTMAN->GetCursorPosition( x, y );
00103     y = x - iLastMouseX;
00104     iLastMouseX = x;
00105     fRotation+=float(y)/4.0f;
00106 
00107     SetRot( MercuryPoint( 0, 0, fRotation ) );
00108     sprPerson.SetRot( MercuryPoint( 0, 0, -fRotation ) );
00109 
00110     sprGround.SetPosition( -1 * pPerson );
00111     sprTarget.SetPosition( -1 * pPerson + pTarget );
00112 
00113     sndTarget->SetPosition( Rotate2DPoint(-AngleToGo,pTarget-pPerson)/50 - MercuryPoint( 320, 240, 0 ) );
00114 
00115     MercuryScreen::Update( dTime );
00116 }
00117 
00118 void ScreenGameForBlind::Message( int Message, PStack &data, const MString &name )
00119 {
00120     MercuryScreen::Message( Message, data, name );
00121 }
00122 
00123 /* 
00124  * Copyright (c) 2005-2006, Joshua Allen, Charles Lohr
00125  * All rights reserved.
00126  *
00127  * Redistribution and use in source and binary forms, with or
00128  * without modification, are permitted provided that the following
00129  * conditions are met:
00130  *  -   Redistributions of source code must retain the above
00131  *      copyright notice, this list of conditions and the following disclaimer.
00132  *  -   Redistributions in binary form must reproduce the above copyright
00133  *      notice, this list of conditions and the following disclaimer in
00134  *      the documentation and/or other materials provided with the distribution.
00135  *  -   Neither the name of the Mercury Engine nor the names of its
00136  *      contributors may be used to endorse or promote products derived from
00137  *      this software without specific prior written permission.
00138  *
00139  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00140  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00141  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00142  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00143  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00144  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00145  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00146  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00147  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00148  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00149  */
00150 

Hosted by SourceForge.net Logo