Exemplo n.º 1
0
Arquivo: Main.cpp Projeto: leod/game
 void createTestWorld() {
     entities.create(
             makeTeapot(netSystem.makeNetEntityId(), vec3(0, 0, 0),
                        vec3(0, 0, 0)));
     entities.create(
             makeTeapot(netSystem.makeNetEntityId(), vec3(-3, 0, 0),
                        vec3(0, 0, 0)));
     entities.create(
             makeTeapot(netSystem.makeNetEntityId(), vec3(3, 0, 0),
                        vec3(0, 0, 0)));
 }
Exemplo n.º 2
0
Arquivo: Main.cpp Projeto: leod/game
    void onPlayerInputWish(ClientId clientId, PlayerInput const& playerInput) {
        auto client = clients.get(clientId);

        auto entity = client->entity;
        if (entity) {
            auto input = entity->component<PlayerInputComponent>();
            auto physics = entity->component<PhysicsComponent>();
            ASSERT(input);
            ASSERT(physics);

            input->onPlayerInput(playerInput);

            if (playerInput.shoot) {
                auto origin = physics->getPosition() +
                              physics->getOrientation() * 0.65f;
                auto orientation =
                    vec3(playerInput.orientation.x, 0,
                         playerInput.orientation.y);
                auto components =
                    makeProjectile(netSystem.makeNetEntityId(),
                                   clientId,
                                   origin,
                                   orientation);
                entities.create(std::move(components));
            }

#ifdef USE_PREDICTION
            vec3 newPosition = physics->getPosition();
            sendEvent<PlayerPositionOrder>(client->peer, newPosition);
#endif
        }
    }
