#include "Background.h" #include #include #include #include #include #include #include #include #include #include using namespace crepe; using namespace std; class MoveCameraScript : public Script { public: void init() { subscribe( [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); } private: bool keypressed(const KeyPressEvent & event) { if (event.key == Keycode::RIGHT) { Transform & cam = this->get_components_by_name("camera").front(); cam.position.x += 100; } else if (event.key == Keycode::LEFT) { Transform & cam = this->get_components_by_name("camera").front(); cam.position.x -= 100; } return true; } }; class Scene1 : public Scene { public: void load_scene() { Background background(*this); GameObject camera = new_object("camera", "camera", vec2(600, 0)); camera.add_component(ivec2(1700, 720), vec2(2000, 800), Camera::Data{ .bg_color = Color::RED, }); camera.add_component().set_script(); camera.add_component(Rigidbody::Data{ .linear_velocity = vec2(100, 0), }); } string get_name() const { return "scene1"; } }; int main(int argc, char * argv[]) { LoopManager gameloop; gameloop.add_scene(); gameloop.start(); return 0; }