mirror of
https://github.com/Ratstail91/Hearts.git
synced 2025-11-29 10:34:28 +11:00
Compare commits
9 Commits
dev-delete
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7a9c009e5 | ||
|
|
e7c6adf486 | ||
|
|
762f6ce11d | ||
|
|
82d918e4d5 | ||
|
|
27996d9511 | ||
|
|
0da4dda9b0 | ||
|
|
98a70e249c | ||
|
|
a97438a81b | ||
|
|
dad75c2dfa |
18
.gitignore
vendored
18
.gitignore
vendored
@@ -1,10 +1,24 @@
|
|||||||
#Editor generated files
|
#Editor generated files
|
||||||
#*.sln
|
*.sln
|
||||||
#*.vcproj
|
*.vcproj
|
||||||
*.suo
|
*.suo
|
||||||
*.ncb
|
*.ncb
|
||||||
*.user
|
*.user
|
||||||
|
|
||||||
#Directories
|
#Directories
|
||||||
Release/
|
Release/
|
||||||
|
release/
|
||||||
Debug/
|
Debug/
|
||||||
|
debug/
|
||||||
|
Out/
|
||||||
|
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
|
|
||||||
@@ -186,7 +186,7 @@ void BaseEngine::RedrawScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BaseEngine::AdditionalInit() {
|
void BaseEngine::AdditionalInit() {
|
||||||
SDL_WM_SetCaption("KAGE: Kayne's All-purpose Game Engine, By Kayne Ruse",NULL);
|
SDL_WM_SetCaption("Hearts",NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int BaseEngine::TranslateMods(SDL_keysym ks) {
|
int BaseEngine::TranslateMods(SDL_keysym ks) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
#ifndef KR_KAGE_BASEENGINE_H_
|
#ifndef KR_KAGE_BASEENGINE_H_
|
||||||
#define KR_KAGE_BASEENGINE_H_
|
#define KR_KAGE_BASEENGINE_H_
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL/SDL.h"
|
||||||
|
|
||||||
namespace KAGE {
|
namespace KAGE {
|
||||||
class BaseEngine {
|
class BaseEngine {
|
||||||
@@ -103,16 +103,4 @@ namespace KAGE {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef START
|
#endif
|
||||||
/* 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
|
|
||||||
114
Hearts/button.cpp
Normal file
114
Hearts/button.cpp
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
91
Hearts/button.hpp
Normal file
91
Hearts/button.hpp
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/* 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,9 +28,7 @@
|
|||||||
#ifndef KR_CARD_H_
|
#ifndef KR_CARD_H_
|
||||||
#define KR_CARD_H_
|
#define KR_CARD_H_
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "image.hpp"
|
||||||
|
|
||||||
#include "image.h"
|
|
||||||
|
|
||||||
#define ISCARD(CARD,RANK,SUIT) (CARD->GetSuit() == Card::SUIT && CARD->GetRank() == Card::RANK)
|
#define ISCARD(CARD,RANK,SUIT) (CARD->GetSuit() == Card::SUIT && CARD->GetRank() == Card::RANK)
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,10 @@
|
|||||||
#ifndef KR_DECK_H_
|
#ifndef KR_DECK_H_
|
||||||
#define KR_DECK_H_
|
#define KR_DECK_H_
|
||||||
|
|
||||||
#include "SDL.h"
|
|
||||||
|
|
||||||
#include "image.h"
|
|
||||||
|
|
||||||
#include "card_list.h"
|
#include "card_list.h"
|
||||||
|
|
||||||
|
#include "image.hpp"
|
||||||
|
|
||||||
class Deck : public CardList {
|
class Deck : public CardList {
|
||||||
public:
|
public:
|
||||||
/* Public access members */
|
/* Public access members */
|
||||||
|
|||||||
@@ -27,24 +27,34 @@
|
|||||||
*/
|
*/
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sstream>
|
||||||
#include "hearts_engine.h"
|
#include "hearts_engine.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define CASE break; case
|
#define CASE break; case
|
||||||
|
|
||||||
|
string itos(int i) {
|
||||||
|
ostringstream ostr;
|
||||||
|
ostr << i;
|
||||||
|
return ostr.str();
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
HeartsEngine::HeartsEngine() {
|
HeartsEngine::HeartsEngine() {
|
||||||
heartSprite.LoadSurface("rsc\\heart.bmp");
|
heartSprite.LoadSurface("rsc/heart.bmp");
|
||||||
heartSprite.SetClipW(64);
|
heartSprite.SetClipW(64);
|
||||||
|
|
||||||
mAudio.Init(0,MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,1,1024);
|
deck.Init("rsc/cards.bmp","rsc/back.bmp");
|
||||||
mAudio.Add("knock","rsc\\knock.wav");
|
|
||||||
mAudio.Add("glass","rsc\\glass_break.wav");
|
|
||||||
|
|
||||||
deck.Init("rsc\\cards.bmp","rsc\\back.bmp");
|
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);
|
||||||
|
|
||||||
player[0] = new PlayerUser();
|
player[0] = new PlayerUser();
|
||||||
player[1] = new PlayerAI();
|
player[1] = new PlayerAI();
|
||||||
@@ -74,15 +84,21 @@ HeartsEngine::~HeartsEngine() {
|
|||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
delete player[i];
|
delete player[i];
|
||||||
|
|
||||||
heartSprite.UnloadSurface();
|
heartSprite.FreeSurface();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Engine members
|
//Engine members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void HeartsEngine::MouseButtonDown(SDL_MouseButtonEvent& button) {
|
void HeartsEngine::MouseMotion(SDL_MouseMotionEvent& motion) {
|
||||||
BaseEngine::MouseButtonDown(button);
|
BaseEngine::MouseMotion(motion);
|
||||||
|
button.MouseMotion(motion);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeartsEngine::MouseButtonDown(SDL_MouseButtonEvent& butt) {
|
||||||
|
BaseEngine::MouseButtonDown(butt);
|
||||||
|
button.MouseButtonDown(butt);
|
||||||
|
|
||||||
switch(gamePhase) {
|
switch(gamePhase) {
|
||||||
CASE SWAP:
|
CASE SWAP:
|
||||||
@@ -93,6 +109,11 @@ void HeartsEngine::MouseButtonDown(SDL_MouseButtonEvent& button) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HeartsEngine::MouseButtonUp(SDL_MouseButtonEvent& butt) {
|
||||||
|
BaseEngine::MouseButtonUp(butt);
|
||||||
|
button.MouseButtonUp(butt);
|
||||||
|
}
|
||||||
|
|
||||||
void HeartsEngine::Process() {
|
void HeartsEngine::Process() {
|
||||||
switch(gamePhase) {
|
switch(gamePhase) {
|
||||||
CASE SETUP: SetupPhase();
|
CASE SETUP: SetupPhase();
|
||||||
@@ -110,16 +131,52 @@ void HeartsEngine::Draw() {
|
|||||||
switch(gamePhase) {
|
switch(gamePhase) {
|
||||||
case SETUP:
|
case SETUP:
|
||||||
case SWAP:
|
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:
|
case TRICK:
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
player[i]->DrawHand(screen);
|
player[i]->DrawHand(screen);
|
||||||
|
|
||||||
table.Draw(screen,firstPlayer);
|
table.Draw(screen,firstPlayer);
|
||||||
break;
|
break;
|
||||||
case SCORE:
|
case SCORE:
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
player[i]->DrawTricks(screen);
|
player[i]->DrawTricks(screen);
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +220,7 @@ void HeartsEngine::SetupPhase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HeartsEngine::SwapPhase() {
|
void HeartsEngine::SwapPhase() {
|
||||||
if (!keyboard[SDLK_F1])
|
if (button.GetState() != Button::State::PRESSED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!player[0]->CheckSwapCards())
|
if (!player[0]->CheckSwapCards())
|
||||||
@@ -207,47 +264,41 @@ void HeartsEngine::TrickPhase() {
|
|||||||
ResetPositions();
|
ResetPositions();
|
||||||
CalcScores();
|
CalcScores();
|
||||||
gamePhase = SCORE;
|
gamePhase = SCORE;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
cout << "Player " << i << ": " << player[i]->Score() << endl;//tmp...
|
|
||||||
}
|
|
||||||
cout << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartsEngine::ScorePhase() {
|
void HeartsEngine::ScorePhase() {
|
||||||
//end of game; temporary functionality...
|
//end of game; temporary functionality...
|
||||||
if (player[0]->Score() >= 100 ||
|
if ((player[0]->Score() >= 100 ||
|
||||||
player[1]->Score() >= 100 ||
|
player[1]->Score() >= 100 ||
|
||||||
player[2]->Score() >= 100 ||
|
player[2]->Score() >= 100 ||
|
||||||
player[3]->Score() >= 100)
|
player[3]->Score() >= 100) && winner == -1)
|
||||||
{
|
{
|
||||||
cout << "GAME OVER" << endl;
|
winner = 0;
|
||||||
int winner = 0;
|
|
||||||
|
|
||||||
|
//find the winner
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (player[i]->Score() < player[winner]->Score()) {
|
if (player[i]->Score() < player[winner]->Score()) {
|
||||||
winner = i;
|
winner = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cout << "Winner is: " << winner << endl;
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
|
//award the winner
|
||||||
player[winner]->Wins(1);
|
player[winner]->Wins(1);
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
cout << "Player " << i << " wins: " << player[i]->Wins() << endl;
|
|
||||||
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
//reset all values
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
player[i]->Score( -player[i]->Score() );
|
|
||||||
rotation = NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//10 second delay
|
//wait for input
|
||||||
if (SDL_GetTicks() - timeTick > 10000 || keyboard[SDLK_F1])//button...
|
if (button.GetState() == Button::State::PRESSED) {
|
||||||
gamePhase = CLEANUP;
|
gamePhase = CLEANUP;
|
||||||
|
|
||||||
|
//reset the game
|
||||||
|
if (winner != -1) {
|
||||||
|
winner = -1;
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
player[i]->Score( -player[i]->Score() );
|
||||||
|
rotation = NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartsEngine::CleanupPhase() {
|
void HeartsEngine::CleanupPhase() {
|
||||||
@@ -267,7 +318,6 @@ void HeartsEngine::CleanupPhase() {
|
|||||||
|
|
||||||
void HeartsEngine::PlayBeforePhase() {
|
void HeartsEngine::PlayBeforePhase() {
|
||||||
if (firstPlayer != 0) {
|
if (firstPlayer != 0) {
|
||||||
mAudio.Play("knock");
|
|
||||||
for (int i = firstPlayer; i < 4; i++) {
|
for (int i = firstPlayer; i < 4; i++) {
|
||||||
bool heartSound = heartsBroken;
|
bool heartSound = heartsBroken;
|
||||||
Card* c = ((PlayerAI*)(player[i]))->PassPlayCard(table.GetLeadingSuit(firstPlayer),trickCount,heartsBroken);
|
Card* c = ((PlayerAI*)(player[i]))->PassPlayCard(table.GetLeadingSuit(firstPlayer),trickCount,heartsBroken);
|
||||||
@@ -280,7 +330,6 @@ void HeartsEngine::PlayBeforePhase() {
|
|||||||
}
|
}
|
||||||
if (heartSound != heartsBroken) {
|
if (heartSound != heartsBroken) {
|
||||||
heartSprite.SetClipX(64);
|
heartSprite.SetClipX(64);
|
||||||
mAudio.Play("glass");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -297,13 +346,11 @@ void HeartsEngine::PlayPlayerPhase() {
|
|||||||
}
|
}
|
||||||
if (heartSound != heartsBroken) {
|
if (heartSound != heartsBroken) {
|
||||||
heartSprite.SetClipX(64);
|
heartSprite.SetClipX(64);
|
||||||
mAudio.Play("glass");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartsEngine::PlayAfterPhase() {
|
void HeartsEngine::PlayAfterPhase() {
|
||||||
mAudio.Play("knock");
|
|
||||||
int max = (firstPlayer == 0)? 4:firstPlayer;
|
int max = (firstPlayer == 0)? 4:firstPlayer;
|
||||||
|
|
||||||
for (int i = 1; i < max; i++) {
|
for (int i = 1; i < max; i++) {
|
||||||
@@ -318,7 +365,6 @@ void HeartsEngine::PlayAfterPhase() {
|
|||||||
}
|
}
|
||||||
if (heartSound != heartsBroken) {
|
if (heartSound != heartsBroken) {
|
||||||
heartSprite.SetClipX(64);
|
heartSprite.SetClipX(64);
|
||||||
mAudio.Play("glass");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,13 +27,16 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef KR_HEARTSENGINE_H_
|
#ifndef KR_HEARTSENGINE_H_
|
||||||
#define KR_HEARTSENGINE_H_
|
#define KR_HEARTSENGINE_H_
|
||||||
|
|
||||||
#include "base_engine.h"
|
#include "base_engine.h"
|
||||||
#include "image.h"
|
|
||||||
#include "audio_manager.h"
|
#include "image.hpp"
|
||||||
#include "deck.h"
|
#include "deck.h"
|
||||||
#include "player_ai.h"
|
#include "player_ai.h"
|
||||||
#include "player_user.h"
|
#include "player_user.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
|
#include "button.hpp"
|
||||||
|
#include "raster_font.hpp"
|
||||||
|
|
||||||
class HeartsEngine : public KAGE::BaseEngine {
|
class HeartsEngine : public KAGE::BaseEngine {
|
||||||
public:
|
public:
|
||||||
@@ -42,13 +45,14 @@ public:
|
|||||||
~HeartsEngine();
|
~HeartsEngine();
|
||||||
private:
|
private:
|
||||||
/* Engine members */
|
/* Engine members */
|
||||||
|
void MouseMotion (SDL_MouseMotionEvent& motion);
|
||||||
void MouseButtonDown (SDL_MouseButtonEvent& button);
|
void MouseButtonDown (SDL_MouseButtonEvent& button);
|
||||||
|
void MouseButtonUp (SDL_MouseButtonEvent& button);
|
||||||
void Process ();
|
void Process ();
|
||||||
void Draw ();
|
void Draw ();
|
||||||
|
|
||||||
/* KAGE Managers */
|
/* KAGE Managers */
|
||||||
Image heartSprite;
|
Image heartSprite;
|
||||||
KAGE::AudioManager mAudio;
|
|
||||||
|
|
||||||
/* Game phase members */ //TODO: "phases"
|
/* Game phase members */ //TODO: "phases"
|
||||||
void SetupPhase();
|
void SetupPhase();
|
||||||
@@ -74,6 +78,9 @@ private:
|
|||||||
}rotation;
|
}rotation;
|
||||||
|
|
||||||
/* Game members */
|
/* Game members */
|
||||||
|
Button button;
|
||||||
|
RasterFont font;
|
||||||
|
|
||||||
Deck deck;
|
Deck deck;
|
||||||
Player *player[4];
|
Player *player[4];
|
||||||
Table table;
|
Table table;
|
||||||
@@ -83,6 +90,8 @@ private:
|
|||||||
bool heartsBroken;
|
bool heartsBroken;
|
||||||
int timeTick;
|
int timeTick;
|
||||||
|
|
||||||
|
int winner = -1;
|
||||||
|
|
||||||
/* Utility members */
|
/* Utility members */
|
||||||
void ResetPositions();
|
void ResetPositions();
|
||||||
void ResetFaces();
|
void ResetFaces();
|
||||||
@@ -90,6 +99,4 @@ private:
|
|||||||
void CalcScores();
|
void CalcScores();
|
||||||
};
|
};
|
||||||
|
|
||||||
START(HeartsEngine)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
194
Hearts/image.cpp
194
Hearts/image.cpp
@@ -1,115 +1,145 @@
|
|||||||
/* File Name: image.cpp
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
* 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
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
* arising from the use of this software.
|
* arising from the use of this software.
|
||||||
*
|
*
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
* including commercial applications, and to alter it and redistribute it
|
* including commercial applications, and to alter it and redistribute it
|
||||||
* freely, subject to the following restrictions:
|
* freely, subject to the following restrictions:
|
||||||
*
|
*
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
* 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
|
* claim that you wrote the original software. If you use this software
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
* appreciated but is not required.
|
* appreciated but is not required.
|
||||||
*
|
*
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
* misrepresented as being the original software.
|
* misrepresented as being the original software.
|
||||||
*
|
*
|
||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* ...
|
|
||||||
*/
|
*/
|
||||||
#include "image.h"
|
#include "image.hpp"
|
||||||
|
|
||||||
#include <exception>
|
#include <stdexcept>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
//-------------------------
|
Image& Image::operator=(Image const& rhs) {
|
||||||
//Public access members
|
//don't screw yourself
|
||||||
//-------------------------
|
if (this == &rhs) {
|
||||||
|
return *this;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
Image& Image::operator=(Image&& rhs) {
|
||||||
if (m_bLocal)
|
//don't screw yourself
|
||||||
throw(std::exception("Failed to set surface, Image has a local surface"));
|
if (this == &rhs) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
if (!pSurface)
|
FreeSurface();
|
||||||
throw(std::exception("Failed to set surface, given surface is NULL"));
|
|
||||||
|
|
||||||
m_pSurface = pSurface;
|
//Steal the other Image's stuff
|
||||||
|
surface = rhs.surface;
|
||||||
|
clip = rhs.clip;
|
||||||
|
local = rhs.local;
|
||||||
|
|
||||||
m_clip.x = 0;
|
rhs.surface = nullptr;
|
||||||
m_clip.y = 0;
|
rhs.clip = {0, 0, 0, 0};
|
||||||
m_clip.w = m_pSurface->w;
|
rhs.local = false;
|
||||||
m_clip.h = m_pSurface->h;
|
|
||||||
|
|
||||||
m_bLocal = false;
|
|
||||||
|
|
||||||
return m_pSurface;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface* Image::GetSurface() {
|
SDL_Surface* Image::LoadSurface(std::string fname) {
|
||||||
return m_pSurface;
|
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) {
|
SDL_Surface* Image::CreateSurface(Uint16 w, Uint16 h) {
|
||||||
if (m_pSurface != NULL)
|
FreeSurface();
|
||||||
SDL_SetColorKey(m_pSurface, SDL_SRCCOLORKEY, SDL_MapRGB(m_pSurface->format, r, g, b));
|
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() {
|
SDL_Surface* Image::SetSurface(SDL_Surface* p) {
|
||||||
if (m_pSurface != NULL)
|
FreeSurface();
|
||||||
SDL_SetColorKey(m_pSurface, 0, 0);
|
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() {
|
||||||
//Rendering
|
if (local) {
|
||||||
//-------------------------
|
SDL_FreeSurface(surface);
|
||||||
|
local = false;
|
||||||
void Image::DrawTo(SDL_Surface* const pDest, Sint16 x, Sint16 y) {
|
}
|
||||||
SDL_Rect sclip = m_clip, dclip = {x,y};
|
surface = nullptr;
|
||||||
|
clip = {0, 0, 0, 0};
|
||||||
SDL_BlitSurface(m_pSurface, &sclip, pDest, &dclip);
|
}
|
||||||
|
|
||||||
|
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
|
||||||
@@ -1,53 +1,45 @@
|
|||||||
/* File Name: sound.h
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
* 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
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
* arising from the use of this software.
|
* arising from the use of this software.
|
||||||
*
|
*
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
* including commercial applications, and to alter it and redistribute it
|
* including commercial applications, and to alter it and redistribute it
|
||||||
* freely, subject to the following restrictions:
|
* freely, subject to the following restrictions:
|
||||||
*
|
*
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
* 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
|
* claim that you wrote the original software. If you use this software
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
* appreciated but is not required.
|
* appreciated but is not required.
|
||||||
*
|
*
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
* misrepresented as being the original software.
|
* misrepresented as being the original software.
|
||||||
*
|
*
|
||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* 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_
|
#include "hearts_engine.h"
|
||||||
#define KR_KAGE_SOUND_H_
|
|
||||||
|
|
||||||
#include "SDL_mixer.h"
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace KAGE {
|
using namespace std;
|
||||||
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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int main(int, char**) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
cout << "Beginning program" << endl;
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
53
Hearts/makefile
Normal file
53
Hearts/makefile
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#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
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,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_
|
#ifndef KR_PLAYER_H_
|
||||||
#define KR_PLAYER_H_
|
#define KR_PLAYER_H_
|
||||||
#include "SDL.h"
|
|
||||||
#include "card_list.h"
|
#include "card_list.h"
|
||||||
|
|
||||||
class Player {
|
class Player {
|
||||||
|
|||||||
60
Hearts/raster_font.cpp
Normal file
60
Hearts/raster_font.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/* 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();
|
||||||
|
}
|
||||||
@@ -1,63 +1,49 @@
|
|||||||
/* File Name: music.h
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
* 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
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
* arising from the use of this software.
|
* arising from the use of this software.
|
||||||
*
|
*
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
* including commercial applications, and to alter it and redistribute it
|
* including commercial applications, and to alter it and redistribute it
|
||||||
* freely, subject to the following restrictions:
|
* freely, subject to the following restrictions:
|
||||||
*
|
*
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
* 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
|
* claim that you wrote the original software. If you use this software
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
* appreciated but is not required.
|
* appreciated but is not required.
|
||||||
*
|
*
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
* misrepresented as being the original software.
|
* misrepresented as being the original software.
|
||||||
*
|
*
|
||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* 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_
|
#ifndef RASTERFONT_HPP_
|
||||||
#define KR_KAGE_MUSIC_H_
|
#define RASTERFONT_HPP_
|
||||||
|
|
||||||
#include "SDL_mixer.h"
|
#include "image.hpp"
|
||||||
|
|
||||||
namespace KAGE {
|
class RasterFont {
|
||||||
class Music {
|
public:
|
||||||
public:
|
RasterFont() = default;
|
||||||
/* Public access members */
|
RasterFont(std::string fname) { LoadSurface(fname); }
|
||||||
Music();
|
RasterFont(SDL_Surface* p) { SetSurface(p); }
|
||||||
~Music();
|
~RasterFont() = default;
|
||||||
|
|
||||||
/* Accessors and mutators */
|
void DrawStringTo(std::string, SDL_Surface* const, Sint16 x, Sint16 y);
|
||||||
int Load (const char* fName);
|
|
||||||
void Free ();
|
|
||||||
|
|
||||||
int Play (int loop = -1);
|
//Accessors and Mutators
|
||||||
void Halt ();
|
SDL_Surface* LoadSurface(std::string);
|
||||||
int Playing ();
|
SDL_Surface* SetSurface(SDL_Surface*);
|
||||||
void Pause ();
|
SDL_Surface* GetSurface() const { return image.GetSurface(); }
|
||||||
void Resume ();
|
void FreeSurface() { image.FreeSurface(); }
|
||||||
int Paused ();
|
|
||||||
void Rewind ();
|
|
||||||
|
|
||||||
int Volume (int volume);
|
Uint16 GetCharW() const { return image.GetClipW(); }
|
||||||
protected:
|
Uint16 GetCharH() const { return image.GetClipH(); }
|
||||||
/* Protected access members */
|
|
||||||
Mix_Music* GetMixMusic();
|
private:
|
||||||
private:
|
Image image;
|
||||||
/* Private access members */
|
};
|
||||||
Mix_Music* music;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef KR_TABLE_H_
|
#ifndef KR_TABLE_H_
|
||||||
#define KR_TABLE_H_
|
#define KR_TABLE_H_
|
||||||
#include "SDL.h"
|
|
||||||
#include "card_list.h"
|
#include "card_list.h"
|
||||||
|
|
||||||
class Table {
|
class Table {
|
||||||
|
|||||||
BIN
Notes/screenshot.png
Normal file
BIN
Notes/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
20
README.md
20
README.md
@@ -1,21 +1,17 @@
|
|||||||
# Project Hearts version 1.0, 22nd June 2011
|
# Project Hearts version 1.1, 6th September 2013
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
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'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.
|
||||||
|
|
||||||
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
|
## Instructions
|
||||||
|
|
||||||
Drop the "rsc" folder into the same directory as the executable
|
Drop the "rsc" folder into the same directory as the executable
|
||||||
To select a card, click on it
|
To select a card, click on it
|
||||||
To pass three cards at the start of the round, select them and press F1
|
To pass three cards at the start of the round, select them and press the pass button
|
||||||
To speed up the wait after a round, press F1
|
Try to keep your score as low as possible by avoiding the hearts cards, and the queen of spades
|
||||||
|
|
||||||
## Copyright
|
## Copyright
|
||||||
|
|
||||||
@@ -33,7 +29,5 @@ Permission is granted to anyone to use this software for any purpose, including
|
|||||||
|
|
||||||
## Contact information
|
## Contact information
|
||||||
|
|
||||||
ratstail91@yahoo.com.au
|
krgamestudios@gmail.com
|
||||||
http://kr-studios.tumblr.com/
|
1.0 Build: https://www.dropbox.com/s/gqo2qqj6v1pejyq/Hearts%20by%20Kayne%20Ruse.rar?dl=1
|
||||||
http://www.facebook.com/krgamestudios
|
|
||||||
Oldest known version: https://dl.dropbox.com/u/46669050/Hearts%20by%20Kayne%20Ruse.rar
|
|
||||||
|
|||||||
33
makefile
Normal file
33
makefile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#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
Normal file
BIN
rsc/button.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
BIN
rsc/pk_white_8.bmp
Normal file
BIN
rsc/pk_white_8.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
Reference in New Issue
Block a user