Merge remote-tracking branch 'origin/master' into Physics

Conflicts:
	src/game/Game/LevelSystem.cpp
This commit is contained in:
viktorljung
2015-10-09 00:22:32 +02:00
48 changed files with 606 additions and 89 deletions
+23
View File
@@ -0,0 +1,23 @@
#ifndef GAME_GUI_ELOADINGFRAMECOMPLETE_H__
#define GAME_GUI_ELOADINGFRAMECOMPLETE_H__
#include "Core/EventBroker.h"
namespace dd
{
namespace GUI { class LoadingFrame; }
namespace Events
{
struct LoadingFrameComplete : Event
{
std::string FrameName;
GUI::LoadingFrame* Frame = nullptr;
};
}
}
#endif
@@ -6,7 +6,7 @@
#include "GUI/NumberFrame.h"
#include "Core/EKeyUp.h"
#include "Game/EScoreEvent.h"
#include "Game/FPSCounter.h"
#include "Game/GUI/FPSCounter.h"
#include "Game/EGameOver.h"
#include "Game/EClusterClear.h"
#include "Game/EKrakenAttack.h"
+73
View File
@@ -0,0 +1,73 @@
#ifndef GAME_GUI_LOADINGFRAME_H__
#define GAME_GUI_LOADINGFRAME_H__
#include "GUI/TextureFrame.h"
#include "GUI/Slider.h"
#include "Core/ResourceManager.h"
#include "Game/GUI/ELoadingFrameComplete.h"
namespace dd
{
namespace GUI
{
class LoadingFrame : public TextureFrame
{
public:
LoadingFrame(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
m_Slider = new GUI::Slider(this, "LoadingFrameSlider");
//m_SFXSlider->X = 0;
m_Slider->Y = 453;
//m_SFXSlider->SetTop(m_TitleSFX->Bottom() + 10);
m_Slider->SetTexture("Textures/GUI/Menu/SliderBackground.png");
m_Slider->SetTextureReleased("Textures/GUI/Menu/SliderHandle.png");
m_Slider->AlignVertically();
m_Slider->SetPercentage(1.f);
m_Slider->X = Width / 2.f - m_Slider->Width / 2.f;
}
void AddTexturePreload(std::string resourceName)
{
m_Items.push_back(resourceName);
}
void Preload()
{
m_Preloading = true;
}
void CancelPreload()
{
m_Preloading = false;
m_CurrentItem = 0;
}
void Update(double dt) override
{
if (m_Preloading) {
ResourceManager::Preload<dd::Texture>(m_Items[m_CurrentItem]);
m_Slider->SetPercentage((m_CurrentItem + 1) / (float)m_Items.size());
m_CurrentItem++;
if (m_CurrentItem >= m_Items.size()) {
m_Preloading = false;
dd::Events::LoadingFrameComplete e;
e.FrameName = Name();
e.Frame = this;
EventBroker->Publish(e);
}
}
}
private:
bool m_Preloading = false;
int m_CurrentItem = 0;
std::vector<std::string> m_Items;
GUI::Slider* m_Slider = nullptr;
};
}
}
#endif
@@ -2,8 +2,8 @@
#define GUI_MAINMENU_H__
#include "GUI/TextureFrame.h"
#include "Game/MainMenuMain.h"
#include "Game/MainMenuOptions.h"
#include "Game/GUI/MainMenuMain.h"
#include "Game/GUI/MainMenuOptions.h"
#include "Core/EKeyUp.h"
namespace dd
@@ -3,8 +3,7 @@
#include "GUI/TextureFrame.h"
#include "GUI/Button.h"
#include "Game/EGameStart.h"
#include "Game/HUD.h"
#include "Game/GUI/Story1.h"
namespace dd
{
@@ -57,10 +56,8 @@ private:
virtual bool OnButtonRelease(const Events::ButtonRelease& event)
{
if (event.Button == m_SquidoutButton) {
Events::GameStart e;
EventBroker->Publish(e);
m_Parent->Hide();
auto hud = new GUI::HUD(BaseFrame, "HUD");
auto story = new GUI::Story1(BaseFrame, "Story1");
}
return true;
+247
View File
@@ -0,0 +1,247 @@
#ifndef GAME_GUI_STORY1_H__
#define GAME_GUI_STORY1_H__
#include "Core/ResourceManager.h"
#include "Game/GUI/StoryboardFrame.h"
#include "Game/GUI/ELoadingFrameComplete.h"
#include "Game/GUI/LoadingFrame.h"
#include "Game/EGameStart.h"
#include "Core/EKeyDown.h"
#include "Game/GUI/HUD.h"
namespace dd
{
namespace GUI
{
class Story1 : public StoryboardFrame
{
public:
Story1(Frame* parent, std::string name)
: StoryboardFrame(parent, name)
{
EVENT_SUBSCRIBE_MEMBER(m_ELoadingFrameComplete, &Story1::OnLoadingFrameComplete);
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Story1::OnKeyDown);
m_LoadingFrame = new GUI::LoadingFrame(this, "Story1LoadingFrame");
m_LoadingFrame->SetTexture("Textures/GUI/Loading.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/Brunn1.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/Brunn2.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/Brunn3.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/Brunn4.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/Brunn5.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene1.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene2.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene3.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene4.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene5.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene6.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene7.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene8.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene9.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene10.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene11.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene12.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene13.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene14.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene15.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene16.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene17.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene18.png");
m_LoadingFrame->AddTexturePreload("Textures/Story/SubScene19.png");
m_LoadingFrame->Preload();
m_Spacebar = new TextureFrame(this, "ZZZSpacebar");
m_Spacebar->SetTexture("Textures/GUI/SpacebarSkip.png");
m_Spacebar->SetRight(Right() - 10);
m_Spacebar->SetBottom(Bottom() - 10);
m_Spacebar->DisableScissor();
Transition t;
/*
Sid in the well scene
*/
t.Time = t.Time + 0;
t.Duration = 0;
t.Texture = "Textures/Story/Brunn1.png";
t.Viewport = Rectangle(3108, 11276, 1376, 2203);
AddTransition(t);
t.Time = t.Time + 2;
t.Duration = 0.5;
t.Texture = "Textures/Story/Brunn2.png";
AddTransition(t);
t.Time = t.Time + 3;
t.Duration = 0.5;
t.Texture = "Textures/Story/Brunn3.png";
AddTransition(t);
t.Time = t.Time + 3;
t.Duration = 4;
t.Texture = "Textures/Story/Brunn4.png";
t.Viewport = Rectangle(2232, 0, 2952, 4725);
AddTransition(t);
t.Time = t.Time + 5;
t.Duration = 0;
t.Texture = "Textures/Story/Brunn5.png";
AddTransition(t);
/*
Submarine scene
*/
t.Time = t.Time + 4;
t.Duration = 2.5;
t.Texture = "Textures/Story/SubScene1.png";
t.Viewport = Rectangle(976, 0, 1615, 2586);
AddTransition(t);
// I'm Tom and stuff!
t.Time = t.Time + 1;
t.Duration = 0.5;
t.Texture = "Textures/Story/SubScene2.png";
AddTransition(t);
// Pan to the right here
t.Time = t.Time + 3.5;
t.Duration = 2;
t.Texture = "Textures/Story/SubScene3.png";
t.Viewport = Rectangle(1574, 0, 1615, 2586);
AddTransition(t);
// ZAP!
t.Time = t.Time + 2.5;
t.Duration = 0.5;
t.Texture = "Textures/Story/SubScene4.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene5.png";
AddTransition(t);
t.Time = t.Time + 0.1;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene6.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene7.png";
AddTransition(t);
// BZZT!
t.Time = t.Time + 1;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene8.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene9.png";
AddTransition(t);
t.Time = t.Time + 0.1;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene10.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene11.png";
AddTransition(t);
t.Time = t.Time + 1;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene12.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene13.png";
AddTransition(t);
t.Time = t.Time + 0.2;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene14.png";
AddTransition(t);
t.Time = t.Time + 0.5;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene15.png";
AddTransition(t);
t.Time = t.Time + 1;
t.Duration = 0.5;
t.Texture = "Textures/Story/SubScene16.png";
AddTransition(t);
t.Time = t.Time + 3.5;
t.Duration = 0.5;
t.Texture = "Textures/Story/SubScene17.png";
AddTransition(t);
t.Time = t.Time + 3;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene18.png";
AddTransition(t);
t.Time = t.Time + 2;
t.Duration = 0;
t.Texture = "Textures/Story/SubScene19.png";
AddTransition(t);
}
void Update(double dt) override
{
StoryboardFrame::Update(dt);
if (m_Spacebar == nullptr) {
}
}
void OnComplete() override
{
m_Spacebar->Show();
}
private:
GUI::LoadingFrame* m_LoadingFrame = nullptr;
TextureFrame* m_Spacebar = nullptr;
EventRelay<Frame, Events::KeyDown> m_EKeyDown;
bool OnKeyDown(const Events::KeyDown& event)
{
if (Hidden()) {
return false;
}
if (event.KeyCode == GLFW_KEY_SPACE) {
m_LoadingFrame->CancelPreload();
Events::GameStart e;
EventBroker->Publish(e);
Hide();
auto hud = new GUI::HUD(BaseFrame, "HUD");
}
return true;
}
EventRelay<Frame, Events::LoadingFrameComplete> m_ELoadingFrameComplete;
bool OnLoadingFrameComplete(const Events::LoadingFrameComplete& event)
{
if (event.FrameName == "Story1LoadingFrame") {
event.Frame->Hide();
m_Spacebar->Hide();
Play();
}
return true;
}
};
}
}
#endif
+128
View File
@@ -0,0 +1,128 @@
#ifndef GAME_GUI_STORYBOARDFRAME_H__
#define GAME_GUI_STORYBOARDFRAME_H__
#include "GUI/TextureFrame.h"
namespace dd
{
namespace GUI
{
class StoryboardFrame : public TextureFrame
{
public:
struct Transition
{
double Time = 0.0;
double Duration = 0.0;
Rectangle Viewport;
std::string Texture;
};
StoryboardFrame(Frame* parent, std::string name)
: TextureFrame(parent, name)
{
m_TextureFrame = new TextureFrame(this, "StoryboardFrameHelper");
//m_TextureFrame->DisableScissor();
}
void AddTransition(Transition& transition)
{
m_Timeline.push_back(transition);
}
void Play()
{
m_Playing = true;
}
void Skip()
{
m_Playing = false;
OnComplete();
}
void Update(double dt)
{
if (Hidden()) {
return;
}
if (m_Playing) {
m_Time += dt;
if (m_NextIndex < m_Timeline.size()) {
if (m_Time >= m_Timeline.at(m_NextIndex).Time) {
m_CurrentIndex = m_NextIndex;
Transition& t = m_Timeline.at(m_CurrentIndex);
m_TextureFrame->FadeToTexture(t.Texture, t.Duration);
//m_TextureFrame->SetTexture(t.Texture);
m_TextureFrame->SizeToTexture();
if (m_StartRect == Rectangle()) {
m_StartRect = Rectangle(0, 0, m_TextureFrame->Width, m_TextureFrame->Height);
}
else {
m_StartRect = m_TargetRect;
}
double wScaleParent = Width / (double)m_TextureFrame->Width;
double wScale = m_TextureFrame->Width / (double)t.Viewport.Width;
LOG_DEBUG("wScale: %f", wScale);
double hScaleParent = Height / (double)m_TextureFrame->Height;
double hScale = m_TextureFrame->Height / (double)t.Viewport.Height;
LOG_DEBUG("hScale: %f", hScale);
m_TargetRect.X = -t.Viewport.X * wScale * wScaleParent;
m_TargetRect.Y = -t.Viewport.Y * hScale * hScaleParent;
m_TargetRect.Width = m_TextureFrame->Width * wScale * wScaleParent;
m_TargetRect.Height = m_TextureFrame->Height * hScale * hScaleParent;
m_NextIndex++;
}
} else {
OnComplete();
}
}
Transition& t = m_Timeline.at(m_CurrentIndex);
double progress = glm::min((m_Time - t.Time)/t.Duration, 1.0);
m_TextureFrame->X = (int)easeSine(progress, m_StartRect.X, (m_TargetRect.X - m_StartRect.X), 1.0);
m_TextureFrame->Y = (int)easeSine(progress, m_StartRect.Y, (m_TargetRect.Y - m_StartRect.Y), 1.0);
m_TextureFrame->Width = (int)easeSine(progress, m_StartRect.Width, (m_TargetRect.Width - m_StartRect.Width), 1.0);
m_TextureFrame->Height = (int)easeSine(progress, m_StartRect.Height, (m_TargetRect.Height - m_StartRect.Height), 1.0);
}
virtual void OnComplete() { }
protected:
TextureFrame* m_TextureFrame = nullptr;
private:
bool m_Playing = false;
double m_Time = 0;
int m_CurrentIndex = 0;
int m_NextIndex = 0;
std::vector<Transition> m_Timeline;
Rectangle m_StartRect;
Rectangle m_TargetRect;
double easeSine(double t, double b, double c, double d)
{
return -c / 2 * (glm::cos(glm::pi<double>()*t / d) - 1) + b;
}
float easeExpo(float t,float b , float c, float d) {
if (t == 0) return b;
if (t == d) return b + c;
if ((t /= d / 2) < 1) return c / 2 * pow(2, 10 * (t - 1)) + b;
return c / 2 * (-pow(2, -10 * --t) + 2) + b;
}
};
}
}
#endif