void UIMainWindow::moveSprite (UINodeSprite* sprite, float speed) const { const float y = 1.0f - (sprite->getRenderHeight() / static_cast<float>(_frontend->getHeight())); const float startX = randBetweenf(-2.2f, -0.2f); const float endX = randBetweenf(2.1f, 3.3f); sprite->setMovement(startX, y, endX, y, speed); }
void UIMainWindow::flyPlayer () { const float spriteSize = _player->getRenderHeight() / static_cast<float>(_frontend->getHeight()); const float y = 1.0f - spriteSize; const float startYRand = randBetweenf(0.0f, y); const float endYRand = randBetweenf(0.0f, y); const bool leftToRight = rand() % 2 == 0; float startX = randBetweenf(-4.5f, -0.5f); float endX = randBetweenf(2.5f, 4.5f); if (!leftToRight) { std::swap(startX, endX); } _player->setMovement(startX, startYRand, endX, endYRand, 0.0004f); }
bool Map::load (const std::string& name) { ScopedPtr<IMapContext> ctx(getMapContext(name)); resetCurrentMap(); if (name.empty()) { info(LOG_MAP, "no map name given"); return false; } info(LOG_MAP, "load map " + name); if (!ctx->load(false)) { error(LOG_MAP, "failed to load the map " + name); return false; } ctx->save(); _settings = ctx->getSettings(); _startPositions = ctx->getStartPositions(); _name = ctx->getName(); _title = ctx->getTitle(); _width = getSetting(msn::WIDTH, "-1").toInt(); _height = getSetting(msn::HEIGHT, "-1").toInt(); _solution = getSolution(); const std::string solutionSteps = string::toString(_solution.length()); _settings.insert(std::make_pair("best", solutionSteps)); info(LOG_MAP, "Solution has " + solutionSteps + " steps"); if (_width <= 0 || _height <= 0) { error(LOG_MAP, "invalid map dimensions given"); return false; } const std::vector<MapTileDefinition>& mapTileList = ctx->getMapTileDefinitions(); for (std::vector<MapTileDefinition>::const_iterator i = mapTileList.begin(); i != mapTileList.end(); ++i) { const SpriteType& t = i->spriteDef->type; info(LOG_MAP, "sprite type: " + t.name + ", " + i->spriteDef->id); MapTile *mapTile = new MapTile(*this, i->x, i->y, getEntityTypeForSpriteType(t)); mapTile->setSpriteID(i->spriteDef->id); mapTile->setAngle(randBetweenf(-0.1, 0.1f)); loadEntity(mapTile); } info(LOG_MAP, String::format("map loading done with %i tiles", mapTileList.size())); ctx->onMapLoaded(); _frontend->onMapLoaded(); const LoadMapMessage msg(_name, _title); _serviceProvider->getNetwork().sendToAllClients(msg); _mapRunning = true; return true; }
Sparkle::Sparkle (IParticleEnvironment& env, int startX, int startY, int sizeW, int sizeH) : Particle(env), _waterSurface(0), _startX(startX), _startY(startY), _sizeW(sizeW), _sizeH(sizeH) { const int i = rand() % SPARKLETYPES; _texture = loadTexture(String::format("sparkle-%02i", i + 1)); _v = vec2(0.0f, randBetweenf(-0.1f, -0.2f)); _omega = 0.4f; _half = _sizeH / 2.0f; _height = _sizeH; }
void Sparkle::run () { // the water height might change, so update this init(); const float magnitude = 0.1f; const float amplitude = 0.5f; _v.x = magnitude * sinf(_v.y * amplitude); // sparkle is under water if (_s.y >= _waterSurface) { _active = false; } else if (_s.y <= 0.000001f) { // init _s.y = _startY - rand() % _half; _s.x = _startX + rand() % _sizeW; } else if (_startY - _s.y > _height) { // high enough - respawn _s.y = _startY - rand() % _half; _s.x = _startX + rand() % _sizeW; _v = vec2(0.0f, randBetweenf(-0.1f, -0.2f)); _height = randBetween(_sizeH, _half); } }