当前位置: 首页>>代码示例>>C++>>正文


C++ PhysicalProperties类代码示例

本文整理汇总了C++中PhysicalProperties的典型用法代码示例。如果您正苦于以下问题:C++ PhysicalProperties类的具体用法?C++ PhysicalProperties怎么用?C++ PhysicalProperties使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PhysicalProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addCollidableObject

//////////////////////////KEEP/////////////////////////////////////////////
void Physics::addCollidableObject(CollidableObject *collidableObjectToAdd)
{
	PhysicalProperties *pp = collidableObjectToAdd->getPhysicalProperties();
	float height = pixelsToMeters(collidableObjectToAdd->getBoundingVolume()->getHeight()) / 2;
	float width = pixelsToMeters(collidableObjectToAdd->getBoundingVolume()->getWidth()) / 2;
	float x = pixelsToMeters(pp->getX());
	float y = pixelsToMeters(-pp->getY());

	// Define the dynamic body. We set its position and call the body factory.
	b2BodyDef bodyDef;
	bodyDef.type = b2_dynamicBody;
	bodyDef.position.Set(x, y);
	b2Body* body = box2DWorld->CreateBody(&bodyDef);

	testSubjectBody = body;

	// Define another box shape for our dynamic body.
	b2PolygonShape dynamicBox;
	dynamicBox.SetAsBox(width, height);

	// Define the dynamic body fixture.
	b2FixtureDef fixtureDef;
	fixtureDef.shape = &dynamicBox;

	// Set the box density to be non-zero, so it will be dynamic.
	fixtureDef.density = 1.0f;

	// Override the default friction.
	fixtureDef.friction = 0.3f;

	// Add the shape to the body.
	body->CreateFixture(&fixtureDef);
}
开发者ID:sherbait,项目名称:kamikaze_fly,代码行数:34,代码来源:Physics.cpp

示例2: Collision

/*
	Default constructor, it initializes all data using default values.
*/
Physics::Physics()
{
	maxVelocity = DEFAULT_MAX_VELOCITY;
	gravity = DEFAULT_GRAVITY;

	/*for(int i = 0; i < 1000; i++)
	{
		Collision *c = new Collision();
		collisionStack.push(c);
	}//end for*/

	for(int i = 0; i < 1000; i++)
	{
		Collision *c = new Collision();
		collisionStack[i] = c;

		if(i < 500)
		{
			CollidableObject* co = new CollidableObject();
			co->setCurrentlyCollidable(true);
			co->setIsStatic(true);
			PhysicalProperties* pp = co->getPhysicalProperties();
			pp->setVelocity(0,0);

			coStack[i] = co;
		}
	}//end for
	
	collisionStackCounter = 999;
	coStackCounter = 499;
}
开发者ID:Esaft,项目名称:esaft-cse380,代码行数:34,代码来源:Physics.cpp

示例3: handleMousePressEvent

void WalkaboutMouseEventHandler::handleMousePressEvent(Game *game, int mouseX, int mouseY)
{
	if (game->getGSM()->isGameInProgress())
	{
		Viewport *viewport = game->getGUI()->getViewport();

		// DETERMINE WHERE ON THE MAP WE HAVE CLICKED
		int worldCoordinateX = mouseX + viewport->getViewportX();
		int worldCoordinateY = mouseY + viewport->getViewportY();

		SpriteManager *spriteManager = game->getGSM()->getSpriteManager();
		Player* player = static_cast<Player*>(spriteManager->getPlayer());
		PhysicalProperties* playerPP = spriteManager->getPlayer()->getPhysicalProperties();

		if(!player->getIsDead() && !player->getIsDying() && player->getAmmo() != 0)
		{
			float dx = worldCoordinateX - playerPP->getX();
			float dy = worldCoordinateY - playerPP->getY();
			float distanceToMouse = sqrtf(dx*dx + dy*dy);
			dx /= distanceToMouse;
			dy /= distanceToMouse;

			float bulletOffset = 60;
			float bulletSpeed = 50;

			//Fire projectile
			spriteManager->createProjectile(playerPP->getX() + bulletOffset*dx, playerPP->getY() + bulletOffset*dy,
				bulletSpeed*dx,bulletSpeed*dy);

			player->decrementAmmo();
		}
	}
}
开发者ID:sherbait,项目名称:kamikaze_fly,代码行数:33,代码来源:WalkaboutMouseEventHandler.cpp

示例4: there

