Ejemplo n.º 1
0
void Level::updateLeaves(float dt) {
    GameModel* gameModel = GameModel::getInstance();
    for (auto iter = this->drowningLeaves->begin(); iter != this->drowningLeaves->end(); iter++) {
        Leaf* drowningLeaf = (Leaf*) *iter;
        if (drowningLeaf->getDrowning()) {
            if (drowningLeaf->getCurrentDrownDuration() != -1) {
                drowningLeaf->setCurrentDrownDuration(drowningLeaf->getCurrentDrownDuration() - dt);
                if (drowningLeaf->getCurrentDrownDuration() < 0) {
                    drowningLeaf->setCurrentDrownDuration(-1);
                    
                    DataEvent* dataEvent = new DataEvent();
                    dataEvent->setEventCode(EVT_LEAF_DROWN);
                    dataEvent->setArgumentReference(drowningLeaf);
                    gameModel->fireEvent(dataEvent);
                    
                    this->leaves->removeObjectForKey(drowningLeaf->getPositionIndex());
                    this->drowningLeaves->eraseObject(drowningLeaf);
                    
                    if (this->leaves->count() == 1) {
                        this->done = true;
                    }
                    break;
                }
            }
            drowningLeaf->play(SPRITE_TYPE_MAIN, FRAME_LEAF_FALL);
        }
    }
}
Ejemplo n.º 2
0
void ConfirmLayer::createLayersContent() {
    GameModel* gameModel = GameModel::getInstance();
    
    Face* backgroundFade = new Face();
    backgroundFade->initWithFile(ANI_BACKGROUND_FADE);
    backgroundFade->setPosition(Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
    backgroundFade->setOpacity(0);
    this->mainLayer->addChild(backgroundFade);
    this->backgroundFade = backgroundFade;
    {
        FiniteTimeAction* fadeIn = FadeIn::create(0.5f);
        backgroundFade->registerState(STATE_FADE_IN, fadeIn);
        
        FiniteTimeAction* fadeOut = FadeOut::create(0.5f);
        backgroundFade->registerState(STATE_FADE_OUT, fadeOut);
    }
    
    Face* menuFace = new Face();
    menuFace->initWithSpriteFrameName(ANI_BOX_CONFIRM);
    menuFace->setPosition(Point(gameModel->getDisplayResolutionSize().width / 2, -500));
    this->mainLayer->addChild(menuFace);
    this->menuFace = menuFace;
    Size menuFaceSize = menuFace->getContentSize();
    
    UGMenu* optionMenu = UGMenu::create();
    optionMenu->setPosition(Point::ZERO);
    menuFace->addChild(optionMenu);
    {
        Label* confirmLabel = Label::createWithBMFont(FONT_GAME_SMALL, TXT_CONFIRM_TEXT);
        confirmLabel->setPosition(menuFaceSize.width / 2, menuFaceSize.height / 2);
        this->menuFace->addChild(confirmLabel);
    }
    {
        FiniteTimeAction* move1 = MoveTo::create(0, menuFace->getPosition());
        FiniteTimeAction* move2 = MoveTo::create(0.5f, Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
        FiniteTimeAction* move3 = CallFunc::create(CC_CALLBACK_0(ConfirmLayer::onOptionBoardMoveUpDone, this));
        FiniteTimeAction* move123 = Sequence::create(move1, move2, move3, NULL);
        menuFace->registerState(STATE_MOVE_UP, move123);
        
        FiniteTimeAction* move4 = MoveTo::create(0, Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
        FiniteTimeAction* move5 = MoveTo::create(0.5f, menuFace->getPosition());
        FiniteTimeAction* move6 = CallFunc::create(CC_CALLBACK_0(ConfirmLayer::onOptionBoardMoveDownDone, this));
        FiniteTimeAction* move456 = Sequence::create(move4, move5, move6, NULL);
        menuFace->registerState(STATE_MOVE_DOWN, move456);
        
        MenuItemSprite* okButton = Utils::createButton((char*) TXT_OK, 16, ANI_BUTTON_SMALL, ANI_BUTTON_SMALL);
        okButton->setCallback(CC_CALLBACK_1(ConfirmLayer::onOkButtonClick, this));
        okButton->setPosition(Point(menuFaceSize.width / 2 - 129, 0));
        okButton->setEnabled(false);
        optionMenu->addChild(okButton);
        this->okButton = okButton;
        
        MenuItemSprite* cancelButton = Utils::createButton((char*) TXT_CANCEL, 16, ANI_BUTTON_SMALL, ANI_BUTTON_SMALL);
        cancelButton->setCallback(CC_CALLBACK_1(ConfirmLayer::onCancelButtonClick, this));
        cancelButton->setPosition(Point(menuFaceSize.width / 2 + 129, 0));
        cancelButton->setEnabled(false);
        optionMenu->addChild(cancelButton);
        this->cancelButton = cancelButton;
    }
}
Ejemplo n.º 3
0
void resetGameLoadMapAddActors( GameModel & game, PathGraph & pathgraph, GameView & view, GameViewSound & sound, ActorControllerKeyboard * & keyboardController, std::map< std::string, ActorControllerAI * > & aiControllers, std::map< std::string, float > & globalVariables, float gametime, const std::string & filename ) {
	// delete ai controllers
	for( std::map< std::string, ActorControllerAI * >::iterator iter = aiControllers.begin( ); iter != aiControllers.end( ); iter++ ) {
		delete iter->second;
	}
	aiControllers.clear( );

	// reset game
	resetGame( game, pathgraph, view, sound );
	setGameVars( game, globalVariables );

	// load map
	loadMap( game, pathgraph, view, sound, globalVariables, filename );
	view.initBrushTextures( );

	// add players
	//addPlayer( game, keyboardController, globalVariables, gametime, "Player" );
	addActor( game, keyboardController, globalVariables, gametime, "Player" );
	for( int i = 0; i < 3; i++ ) {
		aiControllers[ "AI-" + std::string( 1, (char)( i + 49 ) ) ] = new ActorControllerAI( &game, pathgraph );
		//addAI( game, aiControllers[ "AI-" + std::string( 1, (char)( i + 49 ) ) ], globalVariables, gametime, "AI-" + std::string( 1, (char)( i + 49 ) ) );
		addActor( game, aiControllers[ "AI-" + std::string( 1, (char)( i + 49 ) ) ], globalVariables, gametime, "AI-" + std::string( 1, (char)( i + 49 ) ) );
	}
	view.setCamera( &game.getActors( ).front( ) );
	sound.setCamera( &game.getActors( ).front( ) );
}
Ejemplo n.º 4
0
void FreeKickStrategy::assignBeh()
{
    GameModel *gm = GameModel::getModel();

    BehaviorAssignment<KickToGoal> kickToGoalAssignment;
    kickToGoalAssignment.setSingleAssignment(true);
    kickToGoalAssignment.assignBeh(gm->getMyTeam().at(0));
}
Ejemplo n.º 5
0
void DefendOneOnOne::perform(Robot *r)
{
    GameModel * gm = GameModel::getModel();
	
	setMovementTargets(gm->getPenaltyPoint(), 
		Measurments::angleBetween(gm->getPenaltyPoint(), gm->getOpponentGoal()));
		
	GenericMovementBehavior::perform(r);
}
Ejemplo n.º 6
0
void LevelScene::disposeComponents() {
    this->unscheduleUpdate();
    this->eventListeners->clear();
    
    GameModel* gameModel = GameModel::getInstance();
    gameModel->removeEventListener(this->gameEventListener);
    
    this->_eventDispatcher->removeEventListener(this->touchListener);
    this->_eventDispatcher->removeEventListener(this->keyBoardListener);
}
Ejemplo n.º 7
0
void PenaltyStrategy::assignBeh()
{
    GameModel* gamemodel = GameModel::getModel();

    /* This BeheaviorAssignment assigns only once
     * to myTeam[0]. setSingleAssignment is used to check
     * if the robot already has the behavior. If it does,
     * PenaltyBehavior is not assigned
     */
    BehaviorAssignment<PenaltyBehavior> penAssignment;
    penAssignment.setSingleAssignment(true);
    penAssignment.assignBeh(gamemodel->getMyTeam().at(0));
}
Ejemplo n.º 8
0
void DefendFarFromBall::perform(Robot *robot)
{
    GameModel *gm = GameModel::getModel();
    Point robPoint = robot->getRobotPosition();
    Point ballPoint = gm->getBallPoint();
    Point myGoal = gm->getMyGoal();
    double direction = Measurments::angleBetween(myGoal, ballPoint);
    Point defensiveWall(cos(direction)*DISTANCE + myGoal.x,
                        sin(direction)*DISTANCE + myGoal.y);

    /* Check if there are any opp robots within 3000 distance of the ball
    *  This boolean is used to determine if the goalie should wait
    *  before kicking the ball to a teammate in case an opp robot intersepts
    *  the ball
    */
    bool safeToKick = 1;
    for(Robot* opRob:gm->getOponentTeam())
    {
        if (Measurments::distance(opRob->getRobotPosition(),ballPoint) < 3000)
            safeToKick = 0;
    }

    bool isScoreHazard =
            Measurments::distance(myGoal, ballPoint) < 1200
            and not(Measurments::isClose(robPoint, ballPoint, 100))
            and lastKickCounter <= 0
            and safeToKick;

    if(isScoreHazard or isKickingAwayBall) {
        if(wasNotPreviousScoreHazard) {
            KTPSkill = new Skill::KickToPoint(Point(0,0), 50*M_PI/180);
            isKickingAwayBall = true;
            wasNotPreviousScoreHazard = false;
        }
        if(KTPSkill->perform(robot) or
                Measurments::distance(ballPoint, myGoal) > 1200){
            lastKickCounter = 100;
            wasNotPreviousScoreHazard = true;
            isKickingAwayBall = false;
            delete KTPSkill;
            KTPSkill = nullptr;
        }
    } else {
        if(lastKickCounter > 0)
            --lastKickCounter;
        Point defensiveWall(cos(direction)*DISTANCE + myGoal.x,
                            sin(direction)*DISTANCE + myGoal.y);
        setMovementTargets(defensiveWall, direction, false, false);
        GenericMovementBehavior::perform(robot, Movement::Type::facePoint);
    }
}
Ejemplo n.º 9
0
void init(void)
{
	glClearColor(0.0, 0.0, 0.0, 1.0);

	glEnable(GL_DEPTH_TEST);

	model.LoadModel("model/box.obj");
}
Ejemplo n.º 10
0
void resetGame( GameModel & game, PathGraph & pathgraph, GameView & view, GameViewSound & sound ) {
	view.clearObjects( );
	view.uninitActorText( );
	view.uninitBrushes( );

	sound.uninitActors( );

	game = GameModel( );
	pathgraph = PathGraph( );

	game.addObserver( &view );
	view.setGame( &game );
	view.setThirdPerson( );

	game.addObserver( &sound );
	sound.setGame( &game );
}
Ejemplo n.º 11
0
void PadLayer::createLayersContent() {
    GameModel* gameModel = GameModel::getInstance();
    Size displayResolutionSize = gameModel->getDisplayResolutionSize();
    
    this->padA = new Face();
    this->padA->initWithFile(ANI_BUTTON_A);
    this->padA->setPosition(Point(displayResolutionSize.width - CONF_PAD_PADDING_X, CONF_PAD_PADDING_Y) +
                                           Point(CONF_RANGE_TO_TOUCH, 0));
    this->addChild(this->padA);
    this->padA->setOpacity(100);
    
    this->padB = new Face();
    this->padB->initWithFile(ANI_BUTTON_B);
    this->padB->setPosition(Point(displayResolutionSize.width - CONF_PAD_PADDING_X, CONF_PAD_PADDING_Y) +
                      Point(-CONF_RANGE_TO_TOUCH, 0));
    this->addChild(padB);
    this->padB->setOpacity(100);
}
Ejemplo n.º 12
0
void ChapterScene::updatePageAuto() {
    GameModel* gameModel = GameModel::getInstance();
    int chapterSize = gameModel->getMapData()->getLevelSize();
    float distance = this->chapterLayerOffset.x - this->chapterLayer->getPosition().x;
    float result = distance / (this->chapterLayer->getContentSize().width / chapterSize);
    int page = floor(result);
    float redundant = result - page;
    if (redundant > 0.5f) {
        page++;
    }
    page++;
    if (page < 1) {
        page = 1;
    } else if (page > chapterSize) {
        page = chapterSize;
    }
    this->updatePage(page);
}
Ejemplo n.º 13
0
void ChapterScene::onTouchEnded(Touch* touch, Event* event) {
    GameModel* gameModel = GameModel::getInstance();
    this->updatePageAuto();
    
    Point point = this->convertTouchToNodeSpace(touch);
    bool moveTooFar = false;
    float dx = point.x - this->firstPoint.x;
    float dy = point.y - this->firstPoint.y;
    if (abs(dx) > CONF_TOUCH_RANGE || abs(dy) > CONF_TOUCH_RANGE) {
        moveTooFar = true;
    }
    point = point - this->chapterLayer->getPosition();
    
    for (int i = 0; i < this->chapterLayer->getChildren().size(); i++) {
        Face* chapterFace = dynamic_cast<Face*>(this->chapterLayer->getChildren().at(i));
        if (chapterFace != NULL) {
            RectBody* chapterBody = new RectBody(chapterFace->getContentSize().width, chapterFace->getContentSize().height);
            chapterBody->setPosition(chapterFace->getPosition());
            
            if (chapterBody->contains(point)) {
                if (!moveTooFar && chapterFace->getTag() != -1) {
                    if (!gameModel->checkLevelRequireSocial(i + 1)) {
                        this->shareLayer->show(TXT_REQUIRE_SHARE);
                        GameEvent* gameEvent = new GameEvent();
                        gameEvent->setEventCode(EVT_SHOW_SHARE_REQUIRED);
                        this->fireEvent(gameEvent);
                    } else {
                        DataEvent* gameEvent = new DataEvent();
                        gameEvent->setEventCode(EVT_START_PLAY);
                        gameEvent->setArgumentInt(chapterFace->getTag());
                        this->fireEvent(gameEvent);
                        
                        this->_eventDispatcher->removeEventListener(this->touchListener);
                    }
                }
                this->flash(chapterFace);
                break;
            }
        }
    }
}
Ejemplo n.º 14
0
    /* This is the function that communicates outside the FPPA namespace to define
     * obstacle information. In our case, that is getting the GameModel and all the robots
     * from that. However, I would like to have this more generalized in the future.
     */
    void buildObstacleCollection()
    {
        GameModel* mod = GameModel::getModel();
        const auto& myTeam = mod->getMyTeam();
        const auto& opTeam = mod->getOponentTeam();

        currentFrameObstacles.clear();
        currentFrameObstacles.reserve(myTeam.size() + opTeam.size() + 1);

        for(Robot* rob : myTeam)
            currentFrameObstacles.push_back(rob->getRobotPosition());
        for(Robot* rob : opTeam)
            currentFrameObstacles.push_back(rob->getRobotPosition());

        currentFrameObstacles.push_back(mod->getBallPoint());

    #if FPPA_DEBUG
           // std::cout << "[FPPA] All Obstacles: " << std::endl;
            //for(Point pt : *obstacles) std::cout << pt.toString() << std::endl;
    #endif
    }
Ejemplo n.º 15
0
void LevelScene::inialize() {
    GameModel* gameModel = GameModel::getInstance();
    this->gameEventListener = new GameEventListener();
    this->gameEventListener->setHandlerObject(this);
    this->gameEventListener->setHandlerFunction(handler_function(LevelScene::processEvent));
    gameModel->addEventListener(this->gameEventListener);
    
    this->touchListener = EventListenerTouchOneByOne::create();
    this->touchListener->onTouchBegan = CC_CALLBACK_2(LevelScene::onTouchBegan, this);
    this->touchListener->onTouchMoved = CC_CALLBACK_2(LevelScene::onTouchMoved, this);
    this->touchListener->onTouchEnded = CC_CALLBACK_2(LevelScene::onTouchEnded, this);
    this->touchListener->onTouchCancelled = CC_CALLBACK_2(LevelScene::onTouchEnded, this);
    this->_eventDispatcher->addEventListenerWithSceneGraphPriority(this->touchListener, this);
    
    this->keyBoardListener = EventListenerKeyboard::create();
    this->keyBoardListener->onKeyPressed = CC_CALLBACK_2(LevelScene::onKeyPress, this);
    this->keyBoardListener->onKeyReleased = CC_CALLBACK_2(LevelScene::onKeyRelease, this);
    this->_eventDispatcher->addEventListenerWithSceneGraphPriority(this->keyBoardListener, this);
    
    this->createLayers();
    this->createLayersContent();
}
Ejemplo n.º 16
0
int main()
{
    srand((unsigned) time(NULL));
    GameModel *model = new GameModel();
    GameView *view = new GameView();
    view->setModel(model);
    view->presentation();
    int message;
    int reponse;
    reponse = model->saisieChoix();
    cout << endl;

    while(true){
    switch(reponse)
    {
        case 0:
            view->retourMenu();
            message = model->saisieChoix();
            while(message == 0)
            {
                if(model->getEndGame() == true)
                {
                    view->affiche();
                    view->answer_move(model);
                    model->direction(model->get_answer_move());
                }
                else
                {
                    message = model->rejouerPartie();
                }
            }
            if(message == 1)
                return EXIT_SUCCESS;
            break;
        case 1:
            return EXIT_SUCCESS;
            break;
        case 2:
            view->affichageScore(); // affichage du score au menu si demandé
            view->retourMenu();
            cin >> reponse;
            break;

        }
    }

    delete view;
    delete model;

    return EXIT_SUCCESS;
}
Ejemplo n.º 17
0
void TestDatabase::testSave()
{
	DatabaseAPI::connectToDatabase();

	GameModel* game = new GameModel(8008);
	game->teams->team1ID = 666;
	game->teams->team2ID = 999;

	Player* player1 = new Player(220);
	Player* player2 = new Player(225);
	game->teams->Team1.push_back(player1);
	game->teams->Team2.push_back(player2);

	game->SaveGame();

	game->teams->Team1.clear();
	game->teams->Team2.clear();

	delete player1;
	delete player2;
	delete game;


}
Ejemplo n.º 18
0
void loadMap( GameModel & game, PathGraph & pathgraph, GameView & view, GameViewSound & sound, std::map< std::string, float > & globalVariables, const std::string & filename ) {
	std::ifstream mapfile( filename.c_str( ) );
	while( !mapfile.eof( ) ) {
		char c = Map::Consume( mapfile, "{" );
		if( !mapfile.eof( ) ) {
			mapfile.putback( c );
			Map::Entity entity;
			mapfile >> entity;

			if( entity.values[ "classname" ] == "worldspawn" ) {
				addWorldspawn( game, view, entity );
			} else if( entity.values[ "classname" ] == "info_player_start" ) {
				std::istringstream originstream( entity.values[ "origin" ] );
				float x, y, z;
				originstream >> x >> z >> y;
				game.addSpawnPoint( Vector3( x, y, -z ) );
			} else if( entity.values[ "classname" ] == "light" ) {
Ejemplo n.º 19
0
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();

	gluLookAt(0.0, 0.0, -3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	glPushMatrix();
		glRotatef(rotation, 0.0, 1.0, 0.0);
		model.DrawModel();
	glPopMatrix();

	rotation += 0.1;

	if(rotation >= 360.0)
	{
		rotation = 0.0;
	}

	glutSwapBuffers();
}
Ejemplo n.º 20
0
void setGameVars( GameModel & game, std::map< std::string, float > & globalVariables ) {
	game.setDeathTime( globalVariables[ "actor_deathtime" ] );
	game.setActorMaxHealth( globalVariables[ "actor_maxhealth" ] );
	game.setItemRespawnTime( globalVariables[ "item_respawntime" ] );
	game.setItemBoundingRadius( globalVariables[ "item_size" ] );
}
Ejemplo n.º 21
0
void KickToGoal::perform(Robot * r)
{
    GameModel* gm = GameModel::getModel();
    Point ball = gm->getBallPoint();
    Point goal = gm->getOpponentGoal();
	Point rob  = r->getRobotPosition();
	float robAng = r->getOrientation();
    float goalToBall = Measurments::angleBetween(goal,ball);
    float ballToGoal = Measurments::angleBetween(ball, goal);

    Point behindBall(BEHIND_RADIUS*cos(goalToBall)+ball.x,
                     BEHIND_RADIUS*sin(goalToBall)+ball.y);

    // Create a different skill depending on the state
    switch (state) {
        case goingBehind:
            target = behindBall;
            setMovementTargets(behindBall, ballToGoal, true);
            GenericMovementBehavior::perform(r, Movement::Type::Default);
            break;
        case approaching:
            setMovementTargets(ball, ballToGoal, false);
            GenericMovementBehavior::perform(r, Movement::Type::SharpTurns);
            break;
        case kicking:
            {
                Skill::Kick k(0, 0);
                k.perform(r);
            }
            break;
        case stopping:
        {
            Skill::Stop stop;
            stop.perform(r);
        }
            break;
    }

    // Evaluate possible transitions
    switch (state){
    case goingBehind:
        cout << "going behind" << endl;
//        cout << "1\t" << Measurments::distance(behindBall, rob) << endl;
//        cout << "2\t" << abs(Measurments::angleDiff(robAng, ballToGoal))/M_PI*180 << endl;
        if (Measurments::distance(behindBall, rob) < CLOSE_ENOUGH  &&
            Measurments::isClose(robAng, ballToGoal, ANGLE)) {
            state = approaching;
            target = ball;
        }
        else if (!Measurments::isClose(target, behindBall, CLOSE_ENOUGH))
        {
            state = goingBehind;
        }
        break;
    case approaching:
        cout << "approching" << endl;
//        cout << "1\t" << Measurments::distance(ball, rob) << endl;
//        cout << "2\t" << abs(Measurments::angleDiff(robAng, ballToGoal))/M_PI*180 << endl;
        if (Measurments::distance(ball, rob) < CLOSE_ENOUGH &&
            Measurments::isClose(robAng, ballToGoal, ANGLE))
            state = kicking;
        else if (!Measurments::isClose(target, ball, CLOSE_ENOUGH))
        {
            state = goingBehind;
        }
//        else if (Measurments::distance(ball, rob) > CLOSE_ENOUGH*2) {
//            state = goingBehind;
//        }
        break;
    case kicking:
        cout << "kicking" << endl;
        state = stopping;
        break;
    case stopping:
        cout << "stopping" << endl;
       break;
    }
}
Ejemplo n.º 22
0
void ChapterScene::createLayersContent() {
    GameModel* gameModel = GameModel::getInstance();
    Size displayResolutionSize = gameModel->getDisplayResolutionSize();
    
    Face* backgroundFace = new Face();
    backgroundFace->initWithFile(ANI_BACKGROUND);
    backgroundFace->setScale(CONF_FAKE_1);
    backgroundFace->setPosition(displayResolutionSize.width / 2, displayResolutionSize.height / 2);
    this->backgroundLayer->addChild(backgroundFace);
    
    Face* chapterTitle = new Face();
    chapterTitle->initWithSpriteFrameName(ANI_CHAPTER_TITLE);
    chapterTitle->setPosition(displayResolutionSize.width / 2, displayResolutionSize.height - chapterTitle->getContentSize().height / 2 - 20);
    this->mainLayer->addChild(chapterTitle);
    
    UGMenu* mainMenu = UGMenu::create();
    mainMenu->setPosition(Point::ZERO);
    this->mainLayer->addChild(mainMenu);
    
    MenuItemSprite* backButton = Utils::createButton((char*) TXT_BACK, 16, ANI_BUTTON, ANI_BUTTON);
    backButton->setCallback(CC_CALLBACK_1(ChapterScene::backButtonClick, this));
    backButton->setPosition(gameModel->getDisplayResolutionSize().width / 2, 20 + backButton->getContentSize().height / 2);
    mainMenu->addChild(backButton);
    this->nodes->setObject(backButton, NODE_BUTTON_BACK);
    
    // create chapters
    this->chapterLayer = UGLayerColor::create();
    float totalChapterSize = gameModel->getMapData()->getLevelSize();
    float distancePerChapter = CONF_DISTANCE_PER_CHAPTER;
    float totalChapterWidth = (totalChapterSize - 1) * distancePerChapter;
    
    Face* chapterTemp = new Face();
    chapterTemp->initWithSpriteFrameName(ANI_BOX_CHAPTER);
    this->chapterTempSize = chapterTemp->getContentSize();
    
    this->chapterLayer->setContentSize(Size(totalChapterWidth + this->chapterTempSize.width, displayResolutionSize.height / 2));
    this->chapterLayer->setPosition(displayResolutionSize.width / 2 - this->chapterTempSize.width / 2, displayResolutionSize.height / 2 - this->chapterLayer->getContentSize().height / 2);
    this->chapterLayerOffset = this->chapterLayer->getPosition();
    this->mainLayer->addChild(this->chapterLayer);
    
    float posX = this->chapterTempSize.width / 2;
    float posY = this->chapterLayer->getContentSize().height / 2;
    for (int i = 0; i < totalChapterSize; i++) {
        Face* levelBox = new Face();
        if (!gameModel->checkLevelLock(i + 1)) {
            levelBox->initWithSpriteFrameName(ANI_BOX_CHAPTER);
            levelBox->setTag(i + 1);
            {
                int chapter = gameModel->getMapData()->getChapter(i + 1);
                int chapterLevel = gameModel->getMapData()->getChapterLevel(i + 1);
                char mapPath[200];
                sprintf(mapPath, DOC_BG_MAP, chapter, chapterLevel);
                
                SpriteFrameCache* sfc = SpriteFrameCache::getInstance();
                sfc->addSpriteFramesWithFile(mapPath);
                char bg1Path[200];
                sprintf(bg1Path, ANI_MAP, chapter, chapterLevel, 1);

                Face* chapterThumb = new Face();
                chapterThumb->initWithSpriteFrameName(bg1Path);
                chapterThumb->setPosition(levelBox->getContentSize().width / 2, levelBox->getContentSize().height / 2 - 10);
                chapterThumb->setTextureRect(Rect(0, 0, 160, 115));
                levelBox->addChild(chapterThumb);
                
                string levelName = gameModel->getMapData()->getLevelName(i + 1);
                char levelNameChar[200];
                sprintf(levelNameChar, "%s", levelName.data());
                Label* levelNameLabel = Label::createWithBMFont(FONT_GAME_SMALL, levelNameChar);
                levelNameLabel->setPosition(chapterThumb->getPosition() + Point(0, chapterThumb->getContentSize().height / 2 + 12));
                levelBox->addChild(levelNameLabel);
            }
        } else {
            levelBox->setTag(-1);
            levelBox->initWithSpriteFrameName(ANI_BOX_CHAPTER_LOCK);
        }
        
        levelBox->setPosition(posX, posY);
        posX = posX + distancePerChapter;
        this->chapterLayer->addChild(levelBox);
    }
    
    // add parent button for share layer
    this->shareLayer->getParentButtons()->pushBack((MenuItemSprite*) this->nodes->objectForKey(NODE_BUTTON_BACK));
}
Ejemplo n.º 23
0
void Level::frogStop() {
    this->frog->setPosition(this->frog->getCurrentTargetPoint());
    this->frog->getBody()->setVelocity(Point::ZERO);
    this->frog->setJumping(false);
    
    // check if has no ways to goes further
    int remainLeaf = 0;
    __Array* allLeavesKey = this->getLeaves()->allKeys();
    for (int i = 0; i < allLeavesKey->count(); i++) {
        __Integer* key = (__Integer*) allLeavesKey->getObjectAtIndex(i);
        Leaf* leaf = (Leaf*) this->getLeaves()->objectForKey(key->getValue());
        if (!leaf->getDrowning()) {
            remainLeaf++;
        }
    }
    
    if (remainLeaf > 1) {
        int frogRow = (this->frog->getPositionIndex() - 1) / CONFIG_LAGOON_WIDTH;
        int sizeOfLagoon = CONFIG_LAGOON_WIDTH * CONFIG_LAGOON_HEIGHT;
        bool deadLock = true;
        
        if (this->frog->getViewDirection() == VIEW_LEFT ||
            this->frog->getViewDirection() == VIEW_UP ||
            this->frog->getViewDirection() == VIEW_DOWN) {
            
            int checkIndex = this->frog->getPositionIndex();
            while ((--checkIndex - 1) / CONFIG_LAGOON_WIDTH == frogRow) {
                if (this->leaves->objectForKey(checkIndex) != NULL) {
                    deadLock = false;
                    break;
                }
            }
        }
        
        if (this->frog->getViewDirection() == VIEW_RIGHT ||
            this->frog->getViewDirection() == VIEW_UP ||
            this->frog->getViewDirection() == VIEW_DOWN) {
            
            int checkIndex = this->frog->getPositionIndex();
            while ((++checkIndex - 1) / CONFIG_LAGOON_WIDTH == frogRow) {
                if (this->leaves->objectForKey(checkIndex) != NULL) {
                    deadLock = false;
                    break;
                }
            }
        }
        
        if (this->frog->getViewDirection() == VIEW_LEFT ||
            this->frog->getViewDirection() == VIEW_RIGHT ||
            this->frog->getViewDirection() == VIEW_UP) {
            
            int checkIndex = this->frog->getPositionIndex();
            checkIndex += CONFIG_LAGOON_WIDTH;
            while ((checkIndex - 1) < sizeOfLagoon) {
                if (this->leaves->objectForKey(checkIndex) != NULL) {
                    deadLock = false;
                    break;
                }
                checkIndex += CONFIG_LAGOON_WIDTH;
            }
        }
        
        if (this->frog->getViewDirection() == VIEW_LEFT ||
            this->frog->getViewDirection() == VIEW_RIGHT ||
            this->frog->getViewDirection() == VIEW_DOWN) {
            
            int checkIndex = this->frog->getPositionIndex();
            checkIndex -= CONFIG_LAGOON_WIDTH;
            while ((checkIndex - 1) >= 0) {
                if (this->leaves->objectForKey(checkIndex) != NULL) {
                    deadLock = false;
                    break;
                }
                checkIndex -= CONFIG_LAGOON_WIDTH;
            }
        }
        
        if (deadLock) {
            this->hanged = true;
            GameModel* gameModel = GameModel::getInstance();
            GameEvent* gameEvent = new GameEvent();
            gameEvent->setEventCode(EVT_DEAD_LOCK_GAME);
            gameModel->fireEvent(gameEvent);
        }
    }
}
Ejemplo n.º 24
0
void FreeKickStrategy::assignBeh()
{
    GameModel *gm = GameModel::getModel();

    vector <Robot*> myTeam;

    myTeam = gm->getMyTeam();

    if ((gm->getGameState() == 'F' && TEAM == TEAM_BLUE)
            || (gm->getGameState() == 'f' && TEAM == TEAM_YELLOW))
    {
        BehaviorAssignment<KickToGoal> kickToGoalAssignment;
        kickToGoalAssignment.setSingleAssignment(true);

        BehaviorAssignment<SimpleBehaviors> simpleAssignment;
        simpleAssignment.setSingleAssignment(true);

        BehaviorAssignment<DefendFarFromBall> golieAssignment;
        golieAssignment.setSingleAssignment(true);
        for (Robot* rob: myTeam)
        {
            if (rob->getID() == 5)
                golieAssignment.assignBeh(rob);
        }

        Robot *closestRobot;
        int closestRobotID;
        Point ballPoint = gm->getBallPoint();

        /*Finds the closest robot to the ball point (assuming the
         * ball is where the robots should perform free kick)
         * and its ID
         * If there is only one robot on the field, that one robot
         * will perform the free kick
         * */
        if (myTeam.size() == 1)
            closestRobot = myTeam.at(0);
        else if (myTeam.size() > 1)
        {
            if (myTeam.at(0)->getID() != 5)
                closestRobot = myTeam.at(0);
            else
                closestRobot = myTeam.at(1);

            for (unsigned i = 1; i < myTeam.size(); i++)
            {
                if (myTeam.at(i)->getID() != 5)
                {
                    Point iPos = myTeam.at(i)->getRobotPosition();
                    Point closestPos = closestRobot->getRobotPosition();
                    if (Measurments::distance(iPos, ballPoint) < Measurments::distance(closestPos, ballPoint))
                        closestRobot = myTeam.at(i);
                }
            }
            closestRobotID = closestRobot->getID();
        }

        kickToGoalAssignment.assignBeh(closestRobot);  //lets the closest robot to the ball to perform the free kick

        if (myTeam.size() > 1)  // assigns simple behavior to the rest of robots
        {
            for (unsigned i = 0; i < myTeam.size(); i++)
            {
                if (myTeam.at(i)->getID() != closestRobotID && myTeam.at(i)->getID() != 5)
                    simpleAssignment.assignBeh(myTeam.at(i));
            }
        }
    }
    else if ((gm->getGameState() == 'f' && TEAM == TEAM_BLUE)
            || (gm->getGameState() == 'F' && TEAM == TEAM_YELLOW))
    {
        BehaviorAssignment<DefendFarFromBall> golieAssignment;
        golieAssignment.setSingleAssignment(true);
        for (Robot* rob: myTeam)
        {
            if (rob->getID() == 5)
                golieAssignment.assignBeh(rob);
        }
        BehaviorAssignment<SimpleBehaviors> simpleAssignment;
        simpleAssignment.setSingleAssignment(true);
        for (unsigned i = 0; i < myTeam.size(); i++)
        {
            if (myTeam.at(i)->getID() != 5)
                simpleAssignment.assignBeh(myTeam.at(i));
        }
    }
}
void GameOverState::render() {
    Widget_Gamestate::render();
    float midScreen = get_Video().get_screen_width() / 2;
    Font &fontRender = get_Fonts()["title"];

    fontRender.render_text("Game Over!",
      Point2f(midScreen, 50.0f - 0.5f * fontRender.get_text_height()),
        get_Colors()["title_text"],
        ZENI_CENTER);

    Font &smallerFont = get_Fonts()["inGame"];

    smallerFont.render_text("Thanks for playing!",
        Point2f(170, 510),
        get_Colors()["white"],
        ZENI_CENTER);

    /*render_image(
      "ZoidM", // which texture to use
      Point2f(20, 200), // upper-left corner
      Point2f(320, 500), // lower-right corner
      0, //theta, // rotation in radians
      1, // scaling factor
      Point2f(), // point to rotate & scale about
      0, // whether or not to horizontally flip the texture
      Color()); // what Color to "paint" the texture*/
    GameModel *model = GameModel::getInstance();

    smallerFont.render_text("Your Raw Score was : " + itoa(rawScore),
        Point2f(20, 200),
        get_Colors()["white"],
        ZENI_LEFT);
    int numSaved = model->getNumSaved();
    int totalSurv = model->getTotalNumSurvivors();
    int totalZomb = model->getTotalNumZombies();
    int diff = model->getDifficulty();
    //playerScore = rawScore * ((numSaved + 1)/totalSurv * 1000) * totalZomb * diff * diff * 1000;
    smallerFont.render_text("Survivors Saved / Lost : " + itoa(numSaved) + " / " + itoa(totalSurv - numSaved),
        Point2f(20, 250),
        get_Colors()["white"],
        ZENI_LEFT);

    smallerFont.render_text("Number of Zombies faced : " + itoa(totalZomb),
        Point2f(20, 300),
        get_Colors()["white"],
        ZENI_LEFT);

    smallerFont.render_text("Difficulty Multiplier : " + itoa(diff * diff),
        Point2f(20, 350),
        get_Colors()["white"],
        ZENI_LEFT);

    smallerFont.render_text("Final Score : " + itoa(playerScore),
        Point2f(20, 400),
        get_Colors()["yellow"],
        ZENI_LEFT);

    smallerFont.render_text("High Scores",
        Point2f(525, 150),
        get_Colors()["yellow"],
        ZENI_CENTER);
    int yCoords = 180;
    for (setIter_t it = scores.begin(); it != scores.end(); it++, yCoords+=40) {
      smallerFont.render_text((*it).name + " ---- " + itoa((*it).score),
        Point2f(650, yCoords),
        get_Colors()["white"],
        ZENI_RIGHT);  
    }
}
Ejemplo n.º 26
0
void WndPart::Update()
{
	//UPDATE DEFAULT
	ui::Wnd::UpdateDefault();

	DWORD &dwStyle = m_tWindowInfo.dwStyle;
	if (dwStyle & FWS_VISIBLE && !(dwStyle & FWS_DISABLE))
	{
		if (m_pListBoxPart->IsSelChanged())
		{
			WndViewer * pWndViewer = (WndViewer *)GetParent();
			WndSelectLevel * pWndSelectLevel = pWndViewer->GetWndSelectLevel();
			WndModel	* pWndModel = pWndViewer->GetWndModel();
			int			iSelItem   = m_pListBoxPart->GetSelItem();
			BOOL		bChecked   = m_pListBoxPart->GetItemChecked(iSelItem);
			DWORD		dwGroup	   = 0;
			DWORD		dwPart	   = 0;
			strncpy((char *)&dwGroup, m_szCurrentGroupName, 4);
			strncpy((char*)&dwPart, m_pListBoxPart->GetItemText(iSelItem), 4);
			CDisplayModel * pModel;

			if (m_eCurrentModelType == MT_ROLE)
			{
				pModel = pWndViewer->GetModel();

				if (bChecked)
				{
					pModel->ShowGroup(dwGroup, dwPart, pModel->GetLvlOfGroupPart(dwGroup, dwPart), false);

					GameModel * pGM = CGameModelManager::GetInstance()->GetGameModel(pModel->GetGameModelID());

					GameModel::Group	   * pGroup = pGM->GetGroup(dwGroup);
					GameModel::Group::Part * pPart  = pGroup->GetPart(dwPart);
					pWndSelectLevel->AddLevel(dwGroup, dwPart, pPart->GetLevelCount());
					pWndSelectLevel->ShowWnd(true);

					pWndViewer->SetLevelModelIndex(pWndModel->GetSelRoleModel());
					pWndViewer->SetLevelModelType(MT_ROLE);
				}else
				{
					pModel->HideGroup(dwGroup);
					pWndSelectLevel->ShowWnd(false);
				}
			}else if (m_eCurrentModelType == MT_BIND)
			{
				pModel = pWndViewer->GetCurrentSelBindModel();

				if (bChecked)
				{
					pModel->ShowGroup(dwGroup, dwPart, pModel->GetLvlOfGroupPart(dwGroup, dwPart), false);

					GameModel * pGM = CGameModelManager::GetInstance()->GetGameModel(pModel->GetGameModelID());

					GameModel::Group	   * pGroup = pGM->GetGroup(dwGroup);
					GameModel::Group::Part * pPart  = pGroup->GetPart(dwPart);
					pWndSelectLevel->AddLevel(dwGroup, dwPart, pPart->GetLevelCount());
					pWndSelectLevel->ShowWnd(true);

					pWndViewer->SetLevelModelIndex(pWndModel->GetSelBindModel());
					pWndViewer->SetLevelModelType(MT_BIND);
				}else
				{
					pModel->HideGroup(dwGroup);
					pWndSelectLevel->ShowWnd(false);
				}
			}

			for(int iItem = 0; iItem < m_pListBoxPart->GetItemCount(); iItem++)
				m_pListBoxPart->SetItemChecked(iItem, FALSE);

			m_pListBoxPart->SetItemChecked(iSelItem, bChecked);
		}

		ui::Wnd::UpdateChild();		
	}
}