diff options
Diffstat (limited to 'game')
-rw-r--r-- | game/CMakeLists.txt | 14 | ||||
-rw-r--r-- | game/Config.h | 11 | ||||
-rw-r--r-- | game/GameScene.cpp | 23 | ||||
-rw-r--r-- | game/background/CMakeLists.txt | 9 | ||||
-rw-r--r-- | game/main.cpp | 3 | ||||
-rw-r--r-- | game/prefab/CMakeLists.txt | 4 | ||||
-rw-r--r-- | game/prefab/ZapperObject.cpp | 99 | ||||
-rw-r--r-- | game/prefab/ZapperObject.h | 37 | ||||
-rwxr-xr-x | game/util/scrollgen | 36 |
9 files changed, 222 insertions, 14 deletions
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 8e3692b..cc0cc84 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -8,13 +8,11 @@ set(CMAKE_BUILD_TYPE Debug) project(game C CXX) add_subdirectory(../src crepe) -add_executable(main - background/AquariumSubScene.cpp - background/BackgroundSubScene.cpp - background/ForestParallaxScript.cpp - background/ForestSubScene.cpp + +add_executable(main) + +target_sources(main PUBLIC GameScene.cpp - background/HallwaySubScene.cpp MoveCameraManualyScript.cpp player/PlayerScript.cpp player/PlayerSubScene.cpp @@ -24,5 +22,9 @@ add_executable(main main.cpp ) +add_subdirectory(background) +add_subdirectory(prefab) + target_link_libraries(main PUBLIC crepe) +target_include_directories(main PRIVATE .) diff --git a/game/Config.h b/game/Config.h index d6f8349..940bf1d 100644 --- a/game/Config.h +++ b/game/Config.h @@ -1,5 +1,16 @@ #pragma once +#include <crepe/api/Config.h> + +static const crepe::Config ENGINE_CONFIG { + .log { + .level = crepe::Log::Level::DEBUG, + }, + .window_settings { + .window_title = "Jetpack joyride clone", + }, +}; + static constexpr int SORT_IN_LAY_BACK_BACKGROUND = 3; // For all scenes static constexpr int SORT_IN_LAY_BACKGROUND = 4; // For all scenes static constexpr int SORT_IN_LAY_FORE_BACKGROUND = 5; // For all scenes diff --git a/game/GameScene.cpp b/game/GameScene.cpp index a8fcb47..4193581 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -1,11 +1,3 @@ -#include "GameScene.h" -#include "Config.h" -#include "MoveCameraManualyScript.h" -#include "StartGameScript.h" - -#include "background/BackgroundSubScene.h" -#include "player/PlayerSubScene.h" - #include <cmath> #include <crepe/api/Animator.h> #include <crepe/api/Asset.h> @@ -22,10 +14,23 @@ #include <crepe/api/Transform.h> #include <crepe/types.h> +#include "Config.h" +#include "MoveCameraManualyScript.h" +#include "StartGameScript.h" + +#include "GameScene.h" +#include "MoveCameraManualyScript.h" + +#include "player/PlayerSubScene.h" +#include "background/BackgroundSubScene.h" +#include "prefab/ZapperObject.h" + using namespace crepe; using namespace std; void GameScene::load_scene() { + logf(Log::DEBUG, "Loading (main) GameScene..."); + BackgroundSubScene background(*this); GameObject camera = new_object("camera", "camera", vec2(650, 0)); @@ -64,6 +69,8 @@ void GameScene::load_scene() { }); ceiling.add_component<BoxCollider>(vec2(INFINITY, 200)); + ZapperObject {new_object("zapper", "zapper", vec2(800, 0))}; + GameObject start_game_script = new_object("start_game_script", "script", vec2(0, 0)); start_game_script.add_component<BehaviorScript>().set_script<StartGameScript>(); diff --git a/game/background/CMakeLists.txt b/game/background/CMakeLists.txt new file mode 100644 index 0000000..1d705f5 --- /dev/null +++ b/game/background/CMakeLists.txt @@ -0,0 +1,9 @@ +target_sources(main PUBLIC + AquariumSubScene.cpp + BackgroundSubScene.cpp + ForestParallaxScript.cpp + ForestSubScene.cpp + HallwaySubScene.cpp + StartSubScene.cpp +) + diff --git a/game/main.cpp b/game/main.cpp index 325b66d..2198f73 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -1,11 +1,14 @@ #include <crepe/api/Engine.h> #include <crepe/api/Script.h> +#include "Config.h" #include "GameScene.h" using namespace crepe; int main() { + Config::get_instance() = ENGINE_CONFIG; + Engine gameloop; gameloop.add_scene<GameScene>(); diff --git a/game/prefab/CMakeLists.txt b/game/prefab/CMakeLists.txt new file mode 100644 index 0000000..5f8ea6c --- /dev/null +++ b/game/prefab/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(main PUBLIC + ZapperObject.cpp +) + diff --git a/game/prefab/ZapperObject.cpp b/game/prefab/ZapperObject.cpp new file mode 100644 index 0000000..8df2075 --- /dev/null +++ b/game/prefab/ZapperObject.cpp @@ -0,0 +1,99 @@ +#include <crepe/api/Transform.h> + +#include "Config.h" +#include "ZapperObject.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, 42) * SCALE, + } + ), + .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, 42) * SCALE, + } + ), + .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(128, 128) * SCALE, + } + ), + .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(128, 128) * SCALE, + } + ), + .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(0, 40 * SCALE), + .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(16, 1), + Animator::Data { + .fps = 30, + .looping = true, + } + ), + .glow_end = add_component<Animator>( + sprite.glow_end, ivec2(128, 128), uvec2(16, 1), animator.glow_start.data + ), + }, + body {add_component<Rigidbody>(Rigidbody::Data { + .body_type = Rigidbody::BodyType::KINEMATIC, + .kinematic_collision = false, + })}, + collider {add_component<BoxCollider>(vec2(0, 0))} { + this->place(this->transform.position, 0, 300); +} + +void ZapperObject::place(const crepe::vec2 & position, float rotation, float length) { + this->transform.position = position; + this->transform.rotation = rotation; + + vec2 offset = vec2(0, 1) * length / 2; + + this->sprite.orb_start.data.position_offset = offset; + this->sprite.glow_start.data.position_offset = offset; + this->sprite.orb_end.data.position_offset = -offset; + this->sprite.glow_end.data.position_offset = -offset; + + this->sprite.beam.data.size.x = length; + + this->collider.dimensions = offset.rotate(rotation) * 2 + vec2(30, 30) * SCALE; +} diff --git a/game/prefab/ZapperObject.h b/game/prefab/ZapperObject.h new file mode 100644 index 0000000..c43af67 --- /dev/null +++ b/game/prefab/ZapperObject.h @@ -0,0 +1,37 @@ +#pragma once + +#include <crepe/api/Animator.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 { +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; + +private: + static constexpr float SCALE = 0.8; + +public: + void place(const crepe::vec2 & position, float rotation, float length); +}; diff --git a/game/util/scrollgen b/game/util/scrollgen new file mode 100755 index 0000000..0389107 --- /dev/null +++ b/game/util/scrollgen @@ -0,0 +1,36 @@ +#!/bin/sh +INPUT="$1" +FRAMES="$2" + +die() { + echo "$@" + exit 1 +} +check_command() { + cmd="$1" + command -v "$cmd" > /dev/null || die "command '$cmd' not found" +} + +check_command magick +check_command identify +[ "$#" -eq 2 ] || die "usage: $0 <input image> <frame count>" +[ -e "$INPUT" ] || die "file not found: $INPUT" +[ "$FRAMES" -gt 0 ] || die "invalid frame count: $FRAMES" + +tile_width=$(identify -format "%w" "$INPUT") +tile_height=$(identify -format "%h" "$INPUT") + +OUTPUT="$INPUT.scroll.png" +magick -size "${tile_width}x$(( $tile_height * $FRAMES ))" 'xc:#ff00ff00' "$OUTPUT" + +for i in $(seq 0 $(( $FRAMES - 1 ))); do + offset_x=$(( $tile_width * $i / $FRAMES )) + offset_y=$(( i * $tile_height )) + + magick "$OUTPUT" "$INPUT" -geometry "+${offset_x}+${offset_y}" -composite "$OUTPUT" + magick "$OUTPUT" "$INPUT" -geometry "+$(( $offset_x - $tile_width ))+${offset_y}" -composite "$OUTPUT" + echo "+${offset_x}+${offset_y}" +done + +# magick -size ${total_width}x${sprite_height} xc:none canvas.png + |