From: Ricardo Cruz Date: Mon, 18 Oct 2004 16:52:28 +0000 (+0000) Subject: This is a first implementation of a bridge from BadGuys objects to a config file. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b431d0dbe74fbe0a9a453fd5021fd1d67a02d647;p=supertux.git This is a first implementation of a bridge from BadGuys objects to a config file. Currently, it only keeps sprites. Feel free to suggest other stuff together with how the badguys.strf entry should look like. A lot of bugs like enemies with a different face might occur! Feel free to make a list of the issues, but I'd really appreaciate if you'd fix yourself. ;) SVN-Revision: 2023 --- diff --git a/src/Makefile.am b/src/Makefile.am index 06837def6..7108c23f8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,7 +15,7 @@ supertux_SOURCES = badguy.cpp badguy.h bitmask.cpp bitmask.h camera.cpp \ worldmap.h tile.h tile.cpp tile_manager.h tile_manager.cpp resources.h \ resources.cpp gameobjs.h gameobjs.cpp background.h background.cpp tilemap.h \ tilemap.cpp serializable.h sector.cpp sector.h misc.h misc.cpp defines.h \ - statistics.cpp + statistics.cpp badguy_specs.cpp # EOF # INCLUDES = -I$(top_srcdir)/lib diff --git a/src/badguy.cpp b/src/badguy.cpp index 1d9d19729..71a35ad10 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -35,58 +35,16 @@ #include "sector.h" #include "tilemap.h" #include "statistics.h" - -Sprite* img_mriceblock_flat_left; -Sprite* img_mriceblock_flat_right; -Sprite* img_mriceblock_falling_left; -Sprite* img_mriceblock_falling_right; -Sprite* img_mriceblock_left; -Sprite* img_mriceblock_right; -Sprite* img_jumpy_left_up; -Sprite* img_jumpy_left_down; -Sprite* img_jumpy_left_middle; -Sprite* img_jumpy_left_iced; -Sprite* img_mrbomb_left; -Sprite* img_mrbomb_right; -Sprite* img_mrbomb_iced_left; -Sprite* img_mrbomb_iced_right; -Sprite* img_mrbomb_ticking_left; -Sprite* img_mrbomb_ticking_right; -Sprite* img_mrbomb_explosion; -Sprite* img_stalactite; -Sprite* img_stalactite_broken; -Sprite* img_flame; -Sprite* img_fish; -Sprite* img_fish_down; -Sprite* img_fish_iced; -Sprite* img_fish_iced_down; -Sprite* img_flamefish; -Sprite* img_flamefish_down; -Sprite* img_bouncingsnowball_left; -Sprite* img_bouncingsnowball_right; -Sprite* img_bouncingsnowball_squished; -Sprite* img_flyingsnowball; -Sprite* img_flyingsnowball_squished; -Sprite* img_spiky_left; -Sprite* img_spiky_right; -Sprite* img_spiky_iced_left; -Sprite* img_spiky_iced_right; -Sprite* img_snowball_left; -Sprite* img_snowball_right; -Sprite* img_snowball_squished_left; -Sprite* img_snowball_squished_right; -Sprite* img_wingling_left; -Sprite* img_walkingtree_left; -Sprite* img_walkingtree_left_small; +#include "badguy_specs.h" #define BADGUY_WALK_SPEED .8f #define WINGLING_FLY_SPEED 1.6f BadGuyKind badguykind_from_string(const std::string& str) { - if (str == "money" || str == "jumpy") // was money in old maps + if (str == "jumpy" || str == "money") // was "money" in ancient versions return BAD_JUMPY; - else if (str == "laptop" || str == "mriceblock") // was laptop in old maps + else if (str == "mriceblock" || str == "laptop") // was "laptop" in ancient versions return BAD_MRICEBLOCK; else if (str == "mrbomb") return BAD_MRBOMB; @@ -104,7 +62,7 @@ BadGuyKind badguykind_from_string(const std::string& str) return BAD_FLYINGSNOWBALL; else if (str == "spiky") return BAD_SPIKY; - else if (str == "snowball" || str == "bsod") // was bsod in old maps + else if (str == "snowball" || str == "bsod") // was "bsod" in ancient versions return BAD_SNOWBALL; else if (str == "wingling") return BAD_WINGLING; @@ -208,11 +166,12 @@ BadGuy::init() seen = false; animation_offset = 0; target.x = target.y = -1; - sprite_left = sprite_right = 0; physic.reset(); frozen_timer.init(true); timer.init(true); + specs = badguyspecs_manager->load(badguykind_to_string(kind)); + // if we're in a solid tile at start correct that now if(Sector::current()) { if(kind != BAD_FLAME && kind != BAD_FISH && kind != BAD_FLAMEFISH && collision_object_map(base)) @@ -264,52 +223,48 @@ BadGuy::activate(Direction activation_dir) dir = activation_dir; float dirsign = activation_dir == LEFT ? -1 : 1; + set_action("left", "right"); if(kind == BAD_MRBOMB) { physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0); - set_sprite(img_mrbomb_left, img_mrbomb_right); } else if (kind == BAD_MRICEBLOCK) { physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0); - set_sprite(img_mriceblock_left, img_mriceblock_right); } else if(kind == BAD_JUMPY) { - set_sprite(img_jumpy_left_up, img_jumpy_left_up); + set_action("left-up", "left-up"); } else if(kind == BAD_BOMB) { - set_sprite(img_mrbomb_ticking_left, img_mrbomb_ticking_right); + set_action("ticking-left", "ticking-right"); // hack so that the bomb doesn't hurt until it expldes... dying = DYING_SQUISHED; } else if(kind == BAD_FLAME) { angle = 0; physic.enable_gravity(false); - set_sprite(img_flame, img_flame); + set_action("normal", "normal"); } else if(kind == BAD_BOUNCINGSNOWBALL) { physic.set_velocity(dirsign * 1.3, 0); - set_sprite(img_bouncingsnowball_left, img_bouncingsnowball_right); } else if(kind == BAD_STALACTITE) { physic.enable_gravity(false); - set_sprite(img_stalactite, img_stalactite); + set_action("normal", "normal"); } else if(kind == BAD_FISH) { - set_sprite(img_fish, img_fish); + set_action("normal", "normal"); physic.enable_gravity(true); } else if(kind == BAD_FLAMEFISH) { - set_sprite(img_flamefish, img_flamefish); + set_action("normal", "normal"); physic.enable_gravity(true); } else if(kind == BAD_FLYINGSNOWBALL) { - set_sprite(img_flyingsnowball, img_flyingsnowball); + set_action("normal", "normal"); physic.enable_gravity(false); } else if(kind == BAD_SPIKY) { physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0); - set_sprite(img_spiky_left, img_spiky_right); } else if(kind == BAD_SNOWBALL) { physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0); - set_sprite(img_snowball_left, img_snowball_right); } else if(kind == BAD_WINGLING) { physic.set_velocity(dirsign * WINGLING_FLY_SPEED, 0); physic.enable_gravity(false); - set_sprite(img_wingling_left, img_wingling_left); + set_action("left", "left"); } else if (kind == BAD_WALKINGTREE) { - // TODO: why isn't the height/width being set properly in set_sprite? + // TODO: why isn't the height/width being set properly in set_action? physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0); mode = BGM_BIG; - set_sprite(img_walkingtree_left, img_walkingtree_left); + set_action("left", "left"); base.width = 66; base.height = 66; } @@ -320,6 +275,12 @@ BadGuy::activate(Direction activation_dir) seen = true; } +Surface* +BadGuy::get_image() +{ +return specs->sprite->get_frame(0); +} + void BadGuy::action_mriceblock(double elapsed_time) { @@ -373,7 +334,7 @@ BadGuy::action_mriceblock(double elapsed_time) mode=KICK; tux.kick_timer.start(KICKING_TIME); - set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right); + set_action("flat-left", "flat-right"); physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5); SoundManager::get()->play_sound(IDToSound(SND_KICK), this, Sector::current()->player->get_pos()); } @@ -395,7 +356,7 @@ BadGuy::action_mriceblock(double elapsed_time) if(!timer.check()) { mode = NORMAL; - set_sprite(img_mriceblock_left, img_mriceblock_right); + set_action("left", "right"); physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0); } } @@ -505,7 +466,7 @@ BadGuy::action_jumpy(double elapsed_time) { if(frozen_timer.check()) { - set_sprite(img_jumpy_left_iced, img_jumpy_left_iced); + set_action("left-iced", "left-iced"); return; } @@ -513,11 +474,11 @@ BadGuy::action_jumpy(double elapsed_time) // XXX: These tests *should* use location from ground, not velocity if (fabsf(vy) > 5.6f) - set_sprite(img_jumpy_left_down, img_jumpy_left_down); + set_action("left-down", "left-down"); else if (fabsf(vy) > 5.3f) - set_sprite(img_jumpy_left_middle, img_jumpy_left_middle); + set_action("left-middle", "left-middle"); else - set_sprite(img_jumpy_left_up, img_jumpy_left_up); + set_action("left-up", "left-up"); Player& tux = *Sector::current()->player; @@ -554,7 +515,7 @@ BadGuy::action_mrbomb(double elapsed_time) { if(frozen_timer.check()) { - set_sprite(img_mrbomb_iced_left, img_mrbomb_iced_right); + set_action("iced-left", "iced-right"); return; } @@ -582,7 +543,7 @@ BadGuy::action_bomb(double elapsed_time) } else if(!timer.check()) { if(mode == BOMB_TICKING) { mode = BOMB_EXPLODE; - set_sprite(img_mrbomb_explosion, img_mrbomb_explosion); + set_action("explosion", "explosion"); dying = DYING_NOT; // now the bomb hurts timer.start(EXPLODETIME); @@ -628,7 +589,7 @@ BadGuy::action_stalactite(double elapsed_time) timer.start(2000); dying = DYING_SQUISHED; mode = FLAT; - set_sprite(img_stalactite_broken, img_stalactite_broken); + set_action("broken", "broken"); } } else if(mode == FLAT) { fall(); @@ -658,9 +619,9 @@ BadGuy::action_fish(double elapsed_time) if(frozen_timer.check()) { if(physic.get_velocity_y() < 0) - set_sprite(img_fish_iced_down, img_fish_iced_down); + set_action("iced-down", "iced-down"); else - set_sprite(img_fish_iced, img_fish_iced); + set_action("iced", "iced"); return; } @@ -675,7 +636,7 @@ BadGuy::action_fish(double elapsed_time) && physic.get_velocity_y() <= 0 && mode == NORMAL) { mode = FISH_WAIT; - set_sprite(0, 0); + set_action("hide", "hide"); physic.set_velocity(0, 0); physic.enable_gravity(false); timer.start(WAITTIME); @@ -683,10 +644,7 @@ BadGuy::action_fish(double elapsed_time) else if(mode == FISH_WAIT && !timer.check()) { // jump again - if(kind == BAD_FISH) - set_sprite(img_fish, img_fish); - else // BAD_FLAMEFISH - set_sprite(img_flamefish, img_flamefish); + set_action("normal", "normal"); mode = NORMAL; physic.set_velocity(0, JUMPV); physic.enable_gravity(true); @@ -698,10 +656,7 @@ BadGuy::action_fish(double elapsed_time) if(physic.get_velocity_y() < 0) { - if(kind == BAD_FISH) - set_sprite(img_fish_down, img_fish_down); - else // BAD_FLAMEFISH - set_sprite(img_flamefish_down, img_flamefish_down); + set_action("down", "down"); } } @@ -776,7 +731,7 @@ BadGuy::action_spiky(double elapsed_time) { if(frozen_timer.check()) { - set_sprite(img_spiky_iced_left, img_spiky_iced_right); + set_action("iced-left", "iced-right"); return; } @@ -982,14 +937,19 @@ BadGuy::action(float elapsed_time) void BadGuy::draw(DrawingContext& context) { - Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right; - if(sprite == 0) + if((dir == LEFT && action_left == "hide") || + (dir == RIGHT && action_right == "hide")) return; + if(dir == LEFT) + specs->sprite->set_action(action_left); + else // if(dir == RIGHT) + specs->sprite->set_action(action_right); + if(dying == DYING_FALLING && physic.get_velocity_y() < 0) - sprite->draw(context, Vector(base.x, base.y), LAYER_FOREGROUNDTILES+1, VERTICAL_FLIP); + specs->sprite->draw(context, Vector(base.x, base.y), LAYER_FOREGROUNDTILES+1, VERTICAL_FLIP); else - sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS); + specs->sprite->draw(context, Vector(base.x, base.y), LAYER_OBJECTS); if(debug_mode) context.draw_filled_rect(Vector(base.x, base.y), @@ -997,8 +957,15 @@ BadGuy::draw(DrawingContext& context) } void -BadGuy::set_sprite(Sprite* left, Sprite* right) +BadGuy::set_action(std::string left, std::string right) { + base.width = 32; + base.height = 32; + + action_left = left; + action_right = right; + +#if 0 if (1) { base.width = 32; @@ -1028,6 +995,7 @@ BadGuy::set_sprite(Sprite* left, Sprite* right) animation_offset = 0; sprite_left = left; sprite_right = right; +#endif } void @@ -1081,7 +1049,7 @@ BadGuy::squish(Player* player) /* Flatten! */ SoundManager::get()->play_sound(IDToSound(SND_STOMP), get_pos(), Sector::current()->player->get_pos()); mode = FLAT; - set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right); + set_action("flat-left", "flat-right"); physic.set_velocity_x(0); timer.start(4000); @@ -1099,7 +1067,7 @@ BadGuy::squish(Player* player) mode = KICK; player->kick_timer.start(KICKING_TIME); - set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right); + set_action("flat-left", "flat-right"); } player->bounce(this); @@ -1131,23 +1099,23 @@ BadGuy::squish(Player* player) return; } else if(kind == BAD_BOUNCINGSNOWBALL) { squish_me(player); - set_sprite(img_bouncingsnowball_squished,img_bouncingsnowball_squished); + set_action("squished", "squished"); return; } else if(kind == BAD_FLYINGSNOWBALL) { squish_me(player); - set_sprite(img_flyingsnowball_squished,img_flyingsnowball_squished); + set_action("squished", "squished"); return; } else if(kind == BAD_SNOWBALL) { squish_me(player); - set_sprite(img_snowball_squished_left, img_snowball_squished_right); + set_action("squished-left", "squished-right"); return; } else if(kind == BAD_WINGLING) { squish_me(player); - set_sprite(img_wingling_left, img_wingling_left); + set_action("left", "right"); } else if(kind == BAD_WALKINGTREE) { if (mode == BGM_BIG) { - set_sprite(img_walkingtree_left_small, img_walkingtree_left_small); + set_action("left-small", "left-small"); physic.set_velocity_x(physic.get_velocity_x() * 2.0f); /* Move to the player's direction */ @@ -1182,7 +1150,7 @@ BadGuy::kill_me(int score) dying = DYING_FALLING; if(kind == BAD_MRICEBLOCK) { - set_sprite(img_mriceblock_falling_left, img_mriceblock_falling_right); + set_action("falling-left", "falling-right"); if(mode == HELD) { mode = NORMAL; Player& tux = *Sector::current()->player; @@ -1379,64 +1347,11 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type) mode = KICK; player->kick_timer.start(KICKING_TIME); - set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right); + set_action("flat-left", "flat-right"); } break; } } - -//--------------------------------------------------------------------------- - -void load_badguy_gfx() -{ - img_mriceblock_flat_left = sprite_manager->load("mriceblock-flat-left"); - img_mriceblock_flat_right = sprite_manager->load("mriceblock-flat-right"); - img_mriceblock_falling_left = sprite_manager->load("mriceblock-falling-left"); - img_mriceblock_falling_right = sprite_manager->load("mriceblock-falling-right"); - img_mriceblock_left = sprite_manager->load("mriceblock-left"); - img_mriceblock_right = sprite_manager->load("mriceblock-right"); - img_jumpy_left_up = sprite_manager->load("jumpy-left-up"); - img_jumpy_left_down = sprite_manager->load("jumpy-left-down"); - img_jumpy_left_middle = sprite_manager->load("jumpy-left-middle"); - img_jumpy_left_iced = sprite_manager->load("jumpy-left-iced"); - img_mrbomb_left = sprite_manager->load("mrbomb-left"); - img_mrbomb_right = sprite_manager->load("mrbomb-right"); - img_mrbomb_iced_left = sprite_manager->load("mrbomb-iced-left"); - img_mrbomb_iced_right = sprite_manager->load("mrbomb-iced-right"); - img_mrbomb_ticking_left = sprite_manager->load("mrbomb-ticking-left"); - img_mrbomb_ticking_right = sprite_manager->load("mrbomb-ticking-right"); - img_mrbomb_explosion = sprite_manager->load("mrbomb-explosion"); - img_stalactite = sprite_manager->load("stalactite"); - img_stalactite_broken = sprite_manager->load("stalactite-broken"); - img_flame = sprite_manager->load("flame"); - img_fish = sprite_manager->load("fish"); - img_fish_down = sprite_manager->load("fish-down"); - img_fish_iced = sprite_manager->load("fish-iced"); - img_fish_iced_down = sprite_manager->load("fish-iced-down"); - img_flamefish = sprite_manager->load("flamefish"); - img_flamefish_down = sprite_manager->load("flamefish-down"); - img_bouncingsnowball_left = sprite_manager->load("bouncingsnowball-left"); - img_bouncingsnowball_right = sprite_manager->load("bouncingsnowball-right"); - img_bouncingsnowball_squished = sprite_manager->load("bouncingsnowball-squished"); - img_flyingsnowball = sprite_manager->load("flyingsnowball"); - img_flyingsnowball_squished = sprite_manager->load("flyingsnowball-squished"); - img_spiky_left = sprite_manager->load("spiky-left"); - img_spiky_right = sprite_manager->load("spiky-right"); - img_spiky_iced_left = sprite_manager->load("spiky-iced-left"); - img_spiky_iced_right = sprite_manager->load("spiky-iced-right"); - img_snowball_left = sprite_manager->load("snowball-left"); - img_snowball_right = sprite_manager->load("snowball-right"); - img_snowball_squished_left = sprite_manager->load("snowball-squished-left"); - img_snowball_squished_right = sprite_manager->load("snowball-squished-right"); - img_wingling_left = sprite_manager->load("wingling-left"); - img_walkingtree_left = sprite_manager->load("walkingtree-left"); - img_walkingtree_left_small = sprite_manager->load("walkingtree-left-small"); -} - -void free_badguy_gfx() -{ -} - // EOF // diff --git a/src/badguy.h b/src/badguy.h index c4893201b..3ec189bbe 100644 --- a/src/badguy.h +++ b/src/badguy.h @@ -25,10 +25,9 @@ #include "SDL.h" +#include "utils/lispreader.h" #include "special/timer.h" -#include "video/surface.h" #include "math/physic.h" -#include "special/sprite.h" #include "defines.h" #include "special/moving_object.h" #include "collision.h" @@ -64,10 +63,9 @@ enum BadGuyKind { BadGuyKind badguykind_from_string(const std::string& str); std::string badguykind_to_string(BadGuyKind kind); -void load_badguy_gfx(); -void free_badguy_gfx(); class Player; +class BadGuySpecs; /* Badguy type: */ class BadGuy : public MovingObject, public Serializable @@ -120,8 +118,9 @@ private: Physic physic; float angle; - Sprite* sprite_left; - Sprite* sprite_right; + std::string action_left, action_right; + + BadGuySpecs* specs; int animation_offset; @@ -147,8 +146,7 @@ public: /** initializes the badguy (when he appears on screen) */ void activate(Direction direction); // should only be used by BadGuy's objects - Surface* get_image() - { return sprite_left->get_frame(0); } + Surface* get_image(); private: void init(); @@ -184,8 +182,8 @@ private: void squish(Player* player); /** squish ourself, give player score and set dying to DYING_SQICHED */ void squish_me(Player* player); - /** set image of the badguy */ - void set_sprite(Sprite* left, Sprite* right); + /** set sprite's action of the badguy */ + void set_action(std::string action_left, std::string action_right); }; #endif /*SUPERTUX_BADGUY_H*/ diff --git a/src/badguy_specs.cpp b/src/badguy_specs.cpp new file mode 100644 index 000000000..bf139b1f5 --- /dev/null +++ b/src/badguy_specs.cpp @@ -0,0 +1,157 @@ +/*************************************************************************** + badguy_specs.cpp - badguys properties table + ------------------- + begin : Oct, 11 2004 + copyright : (C) 2004 by Ricardo Cruz + email : rick2@aeiou.pt + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include + +#include "special/sprite_manager.h" +#include "resources.h" + +#include "badguy_specs.h" + +BadGuySpecsManager* badguyspecs_manager = 0; + +BadGuySpecsManager::BadGuySpecsManager(const std::string& filename) +{ + load_resfile(filename); +} + +BadGuySpecsManager::~BadGuySpecsManager() +{ + for(std::map::iterator i = + badguys_specs.begin(); i != badguys_specs.end(); ++i) + delete i->second; +} + +void +BadGuySpecsManager::load_resfile(const std::string& filename) +{ + lisp_object_t* root_obj = lisp_read_from_file(filename); + if (!root_obj) + { + std::cout << "BadGuySpecsManager: Couldn't load: " << filename << std::endl; + return; + } + + lisp_object_t* cur = root_obj; + + if (strcmp(lisp_symbol(lisp_car(cur)), "supertux-badguys-specifications") != 0) + return; + cur = lisp_cdr(cur); + + while(cur) + { + lisp_object_t* el = lisp_car(cur); + + if (strcmp(lisp_symbol(lisp_car(el)), "badguy") == 0) + { + LispReader reader(lisp_cdr(lisp_car(cur))); + BadGuySpecs* badguy_specs = new BadGuySpecs(reader); + + BadGuysSpecs::iterator i = badguys_specs.find(badguy_specs->get_name()); + if (i == badguys_specs.end()) + { + badguys_specs[badguy_specs->get_name()] = badguy_specs; + } + else + { + delete i->second; + i->second = badguy_specs; + std::cerr << "Warning: dulpicate entry: '" << badguy_specs->get_name() << "'" << std::endl; + } + } + else + { + std::cout << "BadGuySpecsManager: Unknown tag" << std::endl; + } + + cur = lisp_cdr(cur); + } + + lisp_free(root_obj); +} + +BadGuySpecs* +BadGuySpecsManager::load(const std::string& name) +{ + BadGuysSpecs::iterator i = badguys_specs.find(name); + if (i == badguys_specs.end()) + { + std::cerr << "Warning: BadGuy specification '" << name << "' not found" << std::endl; + return 0; + } + return i->second; +} + +BadGuySpecs::BadGuySpecs(LispReader& reader) +{ + reset(); + + std::string str; + reader.read_string("kind", str); + kind = str; + + str.clear(); + reader.read_string("inherits", str); + if(!str.empty()) + { + BadGuySpecs* bgspecs = badguyspecs_manager->load(str); + if(bgspecs) + { + sprite = bgspecs->sprite; + } + else + std::cerr << "Warning: inherited '" << str + << "was not found.\nProbably, it was declared after" + "this entry '" << kind << std::endl; + } + + str.clear(); + reader.read_string("sprite", str); + if(str.empty()) + std::cerr << "Warning: No sprite has been set to badguy " << kind << std::endl; + else + sprite = sprite_manager->load(str); + + if(!sprite) + { + std::cerr << "Warning: Sprite '" << str << "' could not be loaded.\n"; + } +} + +BadGuySpecs::BadGuySpecs(std::string& kind_) +{ + reset(); + kind = kind_; +} + +BadGuySpecs::~BadGuySpecs() +{ +} + +void +BadGuySpecs::reset() +{ + kind.clear(); +} + +std::string +BadGuySpecs::get_name() +{ +return kind; +} + +// EOF // diff --git a/src/badguy_specs.h b/src/badguy_specs.h new file mode 100644 index 000000000..9d3d851b3 --- /dev/null +++ b/src/badguy_specs.h @@ -0,0 +1,71 @@ +/*************************************************************************** + badguy_specs.h - badguys properties table + ------------------- + begin : Oct, 11 2004 + copyright : (C) 2004 by Ricardo Cruz + email : rick2@aeiou.pt + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef SUPERTUX_BADGUY_SPECS_H +#define SUPERTUX_BADGUY_SPECS_H + +#include +#include + +#include "utils/lispreader.h" + +using namespace SuperTux; + +namespace SuperTux { +class Sprite; +} + +class BadGuySpecs; +class BadGuySpecsManager; +extern BadGuySpecsManager* badguyspecs_manager; + +class BadGuySpecsManager +{ +public: + BadGuySpecsManager(const std::string& filename); + ~BadGuySpecsManager(); + + void load_resfile(const std::string& filename); + /** loads a sprite. + * WARNING: You must not delete the returned object. + */ + BadGuySpecs* load(const std::string& name); + +private: + typedef std::map BadGuysSpecs; + BadGuysSpecs badguys_specs; +}; + +class BadGuySpecs +{ +public: + BadGuySpecs(LispReader& reader); + BadGuySpecs(std::string& kind); + ~BadGuySpecs(); + + std::string get_name(); + + // proprities + std::string kind; + Sprite* sprite; + +private: + void reset(); +}; + + +#endif /*SUPERTUX_BADGUY_SPECS_H*/ diff --git a/src/camera.cpp b/src/camera.cpp index a4c5aba4f..52481fc6f 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -22,6 +22,7 @@ #include #include "camera.h" +#include "utils/lispreader.h" #include "utils/lispwriter.h" #include "player.h" #include "tilemap.h" diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 623a51355..c423e186f 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -992,7 +992,7 @@ for(unsigned int i = 0; i < sizeof(text) / sizeof(text[0]); i++) context.draw_text(blue_text, _("- Level Editor's Help -"), Vector(screen->w/2, 60), CENTER_ALLIGN, LAYER_GUI); - context.draw_text(white_small_text, *text[i], Vector(20, 120), LEFT_ALLIGN, LAYER_GUI); + context.draw_text(white_small_text, *text[i], Vector(/*20*/screen->w/2, 120), CENTER_ALLIGN, LAYER_GUI); sprintf(str,_("Press any key to continue - Page %d/%d"), i+1, sizeof(text) / sizeof(text[0])); context.draw_text(gold_text, str, Vector(screen->w/2, screen->h-60), CENTER_ALLIGN, LAYER_GUI); diff --git a/src/resources.cpp b/src/resources.cpp index be7efec2d..a39da2af3 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -18,17 +18,18 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "app/globals.h" +#include "special/sprite_manager.h" +#include "audio/sound_manager.h" +#include "app/setup.h" +#include "gui/button.h" #include "scene.h" #include "player.h" #include "badguy.h" #include "gameobjs.h" #include "special.h" #include "resources.h" -#include "special/sprite_manager.h" -#include "audio/sound_manager.h" -#include "app/setup.h" #include "door.h" -#include "gui/button.h" +#include "badguy_specs.h" Surface* img_waves[3]; Surface* img_water; @@ -157,6 +158,9 @@ void loadshared() ice_tux->arms = sprite_manager->load("big-tux-arms"); ice_tux->feet = sprite_manager->load("big-tux-feet"); + /* Load Bad Guys resources */ + badguyspecs_manager = new BadGuySpecsManager(datadir + "/badguys.strf"); + /* Water: */ img_water = new Surface(datadir + "/images/shared/water.png", false); @@ -213,10 +217,6 @@ void loadshared() img_cloud[1][3] = new Surface(datadir + "/images/shared/cloud-13.png", true); - - /* Bad guys: */ - load_badguy_gfx(); - /* Upgrades: */ load_special_gfx(); @@ -286,7 +286,6 @@ void unloadshared(void) int i; free_special_gfx(); - free_badguy_gfx(); delete img_water; for (i = 0; i < 3; i++)