(particles-clouds
(layer -200)
)
+ (path
+ (name "cameraPath1")
+ (circular #f)
+ (nodes
+ (node (x 100) (y 300))
+ (node (x 16000) (y 300) (time 177))
+ )
+ )
(camera
(mode "autoscroll")
- (path
- (point (x 100) (y 300) (speed 90.0))
- (point (x 16000) (y 300) (speed 0.0))
- )
+ (path "cameraPath1")
)
(spawnpoint
(name "main")
(particles-clouds\r
(layer -200)\r
)\r
+ (path \r
+ (name "cameraPath1") \r
+ (circular #f)\r
+ (nodes \r
+ (node (x 100) (y 352)) \r
+ (node (x 18500) (y 352) (time 205)) \r
+ )\r
+ )\r
(camera\r
(mode "autoscroll")\r
- (path\r
- (point (x 100) (y 352) (speed 90.0))\r
- (point (x 18500) (y 352) (speed 0.0))\r
- )\r
+ (path "cameraPath1")\r
)\r
(spawnpoint\r
(name "main")\r
(leveltime\r
(time 350)\r
)\r
+ (path \r
+ (name "cameraPath1") \r
+ (circular #f)\r
+ (nodes \r
+ (node (x 100) (y 170)) \r
+ (node (x 22383) (y 225) (time 223)) \r
+ )\r
+ )\r
(camera\r
(mode "autoscroll")\r
- (path\r
- (point (x 100) (y 170) (speed 100.0))\r
- (point (x 22383) (y 225) (speed 0.0))\r
- )\r
+ (path "cameraPath1")\r
)\r
(spawnpoint\r
(name "main")\r
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
))
+ (path
+ (name "cameraPath1")
+ (circular #f)
+ (nodes
+ (node (x 0) (y 0) (speed 50))
+ (node (x 500) (y 0) (time 10))
+ (node (x 1200) (y 0) (time 3.5))
+ (node (x 3000) (y 0) (time 18))
+ (node (x 1500) (y 0) (time 15))
+ (node (x 99999) (y 0) (time 704))
+ )
+ )
(camera
(mode "autoscroll")
- (path
- (point (x 0) (y 0) (speed 50))
- (point (x 500) (y 0) (speed 200))
- (point (x 1200) (y 0) (speed 100))
- (point (x 3000) (y 0) (speed 100))
- (point (x 1500) (y 0) (speed 140))
- (point (x 99999) (y 0))
- )
- )
+ (path "cameraPath1")
+ )
(background
(image "images/background/semi_arctic.jpg")
))
(camera
(mode "normal")
- (path
- ))
+ )
)
)
)
)
- (platform (use_path "path1") (x 200) (y 850) (type "block1"))
- (platform (use_path "path1") (x 232) (y 850) (type "block3"))
- (platform (use_path "path2") (x 264) (y 850) (type "block1"))
- (platform (use_path "path2") (x 296) (y 850) (type "block3"))
- (platform (use_path "path3") (x 328) (y 850) (type "block1"))
- (platform (use_path "path3") (x 360) (y 850) (type "block3"))
- (platform (use_path "path4") (x 392) (y 850) (type "block1"))
- (platform (use_path "path4") (x 424) (y 850) (type "block3"))
- (platform (use_path "path5") (x 456) (y 850) (type "block1"))
- (platform (use_path "path5") (x 488) (y 850) (type "block3"))
+ (platform (path "path1") (x 200) (y 850) (type "block1"))
+ (platform (path "path1") (x 232) (y 850) (type "block3"))
+ (platform (path "path2") (x 264) (y 850) (type "block1"))
+ (platform (path "path2") (x 296) (y 850) (type "block3"))
+ (platform (path "path3") (x 328) (y 850) (type "block1"))
+ (platform (path "path3") (x 360) (y 850) (type "block3"))
+ (platform (path "path4") (x 392) (y 850) (type "block1"))
+ (platform (path "path4") (x 424) (y 850) (type "block3"))
+ (platform (path "path5") (x 456) (y 850) (type "block1"))
+ (platform (path "path5") (x 488) (y 850) (type "block3"))
(powerup (x 100) (y 700) (sprite "images/powerups/egg/egg.sprite"))
(jumpy (x 140) (y 750))
(spawnpoint (name "main") (x 340) (y 800))
#include "object_factory.hpp"
Camera::Camera(Sector* newsector)
- : sector(newsector), do_backscrolling(true), scrollchange(NONE),
- auto_idx(0), auto_t(0)
+ : sector(newsector), do_backscrolling(true), scrollchange(NONE)
{
mode = NORMAL;
}
reader.get("backscrolling", do_backscrolling);
} else if(modename == "autoscroll") {
mode = AUTOSCROLL;
+ std::string use_path;
- const lisp::Lisp* path_lisp = reader.get_lisp("path");
- if(!path_lisp)
- throw std::runtime_error("No path specified in autoscroll camera.");
-
- lisp::ListIterator iter(path_lisp);
- float speed = .5;
- while(iter.next()) {
- if(iter.item() != "point") {
- std::cerr << "Warning: unknown token '" << iter.item()
- << "' in camera path.\n";
- continue;
- }
- const lisp::Lisp* point_lisp = iter.lisp();
-
- ScrollPoint point;
- if(!point_lisp->get("x", point.position.x) ||
- !point_lisp->get("y", point.position.y)) {
- throw std::runtime_error("x and y missing in point of camerapath");
- }
- point_lisp->get("speed", speed);
- point.speed = speed;
- scrollpoints.push_back(point);
+ if (!reader.get("path", use_path)) throw std::runtime_error("No path specified in autoscroll camera.");
+
+ autoscrollPath = Path::GetByName(use_path);
+ if (autoscrollPath == NULL) {
+ std::cerr << "Warning: Path for autoscroll camera not found! Make sure that the name is spelled correctly and that the path is initialized before the platform in the level file!" << std::endl;
}
+
} else if(modename == "manual") {
mode = MANUAL;
} else {
writer.write_bool("backscrolling", do_backscrolling);
} else if(mode == AUTOSCROLL) {
writer.write_string("mode", "autoscroll");
- writer.start_list("path");
- for(std::vector<ScrollPoint>::iterator i = scrollpoints.begin();
- i != scrollpoints.end(); ++i) {
- writer.start_list("point");
- writer.write_float("x", i->position.x);
- writer.write_float("y", i->position.y);
- writer.write_float("speed", i->speed);
- writer.end_list("point");
- }
-
- writer.end_list("path");
+ writer.write_string("path", autoscrollPath->GetName());
} else if(mode == MANUAL) {
writer.write_string("mode", "manual");
}
if(player->is_dying())
return;
- if(auto_t - elapsed_time >= 0) {
- translation += current_dir * elapsed_time;
- auto_t -= elapsed_time;
- } else {
- // do the rest of the old movement
- translation += current_dir * auto_t;
- elapsed_time -= auto_t;
- auto_t = 0;
-
- // construct path for next point
- if(auto_idx+1 >= scrollpoints.size()) {
- keep_in_bounds(translation);
- return;
- }
- Vector distance = scrollpoints[auto_idx+1].position
- - scrollpoints[auto_idx].position;
- current_dir = distance.unit() * scrollpoints[auto_idx].speed;
- auto_t = distance.norm() / scrollpoints[auto_idx].speed;
-
- // do movement for the remaining time
- translation += current_dir * elapsed_time;
- auto_t -= elapsed_time;
- auto_idx++;
- }
+ translation = autoscrollPath->GetPosition();
keep_in_bounds(translation);
shake();
#include "video/drawing_context.hpp"
#include "serializable.hpp"
#include "timer.hpp"
+#include "object/path.hpp"
namespace lisp {
class Lisp;
LeftRightScrollChange scrollchange;
// autoscroll mode
- class ScrollPoint {
- public:
- Vector position;
- float speed;
- };
- std::vector<ScrollPoint> scrollpoints;
- size_t auto_idx;
- float auto_t;
- Vector current_dir;
+ Path* autoscrollPath;
// shaking
Timer shaketimer;
Path::update(float elapsed_time)
{
+ // TODO: carry excess time over to next node? This is how it was done in camera.cpp:
+ /*
+ if(auto_t - elapsed_time >= 0) {
+ translation += current_dir * elapsed_time;
+ auto_t -= elapsed_time;
+ } else {
+ // do the rest of the old movement
+ translation += current_dir * auto_t;
+ elapsed_time -= auto_t;
+ auto_t = 0;
+
+ // construct path for next point
+ if(auto_idx+1 >= scrollpoints.size()) {
+ keep_in_bounds(translation);
+ return;
+ }
+ Vector distance = scrollpoints[auto_idx+1].position
+ - scrollpoints[auto_idx].position;
+ current_dir = distance.unit() * scrollpoints[auto_idx].speed;
+ auto_t = distance.norm() / scrollpoints[auto_idx].speed;
+
+ // do movement for the remaining time
+ translation += current_dir * elapsed_time;
+ auto_t -= elapsed_time;
+ auto_idx++;
+ }
+ */
+
// advance to next node at scheduled time
if (timeToGo <= 0) {
position = pathNodes[destinationNode].position;
return last_movement;
}
+const std::string
+Path::GetName() {
+ return name;
+}
//////////////////////////////////////////////////////////////////////////////
// static stuff
const Vector& GetPosition();
const Vector& GetLastMovement();
+ const std::string GetName();
+
// WARNING: returns NULL if not found !
static Path* GetByName(const std::string& name);
reader.get("x", bbox.p1.x);
reader.get("y", bbox.p1.y);
reader.get("type", type);
- reader.get("use_path", use_path);
+ reader.get("path", use_path);
sprite = sprite_manager->create("images/objects/flying_platform/platform.sprite");
sprite->set_action(type);
bbox.set_size(sprite->get_width(), sprite->get_height());