示例#1
0
/*
 *  slowAnimate
 *  ------
 *  step through the animation process
 */
void slowAnimate()
{
  moveLight();
  moveTowerTops();
  moveShots();
  checkCollisions();
  moveMinions();
  checkCollisions();
  checkTowerRange();
}
void glutTime(int toggle)
{
  if (gameStarted) {
    if (gamePaused != DEF_GAME_PAUSED) {
      moveTowerTops();
      moveBalls();
      checkCollisions();
      moveMinions();
      checkCollisions();
      checkTowerRange();
    }
    glutTimerFunc(50,glutTime,0);
  }
  redisplayAll();
}
示例#3
0
/*
 *  timer
 *  ------
 *  game animation logic turned on or off here
 */
void timer(int toggle)
{
  if (gameStarted) {
    if (gamePaused != DEF_GAME_PAUSED) {
      moveLight();
      moveTowerTops();
      moveShots();
      checkCollisions();
      moveMinions();
      checkCollisions();
      checkTowerRange();
    }
    glutTimerFunc(50,timer,0);
  }
  redisplayAll();
}
示例#4
0
void GameState::update() {

    //update graphical entities.
    for(auto it = mGraphicalEntities.begin(), end = mGraphicalEntities.end(); it != end; ++it) {
        auto graphical_sp = *it;

        graphical_sp->update(this);
        checkCollisions(graphical_sp);
    }

    //update collision zones.
    for(auto it = mCollisionZones.begin(), end = mCollisionZones.end(); it != end; ++it) {
        auto colZone_sp = *it;

        colZone_sp->update(this);
    }

    //update scripts
    for(auto it = mScripts.begin(), end = mScripts.end(); it != end; ++it) {
        auto script_sp = *it;

        script_sp->update(this);
    }

    //delete inactive entities.
    deleteInactives();
}
示例#5
0
void UnstableTile::update(const sf::Time& frameTime) {
	if (m_state == GameObjectState::Crumbling) {
		updateTime(m_crumblingTime, frameTime);
		if (m_crumblingTime == sf::Time::Zero) {
			setDisposed();
		}
	}
	else if (m_isCritical) {
		updateTime(m_criticalTime, frameTime);
		if (m_criticalTime == sf::Time::Zero) {
			m_isFalling = true;
			setState(GameObjectState::Idle);
		}
	}
	else if (m_isFalling) {
		setAcceleration(sf::Vector2f(0.f, GRAVITY_ACCELERATION));
		sf::Vector2f nextPosition;
		calculateNextPosition(frameTime, nextPosition);
		checkCollisions(nextPosition);
	}
	MovableGameObject::update(frameTime);
	if (m_isCritical && !m_wasCritical) {
		m_criticalTime = CRITICAL_TIME;
		m_isCritical = false;
		setState(GameObjectState::Idle);
	}
	m_wasCritical = false;
}
示例#6
0
void TestWorld1::process()
{
	killHalf();
	expireFood();
	autoinsertFood();
	expireCritters();
	autosaveCritters();
	autoinsertCritters();

// 	m_dynamicsWorld->stepSimulation(0.016667f);
	m_dynamicsWorld->stepSimulation(0.016667f, 0, 0.016667f);
// 	m_dynamicsWorld->stepSimulation(Timer::Instance()->bullet_ms / 1000.f);

	renderVision();
	grabVision();

	unsigned int lmax = critters.size();
	for( unsigned int i=0; i < lmax; i++)
	{
		CritterB *c = critters[i];

		checkCollisions(  c );
		c->process();
		freeEnergy += c->energyUsed;
		eat(c);
		procreate(c);
	}
}
示例#7
0
文件: JG_RRT.cpp 项目: ana-GT/Lucy
/**
 * @function tryStep
 */
JG_RRT::StepResult JG_RRT::tryStep( const Eigen::VectorXd &qtry, int NNidx )
{
    Eigen::VectorXd qnear( ndim );
    Eigen::VectorXd qnew( ndim );
    qnear = configVector[NNidx];

    Eigen::VectorXd diff = ( qtry - qnear );
    double edist = diff.norm();

    // If the new node is nearer than the stepSize, don't add it

    if( edist < stepSize )
    {
        return STEP_REACHED;
    }

    // Scale it in order to add it
    double scale = stepSize / edist;
    for( int i = 0; i < ndim; i++ )
    {
        qnew[i] = qnear[i] + diff[i]*scale;
    }

    if( !checkCollisions(qnew) )
    {
        addNode( qnew, NNidx );
        return STEP_PROGRESS;
    }
    else
    {
        return STEP_COLLISION;
    }
}
示例#8
0
	void Moveable::applyPhysics(const UpdateContext& context, std::vector<pf::GameEntity*>& collisions)
	{
		pf::PhysicsInfo info;
		sf::Vector2f currentVelocity = _physicsInfo.getVelocity();
		sf::Vector2f currentAcceleration = _physicsInfo.getAcceleration();

		info.setVelocity(currentVelocity.x, currentVelocity.y);
		info.setAcceleration(currentAcceleration.x, currentAcceleration.y);

		applyMovement(context, &info);

		applyGravity(context, &info);

		checkCollisions(collisions, &info);

		sf::Vector2f newPosition = info.apply(getX(), getY(), context.elapsedTime);

		arrangePosition(newPosition);

		setPosition(newPosition.x, newPosition.y);

		if(_isJumping)
		{
			_jumpFrames++;
		}
	}
示例#9
0
void heartbeat() {
    float now = getCurrentTime() / (float)1000.0;

    startTimer();
    checkCollisions();
    cellsClear(cells);

    cvsFillStyle("black");
    cvsFillRect(0, 0, getWidth(), getHeight());

    for(int i=0; i<numEntities; i++) {
        Entity *ent = objects[i];

        if(ent) {
            updateEntity(ent, now - last);
            renderEntity(ent);

            cellsAdd(cells, ent, ent->pos.x, ent->pos.y);
            cellsAdd(cells, ent, ent->pos.x + ent->size.x, ent->pos.y);
            cellsAdd(cells, ent, ent->pos.x, ent->pos.y + ent->size.y);
            cellsAdd(cells, ent,
                     ent->pos.x + ent->size.x,
                     ent->pos.y + ent->size.y);

        }
    }

    //renderDebug();

    endTimer();
    last = now;
}
示例#10
0
文件: Game.cpp 项目: Cheesezi/FPS
void Game::Gameplay_OnUpdate(float timestep)
{
	
	m_currentCam->Update(timestep);		//Every update we will update the camera

	for (unsigned int i = 0; i < m_gameObjects.size(); i++)
	{
		m_gameObjects[i]->Update(timestep);
		if (m_gameObjects[i]->GetObjectType() == "SphereEnemy")
		{
				static_cast <SphereEnemy*> (m_gameObjects[i])->Bullets[0]->Update(timestep);
		}
	}

	for (unsigned int i = 0; i < m_player->Bullets.size(); i++)
	{
		m_player->Bullets[i]->Update(timestep);
	}


	checkCollisions();
	if (nextSpawnCounter == 0)
		spawnEnemy();
	else
		updateSpawnCounter(-1);

	if (m_player->getHealth() == 0)
		m_stateMachine->ChangeState(GAMEOVER_STATE);

	//m_button->Update();					//Just like every game object we create we need to update the Button here

}
示例#11
0
void Controller::update(int fps, double G) {
  for (int i = 0; i < number; i++) {
    balls[i].update(fps);
  }
  checkCollisions();
  accelerate(fps, G);
  if (debug == 2) {
    for (int i = 0; i < number; i++) {
      std::cout << (i + 1) << ".";
      switch(i % 6) {
        case 0:
          std::cout << "\x1b[36m";
          break;
        case 1:
          std::cout << "\x1b[35m";
          break;
        case 2:
          std::cout << "\x1b[34m";
          break;
        case 3:
          std::cout << "\x1b[33m";
          break;
        case 4:
          std::cout << "\x1b[32m";
          break;
        case 5:
          std::cout << "\x1b[31m";
          break;
      }
      balls[i].debug();
      std::cout << "\x1b[0m";
    }
  }
}
示例#12
0
/*
	Name:	run
	Desc:	main function used to run the game, calling everything else needed to function inside
	Args:	None
	Rtrn:	m_retry,	a bool to determine if the player wants to play again 
*/
bool Game::run()
{
	startingHousekeeping();
	while(m_window->isOpen() && m_stillPlaying)
	{
		//Run the game loop.
		handleEvents();

		if(!m_paused && !m_gameOver)
		{
			spawnNewBalls();
			moveObstacles();
			moveObstacleReactions();
			checkCollisions();
			checkBallsLeavingScreen();
			processObjective();
			processPlayerParticleSys();
			addCumilativePoints();
			generatePointsText();
		}

		if(!m_gameOver)
		{
			checkPause();
			checkGameOver();
		}

		render();
	}
	return m_retry;
}
示例#13
0
void Game::update() {
	checkCollisions();
	generateEnemy();

	if (keys[' '] == true) 
		player->shoot();

	if (keys['a'])
		player->moveLeft();

	if (keys['d'])
		player->moveRight();

	if (keys['w'])
		player->moveForward();

	if (keys['s'])
		player->moveBackward();

	if (keys['q'])
		player->pickAnotherWeapon();

	for (auto bullet : bullets) {
		bullet->update();
	}

	for (auto enemy : enemies) {
		enemy->update();
	}

	player->update();
}
示例#14
0
文件: main.cpp 项目: DrenBx/ft_retro
int			main(int UNUSED(argc), char ** argv, char **envp)
{
	Game *			game = init_game();
	int				i = -1;
	std::string		visual[] = {
		" ",
		"*",
		" ",
		"~"
	};

	while (++i < WIN_WIDTH )
	{
		game->getBg()[i].setY(0);
		game->getBg()[i].setPatern(Patern(visual[rand() % 4]));
		game->getBg2()[i].setY(WIN_HEIGHT - 1);
	}
	while ( 42 )
	{
		usleep( 1000000 / NB_FRAME );
		if ( doKeyAction(game->getPlayer()) )
			break ;
		game->popRandomEnemy();
		game->move_all();
		if (checkCollisions(game, game->getEnemies(), game->getPlayer()->getBullets()))
			endGame(game->getPlayer()->getScore(), argv[0], envp, "You Win !");
		if (game->getPlayer()->getHp() <= 0)
			break ;
		clear();
		game->display_all();
	}
	endGame(game->getPlayer()->getScore(), argv[0], envp, "You loose !");

	COUT << ENDL;
}
示例#15
0
文件: Stage.cpp 项目: Tirmenat/solara
void Stage::perform(double dt, Unit* hero)
{

  for(int i = 0; i < units.size(); i++)
    {
      if(!isOffScreen(units[i]))
	{
	  units[i]->increment(dt); //if it's on screen draw it
	}
      else
	{
	  if(units[i]->isBullet())
	    {
	      units[i]->setHealth(0); //if a bullet goes off screen don't draw it
	    }
	}
      if (units[i]->getHealth() <= 0)
	{
	  removeUnit(units[i]);
	  i--;
	}
      //checkCollisions(units[i],dt);
      checkCollisions(units[i]);
    }
  adjustUnits();
  xoffset = -hero->getx() + SCREEN_WIDTH/2;
  yoffset = -hero->gety() + SCREEN_HEIGHT/2;
}
示例#16
0
文件: engine.cpp 项目: mopalka/smokey
void Engine::update(){

  intCar(player);
  checkCollisions();  

  this->parentWidget()->update();

}
示例#17
0
文件: Game.cpp 项目: julien/ofShooter
void Game::update() {
    float dt = 0.006f;
    ship->update(dt);
    for (unsigned int i = 0; i < asteroids.size(); ++i) {
        asteroids[i]->update(dt);
        asteroids[i]->checkIfBreakable();
    }
    checkCollisions();
}
void MainWindow::updateReading() {
    if (mPause)
        return;

    checkCollisions();
    xAxis = (xAxis + mAccelerometer->reading()->x()) / 2;
    yAxis = (yAxis + mAccelerometer->reading()->y()) / 2;

}
示例#19
0
void update()
{
	//crazy disco lights!!!!
	if(!rLight)
	{
		l1.setPos(0, 700, 0);
		l2.setPos(1400, 700, 0);
		l3.setPos(0, 700, 1400);
		l4.setPos(1400, 700, 1400);
	} 
	else
		randomizeLights();


	//handle continuious input
	Uint8 *keyState = SDL_GetKeyState(NULL);
	mainCam.handleInput(keyState); //update camera movements
	
	
	if (smaug.alive)
	{
		smaug.handleInput(keyState); //update smaugs movements from player controls
		userLight.setPos(smaug.position.getX(), 600, smaug.position.getZ()); //update smaug's spot light
		
		//update smaug's bullets
		for (int i = 0; i < SMAUGS_MAX_BULLETS; ++i)
		{
			if (smaug.bulletArray[i].alive == true)
				smaug.bulletArray[i].update();
		}
	}
	else //player died
	{
		gameOver = true;
	}
 
	//update trogdor's movments
	if (trogdor.alive)
	{
		trogdor.update(rand());
		trogLight.setPos(trogdor.position.getX(), 500, trogdor.position.getZ()); //update trogdor's spot light

		//update enemy bullets
		for (int i = 0; i < ENEMY_MAX_BULLETS; ++i)
		{
			if (trogdor.bulletArray[i].alive == true)
				trogdor.bulletArray[i].update();
		}
	}
	else if (trogdor.lives > 0)
		trogdor.respawn(rand());
	else //no more trogdor
		gameWon = true;

	//Check collisions
	checkCollisions();
}
//--------------------------------------------------------------
void ofxBulletWorldRigid::update( float aDeltaTimef, int aNumIterations ) {
    if(!checkWorld()) return;
    world->stepSimulation( aDeltaTimef, aNumIterations );

    if(bDispatchCollisionEvents) {
        world->performDiscreteCollisionDetection();
        checkCollisions();
    }
}
示例#21
0
void Game::update()
{
    theCar.dump();

    theCar.update();
    car.update();
    handleUserInput();
    checkCollisions();
}
示例#22
0
void GameScene::updateProjectiles(float dt)
{
	if (m_bullets->count() > 0)
	{
		CCObject* ob = NULL;
		CCARRAY_FOREACH(m_bullets, ob)
		{
			Projectile* proj = dynamic_cast<Projectile*>(ob);
			proj->update(dt);

			if (proj->getPositionX() < 0.f - proj->getContentSize().width || proj->getPositionX() > m_visibleSize.width + proj->getContentSize().width)
				m_removableBullets->addObject(proj);
			else if (checkCollisions(m_hero, proj) && proj->getType() == Projectile::Bullet)
			{
				m_removableBullets->addObject(proj);
				updateHealth(10); // dmg value here
			}
			else
			{
				for (uint i = 0; i < m_enemies->count(); ++i)
				{
					Enemy* en = dynamic_cast<Enemy*>(m_enemies->objectAtIndex(i));
					if (checkCollisions(en, proj) && proj->getType() == Projectile::Rocket)
					{
						m_removableBullets->addObject(proj);
						m_removables->addObject(m_enemies->objectAtIndex(i));
						
						CCParticleSystemQuad * smokeParticle = CCParticleSystemQuad::create("textures/smoke.plist"); 
						smokeParticle->setPosition(en->getPosition());
						this->addChild(smokeParticle);
						smokeParticle->setAutoRemoveOnFinish(true);
						
						CCParticleSystemQuad * dustParticle = CCParticleSystemQuad::create("textures/dusts.plist");
						dustParticle->setPosition(en->getPosition());
						this->addChild(dustParticle);
						dustParticle->setAutoRemoveOnFinish(true);
						CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("audio/rocketExplode.wav", false);
						CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("audio/enemyKill.wav", false);

						updateScore(); //score value here
					}
				}
			}
		}
//--------------------------------------------------------------
void chinoWorld::update() {
	if(!checkWorld()) return;
	// should this run on delta time? //
    world->stepSimulation(1.0f/60.0f, 6, 1./60.);
	
	if(bDispatchCollisionEvents) {
		world->performDiscreteCollisionDetection();
		checkCollisions();
	}
}
示例#24
0
文件: Game.cpp 项目: jhpy1024/glfPong
void Game::update(int delta)
{
    if (m_GameOver)
        return;

    for (auto& entity : m_Entities)
        entity.second->update(delta);

    checkCollisions();
}
示例#25
0
void World::update(float deltaTime, float accelX)
{
	updateBob(deltaTime, accelX);
	updatePlatforms(deltaTime);
	updateSquirrels(deltaTime);
	updateCoins(deltaTime);
	if(bob.state != Bob::BOB_STATE_HIT) 
		checkCollisions();
	checkGameOver();
}
示例#26
0
void PhysicsComponent::update(Scene& scene)
{
	updatePosition(scene, Axis::X);
	updatePosition(scene, Axis::Y);

	if (collider_)
	{
		checkCollisions(scene);
	}
}
示例#27
0
    IContextReturnData InGameContext::frameFunc()
    {
        try
        {
            float dt = _hge->Timer_GetDelta();
            auto data = std::dynamic_pointer_cast<InGameContextData>(_data);

            Player& currentPlayer = _players[data->currentPlayerId];
            Player& enemyPlayer = _players[!data->currentPlayerId];

            if (_hge->Input_IsMouseOver() && _hge->Input_GetKeyState(HGEK_LBUTTON))
            {
                timeoutTimer.stop();
                float mouse_x = 0;
                float mouse_y = 0;
                _hge->Input_GetMousePos(&mouse_x, &mouse_y);
                checkAllowedBounds(mouse_x, mouse_y);

                mover.moveTo(mouse_x, mouse_y);
                timeoutTimer.start();
            }

            mover.update(dt);

            Client::getInstance().getEnemyPaddlePos(enemyPlayer.paddle()->x, enemyPlayer.paddle()->y);
            Client::getInstance().getPuckPos(_puck->x, _puck->y);

            checkCollisions();
            checkGoal();

            timers.update(dt);
            timeoutTimer.update(dt);

            if(Client::getInstance().isGameOver())
            {
                bool win = Client::getInstance().getWinnerId() == data->currentPlayerId;

                return IContextReturnData(Context::GameOverContext,
                            std::make_shared<GameOverContextData>(
                                              _data->screenWidth,
                                              _data->screenHeight,
                                              win,
                                              &_players[0], &_players[1]));
            }

            if(Client::getInstance().shouldStop())
                return IContextReturnData(Context::GameErrorContext, nullptr);

            return IContextReturnData(Context::InGameContext, data);
        }
        catch (std::exception& e)
        {
            return IContextReturnData(Context::GameErrorContext, nullptr);
        }
    }
	void animate(){
		frameCount++;
		updateEntities(wEntities);
		updateEntities(wWalls);
		updateEntities(wSoftEntities);

		checkCollisionsSelf(wEntities);
		checkCollisions(wEntities, wWalls);
		checkCollisions(wEntities, wSoftEntities);
		checkCollisions(wWalls, wSoftEntities);

		//update everything in the level that needs to be updated
		wScenes[currentLevel]->update();
		if(wScenes[currentLevel]->levelEnd()){

		}

		//Update the mouse flags
		MOUSE_EDGE_LEFT = MOUSE_EDGE_RIGHT = false;
	}
示例#29
0
bool playerCollisions(std::vector<Enemy>& enemies, Player& player)
{
	//Enemy Collisions
	for (auto enemy : enemies)
	{
		if (checkCollisions(enemy, player)) {
			return true;
		}
	}

	return false;
}
Entity *Entity::getPlayerCollision(void)
{
   std::list<Entity *> e;

   ResourceManager& rm = ResourceManager::getInstance();
   Player *player = (Player *)rm.getData(RES_PLAYER);

   e.push_back(player);

   Entity *ret = checkCollisions(e);
   e.clear();
   return ret;
}