-
Notifications
You must be signed in to change notification settings - Fork 1
/
scene.h
98 lines (71 loc) · 2.66 KB
/
scene.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once
#include "gamedefs.h"
#include "vector.h"
#include <mylly/renderer/colour.h>
#include <mylly/mgui/widget.h>
#include <mylly/audio/audiosystem.h>
#include <mylly/collections/array.h>
// -------------------------------------------------------------------------------------------------
enum SceneType {
SCENE_MENU,
SCENE_GAME
};
// -------------------------------------------------------------------------------------------------
struct LightFlash {
light_t *light;
float intensity;
float duration;
float elapsed;
};
// -------------------------------------------------------------------------------------------------
class Scene
{
public:
Scene(void);
virtual ~Scene(void);
virtual SceneType GetType(void) const = 0;
virtual void Create(Game *game);
virtual void SetupLevel(Game *game) = 0;
virtual void Update(Game *game);
scene_t *GetSceneRoot(void) const { return m_sceneRoot; }
AsteroidHandler *GetAsteroidHandler(void) const { return m_asteroids; }
ProjectileHandler *GetProjectileHandler(void) const { return m_projectiles; }
void CalculateBoundaries(Vec2 &outMin, Vec2 &outMax);
void AddCameraEffect(shader_t *effect);
void RemoveCameraEffect(shader_t *effect);
void FadeCamera(bool fadeIn);
void ShakeCamera(float intensity = 1, float duration = 0.5f);
float GetCameraFadeFactor(void) const { return m_fadeFactor; }
emitter_t *SpawnEffect(const char *effectName, const Vec2 &position) const;
void SpawnLightFlash(const Vec2 &position, const colour_t &colour = COL_WHITE,
float intensity = 1.0f, float duration = 1.0f);
virtual void OnEntityDestroyed(Game *game, Entity *entity) = 0;
protected:
void CreateCamera(void);
void SetBackground(uint32_t backgroundIndex);
object_t *CreateCameraTexture(const char *spriteName, bool isBackground = true);
void SetupLighting(void);
bool IsFading(void) const { return (m_fadeEffectEnds != 0); }
void ProcessFade(Game *game);
bool IsShaking(void) const { return (m_shakeDuration != 0); }
void ProcessShake(void);
protected:
static constexpr float FADE_DURATION = 0.5f;
static constexpr float CAMERA_DEPTH = -50.0f;
AsteroidHandler *m_asteroids = nullptr;
ProjectileHandler *m_projectiles = nullptr;
scene_t *m_sceneRoot = nullptr;
camera_t *m_camera = nullptr;
object_t *m_spaceBackground = nullptr;
light_t *m_directionalLights[2] = { nullptr, nullptr };
uint32_t m_backgroundIndex = 0;
object_t *m_fader = nullptr;
shader_t *m_fadeShader = nullptr;
float m_fadeEffectEnds = 0;
bool m_isFadingIn = false;
float m_fadeFactor = 0;
float m_shakeDuration = 0;
float m_shakeIntensity = 0;
float m_shakeElapsed = 0;
arr_t(LightFlash) m_lightFlashes = arr_initializer;
};