Exemple #1
0
void GameDocument::onContextReceived()
{
	TRACE( "GameDocument::onContextReceived" );

	if ( context() != NULL )
	{
		if ( !client()->isServerTransfer() && !m_EndGame )
		{
			// update the client before changing the scene
			m_pClient->update();
			// pre-cache all the textures
			setGameState( GS_CONNECT_SERVER );
		}
	}
	else
	{
		// failed to receive the context, this is bad...
		pushChat( "Failed to receive the world, disconnecting..." );
		setGameState( GS_DISCONNECTED );
		m_bIsConnected = false;
	}

	// clear the end game flag
	m_EndGame = false;
}
Exemple #2
0
void GameDocument::onShipCaptured( Noun * pCapper )
{
	TRACE( "GameDocument::onShipCaptured" );

	setGameState( GS_DEATH );
	m_bShipLost = true;

	// inform our script
	CharString sSelf = ship()->key().string();
	CharString sCapper = pCapper != NULL ? pCapper->key().string() : "";
	context()->scriptCall( CharString().format("onCaptured( '%s''%s' )", sSelf, sCapper ) );
	
	// reset the camera time
	s_fCamera = 0.0f;

	WindowObserve * pWindow = WidgetCast<WindowObserve>( InterfaceContext::findNode( "ObserveWindow" ) );
	if ( pWindow != NULL )
	{
		pWindow->setCameraMode( WindowObserve::CHASE );
		pWindow->setTargetMode( WindowObserve::LOCKED );
		pWindow->setTarget( ship() );
	}

	WindowText * pMessage = WidgetCast<WindowText>( InterfaceContext::findNode( "TextMessage" ) );
	if ( pMessage != NULL )
	{
		if ( pCapper != NULL )
			pMessage->setText( CharString().format("Ship captured by %s...", pCapper->name()) );
		else
			pMessage->setText( "Ship captured..." );
	}
}
Exemple #3
0
// interface is initialized, this is called by InterfaceContext
void GameDocument::onActivate()
{
#ifdef _DEBUG
	Settings settings( "ClientD" );
#else
	Settings settings( "Client" );
#endif

	// begin playing music
	if ( m_pJukeBox == NULL )
	{
		int musicVolume = settings.get( "musicVolume", 50 );
		if ( musicVolume > 0 )
		{
			CharString musicDirectory = settings.get( "music", ".\\Music\\" );

			// create the jukebox object and initialize
			if ( ( m_pJukeBox = Jukebox::create() ) != NULL )
				m_pJukeBox->initialize( musicDirectory, musicVolume );
		}
	}

	// enable keyboard mapping
	Keyboard::enableKeyMap();
	// load the players keyboard mapping
	Keyboard::loadKeyMap( settings.get( "keyMap", ".\\keyboard.map" ) );
	// begin at the lobby screen
	setGameState( GS_LOBBY );

	// attempt to connect to server at localhost on port 9010
	connect( 0, "localhost", 9010 );
}
Exemple #4
0
void GameDocument::onConnected()
{
	TRACE( "GameDocument::onConnected" );
	pushChat( "Connected to server..." );
	m_bIsConnected = true;

	if (! m_pClient->isServerTransfer() )
		setGameState( GS_CONNECT_SERVER );
}
void titleUpdate()
{
	if(keepDrawing)
		drawingTicks += timerElapsed(0);

	if(releasedKeys & KEY_TOUCH || releasedKeys & KEY_START)
		setGameState(GAME_STATE_BREAKOUT);

}
Exemple #6
0
void GameDocument::onShipDetached()
{
	TRACE( "GameDocument::onShipDetached" );
	// player left game through a jumpgate or exited the zone
	if ( !client()->isServerTransfer() && !m_bShipLost )
		setGameState( GS_SELECT_SHIP );
	// inform our script
	context()->scriptCall( "onShipDetached()" );
}
//*************************************************************************************
bool TheGame::doIntro()
{
    Timer fps;
    int frame = 200;
    bool doingIntro = 1,
         intro = 1;
    fps.start();

    while(intro){
        while(SDL_PollEvent(&gEvent)){
            if(gEvent.type == SDL_QUIT){
                intro = 0;
                setGameState(EXIT); }
						else if(!doingIntro){
                if(gEvent.type == SDL_KEYDOWN){
                    intro = 0;
                    buildLevelI();
                    setGameState(LEVEL_I);
                }
            }
        }

        if(doingIntro){
            introBG->setYPos(introBG->getYPos() + 2);
        }

        if(introBG->getYPos() >= 0){
            introBG->setYPos(0);
            doingIntro = 0;
        }

        if( fps.get_ticks() < 1000 / frame ){
            SDL_Delay( ( 1000 / frame ) - fps.get_ticks() );
        }

        introBG->show(screen);

        if(!render()){
            return 0;
        }
    }

    return 1;
}
Exemple #8
0
void GameDocument::onServerTransfer( const WorldClient::TransferRequest & a_Req )
{
#ifdef _DEBUG
	Settings settings( "ClientD" );
#else
	Settings settings( "Client" );
#endif
	settings.put( "transferAddress", CharString().format( "%s:%d", a_Req.m_sAddress, a_Req.m_nPort) );

	setGameState( GS_SERVER_TRANSFER );
}
Exemple #9
0
void GameDocument::onLogin( bool bLogin )
{
	TRACE( "GameDocument::onLogin" );
	pushChat( bLogin ? "Logged into server..." : "Failed to login..." );

	if (! bLogin )
	{
		setGameState( GS_DISCONNECTED );
		m_bIsConnected = false;
	}
}
Exemple #10
0
GameShow::GameShow()
{

  pGameController = new GameController();
  pGameController->startup();


  // pGameState = new StateDebug();  // This will eventually be defaulting to something like attract
  // ((StateDebug*)pGameState)->startup(pGameController);
  setGameState("basic");
  printf("setup complete\n");
}
Exemple #11
0
bool tickEmpty(bool _doInit) {
  if (_doInit == true) {
    s_state = 0;
    m_player.m_position = GPoint(0, SIZE*9);
    addCluter(20, 20, 0);
    return false;
  }

  if (s_state == 0) { // start initial move
    enterRoom(&s_state);
  } else if (s_state == 1) { // initial move is done
    setGameState(kAwaitInput);
    ++s_state;
  } else if (s_state == 2) {
    moveToExit(&s_state);
  } else if (s_state == 3) {
    setGameState(kFadeOut);
  }

  return false;
}
Exemple #12
0
bool tickStart(bool _doInit) {
  if (_doInit == true) {
    s_state = 0;
    m_player.m_position = GPoint(0, SIZE*9);
    addCluter(4, 0, 20); // Only left
    return false;
  }

  static bool _first = true;
  static const char _msgA[] = "SHAKE TO TURN...";
  static const char _msgB[] = "ON BACKLIGHT";

  if (s_state == 0) { // start initial move
    enterRoom(&s_state);
  } else if (s_state == 1) { // initial move is done
    if (_first == true) {
      setDisplayMsg(_msgA);
      setGameState(kDisplayMsg);
      s_state = 2;
      _first = false;
    } else {
      setGameState(kAwaitInput);
      s_state = 4;
    }
  } else if (s_state == 2) {
    setDisplayMsg(_msgB);
    setGameState(kDisplayMsg);
    ++s_state;
  } else if (s_state == 3) {
    setGameState(kAwaitInput);
    ++s_state;
  } else if (s_state == 4) {
    moveToExit(&s_state);
  } else if (s_state == 5) {
    setGameState(kFadeOut);
  }

  return false;
}
//*************************************************************************************
bool TheGame::doLevelI(){
    Timer fps;
    int frame = 100;
    fps.start();

    while(SDL_PollEvent(&gEvent)){
        if(gEvent.type == SDL_QUIT){
            setGameState(EXIT); }
        else if(gEvent.type == SDL_KEYDOWN){
            if(gEvent.type == SDLK_RETURN){
                setGameState(EXIT); }
            else if(gEvent.type == SDLK_LEFT){

            }
            else if(gEvent.type == SDLK_RIGHT){

            }
        }
    }

    //levels_[0]->setXPos(levels_[0]->getXPos() - 2);

    if(levels_[0]->getXPos() <= -(levels_[0]->getLevelWidth() - screenWidth_)){
        levels_[0]->setXPos(0);
    }

    if( fps.get_ticks() < 1000 / frame ){
        SDL_Delay( ( 1000 / frame ) - fps.get_ticks() );
    }

    levels_[0]->show(screen);

    if(!render()){
        return 0;
    }

    return 1;
}
Exemple #14
0
void cGame::InitializeGame()
{
	//Initialize Questions
	InitQuestions();

	//Shuffle Questions
	///Shuffle();

	//Set Game State To Playing
	if(!getGameState())
	{
		setGameState(true);
	}
}
Exemple #15
0
void GameShow::processWebMessages()
{
  Document* document = pGameController->socketServer()->getNextIncomingMessage();
  if(0 != document){
    // cout << "Got document " << document;

    string message = document->FindMember("message")->value.GetString();
    // cout << "Got message " << document;

    if(message.compare("get_buttons") == 0){
      pGameController->sendWebMessage(pGameController->buttonController()->getInfoString());

    }else if(message.compare("get_lamps") == 0){
      pGameController->sendWebMessage(pGameController->lampController()->getInfoString());

    }else if(message.compare("get_coils") == 0){
      pGameController->sendWebMessage(pGameController->coilController()->getInfoString());

    }else if(message.compare("set_lamp_state") == 0){
      string name = document->FindMember("name")->value.GetString();
      LampState state = (LampState)document->FindMember("value")->value.GetInt();
      pGameController->lampController()->setLampState(name, state);

    }else if(message.compare("set_coil_state") == 0){
      string name = document->FindMember("name")->value.GetString();
      int state = document->FindMember("value")->value.GetInt();
      pGameController->coilController()->setCoilState(name, state);

    }else if(message.compare("set_button_state") == 0){
      string name = document->FindMember("name")->value.GetString();
      int state = document->FindMember("value")->value.GetInt();
      pGameController->buttonController()->overrideButtonState(name, state);

    }else if(message.compare("get_game_states") == 0){ //note the plural S

      pGameState->sendAllStatesToWeb();
    }else if(message.compare("get_game_state") == 0){
      pGameState->sendToWeb();

    }else if(message.compare("set_game_state") == 0){
      string state = document->FindMember("value")->value.GetString();
      setGameState(state);
    }

    //I don't like this here.
    delete(document);
  }
}
void cGame::mWorldMapUpdate(){

	if (player1.getPlayerX() > 0 && player1.getPlayerX() < (SCREEN_WIDTH - player1.getPlayerWidth())){
		player1.mPlayerQuad.x = player1.getPlayerX();
	}
	if (player1.getPlayerY() > 0 && player1.getPlayerY() < (SCREEN_HEIGHT - player1.getPlayerHeight()))
		player1.mPlayerQuad.y = player1.getPlayerY();

	if (player1.mPlayerSteps >= mRandomEncounter){
		setGameState(__eGS_STARTMENU);
		mWorldMapUnload();
	}


	mWorldMapDraw();
}
Exemple #17
0
void GameDocument::onSetSelf( Noun * pShip )
{
	if ( pShip )
	{
		TRACE( CharString().format("GameDocument::onShipSelected, pShip = %p", pShip) );
		m_bShipLost = false;

		context()->scriptCall( CharString().format("onShipAttached( %s )", pShip->key().string()) );

		if ( m_GameState == GS_SERVER_TRANSFER )
			setGameState( GS_GAME );
	}
	else
	{
		onShipDetached();
	}
}
 void hardResetAndGoToScreen()
 {                        
     if (m_game_mode != GAME) GUIEngine::getCurrentScreen()->tearDown();
     m_menu_stack.clear();
     
     GUIEngine::clearScreenCache();
     
     T* instance = T::getInstance();
     
     m_menu_stack.push_back(instance->getName());
     setGameState(MENU);
     
     switchToScreen(instance->getName().c_str());
     getCurrentScreen()->init();
     
     onTopMostScreenChanged();
 }