/*
	update - This method should be called once per frame. It updates
	both the sprites and the game world. Note that even though the game
	world is for static data, should the user wish to put anything dynamic
	there (like a non-collidable moving layer), the updateWorld method
	is called.
*/
void GameStateManager::update(Game *game)
{
	game->getGameRules()->spawnEnemies(game);
	spriteManager->update(game);
	world.update(game);
	physics.update(game);

	AnimatedSprite *p = spriteManager->getPlayer();
	PhysicalProperties *pp = p->getPhysicalProperties();
	float pVelX = pp->getVelocityX();
	float pVelY = pp->getVelocityY();

	//VIEWPORT SCOPING
	/*Viewport *vp = game->getGUI()->getViewport();
	
	if(pVelX < 0 
		&& (pp->round(pp->getX() - vp->getViewportX())) < vp->getViewportWidth()/3)
	{
		vp->setScrollSpeedX(pVelX);
		if(vp->getViewportX() == 0)
			vp->setScrollSpeedX(0);
	}
	else if(pVelX > 0 
		&& (pp->round(pp->getX() - vp->getViewportX())) > (vp->getViewportWidth()/3*2))
	{
		vp->setScrollSpeedX(pVelX);
		if(vp->getViewportX()+vp->getViewportWidth() == world.getWorldWidth())
			vp->setScrollSpeedX(0);
		
	}
	else
	{
		vp->setScrollSpeedX(0);
	}

	if(pVelY < 0 
		&& (pp->round(pp->getY() - vp->getViewportY())) < vp->getViewportHeight()/3)
	{
		vp->setScrollSpeedY(pVelY);
		if(vp->getViewportY() == 0)
			vp->setScrollSpeedY(0);
	}
	else if(pVelY > 0 
		&& (pp->round(pp->getY() - vp->getViewportY())) > (vp->getViewportHeight()/3*2))
	{
		vp->setScrollSpeedY(pVelY);
		if(vp->getViewportY()+vp->getViewportHeight() == world.getWorldHeight())
			vp->setScrollSpeedY(0);
	}
	else
	{
		vp->setScrollSpeedY(0);
	}

	vp->moveViewport(	vp->getScrollSpeedX(),
						vp->getScrollSpeedY(),
						world.getWorldWidth(),
						world.getWorldHeight());*/
}
开发者ID:Esaft,项目名称:esaft-cse380,代码行数:66,代码来源:GameStateManager.cpp

示例5: if

void ScienceMouseEventHandler::handleMousePressEvent(Game *game, int mouseX, int mouseY)
{
	if (game->getGSM()->isGameInProgress())
	{
		Viewport *viewport = game->getGUI()->getViewport();
		
		// DETERMINE WHERE ON THE MAP WE HAVE CLICKED
		int worldCoordinateX = mouseX + viewport->getViewportX();
		int worldCoordinateY = mouseY + viewport->getViewportY();

		// NOW LET'S SEE IF THERE IS A SPRITE THERE
		GameStateManager *gsm = game->getGSM();
		SpriteManager *spriteManager = gsm->getSpriteManager();

		
		// IF THERE IS NO SELECTED SPRITE LOOK FOR ONE
		if (!(spriteManager->getIsSpriteSelected()))
		{
			// IF THIS DOES NOT RETURN NULL THEN YOU FOUND A SPRITE AT THAT LOCATION
			if((spriteManager->getSpriteAt(worldCoordinateX, worldCoordinateY) != NULL))
			{
				AnimatedSprite *selected = spriteManager->getSpriteAt(worldCoordinateX, worldCoordinateY);
				spriteManager->setIsSpriteSelected(true);
			}
		}
		else if (spriteManager->getSelectedSprite() != NULL)
		{
			// MOVE A SPRITE IN A DESIRED DIRECTION 
			AnimatedSprite *selected = spriteManager->getSelectedSprite();
			PhysicalProperties *pp = selected->getPhysicalProperties();
			float spriteX = pp->getX();
			float spriteY = pp->getY();

			//IF A SPRITE IS WHERE YOU WANT IT THEN STOP IT
			if (((spriteX > worldCoordinateX - 64) && (spriteX < worldCoordinateX + 64)) && (spriteY > worldCoordinateY - 64) && (spriteY < worldCoordinateY + 64))
			{
				pp->setVelocity(0, 0);
			}
			else
			{
				float deltaX = worldCoordinateX - spriteX;
				float deltaY = worldCoordinateY - spriteY;
				float hyp = sqrtf((deltaX * deltaX) + (deltaY * deltaY));

				pp->setVelocity((deltaX / hyp) * 3, (deltaY / hyp) * 3);
			}
			spriteManager->setIsSpriteSelected(false);

		//	GridPathfinder *pathfinder = spriteManager->getPathfinder();
		//	pathfinder->mapPath(selected, (float)worldCoordinateX, (float)worldCoordinateY);
		//	gsm->setSpriteSelected(false, selected);
		}
		else
		{
			spriteManager->setIsSpriteSelected(false);
		}
	}
}
开发者ID:kpropper,项目名称:Science,代码行数:58,代码来源:ScienceMouseEventHandler.cpp

