--- /dev/null
+(supertux-sprite
+ (action
+ (name "left")
+ (fps 6)
+ (x-offset 0)
+ (y-offset 40)
+ (images "walk-1.png" "walk-2.png")
+ )
+
+ (action
+ (name "right")
+ (fps 6)
+ (x-offset 0)
+ (y-offset 40)
+ (mirror-action "left")
+ )
+
+ (action
+ (name "stand")
+ (x-offset 0)
+ (y-offset 40)
+ (images "stand.png"))
+
+ (action
+ (name "throw")
+ (fps 6)
+ (x-offset 0)
+ (y-offset 40)
+ (images "throw.png"))
+
+ (action
+ (name "jump")
+ (x-offset 0)
+ (y-offset 40)
+ (images "jump.png"))
+
+ (action
+ (name "dead")
+ (x-offset 0)
+ (y-offset 0)
+ (images "dead.png")
+ )
+)
+
--- /dev/null
+(supertux-sprite
+ (action
+ (name "right")
+ (images "yeti_b.png")
+ )
+ (action
+ (name "left")
+ (mirror-action "right")
+ )
+)
+
--- /dev/null
+(supertux-sprite
+ (action
+ (name "default")
+ (images "blue-potion.png")
+ )
+)
--- /dev/null
+(supertux-sprite
+ (action
+ (name "default")
+ (images "red-potion.png")
+ )
+)
(y-offset 32)
(mirror-action "explosion-left")))
- ; Dummyguy
- (sprite (name "dummyguy")
- (action
- (name "left")
- (fps 6)
- (x-offset 0)
- (y-offset 40)
- (images "creatures/dummyguy/walk-1.png"
- "creatures/dummyguy/walk-2.png"))
-
- (action
- (name "right")
- (fps 6)
- (x-offset 0)
- (y-offset 40)
- (mirror-action "left"))
-
- (action
- (name "stand")
- (x-offset 0)
- (y-offset 40)
- (images "creatures/dummyguy/stand.png"))
-
- (action
- (name "throw")
- (fps 6)
- (x-offset 0)
- (y-offset 40)
- (images "creatures/dummyguy/throw.png"))
-
- (action
- (name "jump")
- (x-offset 0)
- (y-offset 40)
- (images "creatures/dummyguy/jump.png"))
-
- (action
- (name "dead")
- (x-offset 0)
- (y-offset 0)
- (images "creatures/dummyguy/dead.png")))
-
-
; MrTree
(sprite (name "mrtree")
(action
"objects/hatch/hatch-5.png"))
)
- (sprite (name "yeti")
- (action
- (name "right")
- (images "creatures/yeti/yeti_b.png")
- )
- (action
- (name "left")
- (mirror-action "right")
- )
- )
-
- (sprite
- (name "red-potion")
- (action
- (name "default")
- (images "powerups/potions/red-potion.png")
- )
- )
-
- (sprite
- (name "blue-potion")
- (action
- (name "default")
- (images "powerups/potions/blue-potion.png")
- )
- )
-
(sprite
(name "lightmap_light")
(action
(images "objects/keys/outline_gold.png")
)
)
- (sprite
- (name "leveldot")
- (action
- (name "default")
- (x-offset 16)
- (y-offset 16)
- (images "worldmap/common/leveldot_red.png")
- )
- (action
- (name "solved")
- (x-offset 16)
- (y-offset 16)
- (images "worldmap/common/leveldot_green.png")
- )
- )
)
(bonusblock (x 96) (y 800)
(contents "custom")
(powerup
- (sprite "red-potion")
+ (sprite "images/powerups/potions/red-potion.sprite")
(script "
-function wait(time) {
- set_wakeup_time(time);
- suspend();
-}
-
DisplayEffect.set_black(true);
wait(0.1);
DisplayEffect.set_black(false);
(bonusblock (x 470) (y 96)
(contents "custom")
(powerup
- (sprite "blue-potion")
+ (sprite "images/powerups/potions/blue-potion.sprite")
(script "
-function wait(time) {
- set_wakeup_time(time);
- suspend();
-}
DisplayEffect.fade_out(1);
wait(1);
Level.flip_vertically();
(powerup (x 980) (y 140) (sprite "egg"))
(powerup (x 1020) (y 140) (sprite "1up"))
(powerup (x 1400) (y 140)
- (sprite "red-potion")
+ (sprite "images/powerups/potions/images/powerups/potions/red-potion.sprite.sprite")
(contents "custom")
(script "Level.flip_vertically();")
)
(name "PENNY")
(x 390)
(y 510)
- (sprite "dummyguy")
+ (sprite "images/creatures/dummyguy/dummyguy.sprite")
)
(init-script "intro();")
)
(bonusblock (x 160) (y 160)
(contents "custom")
(powerup
- (sprite "red-potion")
+ (sprite "images/powerups/potions/images/powerups/potions/red-potion.sprite.sprite")
(script "
function wait(time) {
set_wakeup_time(time);
(name "TUX")
(x 160)
(y 448)
- (sprite "yeti")
+ (sprite "images/creatues/yeti/yeti.sprite")
)
(scriptedobject
(name "PENNY")
(x 390)
(y 448)
- (sprite "dummyguy")
+ (sprite "images/creatures/dummyguy/dummyguy.sprite")
)
(scriptedobject
(name "NOLOK")
(x 420)
(y 94)
- (sprite "dummyguy")
+ (sprite "images/creatures/dummyguy/dummyguy.sprite")
(visible #f)
(physic-enabled #f)
(solid #f)
(bonusblock (x 160) (y 288)
(contents "custom")
(powerup
- (sprite "red-potion")
+ (sprite "images/powerups/potions/images/powerups/potions/red-potion.sprite.sprite")
(script "
DisplayEffect.set_black(true);
wait(0.1);
Text.set_text(\"You made it!\");
Text.set_font(\"big\");
Text.fade_in(1.5);
-set_wakeup_time(4);
-suspend();
+wait(4);
DisplayEffect.fade_out(1.5);
-set_wakeup_time(1.5);
-suspend();
+wait(1.5);
Level.finish();
")
)
reader.get("x", start_position.x);
reader.get("y", start_position.y);
bbox.set_size(80, 120);
- sprite = sprite_manager->create("yeti");
+ sprite = sprite_manager->create("images/creatures/yeti/yeti.sprite");
sprite->set_action("right");
state = INIT;
side = LEFT;
#include "game_session.hpp"
#include "gameobjs.hpp"
#include "sprite/sprite_manager.hpp"
+#include "sprite/sprite.hpp"
#include "resources.hpp"
#include "sector.hpp"
#include "tilemap.hpp"
ScriptInterpreter::run_script(std::istream& in, const std::string& sourcename,
bool remove_when_terminated)
{
- printf("Stackbefore:\n");
- print_squirrel_stack(v);
if(sq_compile(v, squirrel_read_char, &in, sourcename.c_str(), true) < 0)
throw Scripting::SquirrelError(v, "Couldn't parse script");
if(remove_when_terminated) {
remove_me();
}
- printf("ended.\n");
// remove closure from stack
sq_pop(v, 1);
}
- printf("After:\n");
- print_squirrel_stack(v);
}
void
delete *i;
}
-SpriteData::SpriteData(const lisp::Lisp* lisp)
+SpriteData::SpriteData(const lisp::Lisp* lisp, const std::string& basedir)
{
lisp::ListIterator iter(lisp);
while(iter.next()) {
if(iter.item() == "name") {
iter.value()->get(name);
} else if(iter.item() == "action") {
- parse_action(iter.lisp());
+ parse_action(iter.lisp(), basedir);
} else {
std::cerr << "Unknown sprite field: " << iter.item() << "\n";
}
}
- if(name.empty())
- throw std::runtime_error("Error: Sprite wihtout name.");
if(actions.empty())
throw std::runtime_error("Error: Sprite wihtout actions.");
}
}
void
-SpriteData::parse_action(const lisp::Lisp* lisp)
+SpriteData::parse_action(const lisp::Lisp* lisp, const std::string& basedir)
{
Action* action = new Action;
}
for(std::vector<std::string>::size_type i = 0; i < images.size(); i++) {
- action->surfaces.push_back(new Surface("images/" + images[i], true));
+ action->surfaces.push_back(new Surface(basedir + images[i], true));
}
}
actions[action->name] = action;
class SpriteData
{
public:
- /** cur has to be a pointer to data in the form of ((x-offset 5)
- (y-offset 10) ...) */
- SpriteData(const lisp::Lisp* cur);
- ~SpriteData();
+ /** cur has to be a pointer to data in the form of ((x-offset 5)
+ (y-offset 10) ...) */
+ SpriteData(const lisp::Lisp* cur, const std::string& basedir);
+ ~SpriteData();
- const std::string& get_name() const
- {
- return name;
- }
+ const std::string& get_name() const
+ {
+ return name;
+ }
private:
- friend class Sprite;
+ friend class Sprite;
- struct Action
- {
- Action();
- ~Action();
-
- std::string name;
+ struct Action
+ {
+ Action();
+ ~Action();
- /** Position correction */
- int x_offset;
- int y_offset;
- /** Drawing priority in queue */
- int z_order;
+ std::string name;
- /** Frames per second */
- float fps;
+ /** Position correction */
+ int x_offset;
+ int y_offset;
+ /** Drawing priority in queue */
+ int z_order;
- std::vector<Surface*> surfaces;
- };
+ /** Frames per second */
+ float fps;
- typedef std::map <std::string, Action*> Actions;
- Actions actions;
+ std::vector<Surface*> surfaces;
+ };
- void parse_action(const lisp::Lisp* lispreader);
- /** Get an action */
- Action* get_action(std::string act);
+ typedef std::map <std::string, Action*> Actions;
+ Actions actions;
- std::string name;
+ void parse_action(const lisp::Lisp* lispreader, const std::string& basedir);
+ /** Get an action */
+ Action* get_action(std::string act);
+
+ std::string name;
};
#endif
#include "lisp/lisp.hpp"
#include "lisp/parser.hpp"
#include "lisp/list_iterator.hpp"
+#include "file_system.hpp"
SpriteManager::SpriteManager(const std::string& filename)
{
lisp::ListIterator iter(resources);
while(iter.next()) {
if(iter.item() == "sprite") {
- SpriteData* spritedata = new SpriteData(iter.lisp());
+ SpriteData* spritedata = new SpriteData(iter.lisp(), "images/");
Sprites::iterator i = sprites.find(spritedata->get_name());
if (i == sprites.end()) {
SpriteManager::create(const std::string& name)
{
Sprites::iterator i = sprites.find(name);
+ SpriteData* data;
if(i == sprites.end()) {
- std::stringstream msg;
- msg << "Sprite '" << name << "' not found.";
+ // try loading the spritefile
+ data = load(name);
+ if(data == NULL) {
+ std::stringstream msg;
+ msg << "Sprite '" << name << "' not found.";
+ throw std::runtime_error(msg.str());
+ }
+ } else {
+ data = i->second;
+ }
+
+ return new Sprite(*data);
+}
+
+SpriteData*
+SpriteManager::load(const std::string& filename)
+{
+ lisp::Parser parser;
+ std::auto_ptr<lisp::Lisp> root (parser.parse(filename));
+
+ const lisp::Lisp* sprite = root->get_lisp("supertux-sprite");
+ if(!sprite) {
+ std::ostringstream msg;
+ msg << "'" << filename << "' is not a supertux-sprite file";
throw std::runtime_error(msg.str());
}
- return new Sprite(*i->second);
+
+ std::auto_ptr<SpriteData> data (
+ new SpriteData(sprite, FileSystem::dirname(filename)) );
+ sprites[filename] = data.release();
+
+ return sprites[filename];
}
#include <map>
-#include "sprite.hpp"
+class SpriteData;
+class Sprite;
class SpriteManager
{
private:
- typedef std::map<std::string, SpriteData*> Sprites;
- Sprites sprites;
+ typedef std::map<std::string, SpriteData*> Sprites;
+ Sprites sprites;
+
public:
- SpriteManager(const std::string& filename);
- ~SpriteManager();
+ SpriteManager(const std::string& filename);
+ ~SpriteManager();
- void load_resfile(const std::string& filename);
- /** loads a sprite.
- * (contrary to the old api you have to delete the sprite!)
- */
- Sprite* create(const std::string& name);
+ void load_resfile(const std::string& filename);
+ /** loads a sprite. */
+ Sprite* create(const std::string& filename);
+
+private:
+ SpriteData* load(const std::string& filename);
};
#endif
level.south = true;
level.west = true;
- std::string sprite = "leveldot";
+ std::string sprite = "images/worldmap/common/leveldot.sprite";
level_lisp->get("sprite", sprite);
level.sprite = sprite_manager->create(sprite);