Compare commits
2 Commits
master
...
dev-delete
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a09f2a8f0 | ||
|
|
81a36b3baa |
18
.gitignore
vendored
@@ -1,24 +1,10 @@
|
||||
#Editor generated files
|
||||
*.sln
|
||||
*.vcproj
|
||||
#*.sln
|
||||
#*.vcproj
|
||||
*.suo
|
||||
*.ncb
|
||||
*.user
|
||||
|
||||
#Directories
|
||||
Release/
|
||||
release/
|
||||
Debug/
|
||||
debug/
|
||||
Out/
|
||||
out/
|
||||
|
||||
#Project generated files
|
||||
*.db
|
||||
*.o
|
||||
*.a
|
||||
*.exe
|
||||
|
||||
#Shell files
|
||||
*.bat
|
||||
*.sh
|
||||
|
||||
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "Hearts/Codebase"]
|
||||
path = Hearts/Codebase
|
||||
url = https://github.com/Ratstail91/Codebase.git
|
||||
20
Hearts.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
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
Hearts/Codebase
Submodule
456
Hearts/Hearts.vcproj
Normal file
@@ -0,0 +1,456 @@
|
||||
<?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=".\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>
|
||||
<Filter
|
||||
Name="Codebase"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Codebase\animator.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\animator.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\bbox.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\bbox.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\config_utility.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\config_utility.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\delta.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\delta.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\frame_rate.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\frame_rate.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\image.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\image.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\vector2.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Codebase\vector3.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
ExcludedFromBuild="true"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
139
Hearts/audio_manager.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/* 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);
|
||||
}
|
||||
70
Hearts/audio_manager.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/* 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
|
||||
@@ -186,7 +186,7 @@ void BaseEngine::RedrawScreen() {
|
||||
}
|
||||
|
||||
void BaseEngine::AdditionalInit() {
|
||||
SDL_WM_SetCaption("Hearts",NULL);
|
||||
SDL_WM_SetCaption("KAGE: Kayne's All-purpose Game Engine, By Kayne Ruse",NULL);
|
||||
}
|
||||
|
||||
int BaseEngine::TranslateMods(SDL_keysym ks) {
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#ifndef KR_KAGE_BASEENGINE_H_
|
||||
#define KR_KAGE_BASEENGINE_H_
|
||||
|
||||
#include "SDL/SDL.h"
|
||||
#include "SDL.h"
|
||||
|
||||
namespace KAGE {
|
||||
class BaseEngine {
|
||||
@@ -103,4 +103,16 @@ namespace KAGE {
|
||||
};
|
||||
}
|
||||
|
||||
#ifndef START
|
||||
/* Creates SDL_main(). Place this after the derived engine's
|
||||
* declaration, and pass it the name of the derived engine.
|
||||
*/
|
||||
#define START(ENGINE) \
|
||||
int SDL_main(int,char**) { \
|
||||
ENGINE app; \
|
||||
app.Start(true); \
|
||||
return 0; \
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,114 +0,0 @@
|
||||
/* 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.
|
||||
*/
|
||||
#include "button.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
Button::Button(std::string bgname, std::string fname, std::string t, Sint16 _x, Sint16 _y) {
|
||||
LoadSurface(bgname);
|
||||
LoadFontSurface(fname);
|
||||
SetText(t);
|
||||
SetX(x);
|
||||
SetY(y);
|
||||
}
|
||||
|
||||
Button::Button(SDL_Surface* bg, SDL_Surface* f, std::string t, Sint16 _x, Sint16 _y) {
|
||||
SetSurface(bg);
|
||||
SetFontSurface(f);
|
||||
SetText(t);
|
||||
SetX(x);
|
||||
SetY(y);
|
||||
}
|
||||
|
||||
SDL_Surface* Button::LoadSurface(std::string s) {
|
||||
image.LoadSurface(s);
|
||||
image.SetClipH(image.GetClipH()/3); //3 phases, vertical storage
|
||||
SetText(text); //reset textX & textY
|
||||
return image.GetSurface();
|
||||
}
|
||||
|
||||
SDL_Surface* Button::LoadFontSurface(std::string s) {
|
||||
font.LoadSurface(s);
|
||||
SetText(text); //reset textX & textY
|
||||
return font.GetSurface();
|
||||
}
|
||||
|
||||
SDL_Surface* Button::SetSurface(SDL_Surface* p) {
|
||||
image.SetSurface(p);
|
||||
image.SetClipH(image.GetClipH()/3); //3 phases, vertical storage
|
||||
SetText(text); //reset textX & textY
|
||||
return image.GetSurface();
|
||||
}
|
||||
|
||||
SDL_Surface* Button::SetFontSurface(SDL_Surface* p) {
|
||||
font.SetSurface(p);
|
||||
SetText(text); //reset textX & textY
|
||||
return font.GetSurface();
|
||||
}
|
||||
|
||||
Button::State Button::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
return CalcState(motion.x, motion.y, motion.state & SDL_BUTTON_LMASK);
|
||||
}
|
||||
|
||||
Button::State Button::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
if (button.button == SDL_BUTTON_LEFT) {
|
||||
return CalcState(button.x, button.y, true);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
Button::State Button::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
if (button.button == SDL_BUTTON_LEFT) {
|
||||
return CalcState(button.x, button.y, false);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
void Button::DrawTo(SDL_Surface* const dest) {
|
||||
image.DrawTo(dest, x, y);
|
||||
font.DrawStringTo(text, dest, textX + x, textY + y);
|
||||
}
|
||||
|
||||
std::string Button::SetText(std::string t) {
|
||||
//one line, cache the position
|
||||
text = t;
|
||||
textX = (image.GetClipW() / 2) - (font.GetCharW() * text.size() / 2);
|
||||
textY = (image.GetClipH() / 2) - (font.GetCharH() / 2);
|
||||
return text;
|
||||
}
|
||||
|
||||
Button::State Button::CalcState(Sint16 i, Sint16 j, bool leftPressed) {
|
||||
if (i < x || i > (x + image.GetClipW()) ||
|
||||
j < y || j > (y + image.GetClipH())
|
||||
) {
|
||||
image.SetClipY(0);
|
||||
return state = State::NORMAL;
|
||||
}
|
||||
if (leftPressed) {
|
||||
image.SetClipY(image.GetClipH()*2);
|
||||
return state = State::PRESSED;
|
||||
}
|
||||
else {
|
||||
image.SetClipY(image.GetClipH());
|
||||
return state = State::HOVER;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/* 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 BUTTON_HPP_
|
||||
#define BUTTON_HPP_
|
||||
|
||||
#include "image.hpp"
|
||||
#include "raster_font.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
//3-phases, no toggle, centred text
|
||||
class Button {
|
||||
public:
|
||||
enum class State {
|
||||
NORMAL, HOVER, PRESSED
|
||||
};
|
||||
|
||||
Button() = default;
|
||||
Button(std::string bgname, std::string fontname, std::string t = "", Sint16 x = 0, Sint16 y = 0);
|
||||
Button(SDL_Surface* background, SDL_Surface* font, std::string t = "", Sint16 x = 0, Sint16 y = 0);
|
||||
~Button() = default;
|
||||
|
||||
//graphics
|
||||
SDL_Surface* LoadSurface(std::string);
|
||||
SDL_Surface* LoadFontSurface(std::string);
|
||||
SDL_Surface* SetSurface(SDL_Surface*);
|
||||
SDL_Surface* SetFontSurface(SDL_Surface*);
|
||||
SDL_Surface* GetSurface() const { return image.GetSurface(); }
|
||||
SDL_Surface* GetFontSurface() const { return font.GetSurface(); }
|
||||
void FreeSurface() { image.FreeSurface(); }
|
||||
void FreeFontSurface() { font.FreeSurface(); }
|
||||
|
||||
//handle input
|
||||
State MouseMotion(SDL_MouseMotionEvent const&);
|
||||
State MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||
State MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||
State SetState(State s) { return state = s; }
|
||||
State GetState() const { return state; }
|
||||
|
||||
//yet another draw function
|
||||
void DrawTo(SDL_Surface* const);
|
||||
|
||||
//text string
|
||||
std::string SetText(std::string);
|
||||
std::string GetText() const { return text; }
|
||||
|
||||
//position
|
||||
Sint16 SetX(Sint16 i) { return x = i; }
|
||||
Sint16 SetY(Sint16 i) { return y = i; }
|
||||
Sint16 GetX() const { return x; }
|
||||
Sint16 GetY() const { return y; }
|
||||
|
||||
//OO Breakers
|
||||
Image* GetImage() { return ℑ }
|
||||
RasterFont* GetFont() { return &font; }
|
||||
|
||||
Sint16 SetTextX(Sint16 i) { return textX = i; }
|
||||
Sint16 SetTextY(Sint16 i) { return textY = i; }
|
||||
Sint16 GetTextX() const { return textX; }
|
||||
Sint16 GetTextY() const { return textY; }
|
||||
private:
|
||||
State CalcState(Sint16 x, Sint16 y, bool leftPressed);
|
||||
|
||||
Sint16 x = 0, y = 0;
|
||||
Sint16 textX = 0, textY = 0; //prevent recalc every loop
|
||||
Image image;
|
||||
RasterFont font; //TODO: cache this?
|
||||
State state = State::NORMAL;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -28,7 +28,9 @@
|
||||
#ifndef KR_CARD_H_
|
||||
#define KR_CARD_H_
|
||||
|
||||
#include "image.hpp"
|
||||
#include "SDL.h"
|
||||
|
||||
#include "Codebase/image.h"
|
||||
|
||||
#define ISCARD(CARD,RANK,SUIT) (CARD->GetSuit() == Card::SUIT && CARD->GetRank() == Card::RANK)
|
||||
|
||||
|
||||
@@ -28,9 +28,11 @@
|
||||
#ifndef KR_DECK_H_
|
||||
#define KR_DECK_H_
|
||||
|
||||
#include "card_list.h"
|
||||
#include "SDL.h"
|
||||
|
||||
#include "image.hpp"
|
||||
#include "Codebase/image.h"
|
||||
|
||||
#include "card_list.h"
|
||||
|
||||
class Deck : public CardList {
|
||||
public:
|
||||
|
||||
@@ -27,34 +27,24 @@
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include <sstream>
|
||||
#include "hearts_engine.h"
|
||||
using namespace std;
|
||||
|
||||
#define CASE break; case
|
||||
|
||||
string itos(int i) {
|
||||
ostringstream ostr;
|
||||
ostr << i;
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
HeartsEngine::HeartsEngine() {
|
||||
heartSprite.LoadSurface("rsc/heart.bmp");
|
||||
heartSprite.LoadSurface("rsc\\heart.bmp");
|
||||
heartSprite.SetClipW(64);
|
||||
|
||||
deck.Init("rsc/cards.bmp","rsc/back.bmp");
|
||||
mAudio.Init(0,MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,1,1024);
|
||||
mAudio.Add("knock","rsc\\knock.wav");
|
||||
mAudio.Add("glass","rsc\\glass_break.wav");
|
||||
|
||||
button.LoadSurface("rsc/button.bmp");
|
||||
button.LoadFontSurface("rsc/pk_white_8.bmp");
|
||||
font.LoadSurface("rsc/pk_white_8.bmp");
|
||||
|
||||
button.SetX(300);
|
||||
button.SetY(300);
|
||||
deck.Init("rsc\\cards.bmp","rsc\\back.bmp");
|
||||
|
||||
player[0] = new PlayerUser();
|
||||
player[1] = new PlayerAI();
|
||||
@@ -84,21 +74,15 @@ HeartsEngine::~HeartsEngine() {
|
||||
for (int i = 0; i < 4; i++)
|
||||
delete player[i];
|
||||
|
||||
heartSprite.FreeSurface();
|
||||
heartSprite.UnloadSurface();
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//Engine members
|
||||
//-------------------------
|
||||
|
||||
void HeartsEngine::MouseMotion(SDL_MouseMotionEvent& motion) {
|
||||
BaseEngine::MouseMotion(motion);
|
||||
button.MouseMotion(motion);
|
||||
}
|
||||
|
||||
void HeartsEngine::MouseButtonDown(SDL_MouseButtonEvent& butt) {
|
||||
BaseEngine::MouseButtonDown(butt);
|
||||
button.MouseButtonDown(butt);
|
||||
void HeartsEngine::MouseButtonDown(SDL_MouseButtonEvent& button) {
|
||||
BaseEngine::MouseButtonDown(button);
|
||||
|
||||
switch(gamePhase) {
|
||||
CASE SWAP:
|
||||
@@ -109,11 +93,6 @@ void HeartsEngine::MouseButtonDown(SDL_MouseButtonEvent& butt) {
|
||||
}
|
||||
}
|
||||
|
||||
void HeartsEngine::MouseButtonUp(SDL_MouseButtonEvent& butt) {
|
||||
BaseEngine::MouseButtonUp(butt);
|
||||
button.MouseButtonUp(butt);
|
||||
}
|
||||
|
||||
void HeartsEngine::Process() {
|
||||
switch(gamePhase) {
|
||||
CASE SETUP: SetupPhase();
|
||||
@@ -131,20 +110,6 @@ void HeartsEngine::Draw() {
|
||||
switch(gamePhase) {
|
||||
case SETUP:
|
||||
case SWAP:
|
||||
if (player[0]->CheckSwapCards()) {
|
||||
switch(rotation) {
|
||||
case Rotation::LEFT:
|
||||
button.SetText("Pass Left");
|
||||
break;
|
||||
case Rotation::RIGHT:
|
||||
button.SetText("Pass Right");
|
||||
break;
|
||||
case Rotation::ACROSS:
|
||||
button.SetText("Pass Across");
|
||||
break;
|
||||
}
|
||||
button.DrawTo(screen);
|
||||
}
|
||||
case TRICK:
|
||||
for (int i = 0; i < 4; i++)
|
||||
player[i]->DrawHand(screen);
|
||||
@@ -154,28 +119,6 @@ void HeartsEngine::Draw() {
|
||||
case SCORE:
|
||||
for (int i = 0; i < 4; i++)
|
||||
player[i]->DrawTricks(screen);
|
||||
button.SetText("Continue");
|
||||
button.DrawTo(screen);
|
||||
|
||||
//I know this sucks
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (winner == i) {
|
||||
font.DrawStringTo(
|
||||
string() + "Player " + itos(i+1) + ": " + itos(player[i]->Score()) + " - " + itos(player[i]->Wins()) + " wins <-- Winner!!",
|
||||
screen,
|
||||
300,
|
||||
200 + font.GetCharH() * i
|
||||
);
|
||||
}
|
||||
else {
|
||||
font.DrawStringTo(
|
||||
string() + "Player " + itos(i+1) + ": " + itos(player[i]->Score()) + " - " + itos(player[i]->Wins()) + " wins",
|
||||
screen,
|
||||
300,
|
||||
200 + font.GetCharH() * i
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -220,7 +163,7 @@ void HeartsEngine::SetupPhase() {
|
||||
}
|
||||
|
||||
void HeartsEngine::SwapPhase() {
|
||||
if (button.GetState() != Button::State::PRESSED)
|
||||
if (!keyboard[SDLK_F1])
|
||||
return;
|
||||
|
||||
if (!player[0]->CheckSwapCards())
|
||||
@@ -264,41 +207,47 @@ void HeartsEngine::TrickPhase() {
|
||||
ResetPositions();
|
||||
CalcScores();
|
||||
gamePhase = SCORE;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
cout << "Player " << i << ": " << player[i]->Score() << endl;//tmp...
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void HeartsEngine::ScorePhase() {
|
||||
//end of game; temporary functionality...
|
||||
if ((player[0]->Score() >= 100 ||
|
||||
if (player[0]->Score() >= 100 ||
|
||||
player[1]->Score() >= 100 ||
|
||||
player[2]->Score() >= 100 ||
|
||||
player[3]->Score() >= 100) && winner == -1)
|
||||
player[3]->Score() >= 100)
|
||||
{
|
||||
winner = 0;
|
||||
cout << "GAME OVER" << endl;
|
||||
int winner = 0;
|
||||
|
||||
//find the winner
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (player[i]->Score() < player[winner]->Score()) {
|
||||
winner = i;
|
||||
}
|
||||
}
|
||||
cout << "Winner is: " << winner << endl;
|
||||
cout << endl;
|
||||
|
||||
//award the winner
|
||||
player[winner]->Wins(1);
|
||||
}
|
||||
for (int i = 0; i < 4; i++)
|
||||
cout << "Player " << i << " wins: " << player[i]->Wins() << endl;
|
||||
|
||||
//wait for input
|
||||
if (button.GetState() == Button::State::PRESSED) {
|
||||
gamePhase = CLEANUP;
|
||||
cout << endl;
|
||||
|
||||
//reset the game
|
||||
if (winner != -1) {
|
||||
winner = -1;
|
||||
//reset all values
|
||||
for (int i = 0; i < 4; i++)
|
||||
player[i]->Score( -player[i]->Score() );
|
||||
rotation = NONE;
|
||||
}
|
||||
}
|
||||
|
||||
//10 second delay
|
||||
if (SDL_GetTicks() - timeTick > 10000 || keyboard[SDLK_F1])//button...
|
||||
gamePhase = CLEANUP;
|
||||
}
|
||||
|
||||
void HeartsEngine::CleanupPhase() {
|
||||
@@ -318,6 +267,7 @@ 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);
|
||||
@@ -330,6 +280,7 @@ void HeartsEngine::PlayBeforePhase() {
|
||||
}
|
||||
if (heartSound != heartsBroken) {
|
||||
heartSprite.SetClipX(64);
|
||||
mAudio.Play("glass");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -346,11 +297,13 @@ 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++) {
|
||||
@@ -365,6 +318,7 @@ void HeartsEngine::PlayAfterPhase() {
|
||||
}
|
||||
if (heartSound != heartsBroken) {
|
||||
heartSprite.SetClipX(64);
|
||||
mAudio.Play("glass");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,16 +27,13 @@
|
||||
*/
|
||||
#ifndef KR_HEARTSENGINE_H_
|
||||
#define KR_HEARTSENGINE_H_
|
||||
|
||||
#include "base_engine.h"
|
||||
|
||||
#include "image.hpp"
|
||||
#include "Codebase/image.h"
|
||||
#include "audio_manager.h"
|
||||
#include "deck.h"
|
||||
#include "player_ai.h"
|
||||
#include "player_user.h"
|
||||
#include "table.h"
|
||||
#include "button.hpp"
|
||||
#include "raster_font.hpp"
|
||||
|
||||
class HeartsEngine : public KAGE::BaseEngine {
|
||||
public:
|
||||
@@ -45,14 +42,13 @@ public:
|
||||
~HeartsEngine();
|
||||
private:
|
||||
/* Engine members */
|
||||
void MouseMotion (SDL_MouseMotionEvent& motion);
|
||||
void MouseButtonDown (SDL_MouseButtonEvent& button);
|
||||
void MouseButtonUp (SDL_MouseButtonEvent& button);
|
||||
void Process ();
|
||||
void Draw ();
|
||||
|
||||
/* KAGE Managers */
|
||||
Image heartSprite;
|
||||
KAGE::AudioManager mAudio;
|
||||
|
||||
/* Game phase members */ //TODO: "phases"
|
||||
void SetupPhase();
|
||||
@@ -78,9 +74,6 @@ private:
|
||||
}rotation;
|
||||
|
||||
/* Game members */
|
||||
Button button;
|
||||
RasterFont font;
|
||||
|
||||
Deck deck;
|
||||
Player *player[4];
|
||||
Table table;
|
||||
@@ -90,8 +83,6 @@ private:
|
||||
bool heartsBroken;
|
||||
int timeTick;
|
||||
|
||||
int winner = -1;
|
||||
|
||||
/* Utility members */
|
||||
void ResetPositions();
|
||||
void ResetFaces();
|
||||
@@ -99,4 +90,6 @@ private:
|
||||
void CalcScores();
|
||||
};
|
||||
|
||||
START(HeartsEngine)
|
||||
|
||||
#endif
|
||||
|
||||
145
Hearts/image.cpp
@@ -1,145 +0,0 @@
|
||||
/* 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.
|
||||
*/
|
||||
#include "image.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
Image& Image::operator=(Image const& rhs) {
|
||||
//don't screw yourself
|
||||
if (this == &rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
FreeSurface();
|
||||
|
||||
//Copy the other Image's stuff
|
||||
surface = rhs.surface;
|
||||
clip = rhs.clip;
|
||||
local = false;
|
||||
}
|
||||
|
||||
Image& Image::operator=(Image&& rhs) {
|
||||
//don't screw yourself
|
||||
if (this == &rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
FreeSurface();
|
||||
|
||||
//Steal the other Image's stuff
|
||||
surface = rhs.surface;
|
||||
clip = rhs.clip;
|
||||
local = rhs.local;
|
||||
|
||||
rhs.surface = nullptr;
|
||||
rhs.clip = {0, 0, 0, 0};
|
||||
rhs.local = false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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,73 +0,0 @@
|
||||
/* 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
|
||||
@@ -1,53 +0,0 @@
|
||||
#libraries
|
||||
ifeq ($(OS),Windows_NT)
|
||||
LIBS+=-lmingw32
|
||||
endif
|
||||
LIBS+=-lSDLmain -lSDL
|
||||
|
||||
#flags
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
ifeq ($(shell uname), Linux)
|
||||
#read data about the current install
|
||||
CXXFLAGS+=$(shell sdl-config --cflags --static-libs)
|
||||
endif
|
||||
|
||||
#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) $(LIBS)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
ifeq ($(OS),Windows_NT)
|
||||
$(RM) *.o *.a *.exe
|
||||
else ifeq ($(shell uname), Linux)
|
||||
find . -type f -name '*.o' -exec rm -f -r -v {} \;
|
||||
find . -type f -name '*.a' -exec rm -f -r -v {} \;
|
||||
rm -f -v $(OUT)
|
||||
endif
|
||||
|
||||
rebuild: clean all
|
||||
116
Hearts/music.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/* 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,4 +1,7 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013
|
||||
/* 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
|
||||
@@ -18,32 +21,43 @@
|
||||
*
|
||||
* 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 RASTERFONT_HPP_
|
||||
#define RASTERFONT_HPP_
|
||||
#ifndef KR_KAGE_MUSIC_H_
|
||||
#define KR_KAGE_MUSIC_H_
|
||||
|
||||
#include "image.hpp"
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
class RasterFont {
|
||||
public:
|
||||
RasterFont() = default;
|
||||
RasterFont(std::string fname) { LoadSurface(fname); }
|
||||
RasterFont(SDL_Surface* p) { SetSurface(p); }
|
||||
~RasterFont() = default;
|
||||
namespace KAGE {
|
||||
class Music {
|
||||
public:
|
||||
/* Public access members */
|
||||
Music();
|
||||
~Music();
|
||||
|
||||
void DrawStringTo(std::string, SDL_Surface* const, Sint16 x, Sint16 y);
|
||||
/* Accessors and mutators */
|
||||
int Load (const char* fName);
|
||||
void Free ();
|
||||
|
||||
//Accessors and Mutators
|
||||
SDL_Surface* LoadSurface(std::string);
|
||||
SDL_Surface* SetSurface(SDL_Surface*);
|
||||
SDL_Surface* GetSurface() const { return image.GetSurface(); }
|
||||
void FreeSurface() { image.FreeSurface(); }
|
||||
int Play (int loop = -1);
|
||||
void Halt ();
|
||||
int Playing ();
|
||||
void Pause ();
|
||||
void Resume ();
|
||||
int Paused ();
|
||||
void Rewind ();
|
||||
|
||||
Uint16 GetCharW() const { return image.GetClipW(); }
|
||||
Uint16 GetCharH() const { return image.GetClipH(); }
|
||||
|
||||
private:
|
||||
Image image;
|
||||
};
|
||||
int Volume (int volume);
|
||||
protected:
|
||||
/* Protected access members */
|
||||
Mix_Music* GetMixMusic();
|
||||
private:
|
||||
/* Private access members */
|
||||
Mix_Music* music;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
130
Hearts/named_manager.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/* 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,60 +0,0 @@
|
||||
/* 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.
|
||||
*/
|
||||
#include "raster_font.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
/* It might be more efficient to render to a different surface (like an Image)
|
||||
* rather than calling this function with all of it's '%' and '/'.
|
||||
*/
|
||||
|
||||
void RasterFont::DrawStringTo(std::string s, SDL_Surface* const dest, Sint16 x, Sint16 y) {
|
||||
if (!image.GetSurface()) {
|
||||
throw(std::runtime_error("RasterFont not loaded"));
|
||||
}
|
||||
const Uint16 w = image.GetClipW();
|
||||
const Uint16 h = image.GetClipH();
|
||||
for (int i = 0; i < s.size(); i++) {
|
||||
image.SetClipX(s[i] % 16 * w);
|
||||
image.SetClipY(s[i] / 16 * h);
|
||||
image.DrawTo(dest, x + i * w, y);
|
||||
}
|
||||
}
|
||||
|
||||
/* Note: This class can only take a raster font with 16*16 characters, and the
|
||||
* indevidual characters must have the same dimensions. Overall this class is too
|
||||
* restrictive; I suggest using a 3rd party library.
|
||||
*/
|
||||
|
||||
SDL_Surface* RasterFont::LoadSurface(std::string fname) {
|
||||
image.LoadSurface(fname);
|
||||
image.SetClipW(image.GetSurface()->w/16);
|
||||
image.SetClipH(image.GetSurface()->h/16);
|
||||
return image.GetSurface();
|
||||
}
|
||||
|
||||
SDL_Surface* RasterFont::SetSurface(SDL_Surface* p) {
|
||||
image.SetSurface(p);
|
||||
image.SetClipW(image.GetSurface()->w/16);
|
||||
image.SetClipH(image.GetSurface()->h/16);
|
||||
return image.GetSurface();
|
||||
}
|
||||
70
Hearts/sound.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/* 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,4 +1,7 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013
|
||||
/* 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
|
||||
@@ -18,28 +21,33 @@
|
||||
*
|
||||
* 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 "hearts_engine.h"
|
||||
#ifndef KR_KAGE_SOUND_H_
|
||||
#define KR_KAGE_SOUND_H_
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
using namespace std;
|
||||
namespace KAGE {
|
||||
class Sound {
|
||||
public:
|
||||
/* Public access members */
|
||||
Sound(const char* fName);
|
||||
~Sound();
|
||||
|
||||
int main(int, char**) {
|
||||
#ifdef DEBUG
|
||||
cout << "Beginning program" << endl;
|
||||
#endif
|
||||
try {
|
||||
HeartsEngine app;
|
||||
app.Start(true);
|
||||
}
|
||||
catch(exception& e) {
|
||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||
return 1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
cout << "Clean exit" << endl;
|
||||
#endif
|
||||
return 0;
|
||||
/* 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 {
|
||||
|
||||
|
Before Width: | Height: | Size: 18 KiB |
20
README.md
@@ -1,17 +1,21 @@
|
||||
# Project Hearts version 1.1, 6th September 2013
|
||||
# Project Hearts version 1.0, 22nd June 2011
|
||||
|
||||
## Introduction
|
||||
|
||||
I've added a few features that I wanted, mostly to show off that I can complete a set task. Hopefully the program will be sufficient proof, as long as job interviewers don't look at the code.
|
||||
This project is over 1 1/2 years old, so it doesn't reflect my current programming skills. Regardless, it's a pretty good demonstration of my development. From the KAGE engine, you can see what my thought processes at the time were, and you can probably guess that this evolved into my [Codebase](https://github.com/Ratstail91/Codebase). This has a sound system, and some aspects are different, but it's not a terrible start. I<>ve also included all of the unused modules including NetworkManager, which aren<65>t used here, but are simply part of KAGE.
|
||||
|
||||

|
||||
I'd say that my biggest problem when I was learning was my overreliance on inheritance. You can see this from Card being descended from Image, a common habit in my old code. Also, the presence of NamedManager, which was essentially a wrapper for std::map, and was used to create several different Manager classes isn<73>t something I<>d do today.
|
||||
|
||||
Finally, my biggest mistake I believe, was that I made the KAGE engine closed source. This is a bad idea, since having code visible shows off what you can do. Whether it<69>s to a potential employer, or to someone critiquing your code, it<69>s always a good idea to show what you can do. That<61>s exactly why I<>m uploading this old project. Maybe if I had someone to guide me on the engine<6E>s design at the time, I<>d have a radically different Codebase and coding style today.
|
||||
|
||||
I don<6F>t consider this project complete, since it<69>s still missing a score display and a card passing button, but the scores are shown in the console window (stdout) and the F1 button compensates for a lack of graphical buttons. I<>d like to remake this, using the existing game logic to rely on my current Codebase version. If I do, I<>ll release the modified version under the zlib license.
|
||||
|
||||
## Instructions
|
||||
|
||||
Drop the "rsc" folder into the same directory as the executable
|
||||
To select a card, click on it
|
||||
To pass three cards at the start of the round, select them and press the pass button
|
||||
Try to keep your score as low as possible by avoiding the hearts cards, and the queen of spades
|
||||
To pass three cards at the start of the round, select them and press F1
|
||||
To speed up the wait after a round, press F1
|
||||
|
||||
## Copyright
|
||||
|
||||
@@ -29,5 +33,7 @@ Permission is granted to anyone to use this software for any purpose, including
|
||||
|
||||
## Contact information
|
||||
|
||||
krgamestudios@gmail.com
|
||||
1.0 Build: https://www.dropbox.com/s/gqo2qqj6v1pejyq/Hearts%20by%20Kayne%20Ruse.rar?dl=1
|
||||
ratstail91@yahoo.com.au
|
||||
http://kr-studios.tumblr.com/
|
||||
http://www.facebook.com/krgamestudios
|
||||
Oldest known version: https://dl.dropbox.com/u/46669050/Hearts%20by%20Kayne%20Ruse.rar
|
||||
|
||||
33
makefile
@@ -1,33 +0,0 @@
|
||||
#for use on Windows:
|
||||
|
||||
#MKDIR=mkdir
|
||||
#RM=del /y
|
||||
|
||||
CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||
CFLAGS+=-static-libgcc
|
||||
|
||||
export
|
||||
|
||||
OUTDIR=out
|
||||
|
||||
all: $(OUTDIR)
|
||||
$(MAKE) -C Hearts
|
||||
|
||||
debug: export CXXFLAGS+=-g
|
||||
debug: clean all
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
clean:
|
||||
ifeq ($(OS),Windows_NT)
|
||||
del /S /Q *.o *.a *.exe $(OUTDIR)\*
|
||||
rmdir /S /Q $(OUTDIR)
|
||||
else ifeq ($(shell uname), Linux)
|
||||
find . -type f -name '*.o' -exec rm -f -r -v {} \;
|
||||
find . -type f -name '*.a' -exec rm -f -r -v {} \;
|
||||
rm $(OUTDIR)/* -f
|
||||
find . -empty -type d -delete
|
||||
endif
|
||||
|
||||
rebuild: clean all
|
||||
BIN
rsc/button.bmp
|
Before Width: | Height: | Size: 88 KiB |
BIN
rsc/newdev/heart128x64.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
rsc/newdev/heart32x32.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
rsc/newdev/heart64x64.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
rsc/newdev/heart_b64x64.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 33 KiB |