示例6: willObjectsCollide

bool Physics::willObjectsCollide(CollidableObject* coA, CollidableObject* coB)
{
	PhysicalProperties* pp = coA->getPhysicalProperties();
	BoundingVolume* bv = coA->getBoundingVolume();
	float widthA = bv->getWidth();
	float heightA = bv->getHeight();
	float xA = pp->getX() + bv->getX();
	float yA = pp->getY() + bv->getY();
	float velXA = pp->getVelocityX();
	float velYA = pp->getVelocityY();
	float minXA = xA-(widthA/2);
	float maxXA = xA+(widthA/2);
	float minYA = yA-(heightA/2);
	float maxYA = yA+(heightA/2);

	if(velXA >= 0)
		maxXA += velXA; 
	if(velXA < 0)
		minXA += velXA; 
	if(velYA >= 0)
		maxYA += velYA; 
	if(velYA < 0)
		minYA += velYA; 

	pp = coB->getPhysicalProperties();
	bv = coB->getBoundingVolume();
	float widthB = bv->getWidth();
	float heightB = bv->getHeight();
	float xB = pp->getX() + bv->getX();
	float yB = pp->getY() + bv->getY();
	float velXB = pp->getVelocityX();
	float velYB = pp->getVelocityY();
	float minXB = xB-(widthB/2);
	float maxXB = xB+(widthB/2);
	float minYB = yB-(heightB/2);
	float maxYB = yB+(heightB/2);

	if(velXB >= 0)
		maxXB += velXB; 
	if(velXB < 0)
		minXB += velXB; 
	if(velYB >= 0)
		maxYB += velYB; 
	if(velYB < 0)
		minYB += velYB; 

	if( !(maxXB < minXA || minXB > maxXA || maxYB < minYA || minYB > maxYA))
		return true;
	return false;
}
开发者ID:Esaft,项目名称:esaft-cse380,代码行数:50,代码来源:Physics.cpp

示例7: prepSpriteForCollisionTesting

/*
	Done each frame before collision testing, it updates the "on tile" states
	and then applies acceleration and gravity to the sprite's velocity. Then it
	initializes the swept shape for the sprite.
*/
void Physics::prepSpriteForCollisionTesting(World *world, CollidableObject *sprite)
{
	// THIS GUY HAS ALL THE PHYSICS STUFF FOR THE SPRITE
	PhysicalProperties *pp = sprite->getPhysicalProperties();

	// APPLY ACCELERATION
	pp->applyAcceleration();

	// APPLY GRAVITY
	pp->incVelocity(0.0f, gravity);

	// NOW, IF THE SPRITE WAS ON A TILE LAST FRAME LOOK AHEAD
	// TO SEE IF IT IS ON A TILE NOW. IF IT IS, UNDO GRAVITY.
	// THIS HELPS US AVOID SOME PROBLEMS
	if (sprite->wasOnTileLastFrame())
	{
		// FIRST MAKE SURE IT'S SWEPT SHAPE ACCOUNTS FOR GRAVITY
		sprite->updateSweptShape(1.0f);

		// WE'LL LOOK THROUGH THE COLLIDABLE LAYERS
		vector<WorldLayer*> *layers = world->getLayers();
		for (int i = 0; i < world->getNumLayers(); i++)
		{
			WorldLayer *layer = layers->at(i);
			if (layer->hasCollidableTiles())
			{
				bool test = layer->willSpriteCollideOnTile(this, sprite);
				if (test)
				{
					sprite->setOnTileThisFrame(true);
					pp->setVelocity(pp->getVelocityX(), 0.0f);
					sprite->updateSweptShape(1.0f);
					return;
				}
				else
					cout << "What Happened?";
			}
		}
	}

	// INIT THE SWEPT SHAPE USING THE NEWLY APPLIED
	// VELOCITY. NOTE THAT 100% OF THE FRAME TIME
	// IS LEFT, DENOTED BY 1.0f
	sprite->updateSweptShape(1.0f);
}
开发者ID:CSE380Skulls,项目名称:ForceOfReaction,代码行数:50,代码来源:Physics.cpp

