Example #1
0
void Fireball::onMove(float moveX, float moveY)
{
	int x = getDimensions()->x;
	int maxX = OWindow::sGameWindow.getWidth() + getDimensions()->w;

	//Calculate speed based on fps
	moveX *= OFPS::sFPSController.getSpeedFactor();

	//Update temp location 
	x += (int)moveX;

	//Check for collisions
	checkForCollisions();

	//If outsize screen distroy object
	if (x >= maxX)
	{
		isDeadFlag = true;
	}
	else
	{
		getDimensions()->x = x;
	}

}
Example #2
0
void CharacterManager::update(Uint32 ticks){
    checkForCollisions();

    std::list<ExplodingSprite *>::iterator explode;
    std::list<Projectile *>::iterator project;
    std::list<Enemy *>::iterator enemy;

    Vector2f playerCenter = player->getCenter();
    for(enemy = monsters.begin(); enemy != monsters.end(); ++enemy){
        if(Viewport::getInstance().onScreen((*enemy)->getPosition())){
            //player in sight of enemy
            Vector2f enemyCenter = (*enemy)->getCenter();
		    float dist = Vector2f::distance(enemyCenter,playerCenter);

            //enemy out of patrol zone
            if((*enemy)->getDistanceFromOrigin() > (*enemy)->getRange())
                (*enemy)->Return(ticks);

            else if(dist <= (*enemy)->getSight()){
		    	if(dist <= (*enemy)->attackRange())
                    (*enemy)->attack();

			    else {
                    //Cell adjacent = gameGrid.getAdjacentEmptyCell(player->getGridCell(), 0);
                    //if(adjacent == Cell()) break;
                    (*enemy)->Chase(player->getCenter(), ticks);
                }
		    }

            //all quiet on the western front
            else (*enemy)->Patrol(ticks);

            (*enemy)->update(ticks);
        }
    }

    for(project = projectiles.begin(); project != projectiles.end(); ++project){
        if((*project)->outOfRange()) 
            project = projectiles.erase(project);
        else (**project).update(ticks);
    }


    for(explode = explosions.begin(); explode != explosions.end(); ++explode){
        if ( (*explode)->chunkCount() == 0 )
    		explode = explosions.erase(explode);
        else (*explode)->update(ticks);
    }

    for(enemy = dieing.begin(); enemy != dieing.end(); ++enemy){
        if((*enemy)->isReallyDead()){
            dead.push_back(*enemy);
            enemy = dieing.erase(enemy);            
        }
        else (*enemy)->update(ticks);
    }

	player->update(ticks);
}
Example #3
0
void Context::update()
{
	mWorld->stepSimulation(mStepVal);
	checkForCollisions();
	if( mDrawDebug ) {
		mWorld->debugDrawWorld();
	}
}
Example #4
0
/*
	UPDATES THE GAME CLOCK, KEEPS TRACK OF TIME, VIEWPORT LOCATION
*/
void Manager::update() {
  ++clock;
  Uint32 ticks = clock.getElapsedTicks();
  checkForCollisions(ticks);
  for(unsigned int i = 0; i < sprites.size(); ++i)
		sprites[i]->update(ticks);
  if ( makeVideo && frameCount < frameMax ) {
		makeFrame();
  }

  world.update();
  viewport.update();
  //player->updateVelocity();
}
Example #5
0
//************** TDDD04 FIX ***********
void GameWorld::physicsSimulation(float deltaTime)
{
	Player* player = m_gameObjectManager->getPlayer();

	// Move camera view
	bool cameraMoved = moveCamera(deltaTime);

	// Add time not used before
	deltaTime += m_timeRest;

	// If enough time for a tick have passed
	if (deltaTime > GAME_WORLD_EPS)
	{
		// Break down elapsed time in smaller chucks to get a smouth experience.
		for(; deltaTime > GAME_WORLD_EPS; deltaTime -= GAME_WORLD_EPS)
		{
			// Move player along with camera if camera has moved
			if (cameraMoved)
			{
				player->offsetPosition(Coord(0.0f, -CAMERA_MOVING_SPEED*GAME_WORLD_EPS));
			}

			// Move all objects
			m_physicsComponent->move(m_gameObjectManager, GAME_WORLD_EPS);

			// Move player back in view if outside camera view
			movePlayerBackIntoView(player);

			// Check for collisions
			checkForCollisions();
	
			//PLAYER DEAD
			//TDDD04 FIX
			if (player->isDead())
			{
				m_eventPlayerDied->run();
				return;
			}
		}

		// Store any unused time
		m_timeRest = deltaTime;
	}
	else
	{
		m_timeRest = deltaTime;
	}
}
Example #6
0
void Player::onMove(float moveX, float moveY)
{
	int y = getDimensions()->y; //Move Toon and set int y for reference
	int maxY = OWindow::sGameWindow.getHeight();

	//Calculate actual speed based on frame rate
	moveY *= OFPS::sFPSController.getSpeedFactor();

	//Test if move is valid
	y += (int) moveY;

	checkForCollisions();

	//Make sure dragon is in bounds
	if ((y < 0) || ((y + getDimensions()->h) > maxY))
		y -= (int) moveY; //move back if hitting border
	//Set y to new y
	getDimensions()->y = y;
}
Example #7
0
void BabyDragon::onMove(float moveX, float moveY)
{
	int x = getDimensions()->x;
	int minX = -getDimensions()->w;

	//Calcuation speed based on fps
	moveX *= OFPS::sFPSController.getSpeedFactor();

	//Update temp location
	x -= (int)moveX; //-= because we are moving to the left 

	checkForCollisions();

	//If outside screen disotry the object
	if (x <= minX)
	{
		isDeadFlag = true;
	}
	else
	{
		getDimensions()->x = x;
	}
}
Example #8
0
	Cost BL::calc(const int areaW)
	{
		vector<Id> ids = getImageIds();
		sort(ids.begin(), ids.end(), DecreasingNormalWidthCmp(this));

		typedef vector<S> V;
		typedef V::iterator Itr;

		V v;
		v.push_back(S(Point(0, 0), 0, areaW));

		list<Id> idsList(ids.begin(), ids.end());
		while (!idsList.empty())
		{
			Itr insertItr = v.end();
			int bestY = numeric_limits<int>::max();

			//insertItr
			list<Id>::iterator idsListBestItr = idsList.begin();
			for (list<Id>::iterator idsListItr = idsList.begin(); idsListItr != idsList.end(); ++idsListItr)
			{
				const int w = normalWidth(*idsListItr);
				bool wasBetter = false;
				
				//cache friendly
				for (Itr itr = v.begin(); itr != v.end(); ++itr)
				{
					if (itr->left + itr->right >= w && itr->point.y < bestY)
					{
						insertItr = itr;
						bestY = itr->point.y;
						wasBetter = true;
					}
				}
				if (wasBetter)
					idsListBestItr = idsListItr;

				if (!morePrecisie)
					break;
			}

			const Id item = *idsListBestItr;
			idsList.erase(idsListBestItr);

			//init
			const int itemW = normalWidth(item);
			const int itemH = normalHeight(item);

			Point insertPoint(insertItr->point.x - insertItr->left, insertItr->point.y);
			const int insertY1(insertPoint.y);
			const int insertY2(insertY1 + itemH);
			const int insertX1(insertPoint.x);
			const int insertX2(insertX1 + itemW);

			Itr firstCovered = v.begin();
			Itr firstNotCovered = v.end();

			S s1(Point(insertPoint.x, insertPoint.y + itemH), insertPoint.x, areaW - insertPoint.x);
			S s2(Point(insertPoint.x + itemW, insertPoint.y + itemH), insertPoint.x + itemW, areaW - insertPoint.x - itemW);
			S s3(Point(insertPoint.x + itemW, insertPoint.y), 0, areaW - insertPoint.x - itemW);

			//firstCovered
			firstCovered = insertItr;
			for (Itr itr = v.begin(); itr != v.end(); ++itr)
			{
				if (insertX1 <= itr->point.x && itr->point.x <= insertX2 && itr->point.y <= insertY2)
				{
					firstCovered = itr;
					break;					
				}
			}

			//firstNotCovered
			for (Itr itr = v.begin(); itr != v.end(); ++itr)
			{
				if (insertX2 <= itr->point.x)
				{
					firstNotCovered = itr;
					break;
				}
			}

			//correct existing items
			for (Itr itr = v.begin(); itr != v.end(); ++itr)
			{
			    if (itr->point.y < insertY2) 
				{
					if (itr->point.x <= insertX1)
					{
						int newRight = insertX1 - itr->point.x;
						if (newRight < itr->right)
							itr->right = newRight;
					}
					else if (insertX2 <= itr->point.x)
					{
						int newLeft = itr->point.x - insertX2;
						if (newLeft < itr->left)
							itr->left = newLeft;
					}
				}
			}

			//s1.left
			for (Itr itr = firstCovered; ;)
			{
				if (itr->point.y > s1.point.y)
				{
					s1.left = s1.point.x - itr->point.x;
					break;
				}

				if (itr == v.begin())
					break;

				--itr;
			}

			//s1.right
			for (Itr itr = firstNotCovered; itr != v.end(); ++itr)
			{
				if (itr->point.y > s1.point.y)
				{
					s1.right = itr->point.x - s1.point.x;
					break;
				}
			}

			//s2.left
			s2.left = s1.left + itemW;

			//s2.right
			s2.right = s1.right - itemW;

			//s3.right
			for (Itr itr = firstNotCovered; itr != v.end(); ++itr)
			{
				if (itr->point.y > s3.point.y)
				{
					s3.right = itr->point.x - s3.point.x;
					break;
				}
			}

			//insert item
			result.add(item, normalPoint(insertPoint));

			//reconstruction
			V v2;

			for (Itr itr = v.begin(); itr != firstCovered; ++itr)
				v2.push_back(*itr);

			v2.push_back(s1);
			v2.push_back(s2);
			v2.push_back(s3);

			for (Itr itr = firstNotCovered; itr != v.end(); ++itr)
				v2.push_back(*itr);

			v = v2;
		}

		checkForCollisions();

		return calcResultCost();
	}
