const Process::Return GameLoadingProcess::update(const float deltaTime) { StateManager& stateManager(StateManager::instance()); GameState* gameState(stateManager.getState<GameState>("GameState")); assert(gameState); EntitySystem& entitySystem(EntitySystem::instance()); PlayerShip* playerShip(entitySystem.add<PlayerShip>("Player")); playerShip->setGraphicObject(new SDLGraphicObject); playerShip->writeGraphicObject<SDLGraphicObject>().load("data/playership.bmp"); playerShip->setInputObject(new SDLInputObject(playerShip)); playerShip->writeInputObject<SDLInputObject>().setup(); playerShip->writePosition() = Vector2D(300.0F, 200.0F); playerShip->setMass(3.0F); //playerShip->writeVelocity() = Vector2D(100.0F, 300.0F); entitySystem.addToList(playerShip, "Renderable"); entitySystem.addToList(playerShip, "Collidable"); entitySystem.addToList(playerShip, "Movable"); entitySystem.addToList(playerShip, "Ship"); Bullet* enemyShip(entitySystem.add<Bullet>("Renderable")); enemyShip->setGraphicObject(new SDLGraphicObject); enemyShip->writeGraphicObject<SDLGraphicObject>().load("data/enemy.bmp"); enemyShip->writePosition() = Vector2D(150.0F, 300.0F); enemyShip->setMass(3.0F); entitySystem.addToList(enemyShip, "Movable"); //entitySystem.addToList(enemyShip, "Ship"); GrappleHook* grapple(entitySystem.add<GrappleHook>("Renderable")); grapple->setGraphicObject(new SDLGraphicObject); grapple->writeGraphicObject<SDLGraphicObject>().load("data/hook.bmp"); grapple->setSource(playerShip); grapple->setTarget(enemyShip); for (Uint segment(0U); segment < 10U; ++segment) { HookSegment* hookSegment(entitySystem.add<HookSegment>("Renderable")); hookSegment->setGraphicObject(new SDLGraphicObject); hookSegment->writeGraphicObject<SDLGraphicObject>().load("data/segment.bmp"); grapple->addSegment(hookSegment); } entitySystem.addToList(grapple, "Grapple"); grapple->setSpeed(100.0F); grapple->writePosition() = playerShip->readPosition(); grapple->fire(); std::vector<Process*> processList; processList.push_back(new GameInputProcess); processList.push_back(new GamePhysicsProcess); processList.push_back(new GameRenderProcess); gameState->setProcessor(new Processor(processList)); return Process::STOP; }
EntityPtr EntityFactory::createPhysicsEntity(float x, float y, float width, float height) { EntitySystemPtr entitySystem(makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY))); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(x, y, width, height)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); physicsComponent->setCollider(GCC_NEW Collider(x, y, width, height)); entity->addComponent(ComponentPtr(physicsComponent)); return entity; }
void PlayerShip::fire() { Vector2D position(readPosition()); position.x_ += 16.0F + (cos(deg2rad(getAngle()))); position.y_ -= (sin(deg2rad(getAngle()))); EntitySystem& entitySystem(EntitySystem::instance()); Bullet* const bullet(entitySystem.add<Bullet>("Movable")); entitySystem.addToList(bullet, "Renderable"); bullet->setGraphicObject(new SDLGraphicObject); bullet->writePosition() = position; bullet->writeGraphicObject<SDLGraphicObject>().load("data/shot.bmp"); bullet->setAngle(getAngle()); bullet->setSpeed(600.0F); bullet->fire(); }
int main(int argc, char* argv[]) { // Setup and initialise the Logger Logger& logger(Logger::instance()); //logger.setFile(".html", Logger::LOG_FILE_HTML); //logger.setOutput(Logger::LOG_OUTPUT_FILE_AND_TERMINAL); logger.setOutput(Logger::LOG_OUTPUT_SILENT); //logger.setType(Logger::LOG_TYPE_INFO); // Check the Config Manager and get it to parse the configuration files. ConfigManager& configManager(ConfigManager::instance()); configManager.loadConfig(); // Start up the Graphics System. GraphicsSystem& graphicsSystem(GraphicsSystem::instance()); graphicsSystem.initialise(640U, 480U, 32U); // Start and setup the Entity System with some lists. EntitySystem& entitySystem(EntitySystem::instance()); entitySystem.createList("Player"); entitySystem.createList("Enemy"); entitySystem.createList("Renderable"); entitySystem.createList("Movable"); entitySystem.createList("Collidable"); entitySystem.createList("Grapple"); entitySystem.createList("Ship"); // Start up the State Manager, and feed it the Main States. StateManager& stateManager(StateManager::instance()); stateManager.add<MenuState>("MenuState"); stateManager.add<GameState>("GameState"); stateManager.launch("GameState"); // Tick over the State Manager while we have any States. Timer mainTimer; while (true == stateManager.hasStates()) { stateManager.update(mainTimer.processDelta()); } // Cleanup configManager.saveConfig(); // Goodbye World return 0; }