示例8: initCountdownCounter

void BotSpawningPool::update()
{
	countdownCounter--;
	if (countdownCounter <= 0) {
		// SPAWN A BOT
		Game *game = Game::getSingleton();
		GameStateManager *gsm = game->getGSM();
		SpriteManager *spriteManager = gsm->getSpriteManager();
		BotRecycler *botRecycler = spriteManager->getBotRecycler();
		Bot *spawnedBot = botRecycler->retrieveBot(botType);
		spriteManager->addBot(spawnedBot);
		initCountdownCounter();

		// DO IT'S SPAWNING BEHAVIOR
		BotBehavior *spawningBehavior = spawnedBot->getBehavior(BotState::SPAWNING);
		spawningBehavior->behave(spawnedBot);

		// AND START IT LOCATED AT THE SPAWNING POOL
		PhysicalProperties *pp = spawnedBot->getPhysicalProperties();
		pp->setX(x);
		pp->setY(y);
	}
}
开发者ID:bsbae402,项目名称:McKillasGorilla_repo,代码行数:23,代码来源:BotSpawningPool.cpp

示例9: BackAndForthBot

/*
	clone - this method makes another BackAndForthBot object, but does
	not completely initialize it with similar data to this. Most of the 
	object, like velocity and position, are left uninitialized.
*/
Bot* BackAndForthBot::clone()
{
	BackAndForthBot *botClone = new BackAndForthBot();
	PhysicalProperties* pp = this->getPhysicalProperties();
	PhysicalProperties* bp = botClone->getPhysicalProperties();
	BoundingVolume* pV = this->getBoundingVolume();
	BoundingVolume* bV = botClone->getBoundingVolume();
	botClone->setEnemy(enemy);
	botClone->setItem(item);
	botClone->setPortal(portal);
	botClone->setSpriteType(this->getSpriteType());
	botClone->setAlpha(this->getAlpha());
	botClone->setDead(false);
	bp->setCollidable(pp->isCollidable());
	bp->setGravAffected(pp->isGravAffected());
	bV->setHeight(pV->getHeight());
	bV->setWidth(pV->getWidth());
	bV->setX(pV->getX());
	bV->setY(pV->getY());
	return botClone;
}
开发者ID:Esaft,项目名称:esaft-cse380,代码行数:26,代码来源:BackAndForthBot.cpp

示例10: if

