void
Camera::parse(const lisp::Lisp& reader)
{
  std::string modename;
  
  reader.get("mode", modename);
  if(modename == "normal") {
    mode = NORMAL;

    do_backscrolling = true;
    reader.get("backscrolling", do_backscrolling);
  } else if(modename == "autoscroll") {
    mode = AUTOSCROLL;

    const lisp::Lisp* pathLisp = reader.get_lisp("path");
    if(pathLisp == NULL)
      throw std::runtime_error("No path specified in autoscroll camera.");

    autoscroll_path.reset(new Path());
    autoscroll_path->read(*pathLisp);
    autoscroll_walker.reset(new PathWalker(autoscroll_path.get()));
  } else if(modename == "manual") {
    mode = MANUAL;
  } else {
    std::stringstream str;
    str << "invalid camera mode '" << modename << "'found in worldfile.";
    throw std::runtime_error(str.str());
  }
}
void
PlayerStatus::read(const lisp::Lisp& lisp)
{
  reset();
  
  std::string bonusname;
  if(lisp.get("bonus", bonusname)) {
    if(bonusname == "none") {
      bonus = NO_BONUS;
    } else if(bonusname == "growup") {
      bonus = GROWUP_BONUS;
    } else if(bonusname == "fireflower") {
      bonus = FIRE_BONUS;
    } else if(bonusname == "iceflower") {
      bonus = ICE_BONUS;
    } else {
      log_warning << "Unknown bonus '" << bonusname << "' in savefile" << std::endl;
      bonus = NO_BONUS;
    }
  }
  lisp.get("fireflowers", max_fire_bullets);
  lisp.get("iceflowers", max_ice_bullets);

  lisp.get("coins", coins);
  lisp.get("max-score-multiplier", max_score_multiplier);
}
Beispiel #3
0
void
JoystickConfig::read(const lisp::Lisp& joystick_lisp)
{
  joystick_lisp.get("dead-zone", dead_zone);
  joystick_lisp.get("jump-with-up", jump_with_up_joy);

  lisp::ListIterator iter(&joystick_lisp);
  while(iter.next())
  {
    if (iter.item() == "map")
    {
      int button = -1;
      int axis   = 0;
      int hat    = -1;
      std::string control;
      const lisp::Lisp* map = iter.lisp();

      map->get("control", control);
      int i = 0;
      for(i = 0; Controller::controlNames[i] != 0; ++i)
      {
        if (control == Controller::controlNames[i])
          break;
      }

      if (Controller::controlNames[i] == 0)
      {
        log_info << "Invalid control '" << control << "' in buttonmap" << std::endl;
      }
      else
      {
        if (map->get("button", button))
        {
          bind_joybutton(0, button, Controller::Control(i));
        }
        else if (map->get("axis",   axis))
        {
          bind_joyaxis(0, axis, Controller::Control(i));
        }
        else if (map->get("hat",   hat))
        {
          if (hat != SDL_HAT_UP   &&
              hat != SDL_HAT_DOWN &&
              hat != SDL_HAT_LEFT &&
              hat != SDL_HAT_RIGHT) {
            log_info << "Invalid axis '" << axis << "' in axismap" << std::endl;
          }
          else
          {
            bind_joyhat(0, hat, Controller::Control(i));
          }
        }
      }
    }
  }
}
Flame::Flame(const lisp::Lisp& reader)
  : BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), angle(0), radius(100), speed(2)
{
  reader.get("radius", radius);
  reader.get("speed", speed);
  bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
                      start_position.y + sin(angle) * radius));
  countMe = false;
  sound_manager->preload(SOUNDFILE);
}
Beispiel #5
0
DartTrap::DartTrap(const lisp::Lisp& reader)
	: BadGuy(reader, "images/creatures/darttrap/darttrap.sprite", LAYER_TILES-1), initial_delay(0), fire_delay(2), ammo(-1), state(IDLE)
{
  reader.get("initial-delay", initial_delay);
  reader.get("fire-delay", fire_delay);
  reader.get("ammo", ammo);
  countMe = false;
  sound_manager->preload("sounds/dartfire.wav");
  if (start_dir == AUTO) log_warning << "Setting a DartTrap's direction to AUTO is no good idea" << std::endl;
}
void
Level::load_old_format(const lisp::Lisp& reader)
{
  reader.get("name", name);
  reader.get("author", author);

  Sector* sector = new Sector(this);
  sector->parse_old_format(reader);
  add_sector(sector);
}
WillOWisp::WillOWisp(const lisp::Lisp& reader)
  : mystate(STATE_IDLE), target_sector("main"), target_spawnpoint("main"), soundSource(0)
{
  reader.get("x", start_position.x);
  reader.get("y", start_position.y);
  reader.get("sector", target_sector);
  reader.get("spawnpoint", target_spawnpoint);

  bbox.set_size(32, 32);  
  sprite = sprite_manager->create("images/creatures/willowisp/willowisp.sprite");
  countMe = false;
}
Beispiel #8
0
MovingSprite::MovingSprite(const lisp::Lisp& reader, const std::string& sprite_name, int layer, CollisionGroup collision_group)
	: sprite_name(sprite_name), layer(layer)
{
  if (!reader.get("x", bbox.p1.x))
    throw std::runtime_error("no x position set");
  if (!reader.get("y", bbox.p1.y))
    throw std::runtime_error("no y position set");

  sprite = sprite_manager->create(sprite_name);
  bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
  set_group(collision_group);
}
SnowBall::SnowBall(const lisp::Lisp& reader)
{
  reader.get("x", start_position.x);
  reader.get("y", start_position.y);
  //This is for a hidden badguy :)
  fluffy = false;  
  reader.get("fluffy",fluffy);
  bbox.set_size(31.8, 31.8);
  if (fluffy) sprite = sprite_manager->create("images/creatures/fluffy/fluffy.sprite");
  else sprite = sprite_manager->create("images/creatures/snowball/snowball.sprite");
  set_direction = false;
}
Dispenser::Dispenser(const lisp::Lisp& reader)
	: BadGuy(reader, "images/creatures/dispenser/dispenser.sprite")
{
  reader.get("cycle", cycle);
  reader.get("badguy", badguy);
  if (badguy == "mrrocket") {
     if (start_dir == AUTO) log_warning << "Setting a Dispenser's direction to AUTO is no good idea" << std::endl;
     sprite->set_action(dir == LEFT ? "working-left" : "working-right");
  }
  else {sprite->set_action("dropper");}
  bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
  countMe = false;
}
PowerUp::PowerUp(const lisp::Lisp& lisp)
{
  lisp.get("x", bbox.p1.x);
  lisp.get("y", bbox.p1.y);
  lisp.get("sprite", sprite_name);
  lisp.get("script", script);
  no_physics = false;
  lisp.get("disable-physics", no_physics);
  bbox.set_size(32, 32);   
  sprite = sprite_manager->create(sprite_name);
  physic.enable_gravity(true);

  set_group(COLGROUP_MOVING);
}
Beispiel #12
0
Spiky::Spiky(const lisp::Lisp& reader)
{
  reader.get("x", start_position.x);
  reader.get("y", start_position.y);
  bbox.set_size(31.8, 31.8);
  sprite = sprite_manager->create("images/creatures/spiky/spiky.sprite");
}
MrBomb::MrBomb(const lisp::Lisp& reader)
{
  reader.get("x", start_position.x);
  reader.get("y", start_position.y);
  bbox.set_size(31.8, 31.8);
  sprite = sprite_manager->create("images/creatures/mr_bomb/mr_bomb.sprite");
  set_direction = false;
}
SpiderMite::SpiderMite(const lisp::Lisp& reader)
{
  reader.get("x", start_position.x);
  reader.get("y", start_position.y);
  bbox.set_size(31.8, 31.8);
  sprite = sprite_manager->create("images/creatures/spidermite/spidermite.sprite");
  physic.enable_gravity(false);
}
Beispiel #15
0
Fish::Fish(const lisp::Lisp& reader)
{
  reader.get("x", start_position.x);
  reader.get("y", start_position.y);
  bbox.set_size(31.8, 31.8);
  sprite = sprite_manager->create("images/creatures/fish/fish.sprite");
  physic.enable_gravity(true);
}
Beispiel #16
0
Jumpy::Jumpy(const lisp::Lisp& reader)
    : groundhit_pos_set(false)
{
  reader.get("x", start_position.x);
  reader.get("y", start_position.y);
  bbox.set_size(31.8, 31.8);
  sprite = sprite_manager->create("images/creatures/jumpy/jumpy.sprite");
}
Background::Background(const lisp::Lisp& reader)
  : layer(LAYER_BACKGROUND0)
{
  // read position, defaults to (0,0)
  float px = 0;
  float py = 0;
  reader.get("x", px);
  reader.get("y", py);
  this->pos = Vector(px,py);

  speed = 1.0;
  speed_y = 1.0;

  reader.get("layer", layer);
  if(!reader.get("image", imagefile) || !reader.get("speed", speed))
    throw std::runtime_error("Must specify image and speed for background");
  
  set_image(imagefile, speed);
  reader.get("speed-y", speed_y);
  if (reader.get("image-top", imagefile_top)) {
    image_top.reset(new Surface(imagefile_top));
  }
  if (reader.get("image-bottom", imagefile_bottom)) {
    image_bottom.reset(new Surface(imagefile_bottom));
  }
}
SnowSnail::SnowSnail(const lisp::Lisp& reader)
  : ice_state(ICESTATE_NORMAL), squishcount(0)
{
  reader.get("x", start_position.x);
  reader.get("y", start_position.y);
  bbox.set_size(31.8, 31.8);
  sprite = sprite_manager->create("images/creatures/snowsnail/snowsnail.sprite");
  set_direction = false;
}
Zeekling::Zeekling(const lisp::Lisp& reader)
{
    reader.get("x", start_position.x);
    reader.get("y", start_position.y);
    bbox.set_size(31.8, 31.8);
    sprite = sprite_manager->create("images/creatures/zeekling/zeekling.sprite");
    set_direction = false;
    state = FLYING;
}
Beispiel #20
0
Totem::Totem(const lisp::Lisp& reader)
{
  carrying = 0;
  carried_by = 0;
  bbox.set_size(48, 49);

  reader.get("x", start_position.x);
  reader.get("y", start_position.y);
  sprite = sprite_manager->create("images/creatures/totem/totem.sprite");
}
Beispiel #21
0
MovingSprite::MovingSprite(const lisp::Lisp& reader, const Vector& pos, int layer, CollisionGroup collision_group)
	: layer(layer)
{
  bbox.set_pos(pos);
  if (!reader.get("sprite", sprite_name))
    throw std::runtime_error("no sprite name set");

  sprite = sprite_manager->create(sprite_name);
  bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
  set_group(collision_group);
}
void
KeyboardConfig::read(const lisp::Lisp& keymap_lisp)
{
  // keycode values changed between SDL1 and SDL2, so we skip old SDL1
  // based values and use the defaults instead on the first read of
  // the config file
  bool config_is_sdl2 = false;
  keymap_lisp.get("sdl2", config_is_sdl2);
  if (config_is_sdl2)
  {
    keymap_lisp.get("jump-with-up", jump_with_up_kbd);
    lisp::ListIterator iter(&keymap_lisp);
    while(iter.next())
    {
      if (iter.item() == "map")
      {
        int key = -1;
        std::string control;
        const lisp::Lisp* map = iter.lisp();
        map->get("key", key);

        map->get("control", control);

        int i = 0;
        for(i = 0; Controller::controlNames[i] != 0; ++i)
        {
          if (control == Controller::controlNames[i])
            break;
        }

        if (Controller::controlNames[i] == 0)
        {
          log_info << "Invalid control '" << control << "' in keymap" << std::endl;
          continue;
        }
        keymap[static_cast<SDL_Keycode>(key)] = static_cast<Controller::Control>(i);
      }
    }
  }
}
void
Statistics::parse(const lisp::Lisp& reader)
{
  reader.get("coins-collected", coins);
  reader.get("coins-collected-total", total_coins);
  reader.get("badguys-killed", badguys);
  reader.get("badguys-killed-total", total_badguys);
  reader.get("time-needed", time);
  reader.get("secrets-found", secrets);
  reader.get("secrets-found-total", total_secrets);
}
Platform::Platform(const lisp::Lisp& reader)
{
  std::string sprite_name;
  reader.get("sprite", sprite_name);
  if(sprite_name == "")
    throw std::runtime_error("No sprite specified in platform object"); 
  sprite.reset(sprite_manager->create(sprite_name));

  const lisp::Lisp* pathLisp = reader.get_lisp("path");
  if(pathLisp == NULL)
    throw std::runtime_error("No path specified for platform");
  path.reset(new Path());
  path->read(*pathLisp);
  walker.reset(new PathWalker(path.get()));

  bbox.p1 = path->get_base();
  bbox.set_size(sprite->get_width(), sprite->get_height());
  
  set_group(COLGROUP_STATIC);
  flags |= FLAG_SOLID;
}
Beispiel #25
0
Wind::Wind(const lisp::Lisp& reader)
  : blowing(true), acceleration(100), elapsed_time(0)
{
  reader.get("name", name);
  reader.get("x", bbox.p1.x);
  reader.get("y", bbox.p1.y);
  float w = 32, h = 32;
  reader.get("width", w);
  reader.get("height", h);
  bbox.set_size(w, h);

  reader.get("blowing", blowing);

  float speed_x = 0, speed_y = 0;
  reader.get("speed-x", speed_x);
  reader.get("speed-y", speed_y);
  speed = Vector(speed_x, speed_y);

  reader.get("acceleration", acceleration);

  set_group(COLGROUP_TOUCHABLE);
}
Beispiel #26
0
void
Tile::parse(const lisp::Lisp& reader)
{
  if(!reader.get("id", id)) {
    throw std::runtime_error("Missing tile-id.");
  }
  
  bool value = false;
  if(reader.get("solid", value) && value)
    attributes |= SOLID;
  if(reader.get("unisolid", value) && value)
    attributes |= UNISOLID | SOLID;
  if(reader.get("brick", value) && value)
    attributes |= BRICK;
  if(reader.get("ice", value) && value)
    attributes |= ICE;
  if(reader.get("water", value) && value)
    attributes |= WATER;
  if(reader.get("hurts", value) && value)
    attributes |= HURTS;
  if(reader.get("fullbox", value) && value)
    attributes |= FULLBOX;
  if(reader.get("coin", value) && value)
    attributes |= COIN;
  if(reader.get("goal", value) && value)
    attributes |= GOAL;

  if(reader.get("north", value) && value)
    data |= WORLDMAP_NORTH;
  if(reader.get("south", value) && value)
    data |= WORLDMAP_SOUTH;
  if(reader.get("west", value) && value)
    data |= WORLDMAP_WEST;
  if(reader.get("east", value) && value) 
    data |= WORLDMAP_EAST;
  if(reader.get("stop", value) && value)
    data |= WORLDMAP_STOP;                      

  reader.get("data", data);
  reader.get("anim-fps", anim_fps);

  if(reader.get("slope-type", data)) {
    attributes |= SOLID | SLOPE;
  }
  
  const lisp::Lisp* images = reader.get_lisp("images");
  if(images)
    parse_images(*images);
}
Beispiel #27
0
void
CloudParticleSystem::parse(const lisp::Lisp& reader)
{
  reader.get("z-pos", z_pos);
}
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();
}