Exemplo n.º 3
0
Entity* EntityFactory::createArena()
{
	EntityManager* entityMgr = engine_->entityMgr_;
	Entity* entity = entityMgr->create();

	float arenaHalfX = 150.f;
	float arenaHalfY = 75.f;

	b2BodyDef bd;
	bd.type = b2_staticBody;
	b2Body* body = engine_->sysPhysics_->getWorld()->CreateBody(&bd);

	b2EdgeShape shape;

	b2FixtureDef sd;
	sd.shape = &shape;
	sd.density = 0;
	sd.restitution = 0.4f;
	sd.filter.categoryBits = ComPhysics::CollisionCategory::CATEG_Wall;
	sd.filter.maskBits = ComPhysics::CollisionMask::MASK_Wall;

	// Left vertical
	shape.Set(b2Vec2(-arenaHalfX, -arenaHalfY), b2Vec2(-arenaHalfX, arenaHalfY));
	body->CreateFixture(&sd);
	// Right vertical
	shape.Set(b2Vec2(arenaHalfX, -arenaHalfY), b2Vec2(arenaHalfX, arenaHalfY));
	body->CreateFixture(&sd);
	// Top horizontal
	shape.Set(b2Vec2(-arenaHalfX, arenaHalfY), b2Vec2(arenaHalfX, arenaHalfY));
	body->CreateFixture(&sd);
	// Bottom horizontal
	shape.Set(b2Vec2(-arenaHalfX, -arenaHalfY), b2Vec2(arenaHalfX, -arenaHalfY));
	body->CreateFixture(&sd);

	ComPhysics* comPhysics = entityMgr->assignComponent<ComPhysics>(entity);
	comPhysics->setMainBody(body, entity);

	Ogre::SceneManager* sceneMgr = engine_->sysGraphics_->getSceneManager();
	//Ogre::ManualObject* manual = sceneMgr->createManualObject();
	//manual->begin("white", Ogre::RenderOperation::OT_LINE_STRIP);
	//manual->position(-arenaHalfX, -arenaHalfY, 0);
	//manual->position(arenaHalfX, -arenaHalfY, 0);
	//manual->position(arenaHalfX, arenaHalfY, 0);
	//manual->position(-arenaHalfX, arenaHalfY, 0);
	//manual->index(0);
	//manual->index(1);
	//manual->index(2);
	//manual->index(3);
	//manual->index(0);
	//manual->end();
	Ogre::Entity* meshEntity = sceneMgr->createEntity("ArenaPlane.mesh");
	Ogre::SceneNode* node = engine_->sysGraphics_->getSceneRoot()->createChildSceneNode(
		Ogre::Vector3(0, 0, 0));

	ComGraphics* comGraphics = entityMgr->assignComponent<ComGraphics>(entity);
	comGraphics->sceneNode_ = node;
	comGraphics->attachMovableObject(meshEntity);

	return entity;
}
Exemplo n.º 4
0
Entity* EntityFactory::createShip(const ShipConfig& config)
{
	EntityManager* entityMgr = engine_->entityMgr_;
	Entity* entity = entityMgr->create();

	float boxHalfX = 0.7f;

	b2BodyDef bd;
	bd.type = b2_dynamicBody;
	bd.position.Set(config.posX_, config.posY_);
	b2Body* body = engine_->sysPhysics_->getWorld()->CreateBody(&bd);

	b2PolygonShape shape;
	shape.SetAsBox(boxHalfX, boxHalfX);

	b2FixtureDef sd;
	sd.shape = &shape;
	sd.density = 1.f;
	sd.filter.categoryBits = config.collisionCateg_;
	sd.filter.maskBits = config.collisionMask_;

	body->CreateFixture(&sd);

	ComPhysics* comPhysics = entityMgr->assignComponent<ComPhysics>(entity);
	comPhysics->setMainBody(body, entity);


	Ogre::SceneManager* sceneMgr = engine_->sysGraphics_->getSceneManager();
	
	//Ogre::ManualObject* manual = sceneMgr->createManualObject();
	//manual->begin("green", Ogre::RenderOperation::OT_LINE_STRIP);
	//manual->position(-boxHalfX, -boxHalfX, 0);
	//manual->position(boxHalfX, -boxHalfX, 0);
	//manual->position(boxHalfX, boxHalfX, 0);
	//manual->position(-boxHalfX, boxHalfX, 0);
	//manual->position(-boxHalfX, -boxHalfX, 0);
	//manual->end();
	Ogre::Entity* meshEntity = sceneMgr->createEntity("Ship.mesh");
	Ogre::SceneNode* node = engine_->sysGraphics_->getSceneRoot()->createChildSceneNode(
		Ogre::Vector3(config.posX_, config.posY_, 0));

	ComGraphics* comGraphics = entityMgr->assignComponent<ComGraphics>(entity);
	comGraphics->sceneNode_ = node;
	comGraphics->attachMovableObject(meshEntity);


	if (config.hasAI_)
	{
		ComAI* comAI = entityMgr->assignComponent<ComAI>(entity);
		comAI->entity_ = entity;
		comAI->type_ = config.AIType_;
	}

	return entity;
}
Exemplo n.º 5
0
Entity* EntityFactory::createBeamGun(const BeamGunConfig& config)
{
	EntityManager* entityMgr = engine_->entityMgr_;
	Entity* entity = entityMgr->create();

	float y = 0.1f;

	b2BodyDef bd;
	bd.type = b2_dynamicBody;
	bd.position.Set(config.posX_, config.posY_);
	b2Body* body = engine_->sysPhysics_->getWorld()->CreateBody(&bd);

	b2PolygonShape shape;
	b2Vec2 vertices[4];
	vertices[0].Set(0, y);
	vertices[1].Set(0, -y);
	vertices[2].Set(config.beamRange_, -y);
	vertices[3].Set(config.beamRange_, y);
	shape.Set(vertices, 4);

	b2FixtureDef sd;
	sd.shape = &shape;
	sd.density = 0;
	sd.filter.categoryBits = ComPhysics::CATEG_PlayerBeam;
	sd.filter.maskBits = ComPhysics::MASK_PlayerBeam;

	body->CreateFixture(&sd);

	ComPhysics* comPhysics = entityMgr->assignComponent<ComPhysics>(entity);
	comPhysics->setMainBody(body, entity);


	Ogre::SceneManager* sceneMgr = engine_->sysGraphics_->getSceneManager();
	Ogre::ManualObject* manual = sceneMgr->createManualObject();
	manual->begin("beam", Ogre::RenderOperation::OT_LINE_STRIP);
	manual->position(0, y, 0);
	manual->position(0, -y, 0);
	manual->position(config.beamRange_, -y, 0);
	manual->position(config.beamRange_, y, 0);
	manual->position(0, y, 0);
	manual->end();
	Ogre::SceneNode* node = engine_->sysGraphics_->getSceneRoot()->createChildSceneNode(
		Ogre::Vector3(config.posX_, config.posY_, 0));
	node->attachObject(manual);

	ComGraphics* comGraphics = entityMgr->assignComponent<ComGraphics>(entity);
	comGraphics->sceneNode_ = node;

	return entity;
}
Exemplo n.º 6
0
Arquivo: Main.cpp Projeto: leod/game
    // Implement ENetReceiver
    void onConnect(ENetPeer* peer) {
        auto newClient = clients.add(peer);

        INFO(server) << "Client " << (int)newClient->id << " connected";

        // Tell the client its id. This needs to happen before sending
        // the CreateEntityMessages, so that the client can identify what
        // entities belong to it.
        sendEvent<LoggedInOrder>(peer, newClient->id);
        
        // Create player entity for the client
        newClient->entity = entities.create(
            makePlayer(netSystem.makeNetEntityId(),
                       newClient->id,
                       vec3(0, 0, 0),
                       vec3(0, 0, 0)));

        // Send messages to create our net objects on the client side
        netSystem.sendCreateEntityOrders(newClient);

        // Tell everyone about the new client
        clients.broadcast<ClientConnectedOrder>(newClient->id, "dummy");
    }