Exemple #19
0
void GameDocument::onContextEnd( const char * pMessage )
{
	TRACE( "GameDocument::onContextEnd" );

	// display the end-game screen!
	setGameState( GS_END_GAME );
	// set the end game boolean to true
	m_EndGame = true;
	// inform our script
	context()->scriptCall( "onEndGame()" );

	// clear some pointers
	m_pCursorTarget = NULL;
	m_pLastSpawn = NULL;
	// store the end message into the message window of the EndGame scene
	WindowText * pWindow = WidgetCast<WindowText>( InterfaceContext::findNode( "Message" ) );
	if ( pWindow != NULL )
		pWindow->setText( pMessage );
}
Exemple #20
0
void GameScene::updateLevelTime() {
    setLevelTime(levelTime() - 1);
    if(levelTime() < 1) {
        setLevelUpgrade(true);
        setGameState(GamePaused);
        setLevel(m_level + 1);
        if(highestLevel() < level()) {
            setHighestLevel(level());
        }
        if(gameMode() == GameScene::ModeClassic) {
            if(settings.value("highestLevel", 1).toInt() < level()) {
                settings.setValue("highestLevel", level());
            }
        } else {
            if(settings.value("highestLevelParty", 1).toInt() < level()) {
                settings.setValue("highestLevelParty", level());
            }
        }
#ifdef OS_IS_ANDROID
        qDebug() << "Force syncing settings";
        settings.sync();
#endif
    }
}
Exemple #21
0
void GameDocument::onShipDestroyed( Noun * pKiller )
{
	TRACE( "GameDocument::onShipDestroyed" );

	setGameState( GS_DEATH );
	m_bShipLost = true;

	// inform our script
	CharString sSelf = ship()->key().string();
	CharString sKiller = "";
	if ( pKiller != NULL )
		sKiller = pKiller->key().string();
	context()->scriptCall( CharString().format("onDeath( '%s','%s' )", sSelf, sKiller) );

	// reset the camera time
	s_fCamera = 0.0f;

	WindowObserve * pWindow = WidgetCast<WindowObserve>( InterfaceContext::findNode( "ObserveWindow" ) );
	if ( pWindow != NULL )
	{
		pWindow->setCameraMode( WindowObserve::CHASE );
		pWindow->setTargetMode( WindowObserve::LOCKED );
		pWindow->setTarget( ship() );
	}

	WindowText * pMessage = WidgetCast<WindowText>( InterfaceContext::findNode( "TextMessage" ) );
	if ( pMessage != NULL )
	{
		if ( pKiller && pKiller != ship() )
			pMessage->setText( CharString().format("Ship destroyed by %s...", pKiller->name()) );
		else if ( pKiller == ship() )
			pMessage->setText( "You have self destructed..." );
		else
			pMessage->setText( "Ship destroyed..." );
	}
}
Exemple #22
0
void GameScene::retryGame() {
    setLevel(m_level);
    setGameState(GameRunning);
}
Exemple #23
0
//Constructor
cGame::cGame(){
	setGameState(__eGS_NONE);
}
Exemple #24
0
void Antimony::updateGameState()
{
	switch (getGameState())
	{
		case GAMESTATE_INGAME:				// In-game (non-paused, non-menu etc.)
		{
			if (keys.sk_escape.getState() == BTN_PRESSED && devConsole.isClosed())		// Escape
			{
				if (game.debug)
					PostQuitMessage(0);
				else
					setGameState(GAMESTATE_PAUSEMENU);
			}
			else if (keys.pause.getState() == BTN_PRESSED && devConsole.isClosed())		// Pause key
			{
				setGameState(GAMESTATE_PAUSED);
			}
			break;
		}
		case GAMESTATE_PAUSEMENU:			// Pause menu (in-game inventory/pause menu)
		{
			if (keys.sk_escape.getState() == BTN_PRESSED && devConsole.isClosed())
			{
				// TODO: Implement quit button & pause menu
				//setGameState(GAMESTATE_INGAME);
				PostQuitMessage(0);
			}
			break;
		}
		case GAMESTATE_PAUSED:
		{
			if (keys.sk_escape.getState() == BTN_PRESSED && devConsole.isClosed())		// Escape
			{
				if (game.debug)
					PostQuitMessage(0);
				else
					setGameState(GAMESTATE_PAUSEMENU);
			}
			else if (keys.pause.getState() == BTN_PRESSED && devConsole.isClosed())		// Pause key
			{
				setGameState(GAMESTATE_INGAME);
			}
			break;
		}
	}

	if (keys.console.getState() == BTN_PRESSED)		// Dev console
	{
		if (devConsole.isEnabled())
		{
			if (devConsole.isOpen())
			{
				devConsole.close();
				mouse.acquire();
			}
			else
			{
				devConsole.open();
				mouse.release();
			}
		}
	}
}
Exemple #25
0
GameScene::GameScene(GameView *parent) :
    QGraphicsScene(parent),
    m_level(1),
    m_highestLevel(1),
    m_gameState(GameRunning),
    m_dt(0),
    firstStep(true),
    m_selectedType(ParticlePositive),
    m_isSlowMotionEnabled(false),
    currentTime(0),
    lastFrameTime(0),
    frameNumber(0),
    dtSum(0)
{
    qRegisterMetaType<GameScene::GameMode>("GameMode");
    qRegisterMetaType<GameScene::GameState>("GameState");
#ifdef OS_IS_ANDROID
    qDebug() << "Force syncing settings";
    settings.sync();
#endif
    if(isDemo()) {
        qDebug() << "This is the demo version";
    } else {
        qDebug() << "This is the full version";
    }

    setSelectedType(ParticlePositive);

    // load images
    selectionImage = QImage(":/images/selection-overlay.png");
    positiveImage = QImage(":/images/particle-positive.png");
    negativeImage = QImage(":/images/particle-negative.png");
    neutralImage = QImage(":/images/particle-neutral.png");
    playerImage = QImage(":/images/particle-player.png");
    playerOverchargedImage = QImage(":/images/particle-player-overcharged.png");
    glowingImage = QImage(":/images/particle-glowing.png");
    enemyImage = QImage(":/images/particle-enemy.png");
    slowMotionImage = QImage(":/images/particle-slow-motion.png");
    repellentImage = QImage(":/images/particle-repellent.png");
    transferImage = QImage(":/images/particle-transfer.png");

    setSceneRect(0, 0, 854, 480); // TODO: just for init, should be chosen by the platform
    setItemIndexMethod(QGraphicsScene::NoIndex);

    // Background image
    QPixmap backgroundPixmap(":/images/background.png");
    backgroundImage = this->addPixmap(backgroundPixmap);

    // Main menu
    QDeclarativeEngine *engine = new QDeclarativeEngine;
//#ifdef OS_IS_ANDROID
//    QDeclarativeComponent mainMenuComponent(engine, QUrl(adjustPath("assets:/qml/MainMenu.qml")));
//#else
    QDeclarativeComponent mainMenuComponent(engine, QUrl("qrc:/qml/MainMenu.qml"));
//#endif
    engine->rootContext()->setContextProperty("contextGameScene", this);
    mainMenu = qobject_cast<QGraphicsObject *>(mainMenuComponent.create());
    qDebug() << "Component errors:\n" << mainMenuComponent.errors();
    qDebug() << "End component errors";
    // Connect the QML back to this class
    addItem(mainMenu);
    mainMenu->setZValue(1000);
    m_specialParticles = new QList<int>;

#ifdef OS_IS_HARMATTAN
    mainMenu->setProperty("exit.visible", false);
#endif


#ifdef OS_IS_SYMBIAN
    qreal screenWidth = QApplication::desktop()->screenGeometry().width();
    qreal screenHeight = QApplication::desktop()->screenGeometry().height();
    if(screenWidth  > screenHeight) { // Symbian hack
        mainMenu->setProperty("width", screenWidth);
        mainMenu->setProperty("height", screenHeight);
    } else {
        mainMenu->setProperty("width", screenHeight);
        mainMenu->setProperty("height", screenWidth);
    }
#endif

    // set up timer
    levelTimer = new QTimer(this);
    levelTimer->setInterval(1000);
    connect(levelTimer, SIGNAL(timeout()), SLOT(updateLevelTime()));

    // Set up animations
    timeFactorAnimation = new QPropertyAnimation(this, "timeFactor");
    qDebug() << "Highest level is" << m_level;

    setGameState(GameStarted);

    // just init all in the resize() function
    resized();

    // Start level and start timers
    //    startLevel(level());

    connect(&advanceTimer, SIGNAL(timeout()), SLOT(advance()));
    advanceTimer.start(10);
    time.start();
    qDebug() << "Timers started!";

    // dashboard button
#if (defined(OS_IS_DESKTOP_LINUX) || defined(Q_OS_WIN32) || defined(Q_OS_MAC) || defined(Q_WS_MAEMO_5))
    qDebug() << "Show dashboard button";
    mainMenu->setProperty("dashboardButtonVisible", true);
#else
    qDebug() << "Don't show dashboard button";
    mainMenu->setProperty("dashboardButtonVisible", false);
#endif

    // load settings
    setGameMode((GameMode)settings.value("gameMode", ModeClassic).toInt());
}
Exemple #26
0
cGame::cGame(bool state)
:	mPlayerScore(0)
{
	setGameState(state);
}
Exemple #27
0
void GameDocument::onDisconnected()
{
	TRACE( "GameDocument::onDisconnected" );
	setGameState( GS_DISCONNECTED );
	m_bIsConnected = false;
}
Exemple #28
0
void GameScene::gameOver() {
    setGameState(GameOver);
}
void InputEngine::controllerButtonDown(SDL_Event e, GameState state)
{
    if (state == GameState::PLAY || state == GameState::END)
    {
        if (inputs[e.cdevice.which] == nullptr || cameras[e.cdevice.which] == nullptr) return;

        if (e.cbutton.button == SDL_CONTROLLER_BUTTON_X)
        {
            inputs[e.cdevice.which]->shootPizza = true;
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_A)
        {
            inputs[e.cdevice.which]->handBrake = true;
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_B)
        {
            cameras[e.cdevice.which]->setReverseCam(true);
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_RIGHTSTICK)
        {
            //unFucker();
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_Y)
        {
            inputs[e.cdevice.which]->jump = true;
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_START)
        {
            if (isCheatCode(e.cdevice.which))
            {
                space();
            }
            (state == GameState::PLAY) ? setGameState(GameState::PAUSE) : setGameState(GameState::BACK_TO_MENU);
        }

        pastInputs[e.cdevice.which][pastInputsIndex[e.cdevice.which]] = e.cbutton.button;
        pastInputsIndex[e.cdevice.which] = (pastInputsIndex[e.cdevice.which] + 1) % BUFFER_SIZE;
    }
    else if (state == GameState::MENU)
    {
        if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
        {
            menuInput(InputType::UP);
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
        {
            menuInput(InputType::DOWN);
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT)
        {
            menuInput(InputType::LEFT);
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
        {
            menuInput(InputType::RIGHT);
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_A)
        {
            menuInput(InputType::ENTER);
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_B)
        {
            menuInput(InputType::BACK);
        }
    }
    else if (state == GameState::PAUSE)
    {
        if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_UP)
        {
            pauseInput(InputType::UP);
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN)
        {
            pauseInput(InputType::DOWN);
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_A)
        {
            pauseInput(InputType::ENTER);
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_B)
        {
            pauseInput(InputType::BACK);
        }
        else if (e.cbutton.button == SDL_CONTROLLER_BUTTON_START)
        {
            pauseInput(InputType::BACK);
        }
    }
}
//*************************************************************************************
TheGame::TheGame() : screen(0){
    setGameState(0);
    screenHeight_ = 500;
    screenWidth_ = 800;
    introBG = new Sprite();
}