function intro()
{
- DisplayEffect.sixteen_to_nine();
- PENNY.set_action("stand");
- Text.set_centered(true);
- Text.set_text(translate("SuperTux\nMilestone 2"));
- Text.fade_in(2);
- wait(4);
- Text.fade_out(1);
+ Tux.deactivate();
+ Tux.set_visible(false);
+ DisplayEffect.sixteen_to_nine(0);
+ DisplayEffect.fade_in(2);
+ Camera.scroll_to(0, 945, 15);
+ // Sound.play_music("music/tux_intro.ogg");
+ wait(2);
+
+ wait(20);
+
+ Level.finish();
}
+
(author "No Author")
(sector
(name "main")
- (init-script "")
+ (init-script "intro()")
+ (music "tux_intro.ogg")
(gravity 10.000000)
(tilemap
(layer "background")
exit_status = ES_LEVEL_FINISHED;
// don't add points to stats though...
}
+ if(main_controller->check_cheatcode("camera")) {
+ std::cout << "Camera is at "
+ << Sector::current()->camera->get_translation().x << ","
+ << Sector::current()->camera->get_translation().y << "\n";
+ }
}
void
translation.y = tuxpos.y - SCREEN_HEIGHT/2;
shakespeed = 0;
shaketimer.stop();
- keep_in_bounds();
+ keep_in_bounds(translation);
}
void
shakespeed = M_PI/2 / time;
}
+void
+Camera::scroll_to(const Vector& goal, float scrolltime)
+{
+ scroll_from = translation;
+ scroll_goal = goal;
+ keep_in_bounds(scroll_goal);
+
+ scroll_to_pos = 0;
+ scrollspeed = 1.0 / scrolltime;
+ mode = SCROLLTO;
+}
+
static const float EPSILON = .00001;
static const float max_speed_y = 140;
void
Camera::update(float elapsed_time)
{
- if(mode == NORMAL)
- scroll_normal(elapsed_time);
- else if(mode == AUTOSCROLL)
- scroll_autoscroll(elapsed_time);
+ switch(mode) {
+ case NORMAL:
+ update_scroll_normal(elapsed_time);
+ break;
+ case AUTOSCROLL:
+ update_scroll_autoscroll(elapsed_time);
+ break;
+ case SCROLLTO:
+ update_scroll_to(elapsed_time);
+ break;
+ default:
+ break;
+ }
}
void
-Camera::keep_in_bounds()
+Camera::keep_in_bounds(Vector& translation)
{
float width = sector->solids->get_width() * 32;
float height = sector->solids->get_height() * 32;
}
void
-Camera::scroll_normal(float elapsed_time)
+Camera::update_scroll_normal(float elapsed_time)
{
assert(sector != 0);
Player* player = sector->player;
// apply scrolling
translation.x -= speed_x * elapsed_time;
- keep_in_bounds();
+ keep_in_bounds(translation);
shake();
}
void
-Camera::scroll_autoscroll(float elapsed_time)
+Camera::update_scroll_autoscroll(float elapsed_time)
{
Player* player = sector->player;
// construct path for next point
if(auto_idx+1 >= scrollpoints.size()) {
- keep_in_bounds();
+ keep_in_bounds(translation);
return;
}
Vector distance = scrollpoints[auto_idx+1].position
auto_idx++;
}
- keep_in_bounds();
+ keep_in_bounds(translation);
shake();
}
+void
+Camera::update_scroll_to(float elapsed_time)
+{
+ scroll_to_pos += elapsed_time * scrollspeed;
+ if(scroll_to_pos >= 1.0) {
+ mode = MANUAL;
+ translation = scroll_goal;
+ return;
+ }
+
+ translation = (scroll_goal - scroll_from) * scroll_to_pos;
+}
+
translation.y = scroll_y;
}
+ /**
+ * scroll the upper left edge of the camera in scrolltime seconds
+ * to the position goal
+ */
+ void scroll_to(const Vector& goal, float scrolltime);
+
enum CameraMode
{
- NORMAL, AUTOSCROLL, MANUAL
+ NORMAL, AUTOSCROLL, SCROLLTO, MANUAL
};
CameraMode mode;
private:
- void scroll_normal(float elapsed_time);
- void scroll_autoscroll(float elapsed_time);
- void keep_in_bounds();
+ void update_scroll_normal(float elapsed_time);
+ void update_scroll_autoscroll(float elapsed_time);
+ void update_scroll_to(float elapsed_time);
+ void keep_in_bounds(Vector& vector);
void shake();
enum LeftRightScrollChange
{
NONE, LEFT, RIGHT
};
-
+
Vector translation;
Sector* sector;
float shakespeed;
float shakedepth_x;
float shakedepth_y;
+
+ // scrollto mode
+ Vector scroll_from;
+ Vector scroll_goal;
+ float scroll_to_pos;
+ float scrollspeed;
};
#endif /*SUPERTUX_CAMERA_H*/
#include <string>
#include <stdio.h>
-#include "camera.hpp"
+#include "object/camera.hpp"
+#include "scripting/camera.hpp"
+#include "math/vector.hpp"
#define NOIMPL printf("%s not implemented.\n", __PRETTY_FUNCTION__);
namespace Scripting
{
- Camera::Camera()
+ Camera::Camera(::Camera* camera)
+ : camera(camera)
{ }
Camera::~Camera()
Camera::set_mode(const std::string& )
{
NOIMPL;
- }
+ }
+
+ void
+ Camera::scroll_to(float x, float y, float scrolltime)
+ {
+ camera->scroll_to(Vector(x, y), scrolltime);
+ }
}
#ifndef __CAMERA_H__
#define __CAMERA_H__
+#ifndef SCRIPTING_API
+class Camera;
+typedef Camera _Camera;
+#endif
+
namespace Scripting
{
{
public:
#ifndef SCRIPTING_API
- Camera();
- ~Camera();
+ Camera(_Camera* camera);
+ ~Camera();
#endif
- /** Shake the camera */
- void shake(float speed, float x, float y);
- /** Set camera to a specific coordinate */
- void set_pos(float x, float y);
- /** Set camera to a specific mode, can be "normal", "manual" */
- void set_mode(const std::string& mode);
+ /** Shake the camera */
+ void shake(float speed, float x, float y);
+ /** Set camera to a specific coordinate */
+ void set_pos(float x, float y);
+ /** Set camera to a specific mode, can be "normal", "manual" */
+ void set_mode(const std::string& mode);
+ /** Scroll camera to position x,y in scrolltime seconds */
+ void scroll_to(float x, float y, float scrolltime);
+
+#ifndef SCRIPTING_API
+ _Camera* camera;
+#endif
};
}
ScriptInterpreter* ScriptInterpreter::_current = 0;
ScriptInterpreter::ScriptInterpreter(const std::string& new_working_directory)
- : working_directory(new_working_directory), sound(0), level(0)
+ : working_directory(new_working_directory), sound(0), level(0), camera(0)
{
v = sq_open(1024);
if(v == 0)
Scripting::DisplayEffect* display_effect_api
= static_cast<Scripting::DisplayEffect*> (display_effect);
expose_object(display_effect_api, "DisplayEffect");
+
+ Scripting::Camera* camera = new Scripting::Camera(sector->camera);
+ expose_object(camera, "Camera");
}
ScriptInterpreter::~ScriptInterpreter()
sq_close(v);
delete sound;
delete level;
+ delete camera;
}
static SQInteger squirrel_read_char(SQUserPointer file)
#include "scripting/sound.hpp"
#include "scripting/level.hpp"
#include "scripting/squirrel_error.hpp"
+#include "scripting/camera.hpp"
class Sector;
std::string working_directory;
Scripting::Sound* sound;
Scripting::Level* level;
+ Scripting::Camera* camera;
};
#endif
{}
void
- Sound::play_music(const std::string& name)
+ Sound::play_music(const std::string& filename)
{
- std::string filename = "music/";
- filename += name;
- filename += ".ogg";
sound_manager->play_music(filename);
}
return 0;
}
+static int Camera_scroll_to_wrapper(HSQUIRRELVM v)
+{
+ Scripting::Camera* _this;
+ sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0);
+ float arg0;
+ sq_getfloat(v, 2, &arg0);
+ float arg1;
+ sq_getfloat(v, 3, &arg1);
+ float arg2;
+ sq_getfloat(v, 4, &arg2);
+
+ _this->scroll_to(arg0, arg1, arg2);
+
+ return 0;
+}
+
static int Level_release_hook(SQUserPointer ptr, int )
{
Scripting::Level* _this = reinterpret_cast<Scripting::Level*> (ptr);
throw SquirrelError(v, msg.str());
}
+ sq_pushstring(v, "scroll_to", -1);
+ sq_newclosure(v, &Camera_scroll_to_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ std::ostringstream msg;
+ msg << "Couldn't register function'scroll_to'";
+ throw SquirrelError(v, msg.str());
+ }
+
if(SQ_FAILED(sq_createslot(v, -3))) {
std::ostringstream msg;
msg << "Couldn't register class'Camera'";