From 067aa2536f9f43d07e22696c618258a26ae928b3 Mon Sep 17 00:00:00 2001 From: max-001 Date: Thu, 19 Dec 2024 11:09:26 +0100 Subject: Moved PlayerScript to seperate file --- src/example/CMakeLists.txt | 2 ++ src/example/PlayerScript.cpp | 11 +++++++++++ src/example/PlayerScript.h | 8 ++++++++ src/example/PlayerSubScene.cpp | 9 +-------- 4 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 src/example/PlayerScript.cpp create mode 100644 src/example/PlayerScript.h diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index c1ccdec..f1d165a 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -6,6 +6,7 @@ set(GAME_HEADERS StartSubScene.h GameScene.h PlayerSubScene.h + PlayerScript.h ) set(GAME_SOURCES @@ -17,6 +18,7 @@ set(GAME_SOURCES StartSubScene.cpp GameScene.cpp PlayerSubScene.cpp + PlayerScript.cpp ) add_executable(game ${GAME_SOURCES} ${GAME_HEADERS}) diff --git a/src/example/PlayerScript.cpp b/src/example/PlayerScript.cpp new file mode 100644 index 0000000..a147e06 --- /dev/null +++ b/src/example/PlayerScript.cpp @@ -0,0 +1,11 @@ +#include "PlayerScript.h" + +#include + +using namespace crepe; +using namespace std; + +void PlayerScript::update() { + Rigidbody & rb = this->get_components_by_name("player").front(); + if (this->get_key_state(Keycode::SPACE)) rb.add_force_linear(vec2(0, -10)); +} diff --git a/src/example/PlayerScript.h b/src/example/PlayerScript.h new file mode 100644 index 0000000..254dd41 --- /dev/null +++ b/src/example/PlayerScript.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +class PlayerScript : public crepe::Script { +public: + void update(); +}; diff --git a/src/example/PlayerSubScene.cpp b/src/example/PlayerSubScene.cpp index 180ca17..7d9526b 100644 --- a/src/example/PlayerSubScene.cpp +++ b/src/example/PlayerSubScene.cpp @@ -1,4 +1,5 @@ #include "PlayerSubScene.h" +#include "PlayerScript.h" #include #include @@ -9,14 +10,6 @@ using namespace crepe; using namespace std; -class PlayerScript : public Script { -public: - void update() { - Rigidbody & rb = this->get_components_by_name("player").front(); - if (this->get_key_state(Keycode::SPACE)) rb.add_force_linear(vec2(0, -10)); - } -}; - PlayerSubScene::PlayerSubScene(Scene & scn) { GameObject player = scn.new_object("player", "player", vec2(-100, 200)); Asset player_body_asset{"asset/jetpack_joyride/barry/defaultBody.png"}; -- cgit v1.2.3