示例#1
0
文件: Game.cpp 项目: Deraen/ohj2710
void Game::SelectLevel(Game::Levels level)
{
    level_ = level;

    // Destroying all bodies should also delete current planet_
    b2Body* body = world_.GetBodyList();
    while (body != NULL)
    {
        DestroyBody(body);
        body = body->GetNext();
    }
    planet_ = NULL;

    for (unsigned int i = 0; i < Bomb::BombType::COUNT_; ++i)
    {
        bombs_[i] = 0;
    }

    points_ = 0;

    for (unsigned int i = 0; i < Bomb::BombType::COUNT_; ++i)
    {
        previousReplenish_[i] = SDL_GetTicks();
    }
    previousAsteroid_ = SDL_GetTicks();

    if (level_ != Levels::COUNT_) {
        points_ = LevelInfo()->lives;
        asteroids_ = LevelInfo()->asteroids;

        for (unsigned int i = 0; i < Bomb::BombType::COUNT_; ++i)
        {
            bombs_[i] = LevelInfo()->bombs[i];
        }

        if (level_ == Levels::INF)
        {
            srand(time(NULL));
        }
        else
        {
            srand(LevelInfo()->rand);
        }

        planet_ = new Planet(LevelInfo()->planet);
    }
}
ScreenChooseInfo::ScreenChooseInfo(const Caller& choose)
{
	cLevelInfo = LevelInfo(3.0f);
	addItem(&cLevelInfo);

	bChooseEditor = Button(2.0f, choose, "choose", KEY_ENTER);
	addItem(&bChooseEditor);
}
示例#3
0
    void LevelEditor::onEnter()
    {
        if(r_level == NULL)
        {
            r_level = LevelManager::instance().createLevel(LevelInfo("Level", Vector2f(5,5)));

            Vector2i size(128, 64);
            entity::Map * map = new entity::Map(-1, size);
            r_level->addEntity(map);
        }
        Renderer::setDisplayBoundingBoxes(true);
        enterState(ST_LEVEL_EDIT_TERRAIN);
    }
示例#4
0
LevelInfo infoForLevel(const std::string& f, bool absolute) {
	MapLoad* loader = MapLoad::open(absolute ? f : ("levels/" + f), absolute, false);
	if(!loader) return LevelInfo();

	LevelInfo info;
	info.valid = true;
	info.name = loader->header().name;
	info.path = GetBaseFilename(f);
	info.type = loader->format();
	info.typeShort = loader->formatShort();
	
	delete loader;
	
	return info;
}
示例#5
0
文件: Level.hpp 项目: Zylann/Grid
 void create(const LevelInfo info = LevelInfo())
 {
     clear();
     m_levelInfo = info;
 }
示例#6
0
文件: Level.hpp 项目: Zylann/Grid
 Level(const LevelInfo info = LevelInfo())
 {
     create(info);
 }
示例#7
0
文件: Game.cpp 项目: Deraen/ohj2710
void Game::Step()
{
    static const float DESTROYRADIUS = 150 * 150;

    world_.Step(1.0 / 60.0, 10, 10);
    world_.ClearForces();

    if (planet_ == NULL) return;

    b2Vec2 planetPoint = planet_->GetBody()->GetPosition();

    // unsigned int d_cycles = 0;
    // unsigned int d_time = SDL_GetTicks();

    // All bodies affect all others bodies
    float G = LevelInfo()->g;
    b2Body* body = world_.GetBodyList();
    while (body != NULL)
    {
        Object* obj = (Object*)body->GetUserData();
        float m1 = obj->GetMass();
        b2Vec2 p1 = body->GetPosition();

        b2Body* body2 = world_.GetBodyList();
        while (m1 != 0 && body2 != NULL)
        {
            Object* obj2 = (Object*)body2->GetUserData();
            float m2 = obj2->GetMass();

            if (m2 != 0 && body2->GetType() != b2_staticBody && body != body2)
            {
                // ++d_cycles;

                b2Vec2 d = p1 - body2->GetPosition();
                float len = d.LengthSquared();
                // Strange things could happend if two bombs are over each other
                if (len > 0.01) {
                    d.Normalize();
                    d *= (G * m1 * m2) / len;

                    body2->ApplyForceToCenter(d);
                }
            }
            body2 = body2->GetNext();
        }

        // Slow asteroids
        Timed* timed = dynamic_cast<Timed*>(obj);
        if (timed != NULL)
        {
            timed->Tick();
        }

        // Remove bodies that go too far away
        if ((planetPoint - body->GetPosition()).LengthSquared() > DESTROYRADIUS)
        {
            SDL_Event event;
            event.type = SDL_USEREVENT;
            event.user.code = Game::DELETE_BODY;
            event.user.data1 = body;
            SDL_PushEvent(&event);
        }

        body = body->GetNext();
    }

    // SDL_Log("Gravitation calculation took %i ms (%i loop cycles). %i asteroids.", SDL_GetTicks() - d_time, d_cycles, Asteroid::Count());

    // Create asteroids
    if ((SDL_GetTicks() - previousAsteroid_ > LevelInfo()->asteroidSpawnSec)
            && (asteroids_ == -1 || asteroids_ > 0))
    {
        new Asteroid(planet_->GetBody());
        if (asteroids_ != -1) {
            asteroids_ -= 1;
        }
        previousAsteroid_ = SDL_GetTicks();
    }

    // Replenish weapons
    if (level_ == Levels::INF)
    {
        for (unsigned int i = 0; i < Bomb::BombType::COUNT_; ++i)
        {
            if (SDL_GetTicks() - previousReplenish_[i] > Bomb::INFO[i].replenishTime)
            {
                bombs_[i] += 1;
                if (bombs_[i] > Bomb::INFO[i].quota)
                {
                    bombs_[i] = Bomb::INFO[i].quota;
                }
                previousReplenish_[i] = SDL_GetTicks();
            }
        }
    }
}