Skip to content

Commit

Permalink
Demo (./Menu): Example of Menu scene with fade
Browse files Browse the repository at this point in the history
  • Loading branch information
PharaEthan committed Jan 16, 2024
1 parent eb2f845 commit fe29ee7
Show file tree
Hide file tree
Showing 15 changed files with 555 additions and 17 deletions.
12 changes: 12 additions & 0 deletions SandBox/R-Type/Assets/AssetRegistry.asset
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,15 @@ AssetRegistry:
- Handle: 845124784512548152
Path: Prefabs/Bullets/SuperBullet.prefab
Type: AssetType::Prefabs
- Handle: 845124412025481521
Path: Textures/Menu/LiftIn.png
Type: AssetType::Texture2D
- Handle: 8451244120254815211
Path: Textures/Menu/LiftOut.png
Type: AssetType::Texture2D
- Handle: 8451244120254815212
Path: Textures/Menu/LoadingScreen.png
Type: AssetType::Texture2D
- Handle: 52041201510120120
Path: Prefabs/Menu/PressStart.prefab
Type: AssetType::Prefabs
21 changes: 21 additions & 0 deletions SandBox/R-Type/Assets/Prefabs/Menu/PressStart.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Entities:
- Entity: 956230123451
TagComponent:
Tag: Press Start
TransformComponent:
Translation: [0, 0, 0]
Rotation: [0, 0, 0]
Scale: [0.25, 0.25, 1]
TextRendererComponent:
Text: PRESS START
Color: [1, 1, 1, 1]
Font: 45121874124124
Kerning: 0
LineSpacing: 0
FadeComponent:
Opacity: 0
FadeInSpeed: 0.4
FadeOutSpeed: 0.4
ShouldFadeIn: true
ShouldFadeOut: false
Repeat: true
2 changes: 1 addition & 1 deletion SandBox/R-Type/Assets/R-Type.proj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Project:
Name: R-Type
StartScene: 7402922757700725494
StartScene: 6925943162598913395
AssetsDirectory: ""
AssetRegistryPath: "AssetRegistry.asset"
ScriptsDirectory: "Scripts"
42 changes: 26 additions & 16 deletions SandBox/R-Type/Assets/Scene/Menu.exodia
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
Scene: Menu
Scene: Loading
Entities:
- Entity: 15835038643471288681
- Entity: 455125451521210515
TransformComponent:
Translation: [0, 0, 15]
Translation: [0, 0, 6]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
TagComponent:
Tag: Camera
CameraComponent:
Camera:
ProjectionType: 0
PerspectiveFOV: 0.785398185
PerspectiveFOV: 45
PerspectiveNear: 0.00999999978
PerspectiveFar: 1000
OrthographicSize: 10
OrthographicNear: -1
OrthographicFar: 1
Primary: true
FixedAspectRatio: false
- Entity: 13934990193259798511
FixedAspectRatio: true
- Entity: 458541471201584
TransformComponent:
Translation: [0, 0, 0]
Translation: [0, 0, -0.5]
Rotation: [0, 0, 0]
Scale: [1, 1, 1]
Scale: [13, 8, 1]
TagComponent:
Tag: Pata-Pata
Tag: LoadingBackground
ScriptComponent:
Name: PataPata
RigidBody2DComponent:
BodyType: Dynamic
Velocity: [0, 0]
GravityScale: 1
Mass: 1
Name: Intro
SpriteRendererComponent:
Color: [1, 1, 1, 1]
TilingFactor: 1
Texture:
AssetHandle: 8451244120254815212
Coords: [0, 0]
CellSize: [1, 1]
SpriteSize: [512, 512]
FadeComponent:
Opacity: 0
FadeInSpeed: 0.4
FadeOutSpeed: 0.4
ShouldFadeIn: true
ShouldFadeOut: false
Repeat: true
Systems:
- System: AnimationSystem
- System: MovingSystem
- System: FadeSystem
Binary file added SandBox/R-Type/Assets/Textures/Menu/LiftIn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SandBox/R-Type/Assets/Textures/Menu/LiftOut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions SandBox/R-Type/R-Type/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(SOURCES_GAME_ENGINE
# -- System source files

src/System/AnimationSystem.cpp
src/System/FadeSystem.cpp

# -- Script source files

Expand All @@ -38,6 +39,8 @@ set(SOURCES_GAME_ENGINE
src/Scripts/Mid/Mid.cpp
src/Scripts/Bug/Bug.cpp

src/Scripts/Menu/Intro.cpp

# -- Entity source files

src/Entity/CreateBackground.cpp
Expand Down
15 changes: 15 additions & 0 deletions SandBox/R-Type/R-Type/R-Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "src/Component/Animation.hpp"
#include "src/Component/Clock.hpp"
#include "src/Component/Health.hpp"
#include "src/Component/Fade.hpp"

#include "src/Scripts/Player/PlayerController.hpp"
#include "src/Scripts/Player/BulletPlayer.hpp"
Expand All @@ -37,9 +38,13 @@
#include "src/Scripts/Spawners/PataPataSpawner.hpp"
#include "src/Scripts/Spawners/MidSpawner.hpp"

#include "src/Scripts/Menu/Intro.hpp"

#include "src/System/AnimationSystem.hpp"
#include "src/System/FadeSystem.hpp"

#include "src/Event/TakeDamage.hpp"
#include "src/Event/FadeEvent.hpp"

#include "src/Entity/CreateBackground.hpp"

Expand All @@ -57,6 +62,7 @@ namespace RType {

if (!project) {
EXODIA_ERROR("Failed to load R-Type project");

throw std::runtime_error("Failed to load R-Type project");
}

Expand All @@ -74,6 +80,10 @@ namespace RType {
return new Exodia::ComponentContainer<Exodia::Clock>(data);
});

project->RegisterComponent("FadeComponent", [](Exodia::Buffer data) -> Exodia::IComponentContainer * {
return new Exodia::ComponentContainer<RType::FadeComponent>(data);
});

// -- Register R-Type scripts ------------------------------------------

project->RegisterScript("PlayerController",
Expand Down Expand Up @@ -106,9 +116,14 @@ namespace RType {
[]() -> Exodia::ScriptableEntity * { return new RType::PataPataSpawner(); });

project->RegisterScript("MidSpawner", []() -> Exodia::ScriptableEntity * { return new RType::MidSpawner(); });

project->RegisterScript("Intro", []() -> Exodia::ScriptableEntity * { return new RType::Intro(); });

// -- Register R-Type systems ------------------------------------------

project->RegisterSystem("AnimationSystem", []() -> Exodia::EntitySystem * { return new AnimationSystem(); });

project->RegisterSystem("FadeSystem", []() -> Exodia::EntitySystem * { return new FadeSystem(); });
}
}; // namespace RType

Expand Down
122 changes: 122 additions & 0 deletions SandBox/R-Type/R-Type/src/Component/Fade.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
** EPITECH PROJECT, 2023
** R-Type
** File description:
** Fade
*/

#ifndef FADE_HPP_
#define FADE_HPP_

// Exodia includes
#include "Exodia.hpp"

namespace RType {

struct FadeComponent : public Exodia::Component {
float Opacity;

float FadeInSpeed;
float FadeOutSpeed;

bool ShouldFadeIn;
bool ShouldFadeOut;

bool Repeat;

FadeComponent(const FadeComponent &other) = default;
FadeComponent(float opacity = 1.0f, float fadeInSpeed = 1.0f, float fadeOutSpeed = 1.0f) : Opacity(opacity), FadeInSpeed(fadeInSpeed), FadeOutSpeed(fadeOutSpeed), ShouldFadeIn(false), ShouldFadeOut(false), Repeat(false) {};

void Serialize(YAML::Emitter &out) override
{
out << YAML::Key << "FadeComponent";
out << YAML::BeginMap;
{
out << YAML::Key << "Opacity" << YAML::Value << Opacity;
out << YAML::Key << "FadeInSpeed" << YAML::Value << FadeInSpeed;
out << YAML::Key << "FadeOutSpeed" << YAML::Value << FadeOutSpeed;
out << YAML::Key << "ShouldFadeIn" << YAML::Value << ShouldFadeIn;
out << YAML::Key << "ShouldFadeOut" << YAML::Value << ShouldFadeOut;
out << YAML::Key << "Repeat" << YAML::Value << Repeat;
}
out << YAML::EndMap;
}

void Deserialize(const YAML::Node &node)
{
try {
auto fade = node["FadeComponent"];

Opacity = fade["Opacity"].as<float>();
FadeInSpeed = fade["FadeInSpeed"].as<float>();
FadeOutSpeed = fade["FadeOutSpeed"].as<float>();
ShouldFadeIn = fade["ShouldFadeIn"].as<bool>();
ShouldFadeOut = fade["ShouldFadeOut"].as<bool>();
Repeat = fade["Repeat"].as<bool>();
} catch (YAML::BadConversion &error) {
EXODIA_CORE_WARN("FadeComponent deserialization failed:\n\t{0}", error.what());
}
}

void DeserializeData(Exodia::Buffer data) override
{
if (!data || data.Size == 0)
return;
try {
size_t offset = 0;

Memcopy(&Opacity, data.Data, sizeof(Opacity));
offset += sizeof(Opacity);

Memcopy(&FadeInSpeed, data.Data + offset, sizeof(FadeInSpeed));
offset += sizeof(FadeInSpeed);

Memcopy(&FadeOutSpeed, data.Data + offset, sizeof(FadeOutSpeed));
offset += sizeof(FadeOutSpeed);

Memcopy(&ShouldFadeIn, data.Data + offset, sizeof(ShouldFadeIn));
offset += sizeof(ShouldFadeIn);

Memcopy(&ShouldFadeOut, data.Data + offset, sizeof(ShouldFadeOut));
offset += sizeof(ShouldFadeOut);

Memcopy(&Repeat, data.Data + offset, sizeof(Repeat));
} catch (std::exception &e) {
EXODIA_CORE_WARN("FadeComponent deserialization failed:\n\t{0}", e.what());
}
}

Exodia::Buffer SerializeData() override
{
try {
Exodia::Buffer buffer(sizeof(float) * 3 + sizeof(bool) * 3);
size_t offset = 0;

std::memcpy(buffer.Data, &Opacity, sizeof(Opacity));
offset += sizeof(Opacity);

std::memcpy(buffer.Data + offset, &FadeInSpeed, sizeof(FadeInSpeed));
offset += sizeof(FadeInSpeed);

std::memcpy(buffer.Data + offset, &FadeOutSpeed, sizeof(FadeOutSpeed));
offset += sizeof(FadeOutSpeed);

std::memcpy(buffer.Data + offset, &ShouldFadeIn, sizeof(ShouldFadeIn));
offset += sizeof(ShouldFadeIn);

std::memcpy(buffer.Data + offset, &ShouldFadeOut, sizeof(ShouldFadeOut));
offset += sizeof(ShouldFadeOut);

std::memcpy(buffer.Data + offset, &Repeat, sizeof(Repeat));

return buffer;
} catch (std::exception &e) {
EXODIA_CORE_WARN("FadeComponent serialization failed:\n\t{0}", e.what());

return Exodia::Buffer();
}
}
};
};

#endif /* !FADE_HPP_ */
21 changes: 21 additions & 0 deletions SandBox/R-Type/R-Type/src/Event/FadeEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
** EPITECH PROJECT, 2023
** R-Type
** File description:
** FadeEvent
*/

#ifndef FADEEVENT_HPP_
#define FADEEVENT_HPP_

// Exodia includes
#include "Exodia.hpp"

namespace RType::Events {

struct FadeOutEndEvent {
Exodia::Entity *Entity;
};
};

#endif /* !FADEEVENT_HPP_ */
Loading

0 comments on commit fe29ee7

Please sign in to comment.