void ComponentCreateDebris::createDebris() { GameObjectManager* gameObjectManager = GameManager::getInstance()->getGameObjectManager(); Vector2d velocity(1,1); int angle = 360/nDebris; for(int i=0;i<nDebris;i++) { Vector2d velocityAux = velocity.rotateBy(Math::random(20) + i*angle + angle,Vector2d(0,0)).normalize(); switch (Math::random(0,5)) { case 0: gameObjectManager->createGenericDebris(Resources::MESH_DEBRIS_1,velocityAux * 2,parent->position); break; case 1: gameObjectManager->createGenericDebris(Resources::MESH_DEBRIS_2,velocityAux * 2,parent->position); break; case 2: gameObjectManager->createGenericDebris(Resources::MESH_DEBRIS_3,velocityAux * 2,parent->position); break; case 3: gameObjectManager->createGenericDebris(Resources::MESH_DEBRIS_4,velocityAux * 2,parent->position); break; case 4: gameObjectManager->createGenericDebris(Resources::MESH_DEBRIS_5,velocityAux * 2,parent->position); break; } } gameObjectManager->createMuzzleFlash()->position =parent->position-velocity; gameObjectManager->createMuzzleFlash()->position =parent->position+velocity*2; GameManager::getInstance()->getPhysicsManager()->createExplosion(parent->position,nDebris/5); }
void BaseGameObject::init(GameObjectManager& manager, const ActorData* gameData, Node* node, PlayerObject* player, const Matrix & transform) { _manager = &manager; Player = player; LocalGameData.init(gameData, Player->upgrades()); manager.registerObject(this); if (node) { _node = node->clone()->Auto(); _node->setOrientationAxises(Node::PositiveX, Node::PositiveZ, Node::PositiveY); _node->set(transform); manager.registerSceneNode(_node); } Vector3 translation; transform.getTranslation(&translation); setPosition(translation); //_FogOfWarTimer = createTimer(Timer(2.0f, 0.0f, )) }
int main(int argc, char* argv[]) { for (int i = 1; i < argc; i++) { std::string arg = static_cast<std::string>(argv[i]); if (arg == "-ps3") { keyboard = false; std::cout << "ps3" << std::endl; } } if (keyboard == false) { // Check that joystick #0 is connected. if (sf::Joystick::isConnected(0)) { std::cout << "Joystick is connected." << std::endl; } else { std::cout << "Joystick is NOT connected." << std::endl; return 0; } } srand(time(NULL)); // Initializing game objects. Paddle* player = new Paddle; player->load("images/paddle.png"); player->set_position(SCREEN_WIDTH / 2, SCREEN_HEIGHT - player->get_height()); game_object_manager.add("player", player); Ball* game_ball = new Ball; game_ball->load("images/ball.png"); game_ball->set_position(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2); game_object_manager.add("ball", game_ball); main_window.setFramerateLimit(60); // Game loop while (main_window.isOpen() && end_game == false) { process_input(); update(); render(); } return 0; }
std::string FinishScreen::Show(sf::RenderWindow &window, std::string finString, GameObjectManager &gameObjectManager) { // Declare and load a font sf::Font font; sf::Vector2f pos; pos.x = 139; pos.y = 264; font.loadFromFile("assets/8-BIT WONDER.ttf"); // Create a text sf::Text textLineOne(finString, font); textLineOne.setCharacterSize(26); textLineOne.setStyle(sf::Text::Bold); textLineOne.setColor(sf::Color::Red); textLineOne.setPosition(pos); pos.x = 78; pos.y = 313; sf::Text textLineTwo("Press Space", font); textLineTwo.setCharacterSize(26); textLineTwo.setStyle(sf::Text::Bold); textLineTwo.setColor(sf::Color::Red); textLineTwo.setPosition(pos); window.draw(textLineOne); window.draw(textLineTwo); window.display(); sf::Event menuEvent; while (window.pollEvent(menuEvent)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { gameObjectManager.Remove("NFood"); gameObjectManager.Remove("Pacman"); gameObjectManager.Remove("_Blinky"); gameObjectManager.Remove("_Pinky"); gameObjectManager.Remove("_Inky"); gameObjectManager.Remove("_Clyde"); GameController::Start(); return "menu"; } if (menuEvent.type == sf::Event::Closed) { return "exit"; } } return ""; }
RakNet::Replica3* Connection::AllocReplica(RakNet::BitStream* allocationId, RakNet::ReplicaManager3* replicaManager3) { unsigned char name; allocationId->Read(name); GameObjectManager* gameObjectManager = GameManager::getInstance()->getGameObjectManager(); if(name == GameObject::N_MAIN_PLAYER) { return (RakNet::Replica3*) gameObjectManager->createRemotePlayer(); } if(name == GameObject::N_BULLET) return (RakNet::Replica3*) gameObjectManager->createBullet(20); if(name == GameObject::N_BULLET_BOMBER) return (RakNet::Replica3*) gameObjectManager->createBulletBomber(); if(name == GameObject::N_BULLET_FIGHTER) return (RakNet::Replica3*) gameObjectManager->createBulletFighter(); if(name == GameObject::N_BULLET_ENGINEER) return (RakNet::Replica3*) gameObjectManager->createBulletEngineer(); if(name == GameObject::N_BULLET_BATTLESHIP) return (RakNet::Replica3*) gameObjectManager->createBulletBattleship(); if(name == GameObject::N_ENEMY_BULLET) return (RakNet::Replica3*) gameObjectManager->createEnemyBullet(20); if(name == GameObject::N_PROJECTILE) return (RakNet::Replica3*) gameObjectManager->createRemoteProjectile(); if(name == GameObject::N_ENEMY_BASIC) return (RakNet::Replica3*) gameObjectManager->createRemoteEnemyBasic(); if(name == GameObject::N_TURRET_PROJECTILE) return (RakNet::Replica3*) gameObjectManager->createRemoteTurret(); if(name == GameObject::N_TURRET_BULLET) return (RakNet::Replica3*) gameObjectManager->createRemoteTurretBasic(); if(name == GameObject::N_TURRET_2_CANON) return (RakNet::Replica3*) gameObjectManager->createRemoteTurret2Canon(); if(name == GameObject::N_TURRET_1_CANON) return (RakNet::Replica3*) gameObjectManager->createRemoteTurret1Canon(); if(name == GameObject::N_TURRET_BIG_CANON) return (RakNet::Replica3*) gameObjectManager->createRemoteTurretBigCanon(); if(name == GameObject::N_MINE) return (RakNet::Replica3*) gameObjectManager->createRemoteMine(); if(name == GameObject::N_WALL) return (RakNet::Replica3*) gameObjectManager->createRemoteWall(); if(name == GameObject::N_EXPLOSION) return (RakNet::Replica3*) gameObjectManager->createExplosion(20); if(name == GameObject::N_ENEMY_FURY) return (RakNet::Replica3*) gameObjectManager->createRemoteFury(); if(name == GameObject::N_ENEMY_DEFENDER) return (RakNet::Replica3*) gameObjectManager->createRemoteDefender(); if(name == GameObject::N_ENEMY_BOMBER) return (RakNet::Replica3*) gameObjectManager->createRemoteEnemyBomber(); if(name == GameObject::N_BOMBER_PLAYER) return (RakNet::Replica3*) gameObjectManager->createRemoteBomber(); if(name == GameObject::N_BATTLESHIP_PLAYER) return (RakNet::Replica3*) gameObjectManager->createRemoteBattleship(); if(name == GameObject::N_ENGINEER_PLAYER) return (RakNet::Replica3*) gameObjectManager->createRemoteEngineer(); if(name == GameObject::N_FIGHTER_PLAYER) return (RakNet::Replica3*) gameObjectManager->createRemoteFighter(); if(name == GameObject::N_REPAIR_SYSTEM) return (RakNet::Replica3*) gameObjectManager->createRemoteRepairSystem(); if(name == GameObject::N_SKILL_BOMB) return (RakNet::Replica3*) gameObjectManager->createRemoteSkillBomb(); if(name == GameObject::N_SKILL_HEAL) return (RakNet::Replica3*) gameObjectManager->createRemoteSkillHeal(); if(name == GameObject::N_SPARK) return (RakNet::Replica3*) gameObjectManager->createSpark(); if(name == GameObject::N_BUILDING_MINE) return (RakNet::Replica3*) gameObjectManager->createBuildingMine(Vector2d()); //if(name == GameObject::N_ENERGY_WALL) return (RakNet::Replica3*) gameObjectManager->createEnergyWall(Vector2d(),Vector2d()); if(name == GameObject::N_BUILDING_TURRET_PROJECTILE) return (RakNet::Replica3*) gameObjectManager->createBuildingTurret(Vector2d()); if(name == GameObject::N_BUILDING_TURRET_BULLET) return (RakNet::Replica3*) gameObjectManager->createBuildingTurret2(Vector2d()); if(name == GameObject::N_BUILDING_TURRET_2_CANON) return (RakNet::Replica3*) gameObjectManager->createBuildingTurret2Canon(Vector2d()); if(name == GameObject::N_BUILDING_TURRET_BIG_CANON) return (RakNet::Replica3*) gameObjectManager->createBuildingTurretBigCanon(Vector2d()); if(name == GameObject::N_BUILDING_TURRET_1_CANON) return (RakNet::Replica3*) gameObjectManager->createBuildingTurret1Canon(Vector2d()); if(name == GameObject::N_BASE) return (RakNet::Replica3*) gameObjectManager->createRemoteBase(); if(name == GameObject::N_MINI_BASE) return (RakNet::Replica3*) gameObjectManager->createRemoteMiniBase(); if(name == GameObject::N_MINI_HANGAR) return (RakNet::Replica3*) gameObjectManager->createRemoteMiniHangar(); if(name == GameObject::N_HANGAR) return (RakNet::Replica3*) gameObjectManager->createRemoteHangar(); if(name == GameObject::N_EXTRACTORS) return (RakNet::Replica3*) gameObjectManager->createRemoteExtractors(); if(name == GameObject::N_RAY) return (RakNet::Replica3*) gameObjectManager->createRemoteRay(); if(name == GameObject::N_MINE2) return (RakNet::Replica3*) gameObjectManager->createRemoteMine2(); if(name == GameObject::N_MINE3) return (RakNet::Replica3*) gameObjectManager->createRemoteMine3(); return 0; }
void update() { game_object_manager.update_all(); block_manager.update_all(); }
inline void GameObject::remove_dependency(GameObjectPtr const& dependency) { _manager->remove_object_dependency(GameObjectPtr(this), dependency); }
inline void GameObject::add_dependency(GameObjectPtr const& dependency) { _manager->add_object_dependency(GameObjectPtr(this), dependency); }
int main (int argc, char * const argv[]) { GameObjectManager* objectManager = GameObjectManager::getInstance(); NodeManager *nodeManager = NodeManager::getInstance(); { Node *node; for (int y = 0; y <= 14; y++) { for (int x = 0; x <= 19; x++) { node = new Node(x * 32, y * 32); nodeManager->addNode(node); } } } Hill* hill1 = new Hill(StrainYellow, nodeManager->getEmptyRandomNode()); Hill* hill2 = new Hill(StrainRed, nodeManager->getEmptyRandomNode()); Hill* hill3 = new Hill(StrainBlue, nodeManager->getEmptyRandomNode()); objectManager->add(hill1); objectManager->add(hill2); objectManager->add(hill3); Ants ants; Strain antStrains[4] = { StrainYellow, StrainRed, StrainBlue, StrainRed }; for (int i = 0; i < 4; i++) { Ant* ant = new Ant(antStrains[i], nodeManager->getEmptyRandomNode()); objectManager->add(ant); ants.push_back(ant); } for (int i = 0; i < 10; i++) { Spice *spice = new Spice(nodeManager->getEmptyRandomNode()); objectManager->addSpice(spice); } sf::RenderWindow App(sf::VideoMode(640, 480), "Ants"); App.SetFramerateLimit(60); while (App.IsOpened()) { sf::Event Event; while (App.GetEvent(Event)) { if (Event.Type == sf::Event::Closed) App.Close(); if (Event.Type == sf::Event::MouseButtonPressed) { const sf::Input& Input = App.GetInput(); cout << "Mouse cursor position: " << Input.GetMouseX() << "/" << Input.GetMouseY() << endl; sf::Vector2f mouse(Input.GetMouseX(), Input.GetMouseY()); bool shiftDown = Input.IsKeyDown(sf::Key::LShift) || Input.IsKeyDown(sf::Key::RShift); // cycle all gameobjects // if position matches mouse input -> select // if nothing matches -> deselect all GameObjects allObjects = objectManager->getObjects(); GameObjects::iterator i = allObjects.begin(); for (; i < allObjects.end(); i++) { GameObject* object = *i; sf::Vector2f left_upper = object->getSprite()->GetPosition(); sf::Vector2f right_lower = left_upper; // TODO: clean up with new vector2f class left_upper.x -= 16; left_upper.y -= 16; right_lower.x += PIXELS_PER_NODE/2; right_lower.y += PIXELS_PER_NODE/2; if (left_upper.x <= mouse.x && right_lower.x >= mouse.x && left_upper.y <= mouse.y && right_lower.y >= mouse.y) { object->setSelectionStatus(true); } else if (!shiftDown) { object->setSelectionStatus(false); } } } } App.Clear(); // trigger updates objectManager->trigger(); //display nodes Nodes nodes = nodeManager->getNodes(); Nodes::iterator n = nodes.begin(); for (; n < nodes.end(); n++) { App.Draw(*(*n)->getSprite()); } // update ants Ants::iterator a = ants.begin(); for(; a < ants.end(); a++) { (*a)->handleCurrentAction(App.GetFrameTime()); } // display game objects GameObjects objects = objectManager->getObjects(); GameObjects::iterator i = objects.begin(); for (; i < objects.end(); i++) { GameObject* object = *i; if (object->hasSprite()) { App.Draw(*object->getSprite()); if (object->isSelected()) { // draw rect sf::Vector2f position = object->getSprite()->GetPosition(); sf::Vector2f new_position = position; // TODO: clean up with new vector2f class position.x -= 16; position.y -= 16; new_position.x += PIXELS_PER_NODE/2; new_position.y += PIXELS_PER_NODE/2; sf::Shape rect = sf::Shape::Rectangle(position, new_position, object->getSelectionColor(), true, object->getSelectionColor()); rect.EnableFill(false); App.Draw(rect); } } } App.Display(); } return EXIT_SUCCESS; }
void HiddenObject::init(GameObjectManager& manager, const ActorData* gameData, Node* node, PlayerObject* player, const Matrix & transform) { _manager = &manager; Player = player; manager.registerObject(this); }