Пример #1
0
void
SectorParser::fix_old_tiles()
{
  for(auto i = m_sector.solid_tilemaps.begin(); i != m_sector.solid_tilemaps.end(); i++) {
    TileMap* solids = *i;
    for(size_t x=0; x < solids->get_width(); ++x) {
      for(size_t y=0; y < solids->get_height(); ++y) {
        const Tile *tile = solids->get_tile(x, y);

        if (tile->get_object_name().length() > 0) {
          Vector pos = solids->get_tile_position(x, y);
          try {
            GameObjectPtr object = ObjectFactory::instance().create(tile->get_object_name(), pos, AUTO, tile->get_object_data());
            m_sector.add_object(object);
            solids->change(x, y, 0);
          } catch(std::exception& e) {
            log_warning << e.what() << "" << std::endl;
          }
        }

      }
    }
  }

  // add lights for special tiles
  for(auto i = m_sector.gameobjects.begin(); i != m_sector.gameobjects.end(); i++) {
    TileMap* tm = dynamic_cast<TileMap*>(i->get());
    if (!tm) continue;
    for(size_t x=0; x < tm->get_width(); ++x) {
      for(size_t y=0; y < tm->get_height(); ++y) {
        const Tile* tile = tm->get_tile(x, y);
        uint32_t attributes = tile->getAttributes();
        Vector pos = tm->get_tile_position(x, y);
        Vector center = pos + Vector(16, 16);

        if (attributes & Tile::FIRE) {
          if (attributes & Tile::HURTS) {
            // lava or lavaflow
            // space lights a bit
            if ((tm->get_tile(x-1, y)->getAttributes() != attributes || x%3 == 0)
                 && (tm->get_tile(x, y-1)->getAttributes() != attributes || y%3 == 0)) {
              float pseudo_rnd = (float)((int)pos.x % 10) / 10;
              m_sector.add_object(std::make_shared<PulsingLight>(center, 1.0f + pseudo_rnd, 0.8f, 1.0f, Color(1.0f, 0.3f, 0.0f, 1.0f)));
            }
          } else {
            // torch
            float pseudo_rnd = (float)((int)pos.x % 10) / 10;
            m_sector.add_object(std::make_shared<PulsingLight>(center, 1.0f + pseudo_rnd, 0.9f, 1.0f, Color(1.0f, 1.0f, 0.6f, 1.0f)));
          }
        }

      }
    }
  }
}
Пример #2
0
void
FlipLevelTransformer::transform_tilemap(float height, TileMap& tilemap)
{
  for(int x = 0; x < tilemap.get_width(); ++x) {
    for(int y = 0; y < tilemap.get_height()/2; ++y) {
      // swap tiles
      int y2 = tilemap.get_height()-1-y;
      uint32_t t1 = tilemap.get_tile_id(x, y);
      uint32_t t2 = tilemap.get_tile_id(x, y2);
      tilemap.change(x, y, t2);
      tilemap.change(x, y2, t1);
    }
  }
  tilemap.set_flip(transform_flip(tilemap.get_flip()));
  Vector offset = tilemap.get_offset();
  offset.y = height - offset.y - tilemap.get_bbox().get_height();
  tilemap.set_offset(offset);
  auto path = tilemap.get_path();
  if (path)
    transform_path(height, tilemap.get_bbox().get_height(), *path);
}
Пример #3
0
void
Sector::fix_old_tiles()
{
  for(std::list<TileMap*>::iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
    TileMap* solids = *i;
    for(size_t x=0; x < solids->get_width(); ++x) {
      for(size_t y=0; y < solids->get_height(); ++y) {
	const Tile* tile = solids->get_tile(x, y);
	Vector pos(solids->get_x_offset() + x*32, solids->get_y_offset() + y*32);

	if(tile->getID() == 112) {
	  add_object(new InvisibleBlock(pos));
	  solids->change(x, y, 0);
	} else if(tile->getAttributes() & Tile::COIN) {
	  add_object(new Coin(pos));
	  solids->change(x, y, 0);
	} else if(tile->getAttributes() & Tile::FULLBOX) {
	  add_object(new BonusBlock(pos, tile->getData()));
	  solids->change(x, y, 0);
	} else if(tile->getAttributes() & Tile::BRICK) {
	  add_object(new Brick(pos, tile->getData()));
	  solids->change(x, y, 0);
	} else if(tile->getAttributes() & Tile::GOAL) {
	  std::string sequence = tile->getData() == 0 ? "endsequence" : "stoptux";
	  add_object(new SequenceTrigger(pos, sequence));
	  solids->change(x, y, 0);
	}
      }
    }
  }

  // add lights for special tiles
  for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); i++) {
    TileMap* tm = dynamic_cast<TileMap*>(*i);
    if (!tm) continue;
    for(size_t x=0; x < tm->get_width(); ++x) {
      for(size_t y=0; y < tm->get_height(); ++y) {
	const Tile* tile = tm->get_tile(x, y);
	Vector pos(tm->get_x_offset() + x*32, tm->get_y_offset() + y*32);
	Vector center(pos.x + 16, pos.y + 16);

	// torch
	if (tile->getID() == 1517) {
	  float pseudo_rnd = (float)((int)pos.x % 10) / 10;
	  add_object(new PulsingLight(center, 1.0 + pseudo_rnd, 0.9, 1.0, Color(1.0, 1.0, 0.6, 1.0)));
	}
	// lava or lavaflow
	if ((tile->getID() == 173) || (tile->getID() == 1700) || (tile->getID() == 1705) || (tile->getID() == 1706)) {
	  // space lights a bit
	  if (((tm->get_tile(x-1, y)->getID() != tm->get_tile(x,y)->getID()) 
	      && (tm->get_tile(x, y-1)->getID() != tm->get_tile(x,y)->getID())) 
	      || ((x % 3 == 0) && (y % 3 == 0))) {
	    float pseudo_rnd = (float)((int)pos.x % 10) / 10;
	    add_object(new PulsingLight(center, 1.0 + pseudo_rnd, 0.8, 1.0, Color(1.0, 0.3, 0.0, 1.0)));
	  }
	}

      }
    }
  }


}
Пример #4
0
void
Sector::parse_old_format(const lisp::Lisp& reader)
{
  name = "main";
  reader.get("gravity", gravity);

  std::string backgroundimage;
  if (reader.get("background", backgroundimage) && (backgroundimage != "")) {
    if (backgroundimage == "arctis.png") backgroundimage = "arctis.jpg";
    if (backgroundimage == "arctis2.jpg") backgroundimage = "arctis.jpg";
    if (backgroundimage == "ocean.png") backgroundimage = "ocean.jpg";
    backgroundimage = "images/background/" + backgroundimage;
    if (!PHYSFS_exists(backgroundimage.c_str())) {
      log_warning << "Background image \"" << backgroundimage << "\" not found. Ignoring." << std::endl;
      backgroundimage = "";
    }
  }

  float bgspeed = .5;
  reader.get("bkgd_speed", bgspeed);
  bgspeed /= 100;

  Color bkgd_top, bkgd_bottom;
  int r = 0, g = 0, b = 128;
  reader.get("bkgd_red_top", r);
  reader.get("bkgd_green_top",  g);
  reader.get("bkgd_blue_top",  b);
  bkgd_top.red = static_cast<float> (r) / 255.0f;
  bkgd_top.green = static_cast<float> (g) / 255.0f;
  bkgd_top.blue = static_cast<float> (b) / 255.0f;

  reader.get("bkgd_red_bottom",  r);
  reader.get("bkgd_green_bottom", g);
  reader.get("bkgd_blue_bottom", b);
  bkgd_bottom.red = static_cast<float> (r) / 255.0f;
  bkgd_bottom.green = static_cast<float> (g) / 255.0f;
  bkgd_bottom.blue = static_cast<float> (b) / 255.0f;

  if(backgroundimage != "") {
    Background* background = new Background();
    background->set_image(backgroundimage, bgspeed);
    add_object(background);
  } else {
    Gradient* gradient = new Gradient();
    gradient->set_gradient(bkgd_top, bkgd_bottom);
    add_object(gradient);
  }

  std::string particlesystem;
  reader.get("particle_system", particlesystem);
  if(particlesystem == "clouds")
    add_object(new CloudParticleSystem());
  else if(particlesystem == "snow")
    add_object(new SnowParticleSystem());
  else if(particlesystem == "rain")
    add_object(new RainParticleSystem());

  Vector startpos(100, 170);
  reader.get("start_pos_x", startpos.x);
  reader.get("start_pos_y", startpos.y);

  SpawnPoint* spawn = new SpawnPoint;
  spawn->pos = startpos;
  spawn->name = "main";
  spawnpoints.push_back(spawn);

  music = "chipdisko.ogg";
  // skip reading music filename. It's all .ogg now, anyway
  /*
  reader.get("music", music);
  */
  music = "music/" + music;

  int width = 30, height = 15;
  reader.get("width", width);
  reader.get("height", height);

  std::vector<unsigned int> tiles;
  if(reader.get_vector("interactive-tm", tiles)
      || reader.get_vector("tilemap", tiles)) {
    TileMap* tilemap = new TileMap();
    tilemap->set(width, height, tiles, LAYER_TILES, true);

    // replace tile id 112 (old invisible tile) with 1311 (new invisible tile)
    for(size_t x=0; x < tilemap->get_width(); ++x) {
      for(size_t y=0; y < tilemap->get_height(); ++y) {
        const Tile* tile = tilemap->get_tile(x, y);
        if(tile->getID() == 112) tilemap->change(x, y, 1311);
      }
    }

    if (height < 19) tilemap->resize(width, 19);
    add_object(tilemap);
  }

  if(reader.get_vector("background-tm", tiles)) {
    TileMap* tilemap = new TileMap();
    tilemap->set(width, height, tiles, LAYER_BACKGROUNDTILES, false);
    if (height < 19) tilemap->resize(width, 19);
    add_object(tilemap);
  }

  if(reader.get_vector("foreground-tm", tiles)) {
    TileMap* tilemap = new TileMap();
    tilemap->set(width, height, tiles, LAYER_FOREGROUNDTILES, false);
    
    // fill additional space in foreground with tiles of ID 2035 (lightmap/black)
    if (height < 19) tilemap->resize(width, 19, 2035); 

    add_object(tilemap);
  }

  // read reset-points (now spawn-points)
  const lisp::Lisp* resetpoints = reader.get_lisp("reset-points");
  if(resetpoints) {
    lisp::ListIterator iter(resetpoints);
    while(iter.next()) {
      if(iter.item() == "point") {
        Vector sp_pos;
        if(reader.get("x", sp_pos.x) && reader.get("y", sp_pos.y))
          {
          SpawnPoint* sp = new SpawnPoint;
          sp->name = "main";
          sp->pos = sp_pos;
          spawnpoints.push_back(sp);
          }
      } else {
        log_warning << "Unknown token '" << iter.item() << "' in reset-points." << std::endl;
      }
    }
  }

  // read objects
  const lisp::Lisp* objects = reader.get_lisp("objects");
  if(objects) {
    lisp::ListIterator iter(objects);
    while(iter.next()) {
      GameObject* object = parse_object(iter.item(), *(iter.lisp()));
      if(object) {
        add_object(object);
      } else {
        log_warning << "Unknown object '" << iter.item() << "' in level." << std::endl;
      }
    }
  }

  // add a camera
  Camera* camera = new Camera(this, "Camera");
  add_object(camera);

  update_game_objects();

  if(solid_tilemaps.size() < 1) log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl;

  fix_old_tiles();
  update_game_objects();
}
Пример #5
0
void
Sector::fix_old_tiles()
{
  for(auto i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
    TileMap* solids = *i;
    for(size_t x=0; x < solids->get_width(); ++x) {
      for(size_t y=0; y < solids->get_height(); ++y) {
        uint32_t    id   = solids->get_tile_id(x, y);
        const Tile *tile = solids->get_tile(x, y);
        Vector pos = solids->get_tile_position(x, y);

        if(id == 112) {
          add_object(std::make_shared<InvisibleBlock>(pos));
          solids->change(x, y, 0);
        } else if(tile->getAttributes() & Tile::COIN) {
          add_object(std::make_shared<Coin>(pos, solids));
          solids->change(x, y, 0);
        } else if(tile->getAttributes() & Tile::FULLBOX) {
          add_object(std::make_shared<BonusBlock>(pos, tile->getData()));
          solids->change(x, y, 0);
        } else if(tile->getAttributes() & Tile::BRICK) {
          if( ( id == 3159 ) || ( id == 3160 ) ){
            add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brickWeb.sprite") );
          } else if( ( id == 78 ) || ( id == 105 ) ){
            add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brickIce.sprite") );
          } else if( ( id == 77 ) || ( id == 104 ) ){
            add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brick.sprite") );
          } else {
            log_warning << "attribute 'brick #t' is not supported for tile-id " << id << std::endl;
            add_object( std::make_shared<Brick>(pos, tile->getData(), "images/objects/bonus_block/brick.sprite") );
          }
          solids->change(x, y, 0);
        } else if(tile->getAttributes() & Tile::GOAL) {
          std::string sequence = tile->getData() == 0 ? "endsequence" : "stoptux";
          add_object(std::make_shared<SequenceTrigger>(pos, sequence));
          solids->change(x, y, 0);
        }
      }
    }
  }

  // add lights for special tiles
  for(auto i = gameobjects.begin(); i != gameobjects.end(); i++) {
    TileMap* tm = dynamic_cast<TileMap*>(i->get());
    if (!tm) continue;
    for(size_t x=0; x < tm->get_width(); ++x) {
      for(size_t y=0; y < tm->get_height(); ++y) {
        uint32_t id = tm->get_tile_id(x, y);
        Vector pos = tm->get_tile_position(x, y);
        Vector center = pos + Vector(16, 16);

        // torch
        if (id == 1517) {
          float pseudo_rnd = (float)((int)pos.x % 10) / 10;
          add_object(std::make_shared<PulsingLight>(center, 1.0f + pseudo_rnd, 0.9f, 1.0f, Color(1.0f, 1.0f, 0.6f, 1.0f)));
        }
        // lava or lavaflow
        if ((id == 173) || (id == 1700) || (id == 1705) || (id == 1706)) {
          // space lights a bit
          if ((((tm->get_tile_id(x-1, y)) != tm->get_tile_id(x,y))
               && (tm->get_tile_id(x, y-1) != tm->get_tile_id(x,y)))
              || ((x % 3 == 0) && (y % 3 == 0))) {
            float pseudo_rnd = (float)((int)pos.x % 10) / 10;
            add_object(std::make_shared<PulsingLight>(center, 1.0f + pseudo_rnd, 0.8f, 1.0f, Color(1.0f, 0.3f, 0.0f, 1.0f)));
          }
        }

      }
    }
  }

}