diff --git a/.gitignore b/.gitignore index b034bb8..eb4cc70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ #Editor generated files -#*.sln -#*.vcproj +*.sln +*.vcproj *.suo *.ncb *.user @@ -8,3 +8,14 @@ #Directories Release/ Debug/ +Out/ + +#Project generated files +*.db +*.o +*.a +*.exe + +#Shell files +*.bat +*.sh diff --git a/Hearts.sln b/Hearts.sln deleted file mode 100644 index 0a74e19..0000000 --- a/Hearts.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual C++ Express 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hearts", "Hearts\Hearts.vcproj", "{A3DAA0E4-CC3F-43F4-BCD1-348A090F753B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A3DAA0E4-CC3F-43F4-BCD1-348A090F753B}.Debug|Win32.ActiveCfg = Debug|Win32 - {A3DAA0E4-CC3F-43F4-BCD1-348A090F753B}.Debug|Win32.Build.0 = Debug|Win32 - {A3DAA0E4-CC3F-43F4-BCD1-348A090F753B}.Release|Win32.ActiveCfg = Release|Win32 - {A3DAA0E4-CC3F-43F4-BCD1-348A090F753B}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/Hearts/Hearts.vcproj b/Hearts/Hearts.vcproj deleted file mode 100644 index dcacb6b..0000000 --- a/Hearts/Hearts.vcproj +++ /dev/null @@ -1,308 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Hearts/audio_manager.cpp b/Hearts/audio_manager.cpp deleted file mode 100644 index e3ac794..0000000 --- a/Hearts/audio_manager.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* File Name: audio_manager.cpp - * Author: Kayne Ruse - * Date (dd/mm/yyyy): 21/06/2011 - * Copyright: (c) Kayne Ruse 2011, 2012 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * Description: - * The AudioManager class, used to manage sounds and music. - * Part of the KAGE Game Engine. -*/ -#include -#include "audio_manager.h" -using namespace std; -using namespace KAGE; - -//------------------------- -//Public access members -//------------------------- - -AudioManager::~AudioManager() { - while(Mix_Init(0)) - Mix_Quit(); - Mix_CloseAudio(); -} - -int AudioManager::Init(int flags,int frequency,int format,int channels,int chunkSize) { - if (Mix_OpenAudio(frequency,format,channels,chunkSize) != 0) { - cout << "Error in AudioManager::AudioManager()" << endl; - cout << "Failed to initialise SDL_mixer" << endl; - return -1; - } - - int init = Mix_Init(flags); - - if (init != flags) { - cout << "Error in AudioManager::AudioManager()" << endl; - cout << "Mix_Init() failed to load all components" << endl; - cout << "Is there a .DLL file missing?" << endl; - cout << "flags: " << flags << "; init: " << init << endl; - return -2; - } - - return 0; -} - -//------------------------- -//Sounds -//------------------------- - -Sound* AudioManager::Add(const char* name,const char* fName) { - if (Exists(name)) { - cout << "Error in AudioManager::Add(name,fName)" << endl; - cout << "A Sound of that name already exists" << endl; - cout << "name: " << name << endl; - return NULL; - } - - return NamedManager::Add(name,new Sound(fName)); -} - -int AudioManager::Play(const char* name,int channel,int loop) { - if (!Exists(name)) { - cout << "Error in AudioManager::Play(name,channel,loop)" << endl; - cout << "No such Sound with that name" << endl; - cout << "name: " << name << endl; - return -2; - } - - return Get(name)->Play(channel,loop); -} - -int AudioManager::Volume(const char* name,int volume) { - if (!Exists(name)) { - cout << "Error in AudioManager::Volume(name,volume)" << endl; - cout << "No such Sound with that name" << endl; - cout << "name: " << name << endl; - return -2; - } - - return Get(name)->Volume(volume); -} - -//------------------------- -//Music -//------------------------- - -Music* AudioManager::Music() { - return &music; -} - -//------------------------- -//Channels -//------------------------- - -int AudioManager::ChannelAllocate(int num) { - return Mix_AllocateChannels(num); -} - -int AudioManager::ChannelHalt(int channel) { - return Mix_HaltChannel(channel); -} - -int AudioManager::ChannelPlaying(int channel) { - return Mix_Playing(channel); -} - -void AudioManager::ChannelPause(int channel) { - Mix_Pause(channel); -} - -void AudioManager::ChannelResume(int channel) { - Mix_Resume(channel); -} - -int AudioManager::ChannelPaused(int channel) { - return Mix_Paused(channel); -} - -int AudioManager::ChannelVolume(int volume,int channel) { - return Mix_Volume(channel,volume); -} diff --git a/Hearts/audio_manager.h b/Hearts/audio_manager.h deleted file mode 100644 index f8447f5..0000000 --- a/Hearts/audio_manager.h +++ /dev/null @@ -1,70 +0,0 @@ -/* File Name: audio_manager.h - * Author: Kayne Ruse - * Date (dd/mm/yyyy): 21/06/2011 - * Copyright: (c) Kayne Ruse 2011, 2012 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * Description: - * The AudioManager class, used to manage sounds and music. - * Part of the KAGE Game Engine. -*/ -#ifndef KR_KAGE_AUDIOMANAGER_H_ -#define KR_KAGE_AUDIOMANAGER_H_ - -#include "SDL_mixer.h" -#include "named_manager.h" -#include "sound.h" -#include "music.h" - -namespace KAGE { - class AudioManager : public KAGE::NamedManager { - public: - /* Public access members */ - ~AudioManager(); - - int Init(int flags,int frequency,int format,int channels,int chunkSize); - - /* Sounds */ - Sound* Add (const char* name, const char* fName); - int Play (const char* name, int channel = -1, int loop = 0); - int Volume (const char* name, int volume = -1); - - /* Music */ - KAGE::Music* Music(); - - /* Channels */ - int ChannelAllocate (int num = -1); - - int ChannelHalt (int channel = -1); - int ChannelPlaying (int channel = -1); - - void ChannelPause (int channel = -1); - void ChannelResume (int channel = -1); - int ChannelPaused (int channel = -1); - - int ChannelVolume (int volume = -1,int channel = -1); - private: - /* Private access members */ - KAGE::Music music; - }; -} - -#endif diff --git a/Hearts/base_engine.h b/Hearts/base_engine.h index f3ff774..fe1b29d 100644 --- a/Hearts/base_engine.h +++ b/Hearts/base_engine.h @@ -29,7 +29,7 @@ #ifndef KR_KAGE_BASEENGINE_H_ #define KR_KAGE_BASEENGINE_H_ -#include "SDL.h" +#include "SDL/SDL.h" namespace KAGE { class BaseEngine { diff --git a/Hearts/card.h b/Hearts/card.h index 9b472d5..0b47207 100644 --- a/Hearts/card.h +++ b/Hearts/card.h @@ -28,9 +28,7 @@ #ifndef KR_CARD_H_ #define KR_CARD_H_ -#include "SDL.h" - -#include "image.h" +#include "image.hpp" #define ISCARD(CARD,RANK,SUIT) (CARD->GetSuit() == Card::SUIT && CARD->GetRank() == Card::RANK) diff --git a/Hearts/deck.h b/Hearts/deck.h index 540eda1..89394fd 100644 --- a/Hearts/deck.h +++ b/Hearts/deck.h @@ -28,12 +28,10 @@ #ifndef KR_DECK_H_ #define KR_DECK_H_ -#include "SDL.h" - -#include "image.h" - #include "card_list.h" +#include "image.hpp" + class Deck : public CardList { public: /* Public access members */ diff --git a/Hearts/hearts_engine.cpp b/Hearts/hearts_engine.cpp index 09a4a0f..5a45b14 100644 --- a/Hearts/hearts_engine.cpp +++ b/Hearts/hearts_engine.cpp @@ -40,10 +40,6 @@ HeartsEngine::HeartsEngine() { heartSprite.LoadSurface("rsc\\heart.bmp"); heartSprite.SetClipW(64); - mAudio.Init(0,MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,1,1024); - mAudio.Add("knock","rsc\\knock.wav"); - mAudio.Add("glass","rsc\\glass_break.wav"); - deck.Init("rsc\\cards.bmp","rsc\\back.bmp"); player[0] = new PlayerUser(); @@ -74,7 +70,7 @@ HeartsEngine::~HeartsEngine() { for (int i = 0; i < 4; i++) delete player[i]; - heartSprite.UnloadSurface(); + heartSprite.FreeSurface(); } //------------------------- @@ -267,7 +263,6 @@ void HeartsEngine::CleanupPhase() { void HeartsEngine::PlayBeforePhase() { if (firstPlayer != 0) { - mAudio.Play("knock"); for (int i = firstPlayer; i < 4; i++) { bool heartSound = heartsBroken; Card* c = ((PlayerAI*)(player[i]))->PassPlayCard(table.GetLeadingSuit(firstPlayer),trickCount,heartsBroken); @@ -280,7 +275,6 @@ void HeartsEngine::PlayBeforePhase() { } if (heartSound != heartsBroken) { heartSprite.SetClipX(64); - mAudio.Play("glass"); } } } @@ -297,13 +291,11 @@ void HeartsEngine::PlayPlayerPhase() { } if (heartSound != heartsBroken) { heartSprite.SetClipX(64); - mAudio.Play("glass"); } } } void HeartsEngine::PlayAfterPhase() { - mAudio.Play("knock"); int max = (firstPlayer == 0)? 4:firstPlayer; for (int i = 1; i < max; i++) { @@ -318,7 +310,6 @@ void HeartsEngine::PlayAfterPhase() { } if (heartSound != heartsBroken) { heartSprite.SetClipX(64); - mAudio.Play("glass"); } } diff --git a/Hearts/hearts_engine.h b/Hearts/hearts_engine.h index 8f2dd04..d07ab95 100644 --- a/Hearts/hearts_engine.h +++ b/Hearts/hearts_engine.h @@ -28,8 +28,7 @@ #ifndef KR_HEARTSENGINE_H_ #define KR_HEARTSENGINE_H_ #include "base_engine.h" -#include "image.h" -#include "audio_manager.h" +#include "image.hpp" #include "deck.h" #include "player_ai.h" #include "player_user.h" @@ -48,7 +47,6 @@ private: /* KAGE Managers */ Image heartSprite; - KAGE::AudioManager mAudio; /* Game phase members */ //TODO: "phases" void SetupPhase(); diff --git a/Hearts/image.cpp b/Hearts/image.cpp index a81d70e..474b76d 100644 --- a/Hearts/image.cpp +++ b/Hearts/image.cpp @@ -1,115 +1,145 @@ -/* File Name: image.cpp - * Author: Kayne Ruse - * Date (dd/mm/yyyy): 14/12/2012 - * Copyright: (c) Kayne Ruse 2012 - * +/* Copyright: (c) Kayne Ruse 2013 + * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. - * + * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: - * + * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. - * + * * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. - * + * * 3. This notice may not be removed or altered from any source * distribution. - * - * Description: - * ... */ -#include "image.h" +#include "image.hpp" -#include +#include +#include -//------------------------- -//Public access members -//------------------------- - -Image::Image() { - m_clip.x = m_clip.y = m_clip.w = m_clip.h = 0; - m_pSurface = NULL; - m_bLocal = false; -} - -Image::~Image() { - UnloadSurface(); -} - -//------------------------- -//Surface handlers -//------------------------- - -void Image::LoadSurface(const char* fname) { - SDL_Surface* pSurface; - - if ( (pSurface = SDL_LoadBMP(fname)) == NULL) - throw(std::exception("Failed to load surface")); - - UnloadSurface(); - - SetSurface(pSurface); - - m_bLocal = true; - - SetColorKey(255, 0, 255); -} - -void Image::UnloadSurface() { - if (m_bLocal) { - SDL_FreeSurface(m_pSurface); - m_bLocal = false; +Image& Image::operator=(Image const& rhs) { + //don't screw yourself + if (this == &rhs) { + return *this; } - m_pSurface = NULL; + FreeSurface(); + + //Copy the other Image's stuff + surface = rhs.surface; + clip = rhs.clip; + local = false; } -SDL_Surface* Image::SetSurface(SDL_Surface* pSurface) { - if (m_bLocal) - throw(std::exception("Failed to set surface, Image has a local surface")); +Image& Image::operator=(Image&& rhs) { + //don't screw yourself + if (this == &rhs) { + return *this; + } - if (!pSurface) - throw(std::exception("Failed to set surface, given surface is NULL")); + FreeSurface(); - m_pSurface = pSurface; + //Steal the other Image's stuff + surface = rhs.surface; + clip = rhs.clip; + local = rhs.local; - m_clip.x = 0; - m_clip.y = 0; - m_clip.w = m_pSurface->w; - m_clip.h = m_pSurface->h; - - m_bLocal = false; - - return m_pSurface; + rhs.surface = nullptr; + rhs.clip = {0, 0, 0, 0}; + rhs.local = false; } -SDL_Surface* Image::GetSurface() { - return m_pSurface; +SDL_Surface* Image::LoadSurface(std::string fname) { + FreeSurface(); + SDL_Surface* p = SDL_LoadBMP(fname.c_str()); + if (!p) { + std::ostringstream os; + os << "Failed to load file: " << fname; + throw(std::runtime_error(os.str())); + } + surface = p; + clip = {0, 0, (Uint16)surface->w, (Uint16)surface->h}; + local = true; + SetTransparentColor(255, 0, 255); //default + return surface; } -void Image::SetColorKey(Uint8 r, Uint8 g, Uint8 b) { - if (m_pSurface != NULL) - SDL_SetColorKey(m_pSurface, SDL_SRCCOLORKEY, SDL_MapRGB(m_pSurface->format, r, g, b)); +SDL_Surface* Image::CreateSurface(Uint16 w, Uint16 h) { + FreeSurface(); + Uint32 rmask, gmask, bmask, amask; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif + SDL_Surface* p = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, rmask, gmask, bmask, amask); + if (!p) { + throw(std::runtime_error("Failed to create Image surface")); + } + surface = p; + clip = {0, 0, (Uint16)surface->w, (Uint16)surface->h}; + local = true; + SetTransparentColor(255, 0, 255); //default + return surface; } -void Image::ClearColorKey() { - if (m_pSurface != NULL) - SDL_SetColorKey(m_pSurface, 0, 0); +SDL_Surface* Image::SetSurface(SDL_Surface* p) { + FreeSurface(); + if (!p) { + throw(std::invalid_argument("No surface pointer provided")); + } + surface = p; + clip = {0, 0, (Uint16)surface->w, (Uint16)surface->h}; + local = false; + return surface; } -//------------------------- -//Rendering -//------------------------- - -void Image::DrawTo(SDL_Surface* const pDest, Sint16 x, Sint16 y) { - SDL_Rect sclip = m_clip, dclip = {x,y}; - - SDL_BlitSurface(m_pSurface, &sclip, pDest, &dclip); +void Image::FreeSurface() { + if (local) { + SDL_FreeSurface(surface); + local = false; + } + surface = nullptr; + clip = {0, 0, 0, 0}; +} + +void Image::DrawTo(SDL_Surface* dest, Sint16 x, Sint16 y) { + if (!surface) { + throw(std::logic_error("No image surface to draw")); + } + SDL_Rect sclip = clip, dclip = {x,y}; + SDL_BlitSurface(surface, &sclip, dest, &dclip); +} + +void Image::SetTransparentColor(Uint8 r, Uint8 g, Uint8 b) { + if (!surface) { + throw(std::logic_error("Failed to set the transparent color")); + } + if (!local) { + throw(std::logic_error("Cannot set the transparent color of a non-local surface")); + } + SDL_SetColorKey(surface, SDL_SRCCOLORKEY, SDL_MapRGB(surface->format, r, g, b)); +} + +void Image::ClearTransparentColor() { + if (!surface) { + throw(std::logic_error("Failed to clear the transparent color")); + } + if (!local) { + throw(std::logic_error("Cannot clear the transparent color of a non-local surface")); + } + SDL_SetColorKey(surface, 0, 0); } diff --git a/Hearts/image.h b/Hearts/image.h deleted file mode 100644 index 5cc00cc..0000000 --- a/Hearts/image.h +++ /dev/null @@ -1,75 +0,0 @@ -/* File Name: image.h - * Author: Kayne Ruse - * Date (dd/mm/yyyy): 14/12/2012 - * Copyright: (c) Kayne Ruse 2012 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * Description: - * ... -*/ -#ifndef KR_IMAGE_H_ -#define KR_IMAGE_H_ 2012121401 - -#include "SDL.h" - -class Image { -public: - /* Public access members */ - Image(); - virtual ~Image(); - - /* Surface handlers */ - void LoadSurface(const char* fname); - void UnloadSurface(); - - SDL_Surface* SetSurface(SDL_Surface*); - SDL_Surface* GetSurface(); - - void SetColorKey(Uint8 r, Uint8 g, Uint8 b); - void ClearColorKey(); - - /* Rendering */ - virtual void DrawTo(SDL_Surface* const, Sint16 x, Sint16 y); - - /* Clip handlers */ - SDL_Rect SetClip(SDL_Rect r) { return m_clip = r; } - SDL_Rect GetClip() { return m_clip; } - - Sint16 SetClipX(Sint16 x) { return m_clip.x = x; } - Sint16 SetClipY(Sint16 y) { return m_clip.y = y; } - Uint16 SetClipW(Uint16 w) { return m_clip.w = w; } - Uint16 SetClipH(Uint16 h) { return m_clip.h = h; } - - Sint16 GetClipX() { return m_clip.x; } - Sint16 GetClipY() { return m_clip.y; } - Uint16 GetClipW() { return m_clip.w; } - Uint16 GetClipH() { return m_clip.h; } - - bool IsLoaded() { return m_pSurface != NULL; } - bool IsLocal() { return m_bLocal; } - -private: - SDL_Rect m_clip; - SDL_Surface* m_pSurface; - bool m_bLocal; -}; - -#endif diff --git a/Hearts/image.hpp b/Hearts/image.hpp new file mode 100644 index 0000000..eb684bb --- /dev/null +++ b/Hearts/image.hpp @@ -0,0 +1,73 @@ +/* Copyright: (c) Kayne Ruse 2013 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#ifndef IMAGE_HPP_ +#define IMAGE_HPP_ + +#include "SDL/SDL.h" +#include + +class Image { +public: + Image() = default; + Image(Image const& rhs) { *this = rhs; } + Image(Image&& rhs) { *this = std::move(rhs); } + Image(std::string fname) { LoadSurface(fname); } + Image(Uint16 w, Uint16 h) { CreateSurface(w, h); } + Image(SDL_Surface* p) { SetSurface(p); } + ~Image() { FreeSurface(); } + + Image& operator=(Image const&); + Image& operator=(Image&&); + + SDL_Surface* LoadSurface(std::string fname); + SDL_Surface* CreateSurface(Uint16 w, Uint16 h); + SDL_Surface* SetSurface(SDL_Surface*); + SDL_Surface* GetSurface() const { return surface; } + void FreeSurface(); + + void DrawTo(SDL_Surface* const, Sint16 x, Sint16 y); + + //Clip handlers + SDL_Rect SetClip(SDL_Rect r) { return clip = r; } + SDL_Rect GetClip() const { return clip; } + + Sint16 SetClipX(Sint16 x) { return clip.x = x; } + Sint16 SetClipY(Sint16 y) { return clip.y = y; } + Uint16 SetClipW(Uint16 w) { return clip.w = w; } + Uint16 SetClipH(Uint16 h) { return clip.h = h; } + + Sint16 GetClipX() const { return clip.x; } + Sint16 GetClipY() const { return clip.y; } + Uint16 GetClipW() const { return clip.w; } + Uint16 GetClipH() const { return clip.h; } + + bool GetLocal() const { return local; } + + void SetTransparentColor(Uint8 r, Uint8 g, Uint8 b); + void ClearTransparentColor(); +protected: + SDL_Surface* surface = nullptr; + SDL_Rect clip = {0, 0, 0, 0}; + bool local = false; +}; + +#endif diff --git a/Hearts/makefile b/Hearts/makefile new file mode 100644 index 0000000..ce691d0 --- /dev/null +++ b/Hearts/makefile @@ -0,0 +1,42 @@ +#config +LIB+=-lmingw32 -lSDLmain -lSDL +CXXFLAGS+=-std=c++11 -DDEBUG +CFLAGS+=-DDEBUG + +#source +CXXSRC=$(wildcard *.cpp) +CSRC=$(wildcard *.c) + +#objects +OBJDIR=obj +OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) +OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o)) + +#output +OUTDIR=../out +OUT=$(addprefix $(OUTDIR)/,Hearts) + +#targets +all: $(OBJ) $(OUT) + $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIB) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +$(OBJDIR)/%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all diff --git a/Hearts/music.cpp b/Hearts/music.cpp deleted file mode 100644 index bae6073..0000000 --- a/Hearts/music.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* File Name: music.cpp - * Author: Kayne Ruse - * Date (dd/mm/yyyy): 21/06/2011 - * Copyright: (c) Kayne Ruse 2011, 2012 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * Description: - * The Music class, a wrapper for Mix_Music and other sound functionality. - * Part of the KAGE Game Engine. -*/ -#include -#include "music.h" -using namespace std; -using namespace KAGE; - -//------------------------- -//Public access members -//------------------------- - -Music::Music() { - music = NULL; -} - -Music::~Music() { - Free(); -} - -//------------------------- -//Accessors and mutators -//------------------------- - -int Music::Load(const char* fName) { - Free(); - - music = Mix_LoadMUS(fName); - - if (music == NULL) { - cout << "Error in Music::Load()" << endl; - cout << "Mix_LoadMUS() returned NULL" << endl; - cout << "fName: " << fName << endl; - return -1; - } - - return 0; -} - -void Music::Free() { - if (music != NULL) { - Mix_FreeMusic(music); - music = NULL; - } -} - -int Music::Play(int loop) { - if (music == NULL) { - cout << "Error in Music::Play()" << endl; - cout << "There is no music loaded" << endl; - return -2; - } - - return Mix_PlayMusic(music,loop); -} - -void Music::Halt() { - Mix_HaltMusic(); -} - -int Music::Playing() { - return Mix_PlayingMusic(); -} - -void Music::Pause() { - Mix_PauseMusic(); -} - -void Music::Resume() { - Mix_ResumeMusic(); -} - -int Music::Paused() { - return Mix_PausedMusic(); -} - -void Music::Rewind() { - Mix_RewindMusic(); -} - -int Music::Volume(int volume) { - return Mix_VolumeMusic(volume); -} - -//------------------------- -//Protected access members -//------------------------- - -Mix_Music* Music::GetMixMusic() { - return music; -} diff --git a/Hearts/music.h b/Hearts/music.h deleted file mode 100644 index 9dfd013..0000000 --- a/Hearts/music.h +++ /dev/null @@ -1,63 +0,0 @@ -/* File Name: music.h - * Author: Kayne Ruse - * Date (dd/mm/yyyy): 21/06/2011 - * Copyright: (c) Kayne Ruse 2011, 2012 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * Description: - * The Music class, a wrapper for Mix_Music and other sound functionality. - * Part of the KAGE Game Engine. -*/ -#ifndef KR_KAGE_MUSIC_H_ -#define KR_KAGE_MUSIC_H_ - -#include "SDL_mixer.h" - -namespace KAGE { - class Music { - public: - /* Public access members */ - Music(); - ~Music(); - - /* Accessors and mutators */ - int Load (const char* fName); - void Free (); - - int Play (int loop = -1); - void Halt (); - int Playing (); - void Pause (); - void Resume (); - int Paused (); - void Rewind (); - - int Volume (int volume); - protected: - /* Protected access members */ - Mix_Music* GetMixMusic(); - private: - /* Private access members */ - Mix_Music* music; - }; -} - -#endif diff --git a/Hearts/named_manager.h b/Hearts/named_manager.h deleted file mode 100644 index c2a3d72..0000000 --- a/Hearts/named_manager.h +++ /dev/null @@ -1,130 +0,0 @@ -/* File Name: named_manager.h - * Author: Kayne Ruse - * Date (dd/mm/yyyy): 21/06/2011 - * Copyright: (c) Kayne Ruse 2011, 2012 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * Description: - * The NamedManager template class acts as a parent for all of Kage's managers. - * Part of the KAGE Game Engine. -*/ -#ifndef KR_KAGE_NAMEDMANAGER_H_ -#define KR_KAGE_NAMEDMANAGER_H_ - -#include -#include - -namespace KAGE { -template - class NamedManager { - public: - /* Public access members */ - ~NamedManager (); - - T* Get (const char* name); - T* operator[] (const char* name); - T* Remove (const char* name); - void Delete (const char* name); - void DeleteAll (); - bool Exists (const char* name); - int Size (); - protected: - /* Protected access members */ - T* Add (const char* name,T* item); - - typedef std::map MapType; - MapType mapList; - }; -} - -//------------------------- -//Protected access members -//------------------------- - -template -T* KAGE::NamedManager::Add(const char* name,T* item) { - if (Exists(name)) - return NULL; - return mapList[name] = item; -} - -//------------------------- -//Public access members -//------------------------- - -template -KAGE::NamedManager::~NamedManager() { - DeleteAll(); -} - -template -T* KAGE::NamedManager::Get(const char* name) { - MapType::const_iterator it = mapList.find(name); - if (it != mapList.end()) - return it->second; - else - return NULL; -} - -template -T* KAGE::NamedManager::operator[](const char* name) { - return Get(name); -} - -template -T* KAGE::NamedManager::Remove(const char* name) { - MapType::const_iterator it = mapList.find(name); - if (it == mapList.end()) - return NULL; - - T* ret = it->second; - mapList.erase(it); - return ret; -} - -template -void KAGE::NamedManager::Delete(const char* name) { - MapType::const_iterator it = mapList.find(name); - if (it != mapList.end()) { - delete it->second; - mapList.erase(it); - } -} - -template -void KAGE::NamedManager::DeleteAll() { - for (MapType::iterator it = mapList.begin(); it != mapList.end(); it++) - delete it->second; - mapList.clear(); -} - -template -bool KAGE::NamedManager::Exists(const char* name) { - MapType::const_iterator it = mapList.find(name); - return it != mapList.end(); -} - -template -int KAGE::NamedManager::Size() { - return mapList.size(); -} - -#endif diff --git a/Hearts/player.h b/Hearts/player.h index 1e251be..7a747ab 100644 --- a/Hearts/player.h +++ b/Hearts/player.h @@ -27,7 +27,7 @@ */ #ifndef KR_PLAYER_H_ #define KR_PLAYER_H_ -#include "SDL.h" + #include "card_list.h" class Player { diff --git a/Hearts/sound.cpp b/Hearts/sound.cpp deleted file mode 100644 index 15326af..0000000 --- a/Hearts/sound.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* File Name: sound.cpp - * Author: Kayne Ruse - * Date (dd/mm/yyyy): 13/06/2011 - * Copyright: (c) Kayne Ruse 2011, 2012 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * Description: - * The Sound class, a wrapper for Mix_Chunk and other sound functionality. - * Part of the KAGE Game Engine. -*/ -#include -#include "sound.h" -using namespace std; -using namespace KAGE; - -//------------------------- -//Public access members -//------------------------- - -Sound::Sound(const char* fName) { - chunk = Mix_LoadWAV(fName); - - if (chunk == NULL) { - cout << "Error in Sound::Sound()" << endl; - cout << "Mix_LoadWAV() returned NULL" << endl; - cout << "fName: " << fName << endl; - } -} - -Sound::~Sound() { - Mix_FreeChunk(chunk); -} - -//------------------------- -//Accessors and mutators -//------------------------- - -int Sound::Play(int channel,int loop) { - return Mix_PlayChannel(channel,chunk,loop); -} - -int Sound::Volume(int volume) { - return Mix_VolumeChunk(chunk,volume); -} - -//------------------------- -//Protected access members -//------------------------- - -Mix_Chunk* Sound::GetMixChunk() { - return chunk; -} diff --git a/Hearts/sound.h b/Hearts/sound.h deleted file mode 100644 index c72425b..0000000 --- a/Hearts/sound.h +++ /dev/null @@ -1,53 +0,0 @@ -/* File Name: sound.h - * Author: Kayne Ruse - * Date (dd/mm/yyyy): 13/06/2011 - * Copyright: (c) Kayne Ruse 2011, 2012 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * Description: - * The Sound class, a wrapper for Mix_Chunk and other sound functionality. - * Part of the KAGE Game Engine. -*/ -#ifndef KR_KAGE_SOUND_H_ -#define KR_KAGE_SOUND_H_ - -#include "SDL_mixer.h" - -namespace KAGE { - class Sound { - public: - /* Public access members */ - Sound(const char* fName); - ~Sound(); - - /* Accessors and mutators */ - int Play(int channel = -1,int loop = 0); - int Volume(int volume = -1); - protected: - /* Protected access members */ - Mix_Chunk* GetMixChunk(); - private: - /* Private access members */ - Mix_Chunk* chunk; - }; -} - -#endif diff --git a/Hearts/table.h b/Hearts/table.h index 26137a4..af3a17d 100644 --- a/Hearts/table.h +++ b/Hearts/table.h @@ -27,7 +27,7 @@ */ #ifndef KR_TABLE_H_ #define KR_TABLE_H_ -#include "SDL.h" + #include "card_list.h" class Table { diff --git a/makefile b/makefile new file mode 100644 index 0000000..30ae465 --- /dev/null +++ b/makefile @@ -0,0 +1,17 @@ +#for use on Windows: + +#MKDIR=mkdir +#RM=del /y + +OUTDIR=out + +all: $(OUTDIR) + $(MAKE) -C Hearts + +$(OUTDIR): + mkdir $(OUTDIR) + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all