Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Space-Invaders/Header/AnimationSystem/AnimationService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
#include <vector>
#include <SFML/System/Vector2.hpp>
#include "../../Header/AnimationSystem/AnimationSystem.h"


namespace Animation
{
enum class AnimationType
{
EXPLOSION,
};


class AnimationService
{
private:
std::vector<AnimationSystem*> animationSystemList;
std::vector<AnimationSystem*> flaggedAnimationSystemList;

AnimationSystemConfig GetAnimationSystemConfig(AnimationType animationType);
void DestroyFlaggedAnimationSystem();
void Destroy();

public:
AnimationService();
virtual ~AnimationService();

void Initialize();
void Update();
void Render();

void Reset();

void SpawnAnimationSystem(sf::Vector2f position, AnimationType animationType);
void DestroyAnimationSystem(AnimationSystem* animationSystem);
};
}
35 changes: 35 additions & 0 deletions Space-Invaders/Header/AnimationSystem/AnimationSystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <SFML/Graphics.hpp>
#include "../../Header/AnimationSystem/AnimationSystemConfig.h"
#include "../../Header/UI/UIElement/ImageView.h"


namespace Animation
{
class AnimationSystem
{
private:
AnimationSystemConfig animationSystemConfig;

sf::Vector2f animationPosition;
UI::UIElement::ImageView* animationImage;

void CreateUIElements();
void InitializeImage();

int currentFrame;
sf::Clock clock;
sf::Time frameTime;

public:
AnimationSystem(AnimationSystemConfig config);
~AnimationSystem();

void Initialize(sf::Vector2f position);
void Update();
void Render();

void Destroy();
};
}

32 changes: 32 additions & 0 deletions Space-Invaders/Header/AnimationSystem/AnimationSystemConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once
#include <SFML/Graphics.hpp>


namespace Animation
{
struct AnimationSystemConfig
{
sf::String animationTexturePath;

float spriteSheetWidth;
float spriteSheetHeight;

float tileWidth;
float tileHeight;

int numberOfAnimationFrames;
float frameDuration;

AnimationSystemConfig() = default;

AnimationSystemConfig(sf::String texturePath, float spriteWidth, float spriteHeight,
float tWidth, float tHeight, int frames, float duration) :
animationTexturePath(texturePath),
spriteSheetWidth(spriteWidth),
spriteSheetHeight(spriteHeight),
tileWidth(tWidth),
tileHeight(tHeight),
numberOfAnimationFrames(frames),
frameDuration(duration) {}
};
}
10 changes: 10 additions & 0 deletions Space-Invaders/Header/AnimationSystem/AnimationSystemConfigData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include "AnimationSystemConfig.h"
#include "../../Header/Global/Config.h"


namespace Animation
{
const AnimationSystemConfig explosionAnimationConfig(Global::Config::explosionTexturePath,
70.0f, 80.0f, 14.28f, 20.0f, 7, 0.03f);
}
1 change: 1 addition & 0 deletions Space-Invaders/Header/Global/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ namespace Global
static const sf::String bulletFireSoundPath;
static const sf::String powerupEnabledSoundPath;
static const sf::String powerupDisabledSoundPath;
static const sf::String explosionSoundPath;
};
}
3 changes: 3 additions & 0 deletions Space-Invaders/Header/Global/ServiceLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../Powerups/PowerupService.h"
#include "../Sound/SoundService.h"
#include "../Collision/CollisionService.h"
#include "../AnimationSystem/AnimationService.h"


namespace Global
Expand All @@ -31,6 +32,7 @@ namespace Global
Powerup::PowerupService* powerupService;
Sound::SoundService* soundService;
Collision::CollisionService* collisionService;
Animation::AnimationService* animationService;

ServiceLocator();
~ServiceLocator();
Expand All @@ -57,5 +59,6 @@ namespace Global
Powerup::PowerupService* GetPowerupService();
Sound::SoundService* GetSoundService();
Collision::CollisionService* GetCollisionService();
Animation::AnimationService* GetAnimationService();
};
}
2 changes: 1 addition & 1 deletion Space-Invaders/Header/Main/GameService.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Main
void Initialize();
void InitializeVariables();

void ShowMainMenu();
void ShowSplashScreen();

public:
GameService();
Expand Down
3 changes: 3 additions & 0 deletions Space-Invaders/Header/Sound/SoundService.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ namespace Sound
sf::Sound soundEffect;

sf::Sound powerupSoundEffect;
sf::Sound explosionSoundEffect;

sf::SoundBuffer bufferButtonClick;
sf::SoundBuffer bufferBulletFire;

sf::SoundBuffer bufferPowerupEnabled;
sf::SoundBuffer bufferPowerupDisabled;

sf::SoundBuffer bufferExplosionSound;

void LoadBackgroundMusicFromFile();
void LoadSoundFromFile();

Expand Down
34 changes: 34 additions & 0 deletions Space-Invaders/Header/UI/SplashScreen/SplashScreenUIController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once
#include "../../Header/UI/Interface/IUIController.h"
#include "../../Header/UI/UIElement/AnimatedImageView.h"