void BalloonEscapeCollisionListener::respondToCollision(Game *game, Collision *collision)
{
	// NOTE FROM THE COLLIDABLE OBJECTS, WHICH ARE IN THE COLLISION,
	// WE CAN CHECK AND SEE ON WHICH SIDE THE COLLISION HAPPENED AND
	// CHANGE SOME APPROPRIATE STATE ACCORDINGLY
	GameStateManager *gsm = game->getGSM();
	AnimatedSprite *player = gsm->getSpriteManager()->getPlayer();
	PhysicalProperties *pp = player->getPhysicalProperties();
	//AnimatedSprite *bot = collision
	CollidableObject *sprite2 = collision->getCO2();
	PhysicalProperties *pp2 = sprite2->getPhysicalProperties();
	AnimatedSprite *bot = (AnimatedSprite*)sprite2;
	if (!collision->isCollisionWithTile() && player->getCurrentState() != L"DYING")
	{
		CollidableObject *sprite = collision->getCO1();

		if (sprite2->getPhysicalProperties()->getZ() == 1.0f) {
			
			bot = (AnimatedSprite*)sprite;
				 pp = sprite2->getPhysicalProperties();
					pp2 = sprite->getPhysicalProperties();

			sprite = collision->getCO2();
			sprite2 = collision->getCO1();
			if (sprite->getCollisionEdge() == BOTTOM_EDGE)
			{	
				bot->setCurrentState(L"DYING");
				pp2->setVelocity(0.0f, 0.0f);
				pp2->setAccelerationX(0);
				pp2->setAccelerationY(0);
				// ENEMY IS DEAD - WE SHOULD PLAY A DEATH ANIMATION
				// AND MARK IT FOR REMOVAL
			}
			else if (bot->getCurrentState() != L"DYING")
			{
				if (pp->getDelay() == 0) {
					if (pp->getHP() == 10 ) {
						//lives->setCurrentState(L"TWO");
						if(deadonce == true)
						//lives->setCurrentState(L"ONE");
						player->setCurrentState(L"DYING");
						pp->setDelay(90);
						pp->setVelocity(0.0f, 0.0f);
						pp->setAccelerationX(0);
						pp->setAccelerationY(0);
						deadonce=true;
					}
					else {
						pp->setDelay(90);
						pp->setHP(pp->getHP()-10);
						SpriteManager *spriteManager = gsm->getSpriteManager();
						AnimatedSpriteType *yellowman = spriteManager->getSpriteType(3);
						player->setSpriteType(yellowman);
					}
				}

				// PLAYER IS DEAD - WE SHOULD PLAY A DEATH ANIMATION
				// AND MARK IT FOR REMOVAL/RESPAWN/RESTART GAME, WHATEVER
				// THE DEMANDS OF THE GAME ARE
			}
		}
		else if(sprite->getPhysicalProperties()->getZ() == 1.0f) {
			PhysicalProperties *pp = sprite->getPhysicalProperties();
			if (sprite->getCollisionEdge() == BOTTOM_EDGE)
			{
				
				bot->setCurrentState(L"DYING");
				pp2->setVelocity(0.0f, 0.0f);
				pp2->setAccelerationX(0);
				pp2->setAccelerationY(0);
				// ENEMY IS DEAD - WE SHOULD PLAY A DEATH ANIMATION
				// AND MARK IT FOR REMOVAL

			}
			else if (bot->getCurrentState() != L"DYING")
			{
				if (pp->getDelay() == 0) {
					if (pp->getHP() == 10 ) {


						//lives->setCurrentState(L"TWO");
						if(deadonce == true)
						//lives->setCurrentState(L"ONE");
						player->setCurrentState(L"DYING");
						pp->setDelay(90);
						pp->setVelocity(0.0f, 0.0f);
						pp->setAccelerationX(0);
						pp->setAccelerationY(0);
						deadonce=true;

					}
					else {
						pp->setDelay(90);
						pp->setHP(pp->getHP()-10);
						SpriteManager *spriteManager = gsm->getSpriteManager();
						AnimatedSpriteType *yellowman = spriteManager->getSpriteType(3);
						player->setSpriteType(yellowman);
					}
				}

//.........这里部分代码省略.........
开发者ID:DavidLui,项目名称:-CSE380-Balloon-Escape,代码行数:101,代码来源:BalloonEscapeCollisionListener.cpp

示例11: addSpriteToRenderList

void SpriteManager::addSpriteToRenderList(AnimatedSprite *sprite,
										  RenderList *renderList,
										  Viewport *viewport)
{
	// GET THE SPRITE TYPE INFO FOR THIS SPRITE
	AnimatedSpriteType *spriteType = sprite->getSpriteType();
	PhysicalProperties *pp = sprite->getPhysicalProperties();
	if (i >= 3) {
		b2Body* bods= sprite->getBody();
		b2Vec2 position = bods->GetPosition();
		pp->setX(position.x);
		pp->setY(position.y);
	}
	
		i+=1;


	// IS THE SPRITE VIEWABLE?
	if (viewport->areWorldCoordinatesInViewport(	
									pp->getX(),
									pp->getY(),
									spriteType->getTextureWidth(),
									spriteType->getTextureHeight()) )
	{
		// SINCE IT'S VIEWABLE, ADD IT TO THE RENDER LIST
		RenderItem itemToAdd;
		itemToAdd.id = sprite->getFrameIndex();
		
		
	

		if (spriteType->getTextureWidth()==61) {
		renderList->addRenderItem(	sprite->getCurrentImageID(),
									pp->round(X-viewport->getViewportX()),
									pp->round(Y-25-viewport->getViewportY()),
									pp->round(pp->getZ()),
									sprite->getAlpha(),
									spriteType->getTextureWidth(),
									spriteType->getTextureHeight());	

		}

		else {
		renderList->addRenderItem(	sprite->getCurrentImageID(),
									pp->round(pp->getX()-viewport->getViewportX()),
									pp->round(pp->getY()-viewport->getViewportY()),
									pp->round(pp->getZ()),
									sprite->getAlpha(),
									spriteType->getTextureWidth(),
									spriteType->getTextureHeight());
		}
	
	}
}
开发者ID:DavidLui,项目名称:-CSE380-Balloon-Escape,代码行数:54,代码来源:SpriteManager.cpp

示例12: think

/*
	think - called once per frame, this is where the bot performs its
	decision-making. Note that we might not actually do any thinking each
	frame, depending on the value of cyclesRemainingBeforeThinking.
*/
void BackAndForthBot::think(Game *game)
{
	// EACH FRAME WE'LL TEST THIS BOT TO SEE IF WE NEED
	// TO PICK A DIFFERENT DIRECTION TO FLOAT IN
	PhysicalProperties* pp	= &(this->pp);
	if(!dead)
	{
		if(pp->getVelocityX() == 0)
		{
			pp->setVelocity(vel, pp->getVelocityY());
		}
		if (cyclesRemainingBeforeChange == 0)
		{
			vel *= -1;
			pp->setVelocity(vel, pp->getVelocityY());

			if(pp->isOrientedRight())
			{
				this->setCurrentState(L"WALKL_STATE");
				pp->setOrientedLeft();
			}
			else
			{
				this->setCurrentState(L"WALK_STATE");
				pp->setOrientedRight();
			}

			cyclesRemainingBeforeChange = pathSize;

		}
		else
			cyclesRemainingBeforeChange--;

	}
	else
	{
		wstring curState = this->getCurrentState();
		pp->setVelocity(0,pp->getVelocityY());
		int lastFrame = this->getSpriteType()->getSequenceSize(curState)-2;
		if(this->getFrameIndex() == lastFrame)
		{
			game->getGSM()->getSpriteManager()->removeBot(this);
		}
	}
}
开发者ID:Esaft,项目名称:esaft-cse380,代码行数:50,代码来源:BackAndForthBot.cpp

示例13: handleKeyEvents

/*
	handleKeyEvent - this method handles all keyboard interactions. Note that every frame this method
	gets called and it can respond to key interactions in any custom way. Ask the GameInput class for
	key states since the last frame, which can allow us to respond to key presses, including when keys
	are held down for multiple frames.
*/
void SoSKeyEventHandler::handleKeyEvents(Game *game)
{
	// WE CAN QUERY INPUT TO SEE WHAT WAS PRESSED
	GameInput *input = game->getInput();

	// LET'S GET THE PLAYER'S PHYSICAL PROPERTIES, IN CASE WE WANT TO CHANGE THEM
	GameStateManager *gsm = game->getGSM();
	AnimatedSprite *player = gsm->getSpriteManager()->getPlayer();
	PhysicalProperties *pp = player->getPhysicalProperties();
	
	if(gsm->isAtSplashScreen())
	{
		if(input->isKeyDown(ENTER_KEY))
		{
			gsm->goToMainMenu();
		}
	}

	

	// IF THE GAME IS IN PROGRESS
	if (gsm->isGameInProgress())
	{
		// CHECK FOR WASD KEYS FOR MOVEMENT
		int incX = 0;
		int incY = 0;
		bool movingLR = false;
		bool attacking = false;

		if(!pp->isStunned())
		{
			if(input->isKeyDown(SPACE_KEY))
			{
				attacking = true;
				if(input->isKeyDownForFirstTime(SPACE_KEY))
				{
			
					player->setCurrentState(L"ATTACK_STATE");
					if(!pp->isOrientedRight())
						player->setCurrentState(L"ATTACKL_STATE");
				}
			
			}

			// WASD AND DIRECTION KEY PRESSES WILL CONTROL THE PLAYER,
			// SO WE'LL UPDATE THE PLAYER VELOCITY WHEN THESE KEYS ARE
			// PRESSED, THAT WAY PHYSICS CAN CORRECT AS NEEDED
			float vX = pp->getVelocityX();
			float vY = pp->getVelocityY();

		
			if (input->isKeyDown(A_KEY) || input->isKeyDown(LEFT_KEY))
			{
				movingLR = true;
				pp->setOrientedLeft();
				vX = -PLAYER_SPEED;
				if (vY == 0 && player->getCurrentState().compare(L"LEFT_STATE") != 0)
					player->setCurrentState(L"LEFT_STATE");
				else if(vY != 0 && player->getCurrentState().compare(L"JUMPL_STATE") != 0)
					player->setCurrentState(L"JUMPL_STATE");
			}
			if (input->isKeyDown(D_KEY) || input->isKeyDown(RIGHT_KEY))
			{
				movingLR = true;
				pp->setOrientedRight();
				vX = PLAYER_SPEED;
				if (vY == 0 && player->getCurrentState().compare(L"RIGHT_STATE") != 0)
					player->setCurrentState(L"RIGHT_STATE");
				else if(vY != 0 && player->getCurrentState().compare(L"JUMP_STATE") != 0)
					player->setCurrentState(L"JUMP_STATE");
			}
			/*if (input->isKeyDown(S_KEY) || input->isKeyDown(DOWN_KEY))
			{
				vY = PLAYER_SPEED;
			}*/
			if (input->isKeyDown(W_KEY) || input->isKeyDown(UP_KEY))
			{
			

				if ((input->isKeyDownForFirstTime(W_KEY) || input->isKeyDownForFirstTime(UP_KEY))
					&& pp->hasDoubleJumped() == false)
				{
					if(pp->hasJumped() == true)
						pp->setDoubleJumped(true);
					pp->setJumped(true);

					vY = -PLAYER_SPEED;
					player->setCurrentState(L"JUMP_STATE");
					if(vX < 0)
						player->setCurrentState(L"JUMPL_STATE");
				}
			}	

			if(!movingLR)
//.........这里部分代码省略.........
开发者ID:Esaft,项目名称:esaft-cse380,代码行数:101,代码来源:SoSKeyEventHandler.cpp

示例14: collideTestWithTiles

void Physics::update(Game *game)
{
	// REMEMBER, AT THIS POINT, ALL PLAYER INPUT AND AI
	// HAVE ALREADY BEEN PROCESSED AND BOT AND PLAYER
	// STATES, VELOCITIES, AND ACCELERATIONS HAVE ALREADY
	// BEEN UPDATED. NOW WE HAVE TO PROCESS THE PHYSICS
	// OF ALL THESE OBJECTS INTERACTING WITH EACH OTHER
	// AND THE STATIC GAME WORLD. THIS MEANS WE NEED TO
	// DETECT AND RESOLVE COLLISIONS IN THE ORDER THAT
	// THEY WILL HAPPEN, AND WITH EACH COLLISION, EXECUTE
	// ANY GAMEPLAY RESPONSE CODE, UPDATE VELOCITIES, AND
	// IN THE END, UPDATE POSITIONS

	// FIRST, YOU SHOULD START BY ADDING ACCELERATION TO ALL 
	// VELOCITIES, WHICH INCLUDES GRAVITY, NOTE THE EXAMPLE
	// BELOW DOES NOT DO THAT


	// FOR NOW, WE'LL JUST ADD THE VELOCITIES TO THE
	// POSITIONS, WHICH MEANS WE'RE NOT APPLYING GRAVITY OR
	// ACCELERATION AND WE ARE NOT DOING ANY COLLISION 
	// DETECTION OR RESPONSE
	float timer = 0;

	GameStateManager *gsm = game->getGSM();
	SpriteManager *sm = gsm->getSpriteManager();
	World *w = gsm->getWorld();
	GameRules* gR = game->getGameRules();
	vector<WorldLayer*> *layers = w->getLayers();

	AnimatedSprite *player;
	PhysicalProperties *pp;
	TiledLayer *tL;
	list<Collision*> collisions;
	
	//finding TileLayer
	for(unsigned int i = 0; i < layers->size(); i++)
	{
		WorldLayer *currentLayer = (*layers)[i];
		if(currentLayer->hasCollidableTiles() == true)
		{
			tL = dynamic_cast<TiledLayer*>(currentLayer);
			if(tL != 0)
			{
				i = layers->size();
			}//end if
		}//end if
	}


	player = sm->getPlayer();
	pp = player->getPhysicalProperties();

	//UPDATING ALL VELOCITIES AND DOING TILE COLLISION
	pp->incVelocity(this,pp->getAccelerationX(), pp->getAccelerationY() + gravity); 
	collideTestWithTiles(player, tL, &collisions);

	list<Bot*>::iterator botIterator = sm->getBotsIterator();
	while (botIterator != sm->getEndOfBotsIterator())
	{			
		Bot *bot = (*botIterator);
		pp = bot->getPhysicalProperties();
		pp->incVelocity(this, pp->getAccelerationX(), pp->getAccelerationY());
		if(pp->isGravAffected() == true)
			pp->incVelocity(this, 0, gravity);
		collideTestWithTiles(bot, tL, &collisions);
		botIterator++;
	}

	//HERE, COLLIDE SPRITES WITH OTHER SPRITES
	collideTestWithSprites(game, player, &collisions);
	botIterator = sm->getBotsIterator();
	while (botIterator != sm->getEndOfBotsIterator())
	{			
		Bot *bot = (*botIterator);
		if(bot->isCurrentlyCollidable() == true);
			collideTestWithSprites(game, bot, &collisions);
		botIterator++;
	}

	//SORT COLLISIONS
	collisions.sort(compare_collisionTime);

	//RESOLVING ALL THE COLLISIONS
	while(collisions.empty() == false)
	{
		Collision* currentCollision = collisions.front();
		collisions.pop_front();
		float colTime = currentCollision->getTOC();
		CollidableObject* co1 = currentCollision->getCO1();
		CollidableObject* co2 = currentCollision->getCO2();

		if(colTime >= 0 && colTime <= 1)
		{
			
			pp = co1->getPhysicalProperties();
			//pp->setVelocity(pp->getVelocityX()*9.99f,pp->getVelocityY()*9.99f);
			pp = co2->getPhysicalProperties();
			//pp->setVelocity(pp->getVelocityX()*9.99f,pp->getVelocityY()*9.99f);

//.........这里部分代码省略.........
开发者ID:Esaft,项目名称:esaft-cse380,代码行数:101,代码来源:Physics.cpp

示例15: setCurrentState

void BossBot::update(Game *game){
	////////////////////////
	///////////////////////
	///////////////////////
	if(dead) {
		return;
	}
	// If hitpoints are 0, remove it
	if(hitPoints <= 0){
		setCurrentState(direction==1?DYING_RIGHT:DYING_LEFT);
		game->getGSM()->getSpriteManager()->addBotToRemovalList(this, 15);
		dead = true;
		game->getGSM()->goToLevelWon();
		return;
	}

	// Decrement frames since last attack
	cooldownCounter--;
	if(getCurrentState()==ATTACKING_RIGHT||getCurrentState()==ATTACKING_LEFT){
		if(this->getFrameIndex()==10)
			setCurrentState(direction==1?IDLE_RIGHT:IDLE_LEFT);
	}
	// If can attack, check if player in range.
	if(cooldownCounter <= 0){
		// If player is next to this bot, do something different
		int botX = getCurrentBodyX() * BOX2D_CONVERSION_FACTOR;
		int pX = game->getGSM()->getSpriteManager()->getPlayer()->getCurrentBodyX() * BOX2D_CONVERSION_FACTOR;

		// If the player is within the bots targeting area, go after the player
		if(isInBounds(pX)) {
			int botY = getCurrentBodyY() * BOX2D_CONVERSION_FACTOR;
			int pY = game->getGSM()->getSpriteManager()->getPlayer()->getCurrentBodyY() * BOX2D_CONVERSION_FACTOR;
			// Make sure the player is in the same y area
			if(std::abs(botY - pY) < 200){
				if (pX<botX)
					direction=-1;
				else 
					direction=1;
				cooldownCounter = attackCooldown;
				this->setCurrentState(direction==1?ATTACKING_RIGHT:ATTACKING_LEFT);
				// Seed
				AnimatedSpriteType *seedSpriteType = game->getGSM()->getSpriteManager()->getSpriteType(3);
				Seed *seed = new Seed(PROJECTILE_DESIGNATION, true);

				seed->setHitPoints(1);
				seed->setDamage(SEED_DAMAGE);
				seed->setSpriteType(seedSpriteType);
				seed->setAlpha(255);
				seed->setCurrentState(IDLE_LEFT);
				PhysicalProperties *seedProps = seed->getPhysicalProperties();
				seedProps->setX(botX);
				seedProps->setY(game->getGSM()->getWorld()->getWorldHeight() - botY);
				seedProps->setVelocity(0.0f, 0.0f);
				seedProps->setAccelerationX(0);
				seedProps->setAccelerationY(0);
				seed->setOnTileThisFrame(false);
				seed->setOnTileLastFrame(false);
				seed->affixTightAABBBoundingVolume();

				//create a physics object for the seed
				game->getGSM()->getBoxPhysics()->getPhysicsFactory()->createEnemyObject(game,seed,false);

				float difX = botX - pX;
				float difY = botY - pY;
				// Set the velocity of the seed
				float length = std::sqrt( (difX * difX) + (difY * difY) );

				// Normalize the distances
				difX /= length;
				difY /= length;

				// Scale distances to be x and y velocity
				difX *= PROJECTILE_VELOCITY;
				difY = difY*PROJECTILE_VELOCITY-10;
				seed->getPhysicsBody()->SetLinearVelocity(b2Vec2(-difX, -difY));

				game->getGSM()->getPhysics()->addCollidableObject(seed);
				game->getGSM()->getSpriteManager()->addBot(seed);
			}
		}
	}
	
	
	
	
	
	
	//////////////////////
	///////////////////////
	///////////////////////
	/*
	if(dead) {
		return;
	}
	// If hitpoints are 0, remove it
	if(hitPoints <= 0){
		game->getGSM()->goToLevelWon();
		game->getGSM()->getSpriteManager()->addBotToRemovalList(this, 0);
		dead = true;
		return;
//.........这里部分代码省略.........
开发者ID:CSE380Skulls,项目名称:ForceOfReaction,代码行数:101,代码来源:BossBot.cpp


注:本文中的PhysicalProperties类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。