Add fly animations

This commit is contained in:
Bram Verhulst
2024-05-29 00:00:29 +02:00
parent 3c83e566dd
commit e1165fdcb4
31 changed files with 580 additions and 157 deletions

View File

@@ -29,6 +29,10 @@ namespace Collision
Vector2f vel;
std::map<CollisionDirection, CollisionRect*> ContactMap{};
Rectf getRectf() {
return Rectf{ pos.x, pos.y, size.x, size.y };
}
};
struct TileCollisionRect

View File

@@ -2,76 +2,59 @@
#include <iostream>
#include "SoundEffect.h"
SoundEffect::SoundEffect( const std::string& path )
:m_pMixChunk{ Mix_LoadWAV( path.c_str( ) ) }
{
if ( m_pMixChunk == nullptr )
{
const std::string errorMsg = "SoundEffect: Failed to load " + path + ",\nSDL_mixer Error: " + Mix_GetError( );
SoundEffect::SoundEffect(const std::string& path, int channel)
: m_pMixChunk { Mix_LoadWAV(path.c_str()) }, m_Channel(channel) {
if (m_pMixChunk == nullptr) {
const std::string errorMsg = "SoundEffect: Failed to load " + path + ",\nSDL_mixer Error: " + Mix_GetError();
std::cerr << errorMsg;
}
}
SoundEffect::~SoundEffect( )
{
Mix_FreeChunk( m_pMixChunk );
SoundEffect::~SoundEffect() {
Mix_FreeChunk(m_pMixChunk);
m_pMixChunk = nullptr;
}
bool SoundEffect::IsLoaded( ) const
{
bool SoundEffect::IsLoaded() const {
return m_pMixChunk != nullptr;
}
bool SoundEffect::Play( const int loops ) const
{
// Don't save the channel as a data member,
// because when it stops playing the channel becomes free
// and available for usage by other effects
if ( m_pMixChunk != nullptr )
{
const int channel{ Mix_PlayChannel( -1, m_pMixChunk, loops ) };
return channel == -1 ? false : true;
void SoundEffect::Play(const int loops) const {
if (m_pMixChunk != nullptr) {
const int channel { Mix_PlayChannel(m_Channel, m_pMixChunk, loops) };
}
else
{
return false;
else {
std::cout << "SoundEffect::Play() failed, sound effect not loaded\n";
}
}
void SoundEffect::SetVolume( const int value )
{
if ( m_pMixChunk != nullptr )
{
Mix_VolumeChunk( m_pMixChunk, value );
void SoundEffect::SetVolume(const int value) {
if (m_pMixChunk != nullptr) {
Mix_VolumeChunk(m_pMixChunk, value);
}
}
int SoundEffect::GetVolume( ) const
{
if ( m_pMixChunk != nullptr )
{
return Mix_VolumeChunk( m_pMixChunk, -1 );
int SoundEffect::GetVolume() const {
if (m_pMixChunk != nullptr) {
return Mix_VolumeChunk(m_pMixChunk, -1);
}
else
{
else {
return -1;
}
}
void SoundEffect::StopAll( )
{
Mix_HaltChannel(-1 );
void SoundEffect::Stop() const {
Mix_HaltChannel(m_Channel);
}
void SoundEffect::PauseAll( )
{
Mix_Pause( -1 );
}
void SoundEffect::ResumeAll( )
{
Mix_Resume( -1 );
void SoundEffect::StopAll() {
Mix_HaltChannel(-1);
}
void SoundEffect::PauseAll() {
Mix_Pause(-1);
}
void SoundEffect::ResumeAll() {
Mix_Resume(-1);
}

View File

@@ -4,7 +4,7 @@ class Mix_Chunk;
class SoundEffect final
{
public:
explicit SoundEffect( const std::string& path );
explicit SoundEffect( const std::string& path, int channel = -1);
~SoundEffect( );
SoundEffect(const SoundEffect& other) = delete;
SoundEffect& operator=(const SoundEffect& rhs) = delete;
@@ -12,13 +12,15 @@ public:
SoundEffect& operator=( SoundEffect&& rhs) = delete;
bool IsLoaded( ) const;
bool Play( const int loops ) const;
void Play( const int loops ) const;
void SetVolume( const int value );
int GetVolume( ) const;
int GetVolume( ) const;
void Stop( ) const;
static void StopAll( );
static void PauseAll( );
static void ResumeAll( );
private:
Mix_Chunk* m_pMixChunk;
int m_Channel;
};

View File

@@ -21,6 +21,9 @@ void Text::Draw(const Vector2f& pos) const {
}
}
void Text::ChangeText(const std::string& text) {
if(m_Text == text) {
return;
}
if(m_IsCreatedOk && m_Texture->IsCreationOk()) {
delete m_Texture;
m_Texture = new Texture(text, m_FontPath, m_Size, m_Color);

View File

@@ -14,4 +14,5 @@ namespace Colors
const Color4f MAGENTA{ 1.0f, 0.0f, 1.0f, 1.0f };
const Color4f CYAN{ 0.0f, 1.0f, 1.0f, 1.0f };
const Color4f PINK{ 1.0f, 0.0f, 0.5f, 1.0f };
const Color4f ORANGE{ 1.0f, 0.5f, 0.0f, 1.0f };
}