namespace UI
{
namespace SplashScreen
{
class SplashScreenUIController : public Interface::IUIController
{
private:
const float logoAnimationDuration = 2.0f;
const float logoWidth = 600.f;
const float logoHeight = 134.f;

UIElement::AnimatedImageView* outscalLogoView;

void InitializeOutscalLogo();
void FadeInAnimationCallback();
void FadeOutAnimationCallback();
sf::Vector2f GetLogoPosition();

public:
SplashScreenUIController();
~SplashScreenUIController();

void Initialize() override;
void Update() override;
void Render() override;
void Show() override;
};
}
}
59 changes: 59 additions & 0 deletions Space-Invaders/Header/UI/UIElement/AnimatedImageView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once
#include "../../Header/UI/UIElement/ImageView.h"
#include <functional>


namespace UI
{
namespace UIElement
{
enum class AnimationType
{
FADE_IN,
FADE_OUT,
};


class AnimatedImageView : public ImageView
{
private:
using CallbackFunction = std::function<void()>;

CallbackFunction callbackFunction = nullptr;

void UpdateElapsedDuration();
void HandleAnimationProgress();
void UpdateAnimation();

protected:
const float defaultAnimationDuration = 2.0f;

AnimationType animationType;
float animationDuration;
float elapsedDuration;
sf::Clock clock;

virtual void Reset();

void SetAnimationDuration(float duration);
void SetAnimationType(AnimationType type);

virtual void FadeIn();
virtual void FadeOut();

public:
AnimatedImageView();
virtual ~AnimatedImageView();

virtual void Initialize(sf::String texturePath,
float imageWidth, float imageHeight,
sf::Vector2f position) override;
virtual void Update() override;
virtual void Render() override;

virtual void PlayAnimation(AnimationType type, float duration, CallbackFunction animationEndCallback);

void RegisterCallbackFuntion(CallbackFunction animationEndCallback);
};
}
}
2 changes: 2 additions & 0 deletions Space-Invaders/Header/UI/UIElement/ImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ namespace UI
virtual void Render() override;

virtual void SetTexture(sf::String texturePath);
virtual void SetTextureRect(sf::IntRect textureRect);
virtual void SetScale(float width, float height);
virtual void SetScale(float width, float height, float tileWidth, float tileHeight);
virtual void SetPosition(sf::Vector2f position);
virtual void SetRotation(float rotationAngle);
virtual void SetOriginAtCentre();
Expand Down
2 changes: 2 additions & 0 deletions Space-Invaders/Header/UI/UIService.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "MainMenu/MainMenuUIController.h"
#include "GameplayUI/GameplayUIController.h"
#include "SplashScreen/SplashScreenUIController.h"
#include "Interface/IUIController.h"


Expand All @@ -11,6 +12,7 @@ namespace UI
private:
MainMenu::MainMenuUIController* mainMenuUIController;
GameplayUI::GameplayUIController* gameplayUIController;
SplashScreen::SplashScreenUIController* splashScreenUIController;

void CreateControllers();
void InitializeControllers();
Expand Down
76 changes: 76 additions & 0 deletions Space-Invaders/Source/AnimationSystem/AnimationService.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "../../Header/AnimationSystem/AnimationService.h"
#include "../../Header/AnimationSystem/AnimationSystemConfigData.h"


namespace Animation
{
AnimationService::AnimationService() { }

AnimationService::~AnimationService()
{
Destroy();
}

void AnimationService::Initialize() { }

void AnimationService::Update()
{
for (AnimationSystem* animationSystem : animationSystemList)
{
animationSystem->Update();
}

DestroyFlaggedAnimationSystem();
}

void AnimationService::Render()
{
for (AnimationSystem* animationSystem : animationSystemList)
{
animationSystem->Render();
}
}

void AnimationService::SpawnAnimationSystem(sf::Vector2f position, AnimationType animationType)
{
AnimationSystem* animationSystem = new AnimationSystem(GetAnimationSystemConfig(animationType));
animationSystem->Initialize(position);
animationSystemList.push_back(animationSystem);
}

void AnimationService::DestroyAnimationSystem(AnimationSystem* animationSystem)
{
flaggedAnimationSystemList.push_back(animationSystem);
animationSystemList.erase(std::remove(animationSystemList.begin(), animationSystemList.end(),
animationSystem), animationSystemList.end());
}

AnimationSystemConfig AnimationService::GetAnimationSystemConfig(AnimationType animationType)
{
switch (animationType)
{
case Animation::AnimationType::EXPLOSION:
return explosionAnimationConfig;
}
}

void AnimationService::DestroyFlaggedAnimationSystem()
{
for (AnimationSystem* particleSystem : flaggedAnimationSystemList)
{
delete (particleSystem);
}

flaggedAnimationSystemList.clear();
}

void AnimationService::Reset() { Destroy(); }

void AnimationService::Destroy()
{
for (AnimationSystem* animationSystem : animationSystemList)
{
delete (animationSystem);
}
}
}
Loading