Пример #1
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
					}
				}
			}
		}
Пример #2
0
void RemoteProcessClient::writeProjectile(const Projectile& projectile) {
    writeBoolean(true);

    writeLong(projectile.getId());
    writeDouble(projectile.getMass());
    writeDouble(projectile.getX());
    writeDouble(projectile.getY());
    writeDouble(projectile.getSpeedX());
    writeDouble(projectile.getSpeedY());
    writeDouble(projectile.getAngle());
    writeDouble(projectile.getAngularSpeed());
    writeDouble(projectile.getRadius());
    writeLong(projectile.getCarId());
    writeLong(projectile.getPlayerId());
    writeEnum<ProjectileType>(projectile.getType());
}
Пример #3
0
	void ServerWorldModel::handlePlayerShooting(PlayerId playerId, ServerPlayers &players)
	{	
		int currentTick = getTimeHandler()->getTick();
		Tickf currentTickf = static_cast<Tickf>(currentTick);

		PlayerObj *playerObj = getPlayerObjs()[playerId];
		
		// Copy userCmd, we must have a seperate copy to alter while original is intact.
		UserCmd userCmd(playerObj->getUserCmd());

		ClientIdGenerator *clientIdGenerator = players[playerId]->getIdGenerator();
		int clientNShots = userCmd.nShots;
		
		assert(userCmd.firstShotTick >= currentTickf);
		assert(playerObj->getNextShootTick() >= currentTickf);

		// remove projectiles if client created projectiles which we did't notice before
		while (userCmd.firstProjectileId > clientIdGenerator->getNextId())
		{
			RemoveProjectile removeProjectile(clientIdGenerator->generateGameObjId());
			players[playerId]->link.pushMessage(removeProjectile, getTimeHandler()->getTime(), getTimeHandler()->getTick());
		}
		assert(userCmd.firstProjectileId == clientIdGenerator->getNextId());
		
		if (clientNShots > 0)
		{
			assert(userCmd.firstShotTick >= playerObj->getNextShootTick());
		
			// Do any shooting
			int serverNShots = 0;
			Tickf shotTick;
			Projectile::Type weapon = userCmd.weapon;
			for(int i=0; i<clientNShots; ++i)
			{
				GameObjId projectileId = clientIdGenerator->generateGameObjId();
				if (playerTryShoot(playerId, currentTick, i, projectileId, shotTick))
				{		
					if (serverNShots == 0) userCmd.firstShotTick = shotTick;
					
					Projectile *projectile = (getProjectiles())[projectileId];
					std::cout << "server tick: " << getTimeHandler()->getTick() << "    projectile shot, objLag =  " << projectile->getObjLag() << std::endl;
					
					// send projectile to all clients
					AddProjectile addProjectile(projectileId, projectile->getType(), projectile->getPos(),
												projectile->getAngle().getFloat(), projectile->getShooterId(),
												projectile->getShootTick(), projectile->getObjLag());
					pushMessageToAll(players, addProjectile, getTimeHandler()->getTime(), getTimeHandler()->getTick());

					++serverNShots;
				}
				else
				{					
					RemoveProjectile removeProjectile(projectileId);
					players[playerId]->link.pushMessage(removeProjectile, getTimeHandler()->getTime(), getTimeHandler()->getTick());
				}
			}

			userCmd.nShots = serverNShots;
			
			// Safe to overwrite PlayerObj.userCmd now, write changes
			playerObj->setUserCmd(&userCmd);
		}

	}
Пример #4
0
void ContactListener::BeginContact(b2Contact* contact)
{
	SceneNode* A = static_cast<SceneNode*> (contact -> GetFixtureA() -> GetBody() -> GetUserData() );
	SceneNode* B = static_cast<SceneNode*> (contact -> GetFixtureB() -> GetBody() -> GetUserData() );

	if (A -> getCategory() == Category::Projectile && contact->IsTouching())
	{
		Projectile* proj = static_cast<Projectile*>(A);
		proj->isDead = true;
	}
						 
	if (B -> getCategory() == Category::Projectile && contact->IsTouching())
	{
		Projectile* proj = static_cast<Projectile*>(B);
		proj->isDead = true;
	}

	if (contact->IsTouching() &&  //projectile - ground
		(A -> getCategory() == Category::Projectile || B -> getCategory() == Category::Projectile) &&
		(A -> getCategory() == Category::Ground || B -> getCategory() == Category::Ground))
	{
		Ground* ground = static_cast<Ground*>( (A -> getCategory() == Category::Ground) ? A : B);
		Projectile* proj = static_cast<Projectile*>( (A -> getCategory() == Category::Ground) ? B : A );
		if (proj->getType() == Projectile::Type::Missle)
			ground->explosion(proj->position, 3);
	}

	if (contact->IsTouching() &&  //player - ground
		(A -> getCategory() == Category::Player || B -> getCategory() == Category::Player) &&
		(A -> getCategory() == Category::Ground || B -> getCategory() == Category::Ground))
	{
		Player* player = static_cast<Player*>( (A -> getCategory() == Category::Ground) ? B : A );
		player -> onFloor++;
	}

	if (contact->IsTouching() &&  //player - wreck
		(A -> getCategory() == Category::Player || B -> getCategory() == Category::Player) &&
		(A -> getCategory() == Category::Wreck || B -> getCategory() == Category::Wreck))
	{
		Player* player = static_cast<Player*>( (A -> getCategory() == Category::Wreck) ? B : A );
		player -> onFloor++;
	}

	if (contact->IsTouching() &&  //projectile - enemy
		(A -> getCategory() == Category::Projectile || B -> getCategory() == Category::Projectile) &&
		(A -> getCategory() == Category::Enemy || B -> getCategory() == Category::Enemy))
	{
		Enemy* enemy = static_cast<Enemy*>( (A -> getCategory() == Category::Enemy) ? A : B);
		Projectile* proj = static_cast<Projectile*>( (A -> getCategory() == Category::Enemy) ? B : A );
		enemy->hp -= proj->Table[proj->getType()].Damage;
		if (enemy->hp <= 0)
		{
			enemy -> isDead = true;
		}
	}

	if (contact->IsTouching() &&  //player - enemy
		(A -> getCategory() == Category::Player || B -> getCategory() == Category::Player) &&
		(A -> getCategory() == Category::Enemy || B -> getCategory() == Category::Enemy))
	{
		Player* player = static_cast<Player*>( (A -> getCategory() == Category::Enemy) ? B : A );
		player->isHurting = true;
	}
}