IAction *HorDash::step() { if (_count-- == 0 || (_player(Event::LEFT_WALL) && _player.orient() == -1) || (_player(Event::RIGHT_WALL) && _player.orient() == 1)) { _player.sx(_player.orient()); return (_player[INERTIE]); } return (this); }
void BedItem::wakeUp(Player* player) { // avoid crashes if (!house) { return; } if (sleeperGUID != 0) { if (!player) { Player _player(nullptr); if (IOLoginData::loadPlayerById(&_player, sleeperGUID)) { regeneratePlayer(&_player); IOLoginData::savePlayer(&_player); } } else { regeneratePlayer(player); g_game.addCreatureHealth(player); } } // update the BedSleepersMap Beds::getInstance().setBedSleeper(nullptr, sleeperGUID); BedItem* nextBedItem = getNextBedItem(); // unset sleep info internalRemoveSleeper(); if (nextBedItem) { nextBedItem->internalRemoveSleeper(); } // change self and partner's appearance updateAppearance(nullptr); if (nextBedItem) { nextBedItem->updateAppearance(nullptr); } }
int main() { std::map<std::string, std::string> _texts = std::map<std::string, std::string>(); std::vector<GameObject*> _gameObjects = std::vector<GameObject*>(); sf::RenderWindow window(sf::VideoMode(800, 600), "Collision test"); /* sf::Texture _bkg; _bkg.loadFromFile("gorge.jpg"); _bkg.setRepeated(true); sf::Sprite _background(_bkg, sf::IntRect(0, 0, 2000, 1000)); */ if(load("Brown_Rocks.png", sf::Vector2u(32, 32), nullptr, 800, 600)) std::cout << "YEAH\n"; sf::Texture _bkg; _bkg.loadFromFile("Brown_Rocks.png"); _bkg.setRepeated(true); sf::Sprite _background(_bkg, sf::IntRect(0, 0, 2000, 1000)); std::cout << sf::Texture::getMaximumSize() << "\n"; sf::Texture _cliffsTexture; _cliffsTexture.loadFromFile("Cliffs.png"); _cliffsTexture.setRepeated(true); sf::Sprite _cliffsBottom(_cliffsTexture); sf::Sprite _cliffsTop(_cliffsTexture, sf::IntRect(0, 400, 800, -800)); _cliffsTop.setPosition(-300, 0); std::cout << _cliffsTexture.getSize().x << "," << _cliffsTexture.getSize().y; sf::Texture _platformTexture; _platformTexture.loadFromFile("Rocks_Platform1.png"); _platformTexture.setRepeated(true); sf::Sprite _platform(_platformTexture, sf::IntRect(0, 0, 2000, 32)); _platform.setPosition(0, window.getSize().y - 32); sf::Sprite _platformBottom(_platformTexture, sf::IntRect(0, 32, 2000, -32)); _platformBottom.setPosition(0, 0); sf::Texture texture; texture.loadFromFile("plane.png"); //texture.loadFromFile("player.png"); GameObject _player(texture); _player.setPosition(window.getSize().x / 2.f - 300, window.getSize().y / 2.f - 75); _gameObjects.push_back(&_player); sf::Texture etexture; etexture.loadFromFile("plane.png"); //sf::IntRect textRect(64, 0, -64, 32); //GameObject _enemy(etexture, textRect); GameObject _enemy(etexture); _enemy.setPosition(window.getSize().x / 2.f + 75, window.getSize().y / 2.f - 16); _gameObjects.push_back(&_enemy); sf::RectangleShape _bounding1(sf::Vector2f(_player.getBoundingBox().width - 1, _player.getBoundingBox().height - 1)); _bounding1.setPosition(_player.getPosition()); _bounding1.setFillColor(sf::Color::Transparent); _bounding1.setOutlineColor(sf::Color::Red); _bounding1.setOutlineThickness(1); sf::RectangleShape _bounding2(sf::Vector2f(_enemy.getBoundingBox().width - 1, _enemy.getBoundingBox().height - 1)); _bounding2.setPosition(_enemy.getPosition()); _bounding2.setFillColor(sf::Color::Transparent); _bounding2.setOutlineColor(sf::Color::Red); _bounding2.setOutlineThickness(1); sf::Font font; font.loadFromFile("VeraMono.ttf"); sf::Text _text("Debug", font, 12); _text.setPosition(0, 0); sf::Clock clock; sf::Time timeSinceLastUpdate = sf::Time::Zero; // Start the game loop while (window.isOpen()) { sf::Time elapsedTime = clock.restart(); timeSinceLastUpdate += elapsedTime; while (timeSinceLastUpdate > TimePerFrame) { timeSinceLastUpdate -= TimePerFrame; // Process events sf::Event event; while (window.pollEvent(event)) { // Close window : exit if (event.type == sf::Event::Closed) window.close(); if(event.type == sf::Event::KeyPressed) { short id = 1; for( auto& i : _gameObjects ) { i->update(event, id); id++; } } } if(checkCollisions(_gameObjects, _texts)) _texts["Collision"] = "Detected"; else _texts["Collision"] = "NOT Detected"; std::map<std::string, std::string>::iterator i = _texts.begin(); std::stringstream ss; for( ; i != _texts.end(); ++i ) { ss << i->first << ": " << i->second << std::endl << std::endl; } _text.setString(ss.str()); } _bounding1.setPosition(_player.getPosition()); _bounding2.setPosition(_enemy.getPosition()); _statisticsUpdateTime += elapsedTime; _statisticsNumFrames += 1; if (_statisticsUpdateTime >= sf::seconds(1.0f)) { std::stringstream fps, timeupdate; fps << _statisticsNumFrames; timeupdate << _statisticsUpdateTime.asMicroseconds() / _statisticsNumFrames; _statisticsUpdateTime -= sf::seconds(1.0f); _statisticsNumFrames = 0; _texts["FPS"] = fps.str() + "\n" + "Time / Update = " + timeupdate.str() + "us"; } window.clear(); window.draw(_background); // window.draw(m_vertices, &m_tileset); window.draw(_cliffsBottom); window.draw(_cliffsTop); window.draw(_platform); window.draw(_platformBottom); for( auto& i : _gameObjects ) { window.draw(*i); } window.draw(_text); window.draw(_bounding1); window.draw(_bounding2); window.display(); } }
void HorDash::check() { if (_player(Event::WALL) && !isActive()) _open = 1; }