mirror of
https://github.com/Ratstail91/Hearts.git
synced 2025-11-28 18:14:30 +11:00
Moved build process to GCC
* I've replaced the Image class with the newer version * Removed the sound system to ensure that it compiles & runs
This commit is contained in:
15
.gitignore
vendored
15
.gitignore
vendored
@@ -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
|
||||
|
||||
20
Hearts.sln
20
Hearts.sln
@@ -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
|
||||
@@ -1,308 +0,0 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="Hearts"
|
||||
ProjectGUID="{A3DAA0E4-CC3F-43F4-BCD1-348A090F753B}"
|
||||
RootNamespace="Hearts"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="SDL.lib SDLmain.lib SDL_mixer.lib"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Hearts"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\hearts_engine.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\hearts_engine.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\table.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\table.h"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="Card Systems"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\card.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\card.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\card_list.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\card_list.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\deck.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\deck.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Player Systems"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\player.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\player.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\player_ai.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\player_ai.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\player_user.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\player_user.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="-Notes"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\Notes\Outline.txt"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\Notes\TODO.txt"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="KAGE"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\audio_manager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\audio_manager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\base_engine.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\base_engine.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\image.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\image.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\music.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\music.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\named_manager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\sound.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\sound.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -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 <iostream>
|
||||
#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);
|
||||
}
|
||||
@@ -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<KAGE::Sound> {
|
||||
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
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
194
Hearts/image.cpp
194
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 <exception>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
//-------------------------
|
||||
//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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
73
Hearts/image.hpp
Normal file
73
Hearts/image.hpp
Normal file
@@ -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 <string>
|
||||
|
||||
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
|
||||
42
Hearts/makefile
Normal file
42
Hearts/makefile
Normal file
@@ -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
|
||||
116
Hearts/music.cpp
116
Hearts/music.cpp
@@ -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 <iostream>
|
||||
#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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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 <map>
|
||||
#include <string>
|
||||
|
||||
namespace KAGE {
|
||||
template<typename T>
|
||||
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<std::string,T*> MapType;
|
||||
MapType mapList;
|
||||
};
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//Protected access members
|
||||
//-------------------------
|
||||
|
||||
template<typename T>
|
||||
T* KAGE::NamedManager<T>::Add(const char* name,T* item) {
|
||||
if (Exists(name))
|
||||
return NULL;
|
||||
return mapList[name] = item;
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
template<typename T>
|
||||
KAGE::NamedManager<T>::~NamedManager() {
|
||||
DeleteAll();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* KAGE::NamedManager<T>::Get(const char* name) {
|
||||
MapType::const_iterator it = mapList.find(name);
|
||||
if (it != mapList.end())
|
||||
return it->second;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* KAGE::NamedManager<T>::operator[](const char* name) {
|
||||
return Get(name);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* KAGE::NamedManager<T>::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<typename T>
|
||||
void KAGE::NamedManager<T>::Delete(const char* name) {
|
||||
MapType::const_iterator it = mapList.find(name);
|
||||
if (it != mapList.end()) {
|
||||
delete it->second;
|
||||
mapList.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void KAGE::NamedManager<T>::DeleteAll() {
|
||||
for (MapType::iterator it = mapList.begin(); it != mapList.end(); it++)
|
||||
delete it->second;
|
||||
mapList.clear();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool KAGE::NamedManager<T>::Exists(const char* name) {
|
||||
MapType::const_iterator it = mapList.find(name);
|
||||
return it != mapList.end();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int KAGE::NamedManager<T>::Size() {
|
||||
return mapList.size();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -27,7 +27,7 @@
|
||||
*/
|
||||
#ifndef KR_PLAYER_H_
|
||||
#define KR_PLAYER_H_
|
||||
#include "SDL.h"
|
||||
|
||||
#include "card_list.h"
|
||||
|
||||
class Player {
|
||||
|
||||
@@ -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 <iostream>
|
||||
#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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -27,7 +27,7 @@
|
||||
*/
|
||||
#ifndef KR_TABLE_H_
|
||||
#define KR_TABLE_H_
|
||||
#include "SDL.h"
|
||||
|
||||
#include "card_list.h"
|
||||
|
||||
class Table {
|
||||
|
||||
Reference in New Issue
Block a user