Esempio n. 1
0
//--------------------------------------------------------------
//update() gets called repeatedly. It runs just before draw() so this place is for any updating of variables.
//--------------------------------------------------------------
void testApp::update(){
	ofSetFrameRate(frames);
	ofBackground(myColors[0]*255, myColors[1]*255, myColors[2]*255);

	//fill the array with each cell from the Life to map
	for (int i=0; i<windowcol;i++){
		for(int j=0; j<windowrow;j++){
			map[i][j].col=Life[i][j].col;
			map[i][j].row=Life[i][j].row;
			map[i][j].alive=Life[i][j].alive;
			map[i][j].dx=Life[i][j].dx;
			map[i][j].dy=Life[i][j].dy;
			map[i][j].nextx=Life[i][j].nextx;
			map[i][j].nexty=Life[i][j].nexty;
			//set numItem to 0
			map[i][j].numItems=0;
			//set numItem to 0
			Life[i][j].numItems=0;
			//set the cell color
			map[i][j].cellcolor=Life[i][j].cellcolor;
			//set the hit number for each cell
			map[i][j].counter=Life[i][j].counter;
		}
	}
	//check how many numbers of neighbor it has
	updateLife();
	if(useOSC) parseOSCMsg();
	maintainCircle2(slider);
	
	updateLife();//check if there is any neighbor
	updatePosition();//update the position 
	updateNumOfCircle();//update the number cell in the board
}
Esempio n. 2
0
void Element::update(float dt)
{
	BBGE_PROF(Element_update);
	if (!core->particlesPaused)
	{
		updateLife(dt);
		updateEffects(dt);
		if (drawGrid)
			updateGrid(dt);
	}

//	updateCullVariables();
}
Esempio n. 3
0
void Model::timerEvent(QTimerEvent *timer) {
    if (gameTimer.timerId() == idGameTimer) {
        size_t x = snake.at(0)->getCell().x();
        size_t y = snake.at(0)->getCell().y();

        QPoint prev;
        prev.setX(x);
        prev.setY(y);
        switch (this->presentVector){
            case Qt::Key_Up:
                snake.at(0)->setCell(QPoint(x, y-1));
                break;
            case Qt::Key_Down:
                snake.at(0)->setCell(QPoint(x, y+1));
                break;
            case Qt::Key_Right:
                snake.at(0)->setCell(QPoint(x+1, y));
                break;
            case Qt::Key_Left:
                snake.at(0)->setCell(QPoint(x-1, y));
                break;
        }

        for (int i=1;i<snake.count();i++) {
            QPoint p(snake.at(i)->getCell());
            snake.at(i)->setCell(p);
            prev = p;
            if (i == snake.count()-1) zeroSnakePos = p;
        }
        haveMooved = true;
        if (isBonusVisible) {
            bonusVisibleTimeLeft--;
            emit updateBonusTimeLeft(bonusVisibleTimeLeft);
            if (bonusVisibleTimeLeft == 0) {
                removeGameElement(BONUS);
                isBonusVisible = false;

            }
        }
        if (!isBonusVisible) bonusTiks++;
        if (!isBonusVisible && bonusTiks == 20) {
            addGameElement(BONUS);
            isBonusVisible = true;
            bonusTiks = 0;
            bonusVisibleTimeLeft = 20;
            emit updateBonusTimeLeft(bonusVisibleTimeLeft);
        }
        Model::ObjectType objType = snake.at(0)->collidesWith(&food, &bonus, &snake, &walls);
//?!!!!!!!!!!!!
        if (objType == Model::WALL || objType == Model::SNAKE_PART) {
            this->finishGame();
        }
        if (objType == Model::FOOD) {
            addGameElement(SNAKE_PART);
            addGameElement(FOOD);
            score+=10;
            emit updateScore(score);
            emit updateAte(++ate);
            emit updateLife(++life);

        }
        if (objType == Model::BONUS) {
            snakeSpeed = NORMAL_SNAKE_SPEED;
            removeGameElement(BONUS);
            emit updateBonusAte(++bonusAte);
            QString msg = "";
            int bonusKind = bonus.data.toInt();
            if (bonusKind == 0) {
                score += 100;
                emit updateScore(score);
                msg = "+100 score";
            } else if (bonusKind == 1) {
                snakeSpeed = NORMAL_SNAKE_SPEED;
                msg = "Normal";
            } else if (bonusKind == 2) {
                snakeSpeed = FAST_SNAKE_SPEED;
                msg = "Fast";
            } else if (bonusKind == 3) {
                snakeSpeed = SLOW_SNAKE_SPEED;
                msg = "Slow";
            }
            emit showBonusTimeLeft(msg);
            gameTimer.start(snakeSpeed, this);
            idGameTimer = gameTimer.timerId();
        }


    }
}
void RenderObject::onUpdate(float dt)
{
	if (isDead()) return;
	//collisionShape.updatePosition(position);
	updateLife(dt);

	// FIXME: We might not need to do lifetime checks either; I just
	// left that above for safety since I'm not certain.  --achurch
	if (isHidden()) return;

	position += velocity * dt;
	velocity += gravity * dt;
	position.update(dt);
	velocity.update(dt);
	scale.update(dt);
	rotation.update(dt);
	color.update(dt);
	alpha.update(dt);
	offset.update(dt);
	internalOffset.update(dt);
	beforeScaleOffset.update(dt);
	rotationOffset.update(dt);

	for (Children::iterator i = children.begin(); i != children.end(); i++)
	{
		if (shareAlphaWithChildren)
			(*i)->alpha.x = this->alpha.x;
		if (shareColorWithChildren)
			(*i)->color = this->color;

		if (!(*i)->updateAfterParent && (((*i)->pm == PM_POINTER) || ((*i)->pm == PM_STATIC)))
		{
			(*i)->update(dt);
		}
	}
	
	if (!childGarbage.empty())
	{
		for (Children::iterator i = childGarbage.begin(); i != childGarbage.end(); i++)
		{
			removeChild(*i);
			(*i)->destroy();
			delete (*i);
		}
		childGarbage.clear();
	}

	if (motionBlur)
	{
		if (motionBlurFrameOffsetCounter >= motionBlurFrameOffset)
		{
			motionBlurFrameOffsetCounter = 0;
			motionBlurPositions[0].position = position;
			motionBlurPositions[0].rotz = rotation.z;
			for (int i = motionBlurPositions.size()-1; i > 0; i--)
			{
				motionBlurPositions[i] = motionBlurPositions[i-1];
			}
		}
		else
			motionBlurFrameOffsetCounter ++;
	}
	if (motionBlurTransition)
	{
		motionBlurTransitionTimer -= dt*2;
		if (motionBlurTransitionTimer <= 0)
		{
			motionBlur = motionBlurTransition = false;
			motionBlurTransitionTimer = 0;
		}
	}

//	updateCullVariables();
}