aboutsummaryrefslogtreecommitdiff
path: root/game/prefab
diff options
context:
space:
mode:
Diffstat (limited to 'game/prefab')
-rw-r--r--game/prefab/CMakeLists.txt2
-rw-r--r--game/prefab/ZapperObject.cpp84
-rw-r--r--game/prefab/ZapperObject.h32
-rw-r--r--game/prefab/ZapperScript.cpp23
-rw-r--r--game/prefab/ZapperScript.h18
5 files changed, 158 insertions, 1 deletions
diff --git a/game/prefab/CMakeLists.txt b/game/prefab/CMakeLists.txt
index a588090..03084e4 100644
--- a/game/prefab/CMakeLists.txt
+++ b/game/prefab/CMakeLists.txt
@@ -1,5 +1,7 @@
target_sources(main PUBLIC
PlayerObject.cpp
PlayerScript.cpp
+ ZapperObject.cpp
+ ZapperScript.cpp
)
diff --git a/game/prefab/ZapperObject.cpp b/game/prefab/ZapperObject.cpp
new file mode 100644
index 0000000..2791162
--- /dev/null
+++ b/game/prefab/ZapperObject.cpp
@@ -0,0 +1,84 @@
+#include "Config.h"
+#include "ZapperObject.h"
+#include "ZapperScript.h"
+
+using namespace crepe;
+
+ZapperObject::ZapperObject(crepe::GameObject && base)
+ : GameObject(std::move(base)),
+ sprite {
+ .orb_start = add_component<Sprite>(
+ Asset {"asset/obstacles/zapper/orbAnim.png"},
+ Sprite::Data {
+ .sorting_in_layer = SORT_IN_LAY_OBSTACLES,
+ .order_in_layer = 1,
+ .size = vec2{0, 1} * SCALE,
+ .position_offset = {0, 100},
+ }
+ ),
+ .orb_end = add_component<Sprite>(
+ sprite.orb_start.source,
+ Sprite::Data {
+ .flip = {true, true},
+ .sorting_in_layer = SORT_IN_LAY_OBSTACLES,
+ .order_in_layer = 1,
+ .size = vec2{0, 1} * SCALE,
+ .position_offset = {0, -100},
+ }
+ ),
+ .glow_start = add_component<Sprite>(
+ Asset {"asset/obstacles/zapper/regular_zappers/glow.png"},
+ Sprite::Data {
+ .sorting_in_layer = SORT_IN_LAY_OBSTACLES,
+ .order_in_layer = -1,
+ .size = vec2{2, 2} * SCALE,
+ .position_offset = {0, 100},
+ }
+ ),
+ .glow_end = add_component<Sprite>(
+ sprite.glow_start.source,
+ Sprite::Data {
+ .flip = {true, true},
+ .sorting_in_layer = SORT_IN_LAY_OBSTACLES,
+ .order_in_layer = -1,
+ .size = vec2{2, 2} * SCALE,
+ .position_offset = {0, -100},
+ }
+ ),
+ .beam = add_component<Sprite>(
+ Asset {"asset/obstacles/zapper/regular_zappers/zapEffect.png"},
+ Sprite::Data {
+ .sorting_in_layer = SORT_IN_LAY_OBSTACLES,
+ .order_in_layer = 0,
+ .size = vec2{200, 50},
+ .angle_offset = 90,
+ }
+ ),
+ },
+ animator {
+ .orb_start = add_component<Animator>(
+ sprite.orb_start, ivec2(62, 42), uvec2(4, 1),
+ Animator::Data {
+ .fps = 10,
+ .looping = true,
+ }
+ ),
+ .orb_end = add_component<Animator>(
+ sprite.orb_end, ivec2(62, 42), uvec2(4, 1),
+ animator.orb_start.data
+ ),
+ .glow_start = add_component<Animator>(
+ sprite.glow_start, ivec2(128, 128), uvec2(4, 4),
+ Animator::Data {
+ .fps = 30,
+ .looping = true,
+ }
+ ),
+ .glow_end = add_component<Animator>(
+ sprite.glow_end, ivec2(128, 128), uvec2(4, 4),
+ animator.glow_start.data
+ ),
+ },
+ controller(add_component<BehaviorScript>().set_script<ZapperScript>(*this))
+{ }
+
diff --git a/game/prefab/ZapperObject.h b/game/prefab/ZapperObject.h
index 1f32cd7..6b68146 100644
--- a/game/prefab/ZapperObject.h
+++ b/game/prefab/ZapperObject.h
@@ -1,7 +1,37 @@
#pragma once
+#include <crepe/api/Animator.h>
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/BoxCollider.h>
#include <crepe/api/GameObject.h>
+#include <crepe/api/Rigidbody.h>
+#include <crepe/api/Sprite.h>
class ZapperObject : public crepe::GameObject {
- // afsd
+public:
+ ZapperObject(crepe::GameObject &&);
+
+public:
+ struct {
+ crepe::Sprite & orb_start;
+ crepe::Sprite & orb_end;
+ crepe::Sprite & glow_start;
+ crepe::Sprite & glow_end;
+ crepe::Sprite & beam;
+ } sprite;
+
+ struct {
+ crepe::Animator & orb_start;
+ crepe::Animator & orb_end;
+ crepe::Animator & glow_start;
+ crepe::Animator & glow_end;
+ } animator;
+
+ // crepe::Rigidbody & body;
+ // crepe::BoxCollider & collider;
+ crepe::BehaviorScript & controller;
+
+private:
+ static constexpr int SCALE = 60;
};
+
diff --git a/game/prefab/ZapperScript.cpp b/game/prefab/ZapperScript.cpp
new file mode 100644
index 0000000..b9b24be
--- /dev/null
+++ b/game/prefab/ZapperScript.cpp
@@ -0,0 +1,23 @@
+#include <crepe/api/Rigidbody.h>
+#include <cassert>
+
+#include "ZapperScript.h"
+
+using namespace crepe;
+using namespace std;
+
+ZapperScript::ZapperScript(const ZapperObject & zapper) : zapper(zapper) { }
+
+void ZapperScript::init() {
+ zapper.sprite.beam.mask = {
+ .w = 350,
+ .h = 117,
+ .x = 0,
+ .y = 0,
+ };
+}
+
+void ZapperScript::frame_update(duration_t delta_time) {
+ zapper.sprite.beam.mask.x += 4;
+}
+
diff --git a/game/prefab/ZapperScript.h b/game/prefab/ZapperScript.h
new file mode 100644
index 0000000..5a960df
--- /dev/null
+++ b/game/prefab/ZapperScript.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <crepe/api/Script.h>
+
+#include "ZapperObject.h"
+
+class ZapperScript : public crepe::Script {
+public:
+ ZapperScript(const ZapperObject & zapper);
+
+protected:
+ void init();
+ void frame_update(crepe::duration_t delta_time);
+
+protected:
+ ZapperObject zapper;
+};
+