Ejemplo n.º 1
0
void BlockFalling::onPlace(User* user, int8_t newblock, int32_t x, int8_t y, int32_t z, int8_t direction)
{
   uint8_t oldblock;
   uint8_t oldmeta;

   if (!Mineserver::get()->map()->getBlock(x, y, z, &oldblock, &oldmeta))
      return;

   /* Check block below allows blocks placed on top */
   if (!this->isBlockStackable(oldblock))
      return;

   /* move the x,y,z coords dependent upon placement direction */
   if (!this->translateDirection(&x,&y,&z,direction))
      return;

   if (this->isUserOnBlock(x,y,z))
      return;

   if (!this->isBlockEmpty(x,y,z))
      return;

   direction = user->relativeToBlock(x, y, z);

   Mineserver::get()->map()->setBlock(x, y, z, (char)newblock, direction);
   Mineserver::get()->map()->sendBlockChange(x, y, z, (char)newblock, direction);

   applyPhysics(user,x,y,z);
}
Ejemplo n.º 2
0
void BlockFalling::onNeighbourMove(User* user, int16_t, int32_t x, int16_t y, int32_t z, int8_t direction, int map)
{
	uint8_t block;
	uint8_t meta;

	if(!ServerInstance->map(map)->getBlock(x, y, z, &block, &meta))
		return;
	if (affectedBlock(block)) {
		applyPhysics(user, x, y, z, map);
	}
}
Ejemplo n.º 3
0
void BlockFalling::onNeighbourMove(User* user, int8_t oldblock, int32_t x, int8_t y, int32_t z, int8_t direction)
{
  uint8_t block;
  uint8_t meta;

  if (!Mineserver::get()->map()->getBlock(x, y, z, &block, &meta))
  {
    return;
  }

  applyPhysics(user,x,y,z);
}
void PhysicsSim::shootTestSphere()
{
	removeObject(testSphere);

	testSphere = loadSceneObject("lemon.dae");
	testSphere->setPosition(fpscam->getPosition());
	testSphere->setScale(Vector3D(2,2,2));
	PhysicalObject* phyObj = applyPhysics(testSphere, shSphere, 20);

	vector3df dir = fpscam->getTarget() - fpscam->getPosition();
	dir = 250*dir.normalize();
	phyObj->getRigidBody()->applyCentralImpulse(btVector3(dir.X, dir.Y, dir.Z));

}
Ejemplo n.º 5
0
//Render meshes as they are traversed in the scene graph
void NMS_SceneRenderer::sg_before(Matrix transform, SceneGraphNode * node)
{
	GeometryNode * geomNode = (GeometryNode *) node;
	NMS_Mesh* model = geomNode->getModel();
	btRigidBody *b = geomNode->getCollisionBody();

	glLoadIdentity();
	Matrix t_transposed = ~transform;
	glMultMatrixf(t_transposed.getElements());
	if(b != NULL)
		applyPhysics(b);
	setWireframeModeGL(wireframe);
	(*model).setMaterialGL();
	(*model).render(currentTime);
}
Ejemplo n.º 6
0
void BlockFalling::onNeighbourMove(User* user, int16_t oldblock, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
  uint8_t block;
  uint8_t meta;

  Mineserver::get()->map(map)->getBlock(x, y, z, &block, &meta);
  if (block == BLOCK_SAND || block == BLOCK_SLOW_SAND ||block == BLOCK_GRAVEL)
  {
  if (!Mineserver::get()->map(map)->getBlock(x, y, z, &block, &meta))
  {
    return;
  }

  applyPhysics(user, x, y, z, map);
  }
}
Ejemplo n.º 7
0
bool BlockFalling::onPlace(User* user, int16_t newblock, int32_t x, int8_t y, int32_t z, int map, int8_t direction)
{
  uint8_t oldblock;
  uint8_t oldmeta;

  if (!Mineserver::get()->map(map)->getBlock(x, y, z, &oldblock, &oldmeta))
  {
    revertBlock(user, x, y, z, map);
    return true;
  }

  /* Check block below allows blocks placed on top */
  if (!this->isBlockStackable(oldblock))
  {
    revertBlock(user, x, y, z, map);
    return true;
  }

  /* move the x,y,z coords dependent upon placement direction */
  if (!this->translateDirection(&x, &y, &z, map, direction))
  {
    revertBlock(user, x, y, z, map);
    return true;
  }

  if (this->isUserOnBlock(x, y, z, map))
  {
    revertBlock(user, x, y, z, map);
    return true;
  }

  if (!this->isBlockEmpty(x, y, z, map))
  {
    revertBlock(user, x, y, z, map);
    return true;
  }

  Mineserver::get()->map(map)->setBlock(x, y, z, (char)newblock, 0);
  Mineserver::get()->map(map)->sendBlockChange(x, y, z, (char)newblock, 0);

  applyPhysics(user, x, y, z, map);
  return false;
}
Ejemplo n.º 8
0
void PlaySpace::drawHUD()
{
	LineShape movementPrediction;
	float sizeMult = 1.f / Renderer.Context.Camera.Zoom.length();
	movementPrediction.TexImage = gAssets.DottedLine;
	float step = 1/60.f * sizeMult;
	float maxLength = 5.0 + 5.0 * sizeMult;
	Ship playerCopy = *Player;
	for(float t = 0; t < maxLength; t += step)
	{
		movementPrediction.insert(playerCopy.Position, 3 * sizeMult, Vec4F(Vec3F(1), Min((1.0f - (t / maxLength)) * sizeMult, 1.0f)));
		movementPrediction.Points.back().TexCoord = t * 16 / sizeMult;
		playerCopy.updateControls(step, this);
		applyPhysics(&playerCopy, step);
		for(GravitySource& src : GravitySources)
			src.influence(&playerCopy, step);
	}
	Renderer.draw(movementPrediction, Align2D(0, 0));
}
Ejemplo n.º 9
0
void PlaySpace::update(float time)
{
	if(time > 0.25f)
	{
		ParticleBudget = 0;
		time = 0.25f;
	}
	else
		ParticleBudget = 500;
	
	LastDeltaTime = time;
	GameTime += time;
	GameFrame += 1;
	
	if(!Player)
		TimeSincePlayerDestruction += time;
	
	SoundManager* manager = SoundManager::GetInstance();
	manager->setListenerPosition(CameraPos);
	
	if(IsStressTesting)
		time = 1.f / 30;
	
	if(!IsStressTesting)
		for(int i = 0; i < Systems.UsedLength; ++i)
		{
			Systems[i]->update(time, this);
		}
	
	for(int i = 0; i < Bullets.UsedLength; ++i)
	{
		if(Bullets[i].canBeDespawned())
			Bullets.quickRemove(i--);
	}
	
	for(int i = 0; i < Particles.UsedLength; ++i)
	{
		if(Particles[i].canBeDespawned())
			Particles.quickRemove(i--);
	}
	
	
	for(int i = 0; i < Ships.UsedLength; ++i)
	{
		if(Ships[i]->canBeDespawned())
		{
			ObjectPointer<Ship>(Ships[i]).destroy(); // Object pointer lets other object pointers know that the object got deleted.
			Objects.quickRemove(Objects.findIndex(Ships[i]));
			Ships.quickRemove(i--);
		}
	}
	
	for(PhysicsObject* obj : Objects)
		obj->update(time, this);
	for(GravitySource& src : GravitySources)
		src.update(time, this);
	for(Bullet& obj : Bullets)
		obj.update(time, this);
	
	// The more particles exist the faster time passes for them, the faster they die
	float particleTimeFactor = Max(float(Particles.UsedLength) / SoftMaxParticleCount, 1.0f);
	for(Particle& particle : Particles)
		particle.update(time * particleTimeFactor, this);
	
	// Physics
	for(PhysicsObject* obj : Objects)
		applyPhysics(obj, time);
	for(Bullet& obj : Bullets)
		applyPhysics(&obj, time);
	for(Particle& particle : Particles)
		applyPhysics(&particle, time * particleTimeFactor);
	
	// Add gravity
	for(GravitySource& src : GravitySources)
	{
		float start = src.Position.X - src.Range*2;
		float end = src.Position.X + src.Range*2;
		
		for(auto* obj : Objects)
			src.influence(obj, time);
		for(auto& obj : Bullets)
			src.influence(&obj, time);
		for(auto& obj : Particles)
			src.influence(&obj, time);
	}
	
	
	for(Bullet& bullet : Bullets)
		for(Ship* ship : Ships)
			if(ship->Faction != bullet.Faction)
				if(ship->Status != Ship::Destroyed)
					if(IsIntersecting(bullet.Bounds, ship->Bounds))
						ship->onHit(&bullet, this);
		
	if(Player)
	{
		CameraPos = Player->Position;
		Renderer.Context.Camera.Position = CameraPos;
	
		// Will be reset to true before next PlaySpace::update
		Player->IsShooting = false;
		Player->IsShootingSecondary = false;
		Player->IsBraking = false;
		Player->IsStabilizing = false;
		Player->IsBoosting = false;
		Player->Steering = 0.0f;
	
		if(!IsStressTesting)
		{
			checkSectorGeneration(Player->Position);
			checkSectorGeneration(Player->Position + Vec2F(SectorLookAhead, 0));
			checkSectorGeneration(Player->Position + Vec2F(0, SectorLookAhead));
			checkSectorGeneration(Player->Position - Vec2F(SectorLookAhead, 0));
			checkSectorGeneration(Player->Position - Vec2F(0, SectorLookAhead));
			checkSectorGeneration(Player->Position + Vec2F(SectorLookAhead));
			checkSectorGeneration(Player->Position - Vec2F(SectorLookAhead));
			
			checkSectorGeneration(Player->Position + Vec2F(SectorLookAhead/2, 0));
			checkSectorGeneration(Player->Position + Vec2F(0, SectorLookAhead/2));
			checkSectorGeneration(Player->Position - Vec2F(SectorLookAhead/2, 0));
			checkSectorGeneration(Player->Position - Vec2F(0, SectorLookAhead/2));
			checkSectorGeneration(Player->Position + Vec2F(SectorLookAhead/2));
			checkSectorGeneration(Player->Position - Vec2F(SectorLookAhead/2));
		}
	}
	ParticleBudget = 0;
	
	if(Music->isFinished()){ Music->setOffset(0); Music->resume(); };
}
Ejemplo n.º 10
0
 void Block::Draw(){ // Draw the object on the buffer
    applyPhysics();
    checkBounds();
    rectfill(buffer,X,Y,X+Size,Y+Size,Color);
 }