Example #1
0
void GameLayer::onTouchEnded(Touch *touch, Event *unused_event){
	if(getGameStatus()==GAME_STATUS_READY){
		setGameStatus(GAME_STATUS_START);
		delegator->onGamePlay();
		snake->resetSnake();	
		setBall();
		ball->setVisible(true);
		bSetDirection=false;
		return ;
	}
	if(getGameStatus()==GAME_STATUS_OVER){
		setGameStatus(GAME_STATUS_READY);
		delegator->onGameStart();
		snake->removeAllChildren();
		ball->setVisible(false);
	}

	if(getGameStatus()==GAME_STATUS_START)
		this->setSnakeDirection(touch->getLocation());
}
Example #2
0
/**
 * Hugo game state machine - called during onIdle
 */
void HugoEngine::runMachine() {
	Status &gameStatus = getGameStatus();

	// Don't process if gameover
	if (gameStatus._gameOverFl)
		return;

	_curTime = g_system->getMillis();
	// Process machine once every tick
	while (_curTime - _lastTime < (uint32)(1000 / getTPS())) {
		g_system->delayMillis(5);
		_curTime = g_system->getMillis();
	}

	_lastTime = _curTime;

	switch (gameStatus._viewState) {
	case kViewIdle:                                 // Not processing state machine
		_screen->hideCursor();
		_intro->preNewGame();                       // Any processing before New Game selected
		break;
	case kViewIntroInit:                            // Initialization before intro begins
		_intro->introInit();
		gameStatus._viewState = kViewIntro;
		break;
	case kViewIntro:                                // Do any game-dependant preamble
		if (_intro->introPlay()) {                  // Process intro screen
			_scheduler->newScreen(0);               // Initialize first screen
			gameStatus._viewState = kViewPlay;
		}
		break;
	case kViewPlay:                                 // Playing game
		_screen->showCursor();
		_parser->charHandler();                     // Process user cmd input
		_object->moveObjects();                     // Process object movement
		_scheduler->runScheduler();                 // Process any actions
		_screen->displayList(kDisplayRestore);      // Restore previous background
		_object->updateImages();                    // Draw into _frontBuffer, compile display list
		_screen->drawStatusText();
		_screen->displayList(kDisplayDisplay);      // Blit the display list to screen
		_sound->checkMusic();
		break;
	case kViewInvent:                               // Accessing inventory
		_inventory->runInventory();                 // Process Inventory state machine
		break;
	case kViewExit:                                 // Game over or user exited
		gameStatus._viewState = kViewIdle;
		_status._doQuitFl = true;
		break;
	}
}
Example #3
0
void GameLayer::snakePlay(float at){
	
	if(getGameStatus()==GAME_STATUS_START){
		int width=SCREEN_WIDTH/SNAKE_WIDTH;
		int height=SCREEN_HEIGHT/SNAKE_WIDTH;
		Rect rect(1,1,width-2,height-2);
		if(snake->IsDie(rect)){
			setGameStatus(GAME_STATUS_OVER);
			delegator->onGameEnd();
			return;
		}
		if(IsEatBall()){
			snake->addSnakeNode();
			this->setBall();
		}
		else snake->play();
		bSetDirection=false;
		return;
	}
	
}
bool GoalSideBackground::execute()
{
    if( !getGoalPoles().getObjects().empty())
    {
        int y = getBackgroundY().calculateMode();
        int u = getBackgroundU().calculateMode();
        int v = getBackgroundV().calculateMode();

        //DRAW_TEXT("Background", 10, 20, DebugDrawer::LIGHT_YELLOW, "Y: %d, U: %d, V: %d", y, u, v);
        Debugger::DEBUG("GoalSideBackground", "Y: %d, U: %d, V: %d", y, u, v);

        if( getGameStatus().gameState == IGame::READY) {
            bool firstHalf = getGameStatus().isFirstHalf;
            if( firstHalf != mLastFirstHalf) {
                Debugger::INFO("GoalSideBackground", "Change goal sides!");
                mMyGoalBackgroundY = mOpGoalBackgroundY;
                mMyGoalBackgroundU = mOpGoalBackgroundU;
                mMyGoalBackgroundV = mOpGoalBackgroundV;
                Debugger::DEBUG("GoalSideBackground", "My: %d %d %d",
                                mMyGoalBackgroundY, mMyGoalBackgroundU, mMyGoalBackgroundV);
                mOpGoalBackgroundY = mMyGoalBackgroundY;
                mOpGoalBackgroundU = mMyGoalBackgroundU;
                mOpGoalBackgroundV = mMyGoalBackgroundV;
                Debugger::DEBUG("GoalSideBackground", "Op %d %d %d",
                                mOpGoalBackgroundY, mOpGoalBackgroundU, mOpGoalBackgroundV);
                mLastFirstHalf = firstHalf;
            }
            int pan = getBodyStatus().getPan();
            if( pan >= -45 && pan <= +45) {
                mOpGoalBackgroundY = (3*mOpGoalBackgroundY + y) / 4;
                mOpGoalBackgroundU = (3*mOpGoalBackgroundU + u) / 4;
                mOpGoalBackgroundV = (3*mOpGoalBackgroundV + v) / 4;
                Debugger::INFO("GoalSideBackground", "OpGoal updated!");
                Debugger::DEBUG("GoalSideBackground", "OpGoal: %d %d %d",
                                mOpGoalBackgroundY, mOpGoalBackgroundU, mOpGoalBackgroundV);
            } else if( pan <= -135 || pan >= +135) {
                mMyGoalBackgroundY = (3*mMyGoalBackgroundY + y) / 4;
                mMyGoalBackgroundU = (3*mMyGoalBackgroundU + u) / 4;
                mMyGoalBackgroundV = (3*mMyGoalBackgroundV + v) / 4;
                Debugger::INFO("GoalSideBackground", "MyGoal updated!");
                Debugger::DEBUG("GoalSideBackground", "MyGoal: %d %d %d",
                                mMyGoalBackgroundY, mMyGoalBackgroundU, mMyGoalBackgroundV);
            }
            return true;
        }

        int varMy = abs(mMyGoalBackgroundY - y)
                    + abs(mMyGoalBackgroundU - u)
                    + abs(mMyGoalBackgroundV - v);
        int varOp = abs(mOpGoalBackgroundY - y)
                    + abs(mOpGoalBackgroundU - u)
                    + abs(mOpGoalBackgroundV - v);

        double chanceMy = 0.0;
        if( varMy < COLOR_VARIANCE_MAX) {
            chanceMy = (COLOR_VARIANCE_MAX - (double)varMy) / COLOR_VARIANCE_MAX;
        }

        double chanceOp = 0.0;
        if( varOp < COLOR_VARIANCE_MAX) {
            chanceOp = (COLOR_VARIANCE_MAX - (double)varOp) / COLOR_VARIANCE_MAX;
        }

        chanceOp = chanceOp / (chanceOp + chanceMy);
        chanceMy = chanceMy / (chanceOp + chanceMy);

        Debugger::DEBUG("GoalSideBackground", "My: %.2f (%d), Op: %.2f (%d)", chanceMy, varMy, chanceOp, varOp);

        getGoalSideBackgroundPrediction().setProbability(chanceOp);
    } else {
        getGoalSideBackgroundPrediction().setProbability(0.5);
    }

    return true;
}
bool GoalSidePredictor_MD::execute() {
	bool found = false;

	if (!getRemovedBallCandidates().getObjects().empty()) {
		const vector<Object>& balls = getRemovedBallCandidates().getObjects();
		for (vector<Object>::const_iterator it = balls.begin(); it != balls.end(); ++it) {
			if ((*it).getBoundingBox().width >= mMinRemovedBallWidth) {
				int pan = getBodyStatus().getPan();
				if (abs(pan) >= mMinPanAngle && abs(pan) <= mMaxPanAngle) {
					double aspect = (double)(*it).getBoundingBox().width / (double)(*it).getBoundingBox().height;
					if (1.0 - mAspectRatioRange <= aspect && aspect <= 1.0 + mAspectRatioRange) {
						//Debugger::DEBUG("GoalSidePredictor_MD", "Detected valid orientation object at pan=%d", pan);

						double myPercent = 0;
						double opPercent = 0;
						if (pan > 0) {
							if (mObjectsOnRightInFirstHalf) {
								opPercent = mConfidence;
							} else {
								myPercent = mConfidence;
							}
						} else {
							if (mObjectsOnRightInFirstHalf) {
								myPercent = mConfidence;
							} else {
								opPercent = mConfidence;
							}
						}
						if (!getGameStatus().isFirstHalf) {
							double tmp = myPercent;
							myPercent = opPercent;
							opPercent = tmp;
						}

						if (myPercent != 0.0) {
							mProbability -= myPercent;
						} else {
							mProbability += opPercent;
						}
						if (mProbability < 0) {
							mProbability = 0;
						}
						if (mProbability > 1) {
							mProbability = 1;
						}

						Debugger::DEBUG("GoalSidePredictor_MD", "Object votes for %s goal, new probability=%f", myPercent != 0.0 ? "my" : "opponent", mProbability);
						DRAW_BOX("GoalSidePredictor_MD", (*it).getBoundingBox().topLeft.getX(), (*it).getBoundingBox().topLeft.getY(), (*it).getBoundingBox().width, (*it).getBoundingBox().height, DebugDrawer::RED);
						found = true;
					} else {
						//DRAW_BOX("GoalSidePredictor_MD", (*it).getBoundingBox().topLeft.getX(), (*it).getBoundingBox().topLeft.getY(), (*it).getBoundingBox().width, (*it).getBoundingBox().height, DebugDrawer::LIGHT_GRAY);
						Debugger::DEBUG("GoalSidePredictor_MD", "Object ignored, aspect ratio=%f", aspect);
					}
				}
			}
		}
	}
	if (!found) {
		if (mProbability != 0.5) {
			if (mProbability > 0.5) {
				mProbability -= mDecayValue;
			} else {
				mProbability += mDecayValue;
			}
			//Debugger::DEBUG("GoalSidePredictor_MD", "No orientation objects seen, new probability=%f", mProbability);
		}
	}
	getGoalSideMDPrediction().setProbability(mProbability);

	return true;
}