Example #9
0
void Player::update(sf::Time ft, std::vector<sf::Sprite> sprites, std::vector<sf::Sprite> &collectables)
{
	checkForCollisions(sprites, collectables);
	sprite.update(ft);
	getInput(ft);
}
Example #10
0
task main()
{
	// pose ===========================================================
	float pose[3];
	float* pose_ptr = &pose;
	float x=0,y=0,phi=0;
	pose[0]=x;pose[1]=y;pose[2]=phi;

	// speeds =========================================================
	float v=CRUISE, w=0;

	float w_look = 0.0;
	float w_head = 0.0;

	// logObstacle behavior ===========================================
	// obstacle log
	float obstacles_xy[N_ANGLES][2];
	for(int i=0; i<N_ANGLES; i++){
		obstacles_xy[i][0]=10.0;//x
		obstacles_xy[i][1]=10.0;//y
	}
	float* obstacle_ptr;
	float temp_o_x,temp_o_y;

	//ranging
	float range;

	// head tracking
	float halfViewingAngle = headCalibrate();
	float headAngle = 0;

	float angleDelta = 2.0*halfViewingAngle/(float)N_ANGLES;

	float headAngleWorld = 0.0;
	float prevHeadAngleWorld = headAngleWorld-2.0*angleDelta;

	resetAngleCounter(N_ANGLES-1,-1);

	// collision =====================================================
	bool collision_flag = false;

	//more state variables for pose ===================================
	float ticks[2];
	float* ticks_ptr;
	float prevTicks[2];
	prevTicks[0]=0;prevTicks[1]=0;

	resetWheelEncoders();

	while(1){
		// update state ================================================================================================
		ticks_ptr = readWheelEncoders();
		ticks[0]=ticks_ptr[0];ticks[1]=ticks_ptr[1];

		pose_ptr = update_odometry(pose,ticks,prevTicks);
		pose[0]=pose_ptr[0];pose[1]=pose_ptr[1];pose[2]=pose_ptr[2];
		x=pose_ptr[0];y=pose_ptr[1];phi=pose_ptr[2];

		//store for next pass
		prevTicks[0] = ticks[0];
		prevTicks[1] = ticks[1];
		// end update state ============================================================================================

		// logObstacle behavior ========================================================================================
		headAngle = getHeadAngle();
		range = getRange();

		headAngleWorld = headAngle-halfViewingAngle+phi;
		if(abs(headAngleWorld - prevHeadAngleWorld) >= angleDelta){
			prevHeadAngleWorld = headAngleWorld;

			obstacle_ptr = getObstaclePosition(headAngleWorld,range,pose);
			temp_o_x = obstacle_ptr[0];temp_o_y = obstacle_ptr[1];

			obstacles_xy[AngleCounter][0] = temp_o_x;
			obstacles_xy[AngleCounter][1] = temp_o_y;

			incrementAngleCounter();
		}
		// end logObstacle behavior ====================================================================================

		// collide behavior ============================================================================================

		collision_flag = checkForCollisions(obstacles_xy,pose);

		// end collide behavior ========================================================================================

		// send actuator commands ======================================================================================
		v = CRUISE;
		if(collision_flag && v>0.0){
			v = 0.0;
		}
		set_motor_speeds(v,0.0);

		//worked before the angle was limited
		//if(collision_flag)v
		//	//halt();
		//	//set_motor_speeds(0.0,0.0);
		//	set_motor_speeds(0.0,5.0);
		//}else{
		//	set_motor_speeds(v,0.0);
		//}

		w_look = lookBackAndForth(w_look);
		w_head = w_look;
		headRotate(w_head);
		// end send actuator commands ==================================================================================
	}
}
Example #11
0
void nodeManager::updateNodes() {

    appReactions.clear();

    //implement scheduled commands
    vector<eventComm>::iterator e_it = mFutureEvents.begin();

    while(e_it != mFutureEvents.end()) {
        if(e_it->execAt == ofGetFrameNum()) {
            if(mNodes.find(e_it->ownerIndex) != mNodes.end()) {
                implementReaction(e_it->r, mNodes[e_it->ownerIndex]);
            }
            e_it = mFutureEvents.erase(e_it);
        } else {
            ++e_it;
        }
    }


    for(int i = 0; i < mCollisionMap.size(); i++)mCollisionMap[i].clear();

    map<string, ofPtr<clamourNode> >::iterator it;

    it = mNodes.begin();


    while(it != mNodes.end()) {

        it->second->update();

        if(it->second->getCanSleep()) {
            it->second->setIsSleeping(!it->second->getIsFiring());
        }

        if(!it->second->getIsSleeping()) {
            it->second->updateHistory();
            it->second->updateDrawData();
            it->second->updateSoundData();
            it->second->reconcileSlaves();
            it->second->updateRotHistory();
            it->second->updatePath();
            it->second->updateEvents();
            if(it->second->getIsCollidable())addToCollisionRegions(it->second);
        }

        ++it;

    }



    it = mNodes.begin();

    //now check for collisions
    while(it != mNodes.end()) {
        if(!it->second->getIsSleeping()) {


            if(it->second->getIsCollidable())checkForCollisions(it->second);
            if(it->second->getChanged() == CLAMOUR_ON_OFF) {
                implementReactions(it->second, it->second->getIsFired());
            }
        }
        ++it;
    }
}
Example #12
0
BOOL Game::update()
{
	BOOL updateObjects = FALSE;
	BOOL checkForWinning = FALSE;
	BOOL checkForLosing = FALSE;
	BOOL checkCollisions = FALSE;
	BOOL stopMovement = TRUE;

	switch (itsCurrentState)
	{
		case GAMESTATE_PREGAME :
			// since the pregame section is so different, we will call our own method
			pregameUpdate();
			break;
		case GAMESTATE_INPROGRESS :
			updateObjects = TRUE;
			checkForWinning = TRUE;
			checkForLosing = TRUE;
			checkCollisions = TRUE;
			stopMovement = FALSE;
			break;
		case GAMESTATE_WON :
		{
			updateObjects = TRUE;
			Room *room = itsPlayer->getRoom();
			// we need to change the walls a color for that ending flashiness
			if (itsLastTickTime - itsWinTime >= theWinAnimationLength)
			{	
				for (UINT i=0;i<room->getWalls()->length();i++)
				{
					Wall *wall = (Wall *)(room->getWalls()->elementAt(i));
					wall->setChangesColor(FALSE);
				}
			}
			else
			{
				// since the player will be holding the chalice, we can tell
				// the walls to change colors, and they will change to the color
				// of the chalice, which will make them appear to animate
				for (UINT i=0;i<room->getWalls()->length();i++)
				{
					Wall *wall = (Wall *)(room->getWalls()->elementAt(i));
					wall->setChangesColor(TRUE,1);
				}
			}
			// hack to put the player in the right place for the ending
			itsPlayer->setX(Game::theScreenHeight-64);
			itsPlayer->setY(Game::theScreenWidth/2-16);
		}
		break;
		case GAMESTATE_LOST :
			updateObjects = TRUE;
			stopMovement = FALSE;
			break;
		case GAMESTATE_PAUSED :
			stopMovement = FALSE;
			break;
	}

	theEventDispatcher.update(itsLastTickTime);


	if (updateObjects)
	{
		SimpleArray *objects = NULL;
		if (itsWorld != NULL)
		objects = itsWorld->getObjects();
		for (UINT i=0;i<objects->length();i++)
		{
			((GameObject *)(objects->elementAt(i)))->update(itsLastTickTime);
			if (stopMovement)
			{
				((GameObject *)(objects->elementAt(i)))->stopMoving(itsLastTickTime);
			}
		}
		for (i=0;i<itsWorld->getRooms()->length();i++)
		{
			((Room *)(itsWorld->getRooms()->elementAt(i)))->checkForObjectsLeaving();
		}
	}
	if (checkForWinning && gameWon())
	{
		itsNewStateRequest.itsNewState = GAMESTATE_WON;
		itsNewStateRequest.isActiveRequest = TRUE;
	}
	if (checkForLosing && gameLost())
	{
		itsNewStateRequest.itsNewState = GAMESTATE_LOST;
		itsNewStateRequest.isActiveRequest = TRUE;
	}
	if (checkCollisions)
		return checkForCollisions();
	else
		return TRUE;
}