Esempio n. 1
0
//-------------------------------------------------------------------------------------
// This is the update callback function and is called at each update frame
// before rendering. You should update the game logic here.
//
//-------------------------------------------------------------------------------------
void GameApp::Update()
{

	JGE* engine = JGE::GetInstance();

	// do a screen shot when the TRIANGLE button is pressed
	if (engine->GetButtonClick(PSP_CTRL_TRIANGLE))		
	{
		char s[80];

		// save screen shot to root of Memory Stick 
		sprintf(s, "ms0:/screenshot.png");				
		JRenderer::GetInstance()->ScreenShot(s);
	}

	// exit when the CROSS button is pressed
	if (engine->GetButtonClick(PSP_CTRL_CROSS))	
	{
		engine->End();
		return;
	}

	float dt = engine->GetDelta();		// Get time elapsed since last update.

	mAngle += 2.0f*dt;
	if (mAngle >= M_PI*2)
		mAngle = 0;
}
Esempio n. 2
0
bool GameOptionKeyBindings::read(string input)
{
    istringstream iss(input);
    vector<pair<LocalKeySym, JButton> > assoc;

    while (iss.good())
    {
        stringstream s;
        iss.get(*(s.rdbuf()), ',');
        iss.get();

        LocalKeySym local = 0;
        char sep = 0;
        u32 button = 0;
        s >> local >> sep >> button;

        if (':' != sep)
            return false;
        assoc.push_back(make_pair(local, u32_to_button(button)));
    }

    if (assoc.empty())
        return false;

    JGE* j = JGE::GetInstance();

    j->ClearBindings();
    for (vector<pair<LocalKeySym, JButton> >::const_iterator it = assoc.begin(); it != assoc.end(); ++it)
        j->BindKey(it->first, it->second);

    return true;
}
Esempio n. 3
0
//-------------------------------------------------------------------------------------
// This is the update callback function and is called at each update frame
// before rendering. You should update the game logic here.
//
//-------------------------------------------------------------------------------------
void GameApp::Update()
{

	JGE* engine = JGE::GetInstance();

	// do a screen shot when the TRIANGLE button is pressed
	if (engine->GetButtonClick(PSP_CTRL_TRIANGLE))		
	{
		char s[80];

		// save screen shot to root of Memory Stick 
		sprintf(s, "ms0:/screenshot.png");				
		JRenderer::GetInstance()->ScreenShot(s);
	}

	// exit when the CROSS button is pressed
	if (engine->GetButtonClick(PSP_CTRL_CROSS))	
	{
		engine->End();
		return;
	}

	if (engine->GetButtonClick(PSP_CTRL_CIRCLE))	
	{
		Reset();
		return;
	}

	if (engine->GetButtonClick(PSP_CTRL_RIGHT))
	{

		mCurr++;
		if (mCurr >= DEMO_COUNT)
			mCurr = 0;
		Reset();
		return;
	}

	if (engine->GetButtonClick(PSP_CTRL_LEFT))
	{

		mCurr--;
		if (mCurr < 0)
			mCurr = DEMO_COUNT-1;
		Reset();
		return;
	}

	float dt = engine->GetDelta();		// Get time elapsed since last update.

	//
	// Your updating code here...
	//

	if (mBox2D)
		mBox2D->Update(dt);
	
	

}
Esempio n. 4
0
bool GameOptionKeyBindings::write(std::ofstream* file, string name)
{
    JGE* j = JGE::GetInstance();
    *file << name << "=";
    JGE::keybindings_it start = j->KeyBindings_begin(), end = j->KeyBindings_end();
    if (start != end)
    {
        *file << start->first << ":" << start->second;
        ++start;
    }
    for (JGE::keybindings_it it = start; it != end; ++it)
        *file << "," << it->first << ":" << it->second;
    *file << endl;
    return true;
}
Esempio n. 5
0
SimplePad * GameSettings::keypadStart(string input, string * _dest, bool _cancel, bool _numpad, float _x, float _y)
{
    if (keypad == NULL)
        keypad = NEW SimplePad();
    // show keyboard
#ifdef IOS
    JGE *engine = JGE::GetInstance();
    engine->SendCommand( "displayKeyboard", input);
#elif ANDROID
    JGE *engine = JGE::GetInstance();
    engine->SendCommand( "displayKeyboard:" + input);    
#endif
    keypad->bShowCancel = _cancel;
    keypad->bShowNumpad = _numpad;
    keypad->mX = _x;
    keypad->mY = _y;
    keypad->Start(input, _dest);
    return keypad;
}
Esempio n. 6
0
void GameApp::Render()
{
    if (systemError.size())
    {
        fprintf(stderr, "%s", systemError.c_str());
        WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
        if (mFont)
            mFont->DrawString(systemError.c_str(), 1, 1);
        return;
    }

    JRenderer * renderer = JRenderer::GetInstance();
    renderer->ClearScreen(ARGB(0,0,0,0));

    if (mCurrentState)
        mCurrentState->Render();

#ifdef DEBUG_CACHE
    WResourceManager::Instance()->DebugRender();
#endif

#if defined(DEBUG) && !defined(IOS)
    JGE* mEngine = JGE::GetInstance();
    float fps = mEngine->GetFPS();
    totalFPS += fps;
    nbUpdates+=1;
    WFont * mFont= WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
    char buf[512];
    sprintf(buf, "avg:%.02f - %.02f fps",totalFPS/nbUpdates, fps);
    if (mFont)
    {
        mFont->SetColor(ARGB(255,255,255,255));
        mFont->DrawString(buf, 10, SCREEN_HEIGHT-25);
    }
#endif

}
Esempio n. 7
0
void GameApp::Update()
{

	JGE* engine = JGE::GetInstance();

	if (engine->GetButtonClick(PSP_CTRL_TRIANGLE))		// do a screen shot when the TRIANGLE button is pressed
	{
		char s[80];
		sprintf(s, "ms0:/screenshot.png");
		JRenderer::GetInstance()->ScreenShot(s);
	}

	if (engine->GetButtonClick(PSP_CTRL_CROSS))			// exit when the CROSS button is pressed
	{
		engine->End();
		return;
	}

	if (engine->GetButtonClick(PSP_CTRL_CIRCLE))
	{
		mShowSpline = !mShowSpline;
	}

	float dt = engine->GetDelta();

	mPlane->Update(dt);

	mCounter += 100*dt;
	int curr = (int) mCounter;
	if (mIndex != curr)									// Update position of the plane
	{
		if (curr >= mSpline->GetPixelCount())
		{
			mCounter = 0.0f;
			curr = 0;
		}

		mIndex = curr;

		Point pt;
		mSpline->GetPixel(pt, mIndex);
		mPlane->SetPosition(pt.x, pt.y);

		mSpline->GetPixel(pt, mIndex+1);
		mPlane->SetDirection(pt.x, pt.y);
	}

}
Esempio n. 8
0
//-------------------------------------------------------------------------------------
// This is the update callback function and is called at each update frame
// before rendering. You should update the game logic here.
//
//-------------------------------------------------------------------------------------
void GameApp::Update()
{
    JGE* engine = JGE::GetInstance();

    float dt = engine->GetDelta();
    if (dt > 35.0f)		// min 30 FPS ;)
        dt = 35.0f;

    scroller->Update(dt);

    timer+=dt;
    if (timer > 15) {
        startTransition();
        timer = 0;
    };

    transition+=(int)(dt * 300);
    if (transition > 255)
        endTransition();


    if (gameToExtract.size()) {
        if (!subMenu)
        {
            switch(currentGameState) {
            case GAME_STATE_EXTRACTING_DONE:
                subMenu = new SimpleMenu(1, this,mFont,10,200, "installed to " + extractFolder);
                subMenu->Add(MENU_NO, "OK","", true);
                break;
            default:
                //TODO Check contents of file to see if it matches the zip format.
                subMenu = new SimpleMenu(1, this,mFont,10,200, "Do you want to install this homebrew?");
                subMenu->Add(MENU_YES, "yes");
                subMenu->Add(MENU_NO, "Cancel");
                break;
            }
        }
        subMenu->Update(dt);
        switch(currentGameState) {
        case GAME_STATE_EXTRACTING:
            SAFE_DELETE(subMenu);
            ensureExtractFilesList();
            if (extractError) {
                extractError = 0;
                currentGameState = GAME_STATE_EXTRACTING_CANCEL;
                return;
            }
            extractOneFile();
            if (zipFiles.empty()) {
                currentZipFile.close();
                loadFiles(base.c_str()); //reload menu to update folders
                currentGameState = GAME_STATE_EXTRACTING_DONE;
            }
            break;
        case GAME_STATE_EXTRACTING_CANCEL:
            SAFE_DELETE(subMenu);
            gameToExtract = "";
            currentGameState = GAME_STATE_MENU;
            break;
        case GAME_STATE_EXTRACTING_DONE:
            break;
        default:
            break;
        }

        return;
    }

    menu->Update(dt);

    if (gameSelected == -2) {
        loadFiles(base.c_str());
        gameSelected = -1;
    }
    if (gameSelected > -1) {
        engine->End();
        return;
    }
    // exit when the TRIANGLE button is pressed
    if ( engine->GetButtonState(JGE_BTN_CANCEL))
    {
        strcpy((char *)ebootPath, "quit");
        engine->End();
        return;
    }

    if ( engine->GetButtonState(JGE_BTN_PRI))
    {
        JRenderer::GetInstance()->ScreenShot("ms0:/picture/wMenu.png");
    }

    if ( engine->GetButtonState(JGE_BTN_PREV))
    {
        base = "ms0:/PSP/SAVEDATA";
        loadFiles(base.c_str());
        return;
    }

    if ( engine->GetButtonState(JGE_BTN_NEXT))
    {
        base = "ms0:/PSP/GAME";
        loadFiles(base.c_str());
        return;
    }


}
Esempio n. 9
0
//-------------------------------------------------------------------------------------
// This is the init callback function. You should load and create your in-game
// resources here.
//
//-------------------------------------------------------------------------------------
void GameApp::Create()
{
    JLOG("GameApp:Create 1");
    JFileSystem::init("./"); //to avoid having subfolders
    JLOG("GameApp:Create 2");
    JRenderer* renderer = JRenderer::GetInstance();
    JLOG("GameApp:Create 3");
    loadWalls(".");
    if (wallpapers.size()) {
        JLOG("GameApp:Create 4");
        int rnd = (rand() % wallpapers.size());
        backTex=renderer->LoadTexture(wallpapers[rnd].c_str());
        if (backTex) backQuad = new JQuad(backTex, 0, 0, 480, 272);
    }
    JLOG("GameApp:Create 5");
    // Load a font
    mFont=new JLBFont("font", 11);
    JLOG("GameApp:Create 6");
    scroller = new TextScroller(mFont, SCREEN_WIDTH/2 - 190 , SCREEN_HEIGHT-20,380);
    const char * const CreditsText[] = {
        "Thanks to n00b81, Tyranid, devs of the PSPSDK, Hitmen, Fanjita & Noobz, psp-hacks.com",
        "wMenu uses the JGE++ library ( http://code.google.com/p/wagic )"
    };

    menu = NULL;

#ifdef WIN32
    strcpy(dummy, "D:/Stuff/Programming/wmenu/projects/wmenu/bin/samples");
#else
    strcpy(dummy, "ms0:/PSP/GAME");
#endif
    ebootPath = dummy;
    JLOG("GameApp:Create 7");
    JGE* engine = JGE::GetInstance();
    vector<string>argv = engine->GetARGV();
    int settingsAddr = 0;
    JLOG("GameApp:Create 8");
    if (argv.size() > 1) {
        string hex = argv[1];
        hex[8] = 0; //bug in HBL ?
        fprintf(stderr, "Location: 0x %s\n", hex.c_str());
        settingsAddr = xstrtoi(hex.c_str(), 8);
    }
    fprintf(stderr, " settingsAddr : %d\n", settingsAddr);
    if (settingsAddr) {
        settings = (tMenuApi *) settingsAddr;
        ebootPath = (void *) settings->filename;
    }

    int size = sizeof(CreditsText) / sizeof(CreditsText[0]);
    string scroll = "wMenu 0.4 by Wololo  http://wololo.net    ";
    stringCode(scroll);
    scroll.append("--- HBL Info ---");

    if (settings) {
        scroll.append(settings->VersionName);
        scroll.append(" by ");
        scroll.append(settings->Credits);
        scroll.append("     ");
    }

    for (int i = 0; i < size; i++) {
        scroll.append(CreditsText[i]);
        scroll.append("     ");
    }
    scroller->Add(scroll);
    JLOG("GameApp:Create 9");
    loadFiles((char *)ebootPath);
    if (fileExists("menu.wav")) {
        menuSfx = JSoundSystem::GetInstance()->LoadSample("menu.wav");
        //runSfx = JSoundSystem::GetInstance()->LoadSample("run.wav");

        JSoundSystem::GetInstance()->SetSfxVolume(100);
    }
    JLOG("GameApp:Create 10");

    currentGameState = GAME_STATE_NONE;
}
Esempio n. 10
0
bool CardDisplay::CheckUserInput(JButton key)
{
    if (JGE_BTN_SEC == key || JGE_BTN_PRI == key || JGE_BTN_UP == key || JGE_BTN_DOWN == key)
    {
        if (listener)
        {
            listener->ButtonPressed(mId, 0);
            return true;
        }
    }
    if (!mObjects.size()) return false;

    if (mActionButton == key)
    {
        if (mObjects[mCurr] && mObjects[mCurr]->ButtonPressed())
        {
            CardGui * cardg = (CardGui *) mObjects[mCurr];
            if (tc)
            {
                tc->toggleTarget(cardg->card);
                return true;
            }
            else
            {
                if (observer) observer->ButtonPressed(cardg);
                return true;
            }
        }
        return true;
    }

    switch (key)
    {
    case JGE_BTN_LEFT:
    {
        int n = mCurr;
        n--;
        if (n < start_item)
        {
            if (n < 0)
            {
                n = 0;
            }
            else
            {
                rotateLeft();
            }
        }
        if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_LEFT))
        {
            mCurr = n;
            mObjects[mCurr]->Entering();
        }
        return true;
    }
    case JGE_BTN_RIGHT:
    {
        int n = mCurr;
        n++;
        if (n >= (int) (mObjects.size()))
        {
            n = mObjects.size() - 1;
        }
        if (n >= start_item + nb_displayed_items)
        {
            rotateRight();
        }
        if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_RIGHT))
        {
            mCurr = n;
            mObjects[mCurr]->Entering();
        }
        return true;
    }
    default:
    {
      bool result = false;
      unsigned int distance2;
      unsigned int minDistance2 = -1;
      int n = mCurr;
      int x1,y1;
      JButton key;
      JGE* jge = observer?observer->getInput():JGE::GetInstance();
      if(jge)
      {
          if (jge->GetLeftClickCoordinates(x1, y1))
          {
              for (size_t i = 0; i < mObjects.size(); i++)
              {
                  float top, left;
                  if (mObjects[i]->getTopLeft(top, left))
                  {
                      distance2 = static_cast<unsigned int>((top - y1) * (top - y1) + (left - x1) * (left - x1));
                      if (distance2 < minDistance2)
                      {
                          minDistance2 = distance2;
                          n = i;
                      }
                  }
              }

              if (n < mCurr)
                  key = JGE_BTN_LEFT;
              else
                  key = JGE_BTN_RIGHT;

              if (n < start_item)
              {
                  rotateLeft();
              }
              else if (n >= (int)(mObjects.size()) && mObjects.size())
              {
                  n = mObjects.size() - 1;
              }
              if (n >= start_item + nb_displayed_items)
              {
                  rotateRight();
              }

              if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(key))
              {
                  mCurr = n;
                  mObjects[mCurr]->Entering();
                  result = true;
              }
              jge->LeftClickedProcessed();
          }
      }
      return result;
    }
    }

    return false;
}
Esempio n. 11
0
//-------------------------------------------------------------------------------------
// This is the update callback function and is called at each update frame
// before rendering. You should update the game logic here.
//
//-------------------------------------------------------------------------------------
void GameApp::Update()
{

	JGE* engine = JGE::GetInstance();

	// do a screen shot when the TRIANGLE button is pressed
	if (engine->GetButtonClick(PSP_CTRL_TRIANGLE))		
	{
		char s[80];

		// save screen shot to root of Memory Stick 
		sprintf(s, "ms0:/screenshot.png");				
		JRenderer::GetInstance()->ScreenShot(s);
	}

	// exit when the CROSS button is pressed
	if (engine->GetButtonClick(PSP_CTRL_CROSS))	
	{
		engine->End();
		return;
	}

	int quadIdx[] =
	{
		7, 15, 0, 5, 7, 0, 1, 15, 4
	};

	// change particle image if PSP_CTRL_LEFT or PSP_CTRL_RIGHT is down
	if (engine->GetButtonClick(PSP_CTRL_LEFT))
	{
		mCurrParticle--;
		if (mCurrParticle < 0)
			mCurrParticle = 15;

		mParticleSys->info.sprite = mParticles[mCurrParticle];
		mMovingParticleSys->info.sprite = mParticles[15-mCurrParticle];
	}
	if (engine->GetButtonClick(PSP_CTRL_RIGHT))
	{
		mCurrParticle++;
		if (mCurrParticle > 15)
			mCurrParticle = 0;

		mParticleSys->info.sprite = mParticles[mCurrParticle];
		mMovingParticleSys->info.sprite = mParticles[15-mCurrParticle];
	}

	// change particle system if PSP_CTRL_DOWN or PSP_CTRL_UP is down
	if (engine->GetButtonClick(PSP_CTRL_DOWN))
	{
		mCurrParticleSys--;
		if (mCurrParticleSys < 0)
			mCurrParticleSys = 8;

		mCurrParticle = quadIdx[mCurrParticleSys];
		LoadNewParticleSys();
	}
	if (engine->GetButtonClick(PSP_CTRL_UP))
	{
		mCurrParticleSys++;
		if (mCurrParticleSys > 8)
			mCurrParticleSys = 0;

		mCurrParticle = quadIdx[mCurrParticleSys];
		LoadNewParticleSys();
	}

	float dt = engine->GetDelta();		// Get time elapsed since last update.

	mTimer += dt;
	

	mAngle += 2.0f*dt;
	if (mAngle >= M_PI*2)
		mAngle = 0;

	if (mTimer > 0.01f)		// update the moving circle and particle at about 100fps
	{
		if (engine->GetAnalogX()<64) 
			dx-=mSpeed*mTimer;
		if (engine->GetAnalogX()>192) 
			dx+=mSpeed*mTimer;
		if (engine->GetAnalogY()<64) 
			dy-=mSpeed*mTimer;
		if (engine->GetAnalogY()>192) 
			dy+=mSpeed*mTimer;

		// Do some movement calculations and collision detection	
		dx *= mFriction;
		dy *= mFriction;
		x += dx; 
		y += dy;

		if (x>470) 
		{
			x=470-(x-470);
			dx=-dx;
		}
		if (x<16) 
		{
			x=16+16-x;
			dx=-dx;
		}
		if (y>260)
		{
			y=260-(y-260);
			dy=-dy;
		}
		if (y<16)
		{
			y=16+16-y;
			dy=-dy;
		}

		// Update particle system
		mMovingParticleSys->info.nEmission=(int) (dx*dx+dy*dy)*2;
		mMovingParticleSys->MoveTo(x,y);

		mTimer = 0.0f;
	
	}

	mMovingParticleSys->Update(dt);
	mParticleSys->Update(dt);
	
}
Esempio n. 12
0
bool CardSelector::CheckUserInput(JButton key)
{
    if (!active)
    {
        for (vector<Target*>::iterator it = cards.begin(); it != cards.end(); ++it)
            if ((NULL == limitor) || (limitor->select(*it)))
            {
                active = *it;
                active->Entering();
                return true;
            }
        return true;
    }
    Target* oldactive = active;
    timer = 800;
    int x,y;
    JGE* jge = observer->getInput();
    if(!jge) return false;
    if(jge->GetLeftClickCoordinates(x, y))
    {
        active = closest<CardSelectorTrue> (cards, limitor, static_cast<float> (x), static_cast<float> (y));
    }

    switch (key)
    {
    case JGE_BTN_SEC:
        observer->cancelCurrentAction();
        goto switch_active;
        break;
    case JGE_BTN_OK:
        observer->ButtonPressed(active);
        goto switch_active;
        break;
    case JGE_BTN_LEFT:
        active = closest<CardSelectorLeft> (cards, limitor, active);
        break;
    case JGE_BTN_RIGHT:
        active = closest<CardSelectorRight> (cards, limitor, active);
        break;
    case JGE_BTN_UP:
        active = closest<CardSelectorUp> (cards, limitor, active);
        break;
    case JGE_BTN_DOWN:
        active = closest<CardSelectorDown> (cards, limitor, active);
        break;
    case JGE_BTN_CANCEL:
        mDrawMode = (mDrawMode + 1) % DrawMode::kNumDrawModes;
        if (mDrawMode == DrawMode::kText)
            options[Options::DISABLECARDS].number = 1;
        else
            options[Options::DISABLECARDS].number = 0;
        return true;
    default:
      {
        if(!jge->GetLeftClickCoordinates(x, y))
        {
          return false;
        }
      }
    }
    if(key != JGE_BTN_NONE)
    {
      if (active != oldactive)
      {
          CardView::SelectorZone oldowner, owner;
          if (CardView *q = dynamic_cast<CardView*>(oldactive))
              oldowner = q->owner;
          else
              oldowner = CardView::nullZone;
          if (CardView *q = dynamic_cast<CardView*>(active))
              owner = q->owner;
          else
              owner = CardView::nullZone;
          if (oldowner != owner)
          {
              if (CardView::nullZone != owner)
              {
                  if (PlayGuiObject* old = fetchMemory(lasts[owner]))
                      switch (key)
                      {
                      case JGE_BTN_LEFT:
                          if (old->x < oldactive->x)
                              active = old;
                          break;
                      case JGE_BTN_RIGHT:
                          if (old->x > oldactive->x)
                              active = old;
                          break;
                      case JGE_BTN_UP:
                          if (old->y < oldactive->y)
                              active = old;
                          break;
                      case JGE_BTN_DOWN:
                          if (old->y > oldactive->y)
                              active = old;
                          break;
                      default:
                          if (old)
                              active = old;
                          break;
                      }
              }
              lasts[oldowner] = SelectorMemory(oldactive);
          }
      }
      else
      {
          // active card hasn't changed - that means we're probably at an edge of the battlefield.
          // check if we're not already a selected avatar - if not, select one depending whether we're going up/down.
          GuiAvatar* avatar = dynamic_cast<GuiAvatar*> (active);
          if (!avatar)
          {
              if (key == JGE_BTN_DOWN)
              {
                  active = duel->GetAvatars()->GetSelf();
              }
              else if (key == JGE_BTN_UP)
              {
                  active = duel->GetAvatars()->GetOpponent();
              }
          }
      }
    }

switch_active:
    if (active != oldactive)
    {
        {
            PlayGuiObject* c = dynamic_cast<PlayGuiObject*> (oldactive);
            if (c)
                c->zoom = 1.0f;
        }
        {
            PlayGuiObject* c = dynamic_cast<PlayGuiObject*> (active);
            if (c)
                c->zoom = 1.4f;
        }
        if (oldactive)
            oldactive->Leaving(JGE_BTN_NONE);
        if (active)
            active->Entering();
    }
    else
    {
        timer = 800;
    }
    return true;
}
Esempio n. 13
0
void GameApp::Update()
{
    if (systemError.size())
        return;
    JGE* mEngine = JGE::GetInstance();
#if defined (PSP)
    if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonClick(JGE_BTN_CANCEL))
    {
        char s[80];
        sprintf(s, "ms0:/psp/photo/MTG%d.png", mScreenShotCount++);
        JRenderer::GetInstance()->ScreenShot(s);
    }
    //Exit when START and X ARE PRESSED SIMULTANEOUSLY
    if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonState(JGE_BTN_SEC))
    {
        mEngine->End();
        return;
    }

    //Restart Rendering engine when START and SQUARE ARE PRESSED SIMULTANEOUSLY
    if (mEngine->GetButtonState(JGE_BTN_MENU) && mEngine->GetButtonState(JGE_BTN_PRI))
        JRenderer::Destroy();
#endif //PSP

    float dt = mEngine->GetDelta();
    if (dt > 35.0f) // min 30 FPS ;)
        dt = 35.0f;

    TransitionBase * mTrans = NULL;
    if (mCurrentState)
    {
        mCurrentState->Update(dt);
        if (mGameStates[GAME_STATE_TRANSITION] == mCurrentState)
            mTrans = (TransitionBase *) mGameStates[GAME_STATE_TRANSITION];
    }
    //Check for finished transitions.
    if (mTrans && mTrans->Finished())
    {
        mTrans->End();
        if (mTrans->to != NULL && !mTrans->bAnimationOnly)
        {
            SetCurrentState(mTrans->to);
            SAFE_DELETE(mGameStates[GAME_STATE_TRANSITION]);
            mCurrentState->Start();
        }
        else
        {
            SetCurrentState(mTrans->from);
            SAFE_DELETE(mGameStates[GAME_STATE_TRANSITION]);
        }
    }
    if (mNextState != NULL)
    {
        if (mCurrentState != NULL)
            mCurrentState->End();

        SetCurrentState(mNextState);

#if defined (PSP)
        /*
         int maxLinear = ramAvailableLineareMax();
         int ram = ramAvailable();
         char buf[512];
         sprintf(buf, "Ram : linear max: %i - total : %i\n",maxLinear, ram);
         fprintf(stderr,buf);
         */
#endif
        mCurrentState->Start();
        mNextState = NULL;
    }
}
Esempio n. 14
0
void GameStateOptions::Update(float dt)
{
    timer += dt * 10;

    if (options.keypadActive())
    {
        options.keypadUpdate(dt);

        if (newProfile != "")
        {
            newProfile = options.keypadFinish();
            if (newProfile != "")
            {
                options[Options::ACTIVE_PROFILE] = newProfile;
                options.reloadProfile();
                optionsTabs->Reload();
            }
            newProfile = "";
        }
    }
    else
        switch (mState)
        {
        default:
        case SAVE:
            switch (optionsTabs->needsConfirm())
            {
            case WGuiBase::CONFIRM_CANCEL:
                mState = SHOW_OPTIONS;
                break;
            case WGuiBase::CONFIRM_OK:
                optionsTabs->save();
                JSoundSystem::GetInstance()->SetSfxVolume(options[Options::SFXVOLUME].number);
                JSoundSystem::GetInstance()->SetMusicVolume(options[Options::MUSICVOLUME].number);
                mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
                mState = SHOW_OPTIONS;
                break;
            case WGuiBase::CONFIRM_NEED:
                optionsTabs->yieldFocus();
                break;
            }
            // Note : No break here : must continue to continue updating the menu elements.
        case SHOW_OPTIONS:
        {
            JGE* j = JGE::GetInstance();
            JButton key = JGE_BTN_NONE;
            int x, y;
            if (grabber)
            {
                LocalKeySym sym;
                if (LOCAL_KEY_NONE != (sym = j->ReadLocalKey()))
                    grabber->KeyPressed(sym);
            }
            else
                while ((key = JGE::GetInstance()->ReadButton()) || JGE::GetInstance()->GetLeftClickCoordinates(x,y))
                {
                    if (!optionsTabs->CheckUserInput(key) && key == JGE_BTN_MENU)
                        mState = SHOW_OPTIONS_MENU;
                }
            optionsTabs->Update(dt);
            break;
        }
        case SHOW_OPTIONS_MENU:
            optionsMenu->Update(dt);
            break;
        }
    if (mReload)
    {
        options.reloadProfile();
        Translator::EndInstance();
        Translator::GetInstance()->init();
        optionsTabs->Reload();
        mReload = false;
    }
}