Exemple #1
0
void Scene::display() {
	// Clear screen, initialise culling
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Select model view matrix
	glMatrixMode(GL_MODELVIEW);

	// Draw solid bodies
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	glLoadIdentity();

	Fish* f = Fish::getFirst();
	Vector* v = f->getPosition();
	GLfloat lightPos[] = { static_cast<GLfloat>(v->x),
		static_cast<GLfloat>(v->y - 10), static_cast<GLfloat>(v->z), 1.0 };
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

	// args 1-3: viewer coordinates,
	// args 4-5: point looked at,
	// args 7-9: "up" vector
	gluLookAt(
		camPos[activeCam]->x, camPos[activeCam]->y, camPos[activeCam]->z,
		0.0, 20.0, 0.0,
		0.0, 1.0, 0.0);

	// Draw scene graph
	fishList->work();
	if (!calculateFishCount) {
		sharkList->work();
	}
	graph->work();

	if (drawNames) {
		Text::drawAll();
	} else {
		fpsDisplay->draw();
		for (list<Text*>::iterator it = helpDisplay.begin(); it != helpDisplay.end(); it++) {
			(*it)->draw();
		}
	}

	glFlush();
	glutSwapBuffers();

	if (calculateFishCount) {
		glutPostRedisplay();
	}
	frames++;
}
Exemple #2
0
void M001Logic::Update(GameData* gData, PlayerLayerV2* playLayer)
{
    // create fish
    {
        int disRemainder = ((int)gData->_movedDistance % 5);
        int disDivisor = ((int)gData->_movedDistance / 5);
        int disRemainder4Block = ((int)gData->_movedDistance % 20);
        int disDivisor4Block = ((int)gData->_movedDistance / 20);
        
        if(disRemainder == 0 && disDivisor != _disDivisor)
        {
            _disDivisor = disDivisor;
            
            if(_disDivisor % 4 == 0)
            {
                float rd2 = CCRANDOM_0_1();
                float rd3 = CCRANDOM_0_1();
                log("create fish category:%d, level:%d", 2, 1);
                
                Fish* fish = Fish::createFish(2,
                                              Vec2(25 + 700 * rd2, 1334),
                                              1,
                                              gData->_minRunSpeed + 200 * rd3,
                                              true,
                                              new XMTMoveAI());
                fish->setTag(OBJ_FISH_BUFF);
                playLayer->apiAddFish(fish);
            }
            if(_disDivisor % 2 == 0)
            {
                // create treasure
                float rd2 = CCRANDOM_0_1();
                float rd3 = CCRANDOM_0_1();
                log("create treasure");
                if((int)(rd2* 10) % 3 == 1)
                {
                    this->xCreateTreasure(gData, playLayer, '2', 1, 0, Vec2(50 + 500 * rd2, 1334));
                }
                else
                {
                    this->xCreateTreasure(gData, playLayer, '1', 1, 0, Vec2(50 + 500 * rd2, 1334));
                }
            }
            
            {
                // create fish
                float rd2 = CCRANDOM_0_1();
                float rd3 = CCRANDOM_0_1();
                int level = 1;
                if(rd3 < 0.3)
                {
                    level = gData->_level - 1;
                    if(level <0)
                    {
                        level = 1;
                    }
                }
                else if(rd3 < 0.4)
                {
                    level = gData->_level - 2;
                    if(level < 0)
                    {
                        level = 1;
                    }
                }
                else if(rd3 < 0.5)
                {
                    level = gData->_level + 1;
                }
                else if(rd3 < 0.55)
                {
                    level = gData->_level + 2;
                }
                else if(rd3 < 0.58)
                {
                    level = gData->_level + 3;
                }
                else
                {
                    level = gData->_level;
                }
                
                log("create fish level:%d", level);
            
                Fish* fish = Fish::createFish(1,
                                              Vec2(25 + 700 * rd2, 1334),
                                              level,
                                              gData->_minRunSpeed + 200 * rd3,
                                              true,
                                              nullptr);
                fish->setTag(OBJ_FISH);
                playLayer->apiAddFish(fish);
                
            }
        }
        
        if(disRemainder4Block == 0 && disDivisor4Block != _disDivisor4Block)
        {
            // create block
            _disDivisor4Block = disDivisor4Block;
            
            // create fish
            float rd2 = CCRANDOM_0_1();
            
            float x = 25 + 700 * rd2;
            
            log("create block");
            
            BFBlock* block = BFBlock::createBlock(Vec2(x, 1334));
            block->setTag(OBJ_BLOCK);
            playLayer->apiAddBlock(block);
        }
    }
    
    Fish* player = playLayer->xGetPlayer();
    // collision detection
    {
        Vec2 pPos = player->getPosition();
        gData->_playerPosY = pPos.y;
        
        Rect pRect = player->getBoundingBox();
        Vector<Node*>& children = playLayer->getChildren();
        for(auto a : children)
        {
            if((a->getTag() & OBJ_FISH) == OBJ_FISH)
            {
                Fish* fish = (Fish*)a;
                Rect fRect = fish->getBoundingBox();
                if(fRect.intersectsRect(pRect))
                {
                    if(fish->GetLevel() > player->GetLevel())
                    {
                        // game over
                        gData->_healthPoint = 0;
                        JizGame::getInstance()->playAudioEffect("audioeffect/hurt2.mp3");
                    }
                    else
                    {
                        JizGame::getInstance()->playAudioEffect("audioeffect/eat1.mp3");
                        gData->_experience += (10 + fish->GetLevel());
                        gData->_eatedCount++;
                        gData->_staminaPoint += gData->_staminaRecoverPoint* fish->GetLevel();
                        
                        // eat fish
                        gData->_staminaPoint += 10;
                        
                        fish->Die();
                        fish->setTag(OBJ_ORNAMENTAL);
                        
                        auto layerEffect = (XEffectLayer*)playLayer->getChildByTag(LAYER_EFFECT);
                        layerEffect->XAddFishEatedEffect(fish->getPosition(), fish->GetLevel());
                    }
                }
            }
            else if(a->getTag() == OBJ_BLOCK)
            {
                Rect fRect = a->getBoundingBox();
                if(fRect.intersectsRect(pRect))
                {
                    // game over
                    gData->_healthPoint -= 10;
                    a->setTag(OBJ_ORNAMENTAL);
                    JizGame::getInstance()->playAudioEffect("audioeffect/hurt1.mp3");
                }
            }
            else if(a->getTag() == OBJ_TREASURE)
            {
                // eat treasure
                Fish* fish = (Fish*)a;
                Rect fRect = fish->getBoundingBox();
                if(fRect.intersectsRect(pRect))
                {
                    JizGame::getInstance()->playAudioEffect("audioeffect/eat2.mp3");
                    
                    fish->Die();
                    fish->setTag(OBJ_ORNAMENTAL);
                    
                    auto layerEffect = (XEffectLayer*)playLayer->getChildByTag(LAYER_EFFECT);
                    layerEffect->XAddFishEatedEffect(fish->getPosition(), fish->GetLevel());
                }
            }
        }
    }
    
    // level up
    {
        if(gData->_experience >= gData->GetMaxExperience(gData->_level))
        {
            gData->_level++;
            player->SetLevel(gData->_level);
            // add max speed
            gData->_maxRunSpeed += 50;
            gData->_minRunSpeed += 50;
            JizGame::getInstance()->playAudioEffect("audioeffect/levelup.mp3");
        }
    }
    
    // validate play's positon
    {
        Vec2 curPos = player->getPosition();
        
        if(curPos.y < 0)
        {
            gData->_healthPoint = 0;
            JizGame::getInstance()->playAudioEffect("audioeffect/hurt2.mp3");
        }
        else
        {
            if(curPos.x < gData->EdgeWest)
            {
                curPos.x = gData->EdgeWest;
                player->SetSlidslipSpeed(0);
            }
            else if(curPos.x > gData->EdgeEast)
            {
                curPos.x = gData->EdgeEast;
                player->SetSlidslipSpeed(0);
            }
            player->setPosition(curPos);
        }
    }
}
Exemple #3
0
void GameScene::checkCollision(){
    std::vector<int> catched;
    
    for (int i = 0; i < _fish.size(); i++) {
        Fish *fish = _fish.at(i);
        if (!fish->getIsCatched()) {
            Point fishPoint = fish->getPosition();
            Size fishSize = Size(fish->getContentSize().width * fabs(fish->getScaleX()), fish->getContentSize().height * fabs(fish->getScaleY()));
            Point hookpoint = _fisherman->getHookWorldPoint();
            
            bool x = false;
            bool y = false;
            
            if (((fishPoint.x - (fishSize.width/2)) < hookpoint.x) &&
                ((fishPoint.x + (fishSize.width/2)) > hookpoint.x)) {
                x = true;
            }
            
            if (((fishPoint.y - (fishSize.height/2)) < hookpoint.y) &&
                ((fishPoint.y + (fishSize.height/2)) > hookpoint.y)) {
                y = true;
            }
            
            if (x && y) {
                catched.push_back(i);
            }
        }
    }
    
    for (int i = 0; i < catched.size(); i++) {
        int x = catched.at(i);
        Fish *f = _fish.at(x);
        if(f != _catchedFish) {
            f->setIsCatched(true);
            if (!_catchedFish) {
                CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("new_pick_up.wav");
                _catchedFish = f;
                _catchedFish->setPreventAnimations(true);
                _catchedFish->setRotation(_catchedFish->getScaleX() > 0 ? 90 : 270);
                _scoreMultiplier = 1;
                
                _currentScore = _catchedFish->getScore();
                
            } else {
                if (!dynamic_cast<Turtle*>(f)) {
                    CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("new_pick_up.wav");
                    _scoreMultiplier ++;
                    
                    if (f->getScore() > _catchedFish->getScore()) {
                        //                f->setScore(f->getScore());
                        _fish.erase(std::remove(_fish.begin(), _fish.end(), _catchedFish), _fish.end());
                        _catchedFish->removeFromParent();
                        _catchedFish = NULL;
                        
                        
                        _catchedFish = f;
                        _currentScore += _catchedFish->getScore();
                        _catchedFish->setPreventAnimations(true);
                        _catchedFish->setRotation(_catchedFish->getScaleX() > 0 ? 90 : 270);
                        
                    } else {
                        _currentScore += f->getScore();
                        _fish.erase(std::remove(_fish.begin(), _fish.end(), f), _fish.end());
                        f->removeFromParent();
                        f = NULL;
                        
                    }

                }
                
                
            }

        }
        
        
    }
    
    if (_currentScore > 0) {
        char buff[100];
        sprintf(buff, "%dX%i", (int)roundf(_currentScore),(int)_scoreMultiplier);
        std::string buffAsStdStr = buff;
        _currentLabel->setString(buffAsStdStr);
        
    }
    
}