X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject_factory.cpp;h=667a12f36ceaa3fb4e7fe22e5045508914860c69;hb=91b33d11d2555eb2672b9a9882a224c19e2fcb98;hp=afae27fee9449ddd8b0cd709e8f461f8859f832d;hpb=07ddaed2a657e4d2a3d038fed223fc5827159caf;p=supertux.git diff --git a/src/object_factory.cpp b/src/object_factory.cpp index afae27fee..667a12f36 100644 --- a/src/object_factory.cpp +++ b/src/object_factory.cpp @@ -25,13 +25,12 @@ #include "lisp/lisp.hpp" #include "lisp/parser.hpp" #include "object_factory.hpp" - -Factories* object_factories = 0; +#include "math/vector.hpp" GameObject* create_object(const std::string& name, const lisp::Lisp& reader) { - Factories::iterator i = object_factories->find(name); - if(i == object_factories->end()) { + Factory::Factories::iterator i = Factory::get_factories().find(name); + if(i == Factory::get_factories().end()) { std::stringstream msg; msg << "No factory for object '" << name << "' found."; throw std::runtime_error(msg.str()); @@ -43,11 +42,27 @@ GameObject* create_object(const std::string& name, const lisp::Lisp& reader) GameObject* create_object(const std::string& name, const Vector& pos) { std::stringstream lisptext; - lisptext << "(" << name - << " (x " << pos.x << ")" + lisptext << "((x " << pos.x << ")" << " (y " << pos.y << "))"; - + lisp::Parser parser; - std::auto_ptr lisp (parser.parse(lisptext)); - return create_object(name, *lisp); + const lisp::Lisp* lisp = parser.parse(lisptext, "create_object"); + GameObject* object = create_object(name, *(lisp->get_car())); + + return object; } + +GameObject* create_badguy_object(const std::string& name, const Vector& pos, const Direction dir) +{ + std::stringstream lisptext; + lisptext << "((x " << pos.x << ")" + << " (y " << pos.y << ")" + << " (direction " << dir << "))"; + + lisp::Parser parser; + const lisp::Lisp* lisp = parser.parse(lisptext, "create_object"); + GameObject* object = create_object(name, *(lisp->get_car())); + + return object; +} +