aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-19 11:09:26 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-19 11:09:26 +0100
commit067aa2536f9f43d07e22696c618258a26ae928b3 (patch)
treee9e641ab28cfd8163acee1596d9d07dd339d969a /src
parent1e6aaf13f4ecdc67e75eb26bcd8a6f0059c5cfe9 (diff)
Moved PlayerScript to seperate file
Diffstat (limited to 'src')
-rw-r--r--src/example/CMakeLists.txt2
-rw-r--r--src/example/PlayerScript.cpp11
-rw-r--r--src/example/PlayerScript.h8
-rw-r--r--src/example/PlayerSubScene.cpp9
4 files changed, 22 insertions, 8 deletions
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 <crepe/api/Rigidbody.h>
+
+using namespace crepe;
+using namespace std;
+
+void PlayerScript::update() {
+ Rigidbody & rb = this->get_components_by_name<Rigidbody>("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 <crepe/api/Script.h>
+
+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 <crepe/api/Animator.h>
#include <crepe/api/GameObject.h>
@@ -9,14 +10,6 @@
using namespace crepe;
using namespace std;
-class PlayerScript : public Script {
-public:
- void update() {
- Rigidbody & rb = this->get_components_by_name<Rigidbody>("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"};