start 380 project5
changes to 380 project 4 changes to 350 project 2 Signed-off-by: Amrit Panesar <apanesar@4195tech.com>
This commit is contained in:
1 parent
40ac78074b
commit
39ee821f54
174 files changed
+13356
-80
No files matched your search
+65
@@ -0,0 +1,65 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameAnimationsSoundBinding.h"
|
||||
|
||||
|
||||
GkGameAnimationsSoundBinding::GkGameAnimationsSoundBinding(GkSoundSource *soundSource, GkSoundDevice *soundDevice, bool looping, int numAnimations, ...)
|
||||
: GkGameEntity()
|
||||
{
|
||||
this->soundSource = soundSource;
|
||||
this->soundDevice = soundDevice;
|
||||
this->looping = looping;
|
||||
|
||||
this->numAnimations = numAnimations;
|
||||
GkGameAnimation **parameters = (GkGameAnimation **)((int)&numAnimations + 4);
|
||||
this->animations = new GkGameAnimationsSoundBindingAnimation[numAnimations];
|
||||
for (int i = 0; i < numAnimations; i++)
|
||||
{
|
||||
this->animations[i].animation = parameters[i];
|
||||
this->animations[i].played = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GkGameAnimationsSoundBinding::~GkGameAnimationsSoundBinding(void)
|
||||
{
|
||||
delete[] this->animations;
|
||||
}
|
||||
|
||||
void GkGameAnimationsSoundBinding::Process(GkGame *game)
|
||||
{
|
||||
for (int i = 0; i < this->numAnimations; i++)
|
||||
{
|
||||
if (this->animations[i].animation->visible && this->animations[i].animation->active)
|
||||
{
|
||||
if (!this->animations[i].played)
|
||||
{
|
||||
if (this->looping)
|
||||
this->soundDevice->PlaySourceLooping(this->soundSource);
|
||||
else
|
||||
this->soundDevice->PlaySource(this->soundSource);
|
||||
|
||||
this->animations[i].played = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->looping)
|
||||
{
|
||||
this->soundDevice->PauseSource(this->soundSource);
|
||||
}
|
||||
|
||||
this->animations[i].played = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameAnimation.h"
|
||||
#include "..\..\..\Sound\GkSoundDevice.h"
|
||||
|
||||
struct GkGameAnimationsSoundBindingAnimation
|
||||
{
|
||||
GkGameAnimation *animation;
|
||||
bool played;
|
||||
};
|
||||
|
||||
class GKDLLCLASS GkGameAnimationsSoundBinding :
|
||||
public GkGameEntity
|
||||
{
|
||||
public:
|
||||
GkSoundDevice *soundDevice;
|
||||
GkSoundSource *soundSource;
|
||||
|
||||
int numAnimations;
|
||||
GkGameAnimationsSoundBindingAnimation *animations;
|
||||
|
||||
bool looping;
|
||||
|
||||
GkGameAnimationsSoundBinding(GkSoundSource *soundSource, GkSoundDevice *soundDevice, bool looping, int numAnimations, ...);
|
||||
~GkGameAnimationsSoundBinding(void);
|
||||
|
||||
void Process(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameButtonsBinding.h"
|
||||
|
||||
|
||||
GkGameButtonsBinding::GkGameButtonsBinding(int numGameButtons, ...)
|
||||
{
|
||||
GkGameButton **parameters = (GkGameButton **)((int)&numGameButtons + 4);
|
||||
this->numGameButtons = numGameButtons;
|
||||
this->gameButtons = new GkGameButton*[numGameButtons];
|
||||
for (int i = 0; i < numGameButtons; i++)
|
||||
this->gameButtons[i] = parameters[i];
|
||||
|
||||
this->enabled = true;
|
||||
|
||||
this->pushedValue = false;
|
||||
this->clickedValue = false;
|
||||
}
|
||||
|
||||
|
||||
GkGameButtonsBinding::~GkGameButtonsBinding(void)
|
||||
{
|
||||
delete this->gameButtons;
|
||||
}
|
||||
|
||||
void GkGameButtonsBinding::SyncPush(int syncButtonIndex)
|
||||
{
|
||||
GkGameButton *syncButton = this->gameButtons[syncButtonIndex];
|
||||
|
||||
for (int buttonIndex = 0; buttonIndex < this->numGameButtons; buttonIndex++)
|
||||
{
|
||||
if (buttonIndex != syncButtonIndex)
|
||||
{
|
||||
GkGameButton *button = this->gameButtons[buttonIndex];
|
||||
|
||||
if (button->IsActive())
|
||||
{
|
||||
if (button->pushed != syncButton->pushed)
|
||||
{
|
||||
if (syncButton->pushed)
|
||||
button->Down();
|
||||
else
|
||||
button->Up(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->pushedValue = syncButton->pushed;
|
||||
}
|
||||
|
||||
void GkGameButtonsBinding::SyncClick(int syncButtonIndex)
|
||||
{
|
||||
GkGameButton *syncButton = this->gameButtons[syncButtonIndex];
|
||||
|
||||
for (int buttonIndex = 0; buttonIndex < this->numGameButtons; buttonIndex++)
|
||||
{
|
||||
if (buttonIndex != syncButtonIndex)
|
||||
{
|
||||
GkGameButton *button = this->gameButtons[buttonIndex];
|
||||
|
||||
if (button->IsActive())
|
||||
{
|
||||
button->clicked = syncButton->clicked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->clickedValue = syncButton->clicked;
|
||||
}
|
||||
|
||||
void GkGameButtonsBinding::Process(GkGame *game)
|
||||
{
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
for (int buttonIndex = 0; buttonIndex < this->numGameButtons; buttonIndex++)
|
||||
{
|
||||
GkGameButton *button = this->gameButtons[buttonIndex];
|
||||
if (button->IsActive())
|
||||
{
|
||||
if (button->pushed != this->pushedValue)
|
||||
{
|
||||
this->SyncPush(buttonIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int buttonIndex = 0; buttonIndex < this->numGameButtons; buttonIndex++)
|
||||
{
|
||||
GkGameButton *button = this->gameButtons[buttonIndex];
|
||||
if (button->IsActive())
|
||||
{
|
||||
if (button->clicked != this->clickedValue)
|
||||
{
|
||||
// SyncClick is required beside SyncPush, because mouse events execute separately from the Process sequence and MouseUp usually sets a button pushed to false, which actually prevents SyncPush to execute mouse up (for it checks if the button is pushed)
|
||||
this->SyncClick(buttonIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\..\GkGameEntity.h"
|
||||
#include "..\..\Entities\GkGameButton.h"
|
||||
|
||||
class GKDLLCLASS GkGameButtonsBinding :
|
||||
public GkGameEntity
|
||||
{
|
||||
public:
|
||||
int numGameButtons;
|
||||
GkGameButton **gameButtons;
|
||||
|
||||
bool enabled;
|
||||
|
||||
bool pushedValue, clickedValue;
|
||||
|
||||
GkGameButtonsBinding(int numGameButtons, ...);
|
||||
~GkGameButtonsBinding(void);
|
||||
|
||||
void SyncPush(int syncButtonIndex);
|
||||
void SyncClick(int syncButtonIndex);
|
||||
|
||||
void Process(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameButtonsSoundBinding.h"
|
||||
|
||||
|
||||
GkGameButtonsSoundBinding::GkGameButtonsSoundBinding(GkSoundSource *soundSource, GkSoundDevice *soundDevice, int numButtons, ...)
|
||||
: GkGameEntity()
|
||||
{
|
||||
this->soundSource = soundSource;
|
||||
this->soundDevice = soundDevice;
|
||||
|
||||
this->numButtons = numButtons;
|
||||
GkGameButton **parameters = (GkGameButton **)((int)&numButtons + 4);
|
||||
this->buttons = new GameButtonsSoundBindingButton[numButtons];
|
||||
for (int i = 0; i < numButtons; i++)
|
||||
{
|
||||
this->buttons[i].button = parameters[i];
|
||||
this->buttons[i].played = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GkGameButtonsSoundBinding::~GkGameButtonsSoundBinding(void)
|
||||
{
|
||||
delete[] this->buttons;
|
||||
}
|
||||
|
||||
void GkGameButtonsSoundBinding::Process(GkGame *game)
|
||||
{
|
||||
for (int i = 0; i < this->numButtons; i++)
|
||||
{
|
||||
if (this->buttons[i].button->pushed)
|
||||
{
|
||||
if (!this->buttons[i].played)
|
||||
{
|
||||
this->soundDevice->PlaySource(this->soundSource);
|
||||
|
||||
this->buttons[i].played = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->buttons[i].played = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameButton.h"
|
||||
#include "..\..\..\Sound\GkSoundDevice.h"
|
||||
|
||||
struct GameButtonsSoundBindingButton
|
||||
{
|
||||
GkGameButton *button;
|
||||
bool played;
|
||||
};
|
||||
|
||||
class GKDLLCLASS GkGameButtonsSoundBinding :
|
||||
public GkGameEntity
|
||||
{
|
||||
public:
|
||||
GkSoundDevice *soundDevice;
|
||||
GkSoundSource *soundSource;
|
||||
|
||||
int numButtons;
|
||||
GameButtonsSoundBindingButton *buttons;
|
||||
|
||||
GkGameButtonsSoundBinding(GkSoundSource *soundSource, GkSoundDevice *soundDevice, int numButtons, ...);
|
||||
~GkGameButtonsSoundBinding(void);
|
||||
|
||||
void Process(GkGame *game);
|
||||
};
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameTextsDateTimeBinding.h"
|
||||
|
||||
#include "..\..\..\Utils\GkStrings.h"
|
||||
|
||||
GkGameTextsDateTimeBinding::GkGameTextsDateTimeBinding(DateTime* valueAddress, const wchar_t *formatString, int numGameTexts, ...)
|
||||
: GkGameEntity()
|
||||
{
|
||||
this->valueAddress = valueAddress;
|
||||
this->formatString = GkStrings::Copy(formatString);
|
||||
|
||||
this->numGameTexts = numGameTexts;
|
||||
|
||||
GkGameText **parameters = (GkGameText **)((int)&numGameTexts + 4);
|
||||
this->gameTexts = new GkGameText*[this->numGameTexts];
|
||||
for (int i = 0; i < this->numGameTexts; i++)
|
||||
this->gameTexts[i] = parameters[i];
|
||||
}
|
||||
|
||||
|
||||
GkGameTextsDateTimeBinding::~GkGameTextsDateTimeBinding(void)
|
||||
{
|
||||
delete[] this->formatString;
|
||||
delete[] this->gameTexts;
|
||||
}
|
||||
|
||||
void GkGameTextsDateTimeBinding::Process(GkGame *game)
|
||||
{
|
||||
for (int i = 0; i < this->numGameTexts; i++)
|
||||
this->gameTexts[i]->SetText(GkStrings::Format(this->formatString, GkStrings::IntToString(this->valueAddress->day, 10, 2).c_str(), GkStrings::IntToString(this->valueAddress->month, 10, 2).c_str(), GkStrings::IntToString(this->valueAddress->year, 10, 4).c_str(), GkStrings::IntToString(this->valueAddress->hour, 10, 2).c_str(), GkStrings::IntToString(this->valueAddress->minute, 10, 2).c_str(), GkStrings::IntToString(this->valueAddress->second, 10, 2).c_str()).c_str());
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\..\GkGameEntity.h"
|
||||
|
||||
#include "..\GkGameText.h"
|
||||
|
||||
#include "..\..\..\OSSpecific\GkOSUtils.h"
|
||||
|
||||
class GKDLLCLASS GkGameTextsDateTimeBinding :
|
||||
public GkGameEntity
|
||||
{
|
||||
public:
|
||||
DateTime * valueAddress;
|
||||
|
||||
int numGameTexts;
|
||||
GkGameText **gameTexts;
|
||||
|
||||
wchar_t *formatString;
|
||||
|
||||
GkGameTextsDateTimeBinding(DateTime* valueAddress, const wchar_t *formatString, int numGameTexts, ...);
|
||||
~GkGameTextsDateTimeBinding(void);
|
||||
|
||||
void Process(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameTextsFormatBinding.h"
|
||||
|
||||
|
||||
GkGameTextsFormatBinding::GkGameTextsFormatBinding(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GkGameTextsFormatBinding::~GkGameTextsFormatBinding(void)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\..\GkGameEntity.h"
|
||||
|
||||
class GKDLLCLASS GkGameTextsFormatBinding :
|
||||
public GkGameEntity
|
||||
{
|
||||
public:
|
||||
GkGameTextsFormatBinding(void);
|
||||
~GkGameTextsFormatBinding(void);
|
||||
};
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameTextsFormatIntBinding.h"
|
||||
|
||||
#include "..\..\..\Utils\GkStrings.h"
|
||||
|
||||
|
||||
GkGameTextsFormatIntBinding::GkGameTextsFormatIntBinding(const wchar_t *format, int numValues, int numGameTexts, ...)
|
||||
{
|
||||
this->numValues = numValues;
|
||||
this->numGameTexts = numGameTexts;
|
||||
this->format = GkStrings::Copy(format);
|
||||
|
||||
int **valueAddressParams = (int**)((int)&numGameTexts + 4);
|
||||
this->valueAddresses = new int*[this->numValues];
|
||||
this->values = new wchar_t*[this->numValues];
|
||||
for (int i = 0; i < this->numValues; i++)
|
||||
this->valueAddresses[i] = valueAddressParams[i];
|
||||
|
||||
GkGameText **gameTextParams = (GkGameText **)((int)&valueAddressParams[this->numValues - 1] + 4);
|
||||
this->gameTexts = new GkGameText*[this->numGameTexts];
|
||||
for (int i = 0; i < this->numGameTexts; i++)
|
||||
this->gameTexts[i] = gameTextParams[i];
|
||||
}
|
||||
|
||||
|
||||
GkGameTextsFormatIntBinding::~GkGameTextsFormatIntBinding(void)
|
||||
{
|
||||
delete[] this->valueAddresses;
|
||||
delete[] this->values;
|
||||
|
||||
delete[] this->gameTexts;
|
||||
|
||||
delete[] this->format;
|
||||
}
|
||||
|
||||
void GkGameTextsFormatIntBinding::Process(GkGame *game)
|
||||
{
|
||||
for (int i = 0; i < this->numValues; i++)
|
||||
this->values[i] = GkStrings::Copy(GkStrings::IntToString(*this->valueAddresses[i]).c_str());
|
||||
|
||||
for (int gameTextIndex = 0; gameTextIndex < this->numGameTexts; gameTextIndex++)
|
||||
{
|
||||
this->gameTexts[gameTextIndex]->SetText(GkStrings::FormatArray(this->format, this->values).c_str());
|
||||
}
|
||||
|
||||
for (int i = 0; i < this->numValues; i++)
|
||||
delete[] this->values[i];
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\..\GkGameEntity.h"
|
||||
|
||||
#include "..\GkGameText.h"
|
||||
|
||||
|
||||
class GKDLLCLASS GkGameTextsFormatIntBinding :
|
||||
public GkGameEntity
|
||||
{
|
||||
public:
|
||||
int numValues;
|
||||
int **valueAddresses;
|
||||
wchar_t **values;
|
||||
|
||||
int numGameTexts;
|
||||
GkGameText **gameTexts;
|
||||
|
||||
wchar_t *format;
|
||||
|
||||
GkGameTextsFormatIntBinding(const wchar_t *format, int numValues, int numGameTexts, ...);
|
||||
~GkGameTextsFormatIntBinding(void);
|
||||
|
||||
void Process(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameTextsIntBinding.h"
|
||||
|
||||
#include "..\..\..\Utils\GkStrings.h"
|
||||
|
||||
GkGameTextsIntBinding::GkGameTextsIntBinding(int* valueAddress, int numGameTexts, ...)
|
||||
: GkGameEntity()
|
||||
{
|
||||
this->valueAddress = valueAddress;
|
||||
|
||||
this->numGameTexts = numGameTexts;
|
||||
|
||||
GkGameText **parameters = (GkGameText **)((int)&numGameTexts + 4);
|
||||
this->gameTexts = new GkGameText*[this->numGameTexts];
|
||||
for (int i = 0; i < this->numGameTexts; i++)
|
||||
this->gameTexts[i] = parameters[i];
|
||||
}
|
||||
|
||||
|
||||
GkGameTextsIntBinding::~GkGameTextsIntBinding(void)
|
||||
{
|
||||
delete[] this->gameTexts;
|
||||
}
|
||||
|
||||
void GkGameTextsIntBinding::Process(GkGame *game)
|
||||
{
|
||||
for (int i = 0; i < this->numGameTexts; i++)
|
||||
this->gameTexts[i]->SetText(GkStrings::IntToString(*this->valueAddress).c_str());
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\..\GkGameEntity.h"
|
||||
|
||||
#include "..\GkGameText.h"
|
||||
|
||||
class GKDLLCLASS GkGameTextsIntBinding :
|
||||
public GkGameEntity
|
||||
{
|
||||
public:
|
||||
int * valueAddress;
|
||||
|
||||
int numGameTexts;
|
||||
GkGameText **gameTexts;
|
||||
|
||||
GkGameTextsIntBinding(int* valueAddress, int numGameTexts, ...);
|
||||
~GkGameTextsIntBinding(void);
|
||||
|
||||
void Process(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameAnimationButton.h"
|
||||
|
||||
//#include "..\..\Utils\GkMaths.h"
|
||||
|
||||
GkGameAnimationButton::GkGameAnimationButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace, GkGameEntity *disabledFace, bool autoEnable, int x, int y, int width, int height)
|
||||
: GkGameButton(defaultFace, selectedFace, disabledFace, autoEnable, x, y, width, height)
|
||||
{
|
||||
GkGameAnimation *face = dynamic_cast<GkGameAnimation*>(this->defaultFace);
|
||||
if (face != 0)
|
||||
face->EndAnimation();
|
||||
|
||||
face = dynamic_cast<GkGameAnimation*>(this->selectedFace);
|
||||
if (face != 0)
|
||||
face->EndAnimation();
|
||||
|
||||
face = dynamic_cast<GkGameAnimation*>(this->disabledFace);
|
||||
if (face != 0)
|
||||
face->EndAnimation();
|
||||
|
||||
this->lastFace = this->GetCurrentFace();
|
||||
}
|
||||
|
||||
|
||||
GkGameAnimationButton::~GkGameAnimationButton(void)
|
||||
{
|
||||
}
|
||||
|
||||
void GkGameAnimationButton::Down()
|
||||
{
|
||||
GkGameButton::Down();
|
||||
|
||||
//GkGameAnimation *currentFace = dynamic_cast<GkGameAnimation*>(this->GetCurrentFace());
|
||||
//if ((currentFace != 0) && (!currentFace->active))
|
||||
//{
|
||||
// currentFace->ResetAnimation();
|
||||
//}
|
||||
}
|
||||
|
||||
GkGameEntity* GkGameAnimationButton::GetCurrentFace()
|
||||
{
|
||||
GkGameAnimation *face = this->GetAnimatingFace();
|
||||
if (face != 0)
|
||||
return face;
|
||||
|
||||
return GkGameButton::GetCurrentFace();
|
||||
}
|
||||
|
||||
GkGameAnimation* GkGameAnimationButton::GetAnimatingFace()
|
||||
{
|
||||
GkGameAnimation *face = dynamic_cast<GkGameAnimation*>(this->defaultFace);
|
||||
if ((face != 0) && (face->active) && (!face->loop))
|
||||
return face;
|
||||
|
||||
face = dynamic_cast<GkGameAnimation*>(this->selectedFace);
|
||||
if ((face != 0) && (face->active) && (!face->loop))
|
||||
return face;
|
||||
|
||||
face = dynamic_cast<GkGameAnimation*>(this->disabledFace);
|
||||
if ((face != 0) && (face->active) && (!face->loop))
|
||||
return face;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GkGameAnimationButton::Process(GkGame *game)
|
||||
{
|
||||
GkGameEntity *currentFace = this->GetCurrentFace();
|
||||
|
||||
if (currentFace != this->lastFace)
|
||||
{
|
||||
GkGameAnimation *lastAnimation = dynamic_cast<GkGameAnimation*>(this->lastFace);
|
||||
if (lastAnimation != 0)
|
||||
lastAnimation->EndAnimation();
|
||||
|
||||
GkGameAnimation *currentAnimation = dynamic_cast<GkGameAnimation*>(currentFace);
|
||||
if (currentAnimation != 0)
|
||||
currentAnimation->ResetAnimation();
|
||||
|
||||
this->lastFace = currentFace;
|
||||
}
|
||||
|
||||
GkGameButton::Process(game);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameButton.h"
|
||||
#include "..\GkGameAnimation.h"
|
||||
|
||||
class GKDLLCLASS GkGameAnimationButton :
|
||||
public GkGameButton
|
||||
{
|
||||
public:
|
||||
GkGameAnimationButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace = 0, GkGameEntity *disabledFace = 0, bool autoEnable = true, int x = 0, int y = 0, int width = 0, int heght = 0);
|
||||
~GkGameAnimationButton(void);
|
||||
|
||||
GkGameAnimation* GetAnimatingFace();
|
||||
GkGameEntity *lastFace;
|
||||
|
||||
virtual void Down();
|
||||
virtual GkGameEntity* GetCurrentFace();
|
||||
|
||||
void Process(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameCheckButton.h"
|
||||
|
||||
GkGameCheckButton::GkGameCheckButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace, GkGameEntity *disabledFace, bool autoEnable, int x, int y, int width, int heght)
|
||||
: GkGameAnimationButton(defaultFace, selectedFace, disabledFace, autoEnable, x, y, width, heght)
|
||||
{
|
||||
this->checked = false;
|
||||
}
|
||||
|
||||
void GkGameCheckButton::Down()
|
||||
{
|
||||
GkGameAnimationButton::Down();
|
||||
|
||||
if (!this->IsActive())
|
||||
return;
|
||||
|
||||
this->checked = !this->checked;
|
||||
}
|
||||
|
||||
GkGameEntity* GkGameCheckButton::GetCurrentFace()
|
||||
{
|
||||
GkGameAnimation *face = this->GetAnimatingFace();
|
||||
if (face != 0)
|
||||
return face;
|
||||
|
||||
//if (this->enabled)
|
||||
//{
|
||||
if (this->checked)
|
||||
{
|
||||
return this->selectedFace != 0 ? this->selectedFace : this->defaultFace;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->defaultFace;
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// return this->disabledFace != 0 ? this->disabledFace : this->defaultFace;
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\..\GkDefinitions.h"
|
||||
|
||||
#include "GkGameAnimationButton.h"
|
||||
|
||||
class GKDLLCLASS GkGameCheckButton :
|
||||
public GkGameAnimationButton
|
||||
{
|
||||
public:
|
||||
bool checked;
|
||||
|
||||
GkGameCheckButton::GkGameCheckButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace = 0, GkGameEntity *disabledFace = 0, bool autoEnable = true, int x = 0, int y = 0, int width = 0, int heght = 0);
|
||||
|
||||
void GkGameCheckButton::Down();
|
||||
GkGameEntity* GkGameCheckButton::GetCurrentFace();
|
||||
|
||||
void GkGameCheckButton::SynchWith(GkGameCheckButton *button);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameClickButton.h"
|
||||
|
||||
GkGameClickButton::GkGameClickButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace, GkGameEntity *disabledFace, bool autoEnable, int x, int y, int width, int height)
|
||||
: GkGameAnimationButton(defaultFace, selectedFace, disabledFace, autoEnable, x, y, width, height)
|
||||
{
|
||||
}
|
||||
|
||||
GkGameClickButton::~GkGameClickButton()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\..\GkDefinitions.h"
|
||||
|
||||
#include "GkGameAnimationButton.h"
|
||||
|
||||
|
||||
class GKDLLCLASS GkGameClickButton :
|
||||
public GkGameAnimationButton
|
||||
{
|
||||
public:
|
||||
GkGameClickButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace = 0, GkGameEntity *disabledFace = 0, bool autoEnable = true, int x = 0, int y = 0, int width = 0, int height = 0);
|
||||
~GkGameClickButton();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameAnimation.h"
|
||||
|
||||
#include "..\..\Graphics\GkImage.h"
|
||||
|
||||
#include "..\GkGame.h"
|
||||
|
||||
GkGameAnimation::GkGameAnimation(GkAnimatedTexture *animatedTexture, int x, int y, bool active, bool loop, bool visible, bool flipX, bool flipY, float framesPerSecond, int width, int height)
|
||||
{
|
||||
this->SetAnimatedTexture(animatedTexture, framesPerSecond);
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->framesPerSecond = framesPerSecond != 0.0f ? framesPerSecond : animatedTexture != 0 ? animatedTexture->framesPerSecond : 0.0f;
|
||||
this->active = active && (animatedTexture != NULL);
|
||||
this->loop = loop && (animatedTexture != NULL);
|
||||
this->visible = visible && (animatedTexture != NULL);
|
||||
this->flipX = flipX;
|
||||
this->flipY = flipY;
|
||||
}
|
||||
|
||||
GkGameAnimation::~GkGameAnimation(void)
|
||||
{
|
||||
}
|
||||
|
||||
void GkGameAnimation::SetAnimatedTexture(GkAnimatedTexture *animatedTexture, float framesPerSecond)
|
||||
{
|
||||
this->animatedTexture = animatedTexture;
|
||||
this->framesPerSecond = framesPerSecond != 0.0f ? framesPerSecond : animatedTexture != 0 ? animatedTexture->framesPerSecond : 0.0f;
|
||||
this->ResetAnimation(this->active);
|
||||
}
|
||||
|
||||
void GkGameAnimation::Process(GkGame *game)
|
||||
{
|
||||
if (!(this->active && this->visible))
|
||||
return;
|
||||
|
||||
if (this->flipX)
|
||||
this->flipX = true;
|
||||
|
||||
this->currentFrame += this->framesPerSecond * game->timer->tickTime;
|
||||
|
||||
if (this->currentFrame > this->animatedTexture->numFrames)
|
||||
{
|
||||
if (this->loop)
|
||||
{
|
||||
int intFrame = (int)this->currentFrame;
|
||||
float fracFrame = this->currentFrame - intFrame;
|
||||
this->currentFrame = intFrame % this->animatedTexture->numFrames + fracFrame;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->EndAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->currentFrame < 0)
|
||||
{
|
||||
if (this->loop)
|
||||
{
|
||||
int intFrame = (int)this->currentFrame;
|
||||
float fracFrame = this->currentFrame - intFrame;
|
||||
this->currentFrame = (this->animatedTexture->numFrames - 1 - intFrame) % this->animatedTexture->numFrames + fracFrame;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->EndAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameAnimation::Draw(GkGame *game)
|
||||
{
|
||||
if (!this->visible)
|
||||
return;
|
||||
|
||||
GkTexture *frame = this->animatedTexture->frames[(int)this->currentFrame];
|
||||
int width = this->width != 0 ? this->width : frame->width;
|
||||
int height = this->height != 0 ? this->height : frame->height;
|
||||
if (this->flipX)
|
||||
if (this->flipY)
|
||||
game->graphicsDevice->Draw(this->x + width, this->y + height, -width, -height, 0, 0, frame->width,frame->height, frame);
|
||||
else
|
||||
game->graphicsDevice->Draw(this->x + width, this->y, -width, height, 0, 0, frame->width, frame->height, frame);
|
||||
else
|
||||
if (this->flipY)
|
||||
game->graphicsDevice->Draw(this->x, this->y + height, width, -height, 0, 0, frame->width, frame->height, frame);
|
||||
else
|
||||
game->graphicsDevice->Draw(this->x, this->y, width, height, 0, 0, frame->width, frame->height, frame);
|
||||
}
|
||||
|
||||
bool GkGameAnimation::GetBoundaries(int *x1, int *y1, int *x2, int*y2)
|
||||
{
|
||||
*x1 = this->x;
|
||||
*y1 = this->y;
|
||||
*x2 = this->x + this->animatedTexture->frames[0]->width;
|
||||
*y2 = this->y + this->animatedTexture->frames[0]->height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void GkGameAnimation::ResetAnimation(bool start)
|
||||
{
|
||||
this->currentFrame = this->framesPerSecond < 0 ? this->animatedTexture != 0 ? (float)(this->animatedTexture->numFrames - 1) : 0.0f : 0.0f;
|
||||
this->active = start;
|
||||
}
|
||||
|
||||
void GkGameAnimation::EndAnimation()
|
||||
{
|
||||
this->currentFrame = this->framesPerSecond < 0 ? 0.0f : this->animatedTexture != 0 ? (float)(this->animatedTexture->numFrames - 1) : 0.0f;
|
||||
this->active = false;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameEntity.h"
|
||||
#include "..\..\Graphics\GkAnimatedTexture.h"
|
||||
|
||||
class GKDLLCLASS GkGameAnimation :
|
||||
public GkGameEntity
|
||||
{
|
||||
public:
|
||||
GkAnimatedTexture *animatedTexture;
|
||||
|
||||
int x, y, width, height;
|
||||
bool visible, active, loop;
|
||||
float framesPerSecond, currentFrame;
|
||||
|
||||
bool flipX, flipY;
|
||||
|
||||
|
||||
GkGameAnimation::GkGameAnimation(GkAnimatedTexture *animatedTexture = 0, int x = 0, int y = 0, bool active = true, bool loop = true, bool visible = true, bool flipX = false, bool flipY = false, float framesPerSecond = 0.0f, int width = 0, int height = 0);
|
||||
GkGameAnimation::~GkGameAnimation(void);
|
||||
|
||||
void GkGameAnimation::SetAnimatedTexture(GkAnimatedTexture *animatedTexture = 0, float framesPerSecond = 0.0f);
|
||||
virtual void GkGameAnimation::Process(GkGame *game);
|
||||
virtual void GkGameAnimation::Draw(GkGame *game);
|
||||
bool GkGameAnimation::GetBoundaries(int *x1, int *y1, int *x2, int*y2);
|
||||
void ResetAnimation(bool start = true);
|
||||
void EndAnimation();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameButton.h"
|
||||
|
||||
GkGameButton::GkGameButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace, GkGameEntity *disabledFace, bool autoEnable, int x, int y, int width, int height)
|
||||
: GkGameEntity()
|
||||
{
|
||||
this->defaultFace = defaultFace;
|
||||
this->selectedFace = selectedFace;
|
||||
this->disabledFace = disabledFace;
|
||||
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
|
||||
if ((width == 0) && (height == 0))
|
||||
{
|
||||
if (defaultFace != 0)
|
||||
{
|
||||
int x1, y1, x2, y2;
|
||||
if (defaultFace->GetBoundaries(&x1, &y1, &x2, &y2))
|
||||
{
|
||||
this->width = x2 - x1;
|
||||
this->height = y2 - y1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
this->visible = true;
|
||||
this->clicked = false;
|
||||
this->down = false;
|
||||
this->enabled = true;
|
||||
this->autoEnable = autoEnable;
|
||||
this->pushed = false;
|
||||
}
|
||||
|
||||
|
||||
GkGameButton::~GkGameButton(void)
|
||||
{
|
||||
if (this->defaultFace != 0)
|
||||
delete this->defaultFace;
|
||||
|
||||
if (this->selectedFace != 0)
|
||||
delete this->selectedFace;
|
||||
|
||||
if (this->disabledFace != 0)
|
||||
delete this->disabledFace;
|
||||
}
|
||||
|
||||
|
||||
void GkGameButton::Down()
|
||||
{
|
||||
if (!this->IsActive())
|
||||
return;
|
||||
|
||||
this->pushed = true;
|
||||
this->down = true;
|
||||
}
|
||||
|
||||
void GkGameButton::Up(bool click)
|
||||
{
|
||||
if (!this->IsActive())
|
||||
return;
|
||||
|
||||
this->pushed = false;
|
||||
this->clicked = click;
|
||||
}
|
||||
|
||||
void GkGameButton::MouseDown(int x, int y)
|
||||
{
|
||||
if (this->IsMouseOver(x, y))
|
||||
this->Down();
|
||||
}
|
||||
|
||||
void GkGameButton::MouseUp(int x, int y)
|
||||
{
|
||||
this->Up(this->pushed && this->IsMouseOver(x, y));
|
||||
}
|
||||
|
||||
bool GkGameButton::WasDown()
|
||||
{
|
||||
bool result = this->down;
|
||||
|
||||
this->clicked = false;
|
||||
this->down = false;
|
||||
this->read = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GkGameButton::IsClicked()
|
||||
{
|
||||
bool result = this->clicked;
|
||||
|
||||
this->clicked = false;
|
||||
this->down = false;
|
||||
this->read = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GkGameButton::IsActive()
|
||||
{
|
||||
return this->enabled && this->visible;
|
||||
}
|
||||
|
||||
GkGameEntity* GkGameButton::GetCurrentFace()
|
||||
{
|
||||
if (this->enabled)
|
||||
{
|
||||
if (this->pushed)
|
||||
return this->selectedFace != 0 ? this->selectedFace : this->defaultFace;
|
||||
else
|
||||
return this->defaultFace;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->disabledFace != 0 ? this->disabledFace : this->defaultFace;
|
||||
}
|
||||
}
|
||||
|
||||
bool GkGameButton::IsMouseOver(int x, int y)
|
||||
{
|
||||
if (this->defaultFace != 0)
|
||||
{
|
||||
// if a defaultFace is given, check a region, relative to it
|
||||
int x1, y1, x2, y2;
|
||||
if (defaultFace->GetBoundaries(&x1, &y1, &x2, &y2))
|
||||
return (x > x1 + this->x) && (x < x1 + this->x + this->width) && (y > y1 + this->y) && (y < y1 + this->y + this->height);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if defaultFace is not given, i.e. the button has no visible part, check its region without relation
|
||||
return (x > this->x) && (x < this->x + this->width) && (y > this->y) && (y < this->y + this->height);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GkGameButton::Process(GkGame *game)
|
||||
{
|
||||
if (this->autoEnable)
|
||||
{
|
||||
this->enabled = this->read;
|
||||
this->read = false;
|
||||
}
|
||||
|
||||
GkGameEntity *face = this->GetCurrentFace();
|
||||
if (face != 0)
|
||||
face->Process(game);
|
||||
}
|
||||
|
||||
void GkGameButton::Draw(GkGame *game)
|
||||
{
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
GkGameEntity *currentFace = this->GetCurrentFace();
|
||||
|
||||
if (currentFace != 0)
|
||||
currentFace->Draw(game);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameEntity.h"
|
||||
|
||||
class GKDLLCLASS GkGameButton :
|
||||
public GkGameEntity
|
||||
{
|
||||
public:
|
||||
GkGameEntity *defaultFace, *selectedFace, *disabledFace;
|
||||
int x, y, width, height;
|
||||
|
||||
bool visible, enabled, autoEnable, pushed;
|
||||
bool clicked, down, read;
|
||||
|
||||
GkGameButton::GkGameButton(GkGameEntity *defaultFace, GkGameEntity *selectedFace = 0, GkGameEntity *disabledFace = 0, bool autoEnable = true, int x = 0, int y = 0, int width = 0, int heght = 0);
|
||||
virtual GkGameButton::~GkGameButton(void);
|
||||
|
||||
virtual void GkGameButton::Down();
|
||||
virtual void GkGameButton::Up(bool click);
|
||||
virtual void GkGameButton::MouseDown(int x, int y);
|
||||
virtual void GkGameButton::MouseUp(int x, int y);
|
||||
virtual GkGameEntity* GkGameButton::GetCurrentFace();
|
||||
|
||||
bool GkGameButton::WasDown();
|
||||
bool GkGameButton::IsClicked();
|
||||
bool GkGameButton::IsActive();
|
||||
bool GkGameButton::IsMouseOver(int x, int y);
|
||||
void GkGameButton::Process(GkGame *game);
|
||||
void GkGameButton::Draw(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,516 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//#include <stdlib.h>
|
||||
|
||||
// Consider reels options:
|
||||
// 1. GkGameReel is a class, a fully visual GkGameEntity
|
||||
// GkGameReels is a collection of GkGameReel objects and manager for lines, winnings, sequential starting/stopping a reel, etc.
|
||||
// Pros. GkGameReels is lighest, GkGameReel is a fully useful GkGameEntity
|
||||
// Cons. Many settings, such as the "items" collection of AnimatedTextures, the "reelMap" and etc. must reoccur in all GkGameReel objects and the GkGameReels object, Changing a setting in GkGameReels will not "automatically" take effect until it is changed in all GkGameReel objects also
|
||||
// 2. GkGameReel is a class, and is abstract in a sense that it provides only the mechanics of a reel via a spinning position
|
||||
// GkGameReels is a collection of GkGameReel objects and aside from all the other things, also does the drawing of the reels
|
||||
// Pros. GkGameReels is relatively light, GkGameReel functionality is separated in its own class
|
||||
// Cons. GkGameReel is not useful unless used with GkGameReels. GkGameReels holds relatively little (maybe close to irrelevant for a whole class) logic and value
|
||||
// 3. GkGameReels has each reel internal and has methods processing a reel. All the logic is inside that class.
|
||||
// Pros. No GkGameReel class, no need for different objects to share or have the same information (for settings)
|
||||
// Cons. GkGameReels is more heavily loaded with code logic. Does not quite correspond to the architecture model so far.
|
||||
|
||||
#include "GkGameReels.h"
|
||||
|
||||
#include "..\..\OSSpecific\GkOSUtils.h"
|
||||
#include "..\..\Utils\GkMaths.h"
|
||||
|
||||
#include "..\GkGame.h"
|
||||
#include "..\..\Utils\GkMaths.h"
|
||||
|
||||
|
||||
GkGameReels::GkGameReels(int numReels, int numReelItems, int numSymbols, int width, int height)
|
||||
: GkBaseReelMap(numReels, numReelItems)
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->numSymbols = numSymbols;
|
||||
this->state = Idle;
|
||||
this->stateOld = Idle;
|
||||
this->stateChange = Undefined;
|
||||
|
||||
this->numReelAnimations = this->numReelItems + 2;
|
||||
|
||||
this->reels = new GkGameReelInfo[numReels];
|
||||
for (int i = 0; i < numReels; i++)
|
||||
{
|
||||
this->reels[i].state = Idle;
|
||||
this->reels[i].stateOld = Idle;
|
||||
this->reels[i].stateChange = Undefined;
|
||||
this->reels[i].position = 0.0f;
|
||||
|
||||
this->reels[i].animations = new GkGameAnimation*[this->numReelAnimations];
|
||||
|
||||
for (int itemIndex = 0; itemIndex < this->numReelAnimations; itemIndex++)
|
||||
{
|
||||
this->reels[i].animations[itemIndex] = new GkGameAnimation();
|
||||
this->reels[i].animations[itemIndex]->visible = true;
|
||||
this->reels[i].animations[itemIndex]->active = false;
|
||||
this->reels[i].animations[itemIndex]->loop = false;
|
||||
}
|
||||
}
|
||||
|
||||
this->symbols = new GkAnimatedTexture*[numSymbols];
|
||||
|
||||
this->speed = 20.0f;
|
||||
this->acceleration = 40.0f;
|
||||
this->stoppingTime = 1.0f;
|
||||
|
||||
this->preStartOffset = 0.15f;
|
||||
this->preStartSpeed = 2.0f;
|
||||
this->postStopOffset = 0.15f;
|
||||
this->postStopSpeed = 2.0f;
|
||||
|
||||
this->itemGenerator = 0;
|
||||
}
|
||||
|
||||
|
||||
GkGameReels::~GkGameReels(void)
|
||||
{
|
||||
for (int i = 0; i < numReels; i++)
|
||||
{
|
||||
for (int j = 0; j < this->numReelAnimations; j++)
|
||||
{
|
||||
delete[] this->reels[i].animations[j];
|
||||
}
|
||||
|
||||
delete[] this->reels[i].animations;
|
||||
}
|
||||
|
||||
delete[] this->symbols;
|
||||
delete[] this->reels;
|
||||
}
|
||||
|
||||
void GkGameReels::SetItemGenerator(GkGameReelsCombinationGenerator *itemGenerator)
|
||||
{
|
||||
this->itemGenerator = itemGenerator;
|
||||
}
|
||||
|
||||
GkAnimatedTexture *GkGameReels::Reel_GetNewSymbol(int reelIndex)
|
||||
{
|
||||
if (this->itemGenerator != 0)
|
||||
{
|
||||
return this->symbols[this->itemGenerator->reels[reelIndex].model->GetSymbol()];
|
||||
}
|
||||
else
|
||||
return this->symbols[GkMaths::Random(this->numSymbols)];
|
||||
}
|
||||
|
||||
void GkGameReels::Reel_ProcessPosition(int reelIndex, GkGame *game)
|
||||
{
|
||||
GkGameReelInfo *reel = &this->reels[reelIndex];
|
||||
|
||||
// Handle position ranging and shifting of symbols when position hops over 1.0
|
||||
reel->position += game->timer->tickTime * reel->speed;
|
||||
if (reel->position >= 1.0f)
|
||||
{
|
||||
int numShifts = (int)reel->position;
|
||||
|
||||
reel->position -= numShifts;
|
||||
|
||||
int reelShifts = GkMaths::Min(numShifts, this->numReelItems - reel->reelMapSetIndex + 1);
|
||||
|
||||
for (int shiftIndex = 0; shiftIndex < reelShifts; shiftIndex++)
|
||||
{
|
||||
GkGameAnimation *rotAnimation = reel->animations[this->numReelAnimations - 1];
|
||||
for (int i = 0; i < this->numReelAnimations; i++)
|
||||
{
|
||||
GkGameAnimation *t = reel->animations[i];
|
||||
reel->animations[i] = rotAnimation;
|
||||
rotAnimation = t;
|
||||
}
|
||||
|
||||
if (reel->state == Stopping)
|
||||
{
|
||||
if (reel->reelMapSetIndex < this->numReelItems)
|
||||
reel->animations[0]->SetAnimatedTexture(this->symbols[this->GetSymbol(reelIndex, this->numReelItems - 1 - reel->reelMapSetIndex)]);
|
||||
else
|
||||
{
|
||||
reel->animations[0]->SetAnimatedTexture(this->Reel_GetNewSymbol(reelIndex));
|
||||
}
|
||||
|
||||
reel->reelMapSetIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
reel->animations[0]->SetAnimatedTexture(this->Reel_GetNewSymbol(reelIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < this->numReelAnimations; i++)
|
||||
{
|
||||
reel->animations[i]->Process(game);
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameReels::Reel_ProcessState(int reelIndex, GkGameTimer *timer)
|
||||
{
|
||||
GkGameReelInfo *reel = &this->reels[reelIndex];
|
||||
|
||||
switch (reel->state)
|
||||
{
|
||||
case Idle:
|
||||
{
|
||||
reel->speed = 0.0f;
|
||||
reel->position = 0.0f;
|
||||
|
||||
// User interaction expected
|
||||
break;
|
||||
}
|
||||
|
||||
case PreStarting:
|
||||
{
|
||||
reel->speed = 0.0f;
|
||||
reel->position -= timer->tickTime * this->preStartSpeed;
|
||||
|
||||
if (reel->position < -this->preStartOffset)
|
||||
{
|
||||
reel->position = -this->preStartOffset;
|
||||
reel->state = Starting;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Starting:
|
||||
{
|
||||
reel->speed += this->acceleration * timer->tickTime;
|
||||
|
||||
if (reel->speed >= this->speed)
|
||||
{
|
||||
reel->speed = this->speed;
|
||||
reel->state = Spinning;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Spinning:
|
||||
{
|
||||
// User interaction expected
|
||||
break;
|
||||
}
|
||||
|
||||
case Stopping:
|
||||
{
|
||||
if ((reel->reelMapSetIndex > this->numReelItems) && (reel->position >= this->postStopOffset))
|
||||
{
|
||||
reel->position = this->postStopOffset;
|
||||
|
||||
reel->state = PostStopping;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case PostStopping:
|
||||
{
|
||||
reel->speed = 0.0f;
|
||||
reel->position -= timer->tickTime * this->postStopSpeed;
|
||||
|
||||
if (reel->position < 0.0f)
|
||||
{
|
||||
reel->position = 0.0f;
|
||||
reel->state = Idle;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
reel->stateChange = reel->state != reel->stateOld ? reel->state : Undefined;
|
||||
reel->stateOld = reel->state;
|
||||
}
|
||||
|
||||
bool GkGameReels::Reel_Start(int reelIndex)
|
||||
{
|
||||
GkGameReelInfo *reel = &this->reels[reelIndex];
|
||||
|
||||
if (reel->state == Idle)
|
||||
{
|
||||
reel->state = PreStarting;
|
||||
reel->reelMapSetIndex = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GkGameReels::Reel_Stop(int reelIndex)
|
||||
{
|
||||
GkGameReelInfo *reel = &this->reels[reelIndex];
|
||||
|
||||
if (reel->state == Spinning)
|
||||
{
|
||||
reel->state = Stopping;
|
||||
reel->reelMapSetIndex = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Gives a summary state. If all reels have the same state, returns that state, otherwise returns Undefined. If a reel has a Blocked state, it's ignored, unless all reels have Blocked state, in which case Blocked is returned.
|
||||
GameReelState GkGameReels::GetGeneralState()
|
||||
{
|
||||
GameReelState result = Undefined;
|
||||
|
||||
int reelIndex = 0;
|
||||
while (reelIndex < this->numReels)
|
||||
{
|
||||
GameReelState reelState = this->reels[reelIndex].state;
|
||||
|
||||
if (result == Undefined)
|
||||
{
|
||||
result = reelState;
|
||||
}
|
||||
else if (result == Blocked)
|
||||
{
|
||||
if (reelState != Blocked)
|
||||
{
|
||||
result = reelState;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((result != reelState) && (reelState != Blocked))
|
||||
{
|
||||
return Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
reelIndex++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void GkGameReels::ProcessState(GkGameTimer *timer)
|
||||
{
|
||||
GameReelState generalState = this->GetGeneralState();
|
||||
|
||||
// Ensure each state is followed by the next for at least one frame
|
||||
switch (this->state)
|
||||
{
|
||||
case Idle:
|
||||
{
|
||||
if ((this->state != generalState) && (generalState != Undefined))
|
||||
this->state = PreStarting;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PreStarting:
|
||||
{
|
||||
if ((this->state != generalState) && (generalState != Undefined))
|
||||
this->state = Starting;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Starting:
|
||||
{
|
||||
if ((this->state != generalState) && (generalState != Undefined))
|
||||
this->state = Spinning;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Spinning:
|
||||
{
|
||||
if ((this->state != generalState) && (generalState != Undefined))
|
||||
this->state = Stopping;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Stopping:
|
||||
{
|
||||
float fullStopTime = GkMaths::Max(this->stoppingTime - this->numReelItems / this->speed - this->postStopOffset / this->postStopSpeed, 0.0f);
|
||||
float timeSinceStopInitiated = GkGameTimer::GetSampleTime(this->stopInitiatedTime);
|
||||
int reelsStopped = fullStopTime != 0 ? GkMaths::Min((int)(1 + (this->numReels - 1) * timeSinceStopInitiated / fullStopTime), this->numReels) : this->numReels;
|
||||
|
||||
int stopCount = 0;
|
||||
for (int i = 0; i < this->numReels; i++)
|
||||
{
|
||||
this->Reel_Stop(i);
|
||||
|
||||
if ((this->reels[i].state != Blocked) && (this->reels[i].state != Spinning))
|
||||
stopCount++;
|
||||
|
||||
if (stopCount >= reelsStopped)
|
||||
break;
|
||||
}
|
||||
|
||||
if (reelsStopped == this->numReels)
|
||||
this->state = PostStopping;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PostStopping:
|
||||
{
|
||||
if ((generalState == Idle) | (generalState == Blocked))
|
||||
this->state = Idle;
|
||||
//if ((this->state != generalState) && (generalState != Undefined))
|
||||
// this->state = Idle;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
this->state = generalState;
|
||||
}
|
||||
}
|
||||
|
||||
this->stateChange = this->state != this->stateOld ? this->state : Undefined;
|
||||
this->stateOld = this->state;
|
||||
}
|
||||
|
||||
void GkGameReels::Process(GkGame *game)
|
||||
{
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
this->Reel_ProcessPosition(reelIndex, game);
|
||||
|
||||
this->Reel_ProcessState(reelIndex, game->timer);
|
||||
}
|
||||
|
||||
this->ProcessState(game->timer);
|
||||
}
|
||||
|
||||
void GkGameReels::Draw(GkGame *game)
|
||||
{
|
||||
int itemWidth = this->symbols[0]->frames[0]->width;
|
||||
int itemHeight = this->symbols[0]->frames[0]->height;
|
||||
|
||||
float horizontalDistance = this->numReels == 1 ? itemWidth : itemWidth + (this->width - this->numReels * itemWidth) / ((float)this->numReels - 1.0f);
|
||||
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
int x = (int)(this->x + reelIndex * horizontalDistance);
|
||||
|
||||
for (int itemIndex = 0; itemIndex < this->numReelAnimations; itemIndex++)
|
||||
{
|
||||
int y = (int)(this->y + (this->height - this->numReelAnimations * itemHeight) / 2 + this->reels[reelIndex].position * itemHeight + itemIndex * itemHeight);
|
||||
|
||||
GkGameAnimation *reelItemAnimation = this->reels[reelIndex].animations[itemIndex];
|
||||
|
||||
game->graphicsDevice->DrawClipped(x, y, this->x, this->y, this->width, this->height, reelItemAnimation->animatedTexture->frames[(int)reelItemAnimation->currentFrame]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameReels::ApplyReelMap(const int *fullItemMap)
|
||||
{
|
||||
if (fullItemMap != 0)
|
||||
{
|
||||
this->SetItems(fullItemMap);
|
||||
}
|
||||
|
||||
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
this->reels[reelIndex].animations[0]->SetAnimatedTexture(this->symbols[GkMaths::Random(this->numSymbols)]);
|
||||
this->reels[reelIndex].animations[this->numReelAnimations - 1]->SetAnimatedTexture(this->symbols[GkMaths::Random(this->numSymbols)]);
|
||||
}
|
||||
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
|
||||
{
|
||||
this->reels[reelIndex].animations[itemIndex + 1]->SetAnimatedTexture(this->symbols[this->GetSymbol(reelIndex, itemIndex)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GkGameReels::Start()
|
||||
{
|
||||
this->reelingTime = GkGameTimer::GetSample();
|
||||
|
||||
bool result = true;
|
||||
if (this->state == Idle)
|
||||
{
|
||||
for (int i = 0; i < this->numReels; i++)
|
||||
result &= this->Reel_Start(i);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GkGameReels::Stop()
|
||||
{
|
||||
if (this->state = Spinning)
|
||||
{
|
||||
this->stopInitiatedTime = GkGameTimer::GetSample();
|
||||
|
||||
this->state = Stopping;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
bool result = true;
|
||||
if (this->state == Spinning)
|
||||
{
|
||||
for (int i = 0; i < this->numReels; i++)
|
||||
result &= this->Reel_Stop(i);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GkGameReels::ItemsAnimationsPlaying()
|
||||
{
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
|
||||
{
|
||||
if (this->reels[reelIndex].animations[itemIndex + 1]->active)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GkGameReels::StopItemsAnimations()
|
||||
{
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
|
||||
{
|
||||
this->reels[reelIndex].animations[itemIndex + 1]->active = false;
|
||||
this->reels[reelIndex].animations[itemIndex + 1]->currentFrame = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float GkGameReels::GetReelingTime()
|
||||
{
|
||||
return GkGameTimer::GetSampleTime(this->reelingTime);
|
||||
}
|
||||
|
||||
float GkGameReels::GetIdleTime()
|
||||
{
|
||||
return GkGameTimer::GetSampleTime(this->idleTime);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameEntity.h"
|
||||
#include "GkGameAnimation.h"
|
||||
#include "..\..\Base\GkBaseReelMap.h"
|
||||
#include "..\GkGameReelsCombinationGenerator.h"
|
||||
|
||||
class GKDLLCLASS GkGameTimer;
|
||||
|
||||
enum GameReelState
|
||||
{
|
||||
Idle = 0,
|
||||
PreStarting = 1,
|
||||
Starting = 2,
|
||||
Spinning = 3,
|
||||
Stopping = 4,
|
||||
PostStopping = 5,
|
||||
Blocked = 6,
|
||||
Undefined = 7
|
||||
};
|
||||
|
||||
struct GkGameReelInfo
|
||||
{
|
||||
GameReelState state, stateOld, stateChange;
|
||||
float position, speed;
|
||||
int reelMapSetIndex;
|
||||
|
||||
GkGameAnimation **animations;
|
||||
};
|
||||
|
||||
class GKDLLCLASS GkGameReels :
|
||||
public GkGameEntity,
|
||||
public GkBaseReelMap
|
||||
{
|
||||
private:
|
||||
GameReelState stateOld;
|
||||
long long stopInitiatedTime, reelingTime, idleTime;
|
||||
|
||||
// GkGameReel related methods
|
||||
GkAnimatedTexture *GkGameReels::Reel_GetNewSymbol(int reelIndex);
|
||||
void GkGameReels::Reel_ProcessState(int reelIndex, GkGameTimer *gameTimer);
|
||||
void GkGameReels::Reel_ProcessPosition(int reelIndex, GkGame *game);
|
||||
bool GkGameReels::Reel_Start(int reelIndex);
|
||||
bool GkGameReels::Reel_Stop(int reelIndex);
|
||||
|
||||
void GkGameReels::ProcessState(GkGameTimer *gameTimer);
|
||||
|
||||
public:
|
||||
GkGameReelInfo *reels;
|
||||
|
||||
|
||||
GameReelState state, // GkGameReels acquires certain state when all of its reels reach that state
|
||||
stateChange; // Gives the state that reels have just obtained in the last frame
|
||||
|
||||
int numSymbols, numReelAnimations;
|
||||
|
||||
int x, y, width, height;
|
||||
|
||||
float speed, // items per second
|
||||
acceleration, // items per second^2
|
||||
stoppingTime, // seconds
|
||||
preStartOffset, postStopOffset, // number of items
|
||||
preStartSpeed, postStopSpeed; // items per second
|
||||
|
||||
GkAnimatedTexture **symbols;
|
||||
|
||||
GkGameReelsCombinationGenerator *itemGenerator;
|
||||
|
||||
GkGameReels::GkGameReels(int numReels, int numReelItems, int numSymbols, int width, int height);
|
||||
GkGameReels::~GkGameReels(void);
|
||||
|
||||
void GkGameReels::SetItemGenerator(GkGameReelsCombinationGenerator *itemGenerator);
|
||||
void GkGameReels::Process(GkGame *game);
|
||||
void GkGameReels::Draw(GkGame *game);
|
||||
void GkGameReels::ApplyReelMap(const int *fullItemMap = 0);
|
||||
bool GkGameReels::Start();
|
||||
bool GkGameReels::Stop();
|
||||
bool GkGameReels::ItemsAnimationsPlaying();
|
||||
void GkGameReels::StopItemsAnimations();
|
||||
float GkGameReels::GetReelingTime();
|
||||
float GkGameReels::GetIdleTime();
|
||||
GameReelState GkGameReels::GetGeneralState();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameStreamingAnimation.h"
|
||||
|
||||
#include "..\..\Utils\GkStrings.h"
|
||||
#include "..\..\OSSpecific\GkFileSystem.h"
|
||||
|
||||
GkGameStreamingAnimation::GkGameStreamingAnimation(const wchar_t *fileName, const wchar_t *loadExpression, int x, int y, bool freeAtEnd, float framesPerSecond, int numFrames)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->visible = false;
|
||||
this->active = true;
|
||||
this->loop = false;
|
||||
this->freeAtEnd = freeAtEnd;
|
||||
this->currentFrame = framesPerSecond >= 0.0f ? 0.0f : (float)(numFrames - 1);
|
||||
this->framesPerSecond = framesPerSecond;
|
||||
this->numFrames = numFrames;
|
||||
|
||||
this->loadExpression = GkStrings::Copy(loadExpression);
|
||||
this->fileName = GkStrings::Copy(fileName);
|
||||
this->texture = 0;
|
||||
}
|
||||
|
||||
|
||||
GkGameStreamingAnimation::~GkGameStreamingAnimation(void)
|
||||
{
|
||||
this->Free();
|
||||
|
||||
GkStrings::Dispose(&this->fileName);
|
||||
GkStrings::Dispose(&this->loadExpression);
|
||||
}
|
||||
|
||||
void GkGameStreamingAnimation::SetSource(const wchar_t *fileName, const wchar_t *loadExpression, float framesPerSecond, int numFrames)
|
||||
{
|
||||
this->Free();
|
||||
|
||||
this->active = true;
|
||||
this->loop = false;
|
||||
this->currentFrame = framesPerSecond >= 0.0f ? 0.0f : (float)(numFrames - 1);
|
||||
this->framesPerSecond = framesPerSecond;
|
||||
this->numFrames = numFrames;
|
||||
|
||||
GkStrings::Dispose(&this->fileName);
|
||||
GkStrings::Dispose(&this->loadExpression);
|
||||
this->loadExpression = GkStrings::Copy(loadExpression);
|
||||
this->fileName = GkStrings::Copy(fileName);
|
||||
}
|
||||
|
||||
void GkGameStreamingAnimation::Free()
|
||||
{
|
||||
if (this->texture != 0)
|
||||
{
|
||||
delete this->texture;
|
||||
this->texture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool GkGameStreamingAnimation::Load(int index)
|
||||
{
|
||||
void *data;
|
||||
unsigned int dataSize;
|
||||
|
||||
if (GkFileSystem::LoadFile(GkStrings::Format(this->loadExpression, GkStrings::IntToString(index, 10, 5).c_str()).c_str(), &data, &dataSize))
|
||||
{
|
||||
this->Free();
|
||||
|
||||
GkImage image;
|
||||
image.LoadFromMemory(data, dataSize);
|
||||
|
||||
this->texture = new GkTexture();
|
||||
this->texture->LoadFromImage(&image);
|
||||
|
||||
delete data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GkGameStreamingAnimation::Start()
|
||||
{
|
||||
this->currentFrame = framesPerSecond >= 0.0f ? 0.0f : (float)(numFrames - 1);
|
||||
this->lastRenderedFrame = (int)this->currentFrame;
|
||||
this->visible = this->Load(this->lastRenderedFrame);
|
||||
this->active = this->visible;
|
||||
}
|
||||
|
||||
void GkGameStreamingAnimation::Process(GkGame *game)
|
||||
{
|
||||
if (!(this->active && this->visible))
|
||||
return;
|
||||
|
||||
this->currentFrame += this->framesPerSecond * game->timer->tickTime;
|
||||
if ((this->lastRenderedFrame != (int)this->currentFrame) || (this->texture == 0))
|
||||
{
|
||||
bool terminate = false;
|
||||
if (!this->Load((int)this->currentFrame))
|
||||
{
|
||||
if (this->loop)
|
||||
{
|
||||
this->currentFrame = this->framesPerSecond >= 0 ? 0.0f : (float)(this->numFrames - 1);
|
||||
if (!this->Load((int)this->currentFrame))
|
||||
{
|
||||
terminate = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
terminate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (terminate)
|
||||
{
|
||||
this->currentFrame = (float)(this->lastRenderedFrame);
|
||||
this->active = false;
|
||||
this->visible = (!this->freeAtEnd) && (this->texture != 0);
|
||||
}
|
||||
}
|
||||
|
||||
this->lastRenderedFrame = (int)this->currentFrame;
|
||||
}
|
||||
|
||||
void GkGameStreamingAnimation::Draw(GkGame *game)
|
||||
{
|
||||
if (!this->visible)
|
||||
{
|
||||
this->Free();
|
||||
return;
|
||||
}
|
||||
|
||||
game->graphicsDevice->Draw(this->x, this->y, this->texture);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGame.h"
|
||||
#include "..\Entities\GkGameAnimation.h"
|
||||
#include "..\..\Graphics\GkTexture.h"
|
||||
|
||||
class GKDLLCLASS GkGameStreamingAnimation :
|
||||
public GkGameAnimation
|
||||
{
|
||||
public:
|
||||
GkTexture *texture;
|
||||
|
||||
wchar_t *fileName, *loadExpression;
|
||||
|
||||
bool freeAtEnd;
|
||||
int lastRenderedFrame;
|
||||
int numFrames; // required only if animation is backwards, i.e. if framesPerSecond is negative
|
||||
|
||||
// Because the animation is streaming and the number of frames is practically unknown, if it is played backwards, i.e. framesPerSecond is negative, then numFrames must be provided
|
||||
GkGameStreamingAnimation::GkGameStreamingAnimation(const wchar_t *fileName, const wchar_t *loadExpression, int x = 0, int y = 0, bool freeAtEnd = true, float framesPerSecond = 25.0f, int numFrames = 0);
|
||||
GkGameStreamingAnimation::~GkGameStreamingAnimation(void);
|
||||
|
||||
void GkGameStreamingAnimation::SetSource(const wchar_t *fileName, const wchar_t *loadExpression, float framesPerSecond = 25.0f, int numFrames = 0);
|
||||
void GkGameStreamingAnimation::Free();
|
||||
bool GkGameStreamingAnimation::Load(int index);
|
||||
void GkGameStreamingAnimation::Start();
|
||||
void GkGameStreamingAnimation::Process(GkGame *game);
|
||||
void GkGameStreamingAnimation::Draw(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameText.h"
|
||||
|
||||
#include "..\GkGame.h"
|
||||
#include "..\..\Utils\GkStrings.h"
|
||||
|
||||
GkGameText::GkGameText(GkAnimatedFont *animatedFont, int x, int y, int characterSpacing, int textAlignment, int maxWidth, float framesPerSecond)
|
||||
: GkGameEntity()
|
||||
{
|
||||
this->animatedFont = animatedFont;
|
||||
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->characterSpacing = characterSpacing;
|
||||
this->maxWidth = maxWidth;
|
||||
this->textAlignment = textAlignment;
|
||||
this->visible = animatedFont != NULL;
|
||||
this->active = animatedFont != NULL;
|
||||
this->loop = animatedFont != NULL;
|
||||
|
||||
this->framesPerSecond = framesPerSecond != 0.0f ? framesPerSecond : animatedFont != 0 ? animatedFont->framesPerSecond : 0.0f;
|
||||
this->currentFrame = 0.0f;
|
||||
|
||||
this->text = 0;
|
||||
this->textTextureIndices = 0;
|
||||
this->textLength = 0;
|
||||
}
|
||||
|
||||
|
||||
GkGameText::~GkGameText(void)
|
||||
{
|
||||
if (this->text != 0)
|
||||
delete[] this->text;
|
||||
|
||||
if (this->textTextureIndices != 0)
|
||||
delete[] this->textTextureIndices;
|
||||
}
|
||||
|
||||
bool GkGameText::SetText(const wchar_t *text)
|
||||
{
|
||||
if ((this->text != 0) && (GkStrings::Compare(this->text, text) == 0))
|
||||
return false;
|
||||
|
||||
if (this->text != 0)
|
||||
delete[] this->text;
|
||||
|
||||
if (this->textTextureIndices != 0)
|
||||
delete[] this->textTextureIndices;
|
||||
|
||||
this->text = GkStrings::Copy(text);
|
||||
this->textLength = GkStrings::GetLength(this->text);
|
||||
this->textTextureIndices = new int[this->textLength];
|
||||
|
||||
this->textWidth = 0;
|
||||
for (int i = 0; i < this->textLength; i++)
|
||||
{
|
||||
this->textTextureIndices[i] = GkStrings::SubChar(this->animatedFont->charMap, this->text[i]);
|
||||
|
||||
if (this->textTextureIndices[i] != -1)
|
||||
{
|
||||
this->textWidth += this->animatedFont->letterTextures[this->textTextureIndices[i]]->frames[0]->width + this->characterSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
this->textWidth -= this->characterSpacing;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GkGameText::Process(GkGame *game)
|
||||
{
|
||||
if (!(this->active && this->visible))
|
||||
return;
|
||||
|
||||
this->currentFrame += this->framesPerSecond * game->timer->tickTime;
|
||||
if (this->currentFrame > this->animatedFont->letterTextures[0]->numFrames)
|
||||
{
|
||||
if (this->loop)
|
||||
{
|
||||
int intFrame = (int)this->currentFrame;
|
||||
float fracFrame = this->currentFrame - intFrame;
|
||||
this->currentFrame = intFrame % this->animatedFont->letterTextures[0]->numFrames + fracFrame;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->currentFrame = (float)(this->animatedFont->letterTextures[0]->numFrames - 1);
|
||||
this->active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameText::Draw(GkGame *game)
|
||||
{
|
||||
if (!this->visible)
|
||||
return;
|
||||
|
||||
if ((this->maxWidth == 0) || (this->textWidth <= this->maxWidth))
|
||||
{
|
||||
int x = this->textAlignment == GkGameText::GameTextAlignment_Right ? this->x : this->textAlignment == GkGameText::GameTextAlignment_Center ? this->x - this->textWidth / 2 : this->x - this->textWidth;
|
||||
|
||||
for (int i = 0; i < this->textLength; i++)
|
||||
{
|
||||
int letterTextureIndex = this->textTextureIndices[i];
|
||||
|
||||
if (letterTextureIndex != -1)
|
||||
{
|
||||
GkTexture *letterTexture = this->animatedFont->letterTextures[letterTextureIndex]->frames[(int)this->currentFrame];
|
||||
|
||||
game->graphicsDevice->Draw(x, this->y, letterTexture);
|
||||
|
||||
x += letterTexture->width + this->characterSpacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float scalingFactor = (float)this->maxWidth / (float)this->textWidth;
|
||||
|
||||
float x = this->textAlignment == GkGameText::GameTextAlignment_Right ? this->x : this->textAlignment == GkGameText::GameTextAlignment_Center ? this->x - (float)(scalingFactor * (float)this->textWidth / 2.0f) : this->x - (float)(scalingFactor * (float)this->textWidth);
|
||||
int y = this->y + (int)(((1.0f - scalingFactor) * (float)this->animatedFont->letterTextures[0]->frames[0]->height) / 2.0f);
|
||||
|
||||
for (int i = 0; i < this->textLength; i++)
|
||||
{
|
||||
int letterTextureIndex = this->textTextureIndices[i];
|
||||
|
||||
if (letterTextureIndex != -1)
|
||||
{
|
||||
GkTexture *letterTexture = this->animatedFont->letterTextures[letterTextureIndex]->frames[(int)this->currentFrame];
|
||||
|
||||
game->graphicsDevice->Draw((int)x, y, (int)(letterTexture->width * scalingFactor), (int)(letterTexture->height * scalingFactor), 0, 0, letterTexture->width, letterTexture->height, letterTexture);
|
||||
|
||||
x += scalingFactor * (letterTexture->width + this->characterSpacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameEntity.h"
|
||||
#include "..\..\Graphics\GkAnimatedFont.h"
|
||||
|
||||
class GKDLLCLASS GkGameText :
|
||||
public GkGameEntity
|
||||
{
|
||||
public:
|
||||
static const int GameTextAlignment_Right = 0,
|
||||
GameTextAlignment_Center = 1,
|
||||
GameTextAlignment_Left = 2;
|
||||
|
||||
GkAnimatedFont *animatedFont;
|
||||
wchar_t *text;
|
||||
int textLength, textWidth;
|
||||
int *textTextureIndices;
|
||||
|
||||
int x, y;
|
||||
bool visible, active, loop;
|
||||
float framesPerSecond, currentFrame;
|
||||
int textAlignment;
|
||||
int characterSpacing;
|
||||
int maxWidth;
|
||||
|
||||
|
||||
GkGameText::GkGameText(GkAnimatedFont *animatedFont, int x = 0, int y = 0, int characterSpacing = 0, int textAlignment = GameTextAlignment_Right, int maxWidth = 0, float framesPerSecond = 0.0f);
|
||||
GkGameText::~GkGameText(void);
|
||||
|
||||
bool GkGameText::SetText(const wchar_t *text);
|
||||
void GkGameText::Process(GkGame *game);
|
||||
void GkGameText::Draw(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameWinningCounter.h"
|
||||
|
||||
#include "..\GkGame.h"
|
||||
|
||||
GkGameWinningCounter::GkGameWinningCounter(int *actualValue, float minSpeed, float maxTime)
|
||||
: GkGameEntity()
|
||||
|
||||
{
|
||||
this->actualValue = actualValue;
|
||||
this->minSpeed = minSpeed;
|
||||
this->maxTime = maxTime;
|
||||
|
||||
this->SetValue((float)*this->actualValue, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
GkGameWinningCounter::~GkGameWinningCounter(void)
|
||||
{
|
||||
}
|
||||
|
||||
void GkGameWinningCounter::SetValue(float value, float maxTime)
|
||||
{
|
||||
float delta = value - this->displayValue;
|
||||
if (maxTime == -1.0f)
|
||||
maxTime = this->maxTime;
|
||||
|
||||
if (maxTime == 0.0f)
|
||||
{
|
||||
this->displayValue = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
float minSpeed = delta / maxTime;
|
||||
this->speed = this->minSpeed > minSpeed ? this->minSpeed : minSpeed;
|
||||
}
|
||||
|
||||
this->oldValue = value;
|
||||
}
|
||||
|
||||
void GkGameWinningCounter::Reach(float maxTime)
|
||||
{
|
||||
this->SetValue((float)*this->actualValue, maxTime);
|
||||
}
|
||||
|
||||
bool GkGameWinningCounter::IsCounting()
|
||||
{
|
||||
return this->intDisplayValue != *this->actualValue;
|
||||
}
|
||||
|
||||
void GkGameWinningCounter::Process(GkGame *game)
|
||||
{
|
||||
float value = (float)*this->actualValue;
|
||||
|
||||
if (value != this->oldValue)
|
||||
this->SetValue(value, this->maxTime);
|
||||
|
||||
this->displayValue += this->speed * game->timer->tickTime;
|
||||
|
||||
if (this->speed > 0.0f)
|
||||
{
|
||||
if (this->displayValue > value)
|
||||
this->displayValue = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->displayValue < value)
|
||||
this->displayValue = value;
|
||||
}
|
||||
|
||||
this->intDisplayValue = (int)this->displayValue;
|
||||
|
||||
GkGameEntity::Process(game);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameEntity.h"
|
||||
|
||||
class GKDLLCLASS GkGameWinningCounter :
|
||||
public GkGameEntity
|
||||
{
|
||||
private:
|
||||
float oldValue;
|
||||
|
||||
void SetValue(float value, float maxTime);
|
||||
|
||||
public:
|
||||
int *actualValue;
|
||||
|
||||
float minSpeed, maxTime,
|
||||
displayValue,
|
||||
speed;
|
||||
|
||||
int intDisplayValue;
|
||||
|
||||
GkGameWinningCounter(int *actualValue, float minSpeed = 500.0f, float maxTime = 1.0f);
|
||||
~GkGameWinningCounter(void);
|
||||
|
||||
void Reach(float maxTime = 0.0f);
|
||||
bool IsCounting();
|
||||
|
||||
void Process(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGame.h"
|
||||
|
||||
#include "..\OSSpecific\GkFileSystem.h"
|
||||
#include "..\Utils\GkStrings.h"
|
||||
|
||||
|
||||
ResourcePoolEntry::ResourcePoolEntry(GkBase *resource, const wchar_t *id)
|
||||
{
|
||||
this->resource = resource;
|
||||
|
||||
if (id == NULL)
|
||||
{
|
||||
this->id = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
int l = wcslen(id);
|
||||
this->id = new wchar_t[l + 1];
|
||||
wcscpy_s(this->id, l + 1, id);
|
||||
}
|
||||
}
|
||||
|
||||
GkGame::GkGame(GkGraphicsDevice *graphicsDevice, GkSoundDevice *soundDevice)
|
||||
{
|
||||
this->graphicsDevice = graphicsDevice;
|
||||
this->soundDevice = soundDevice;
|
||||
|
||||
this->currentGamePage = 0;
|
||||
|
||||
this->timer = new GkGameTimer();
|
||||
}
|
||||
|
||||
|
||||
GkGame::~GkGame(void)
|
||||
{
|
||||
int numPages = this->gamePages.size();
|
||||
for (int i = 0; i < numPages; i++)
|
||||
{
|
||||
delete this->gamePages[i];
|
||||
}
|
||||
|
||||
int numResources = this->resourcePool.size();
|
||||
for (int i = 0; i < numResources; i++)
|
||||
{
|
||||
delete this->resourcePool[i].resource;
|
||||
|
||||
if (this->resourcePool[i].id != NULL)
|
||||
{
|
||||
delete this->resourcePool[i].id;
|
||||
this->resourcePool[i].id = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
delete this->timer;
|
||||
}
|
||||
|
||||
void GkGame::SetPage(GkGamePage *page)
|
||||
{
|
||||
if (this->currentGamePage != 0)
|
||||
this->currentGamePage->OnHide(page);
|
||||
|
||||
if (page != 0)
|
||||
page->OnShow(this->currentGamePage);
|
||||
|
||||
this->currentGamePage = page;
|
||||
}
|
||||
|
||||
GkAnimatedTexture* GkGame::AddAnimatedTexture(GkAnimatedTexture *animatedTexture, const wchar_t* id)
|
||||
{
|
||||
this->resourcePool.push_back(ResourcePoolEntry(animatedTexture, id));
|
||||
return animatedTexture;
|
||||
}
|
||||
|
||||
void* GkGame::GetResource(const wchar_t* id)
|
||||
{
|
||||
int numResources = this->resourcePool.size();
|
||||
for (int i = 0; i < numResources; i++)
|
||||
{
|
||||
if (wcscmp(this->resourcePool[i].id, id) == 0)
|
||||
return this->resourcePool[i].resource;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool GkGame::ReleaseResource(const wchar_t* id)
|
||||
{
|
||||
int numResources = this->resourcePool.size();
|
||||
for (int i = 0; i < numResources; i++)
|
||||
{
|
||||
if (wcscmp(this->resourcePool[i].id, id) == 0)
|
||||
{
|
||||
delete this->resourcePool[i].resource;
|
||||
|
||||
if (this->resourcePool[i].id != NULL)
|
||||
{
|
||||
delete this->resourcePool[i].id;
|
||||
this->resourcePool[i].id = NULL;
|
||||
}
|
||||
|
||||
this->resourcePool[i] = this->resourcePool[numResources - 1];
|
||||
this->resourcePool.pop_back();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
GkAnimatedFont* GkGame::AcquireAnimatedFontFromMultipleFiles(const wchar_t* virtualFileName, const wchar_t *charMap, int numFrames)
|
||||
{
|
||||
GkAnimatedFont* result = (GkAnimatedFont*)this->GetResource(virtualFileName);
|
||||
if (result != NULL)
|
||||
return result;
|
||||
|
||||
|
||||
result = new GkAnimatedFont(charMap, numFrames);
|
||||
|
||||
void *data;
|
||||
unsigned int dataSize;
|
||||
|
||||
for (int i = 0; i < result->numLetters; i++)
|
||||
{
|
||||
if (GkFileSystem::LoadFile(GkStrings::Format(virtualFileName, GkStrings::IntToString(i, 10, 5).c_str()).c_str(), &data, &dataSize))
|
||||
{
|
||||
result->LoadAnimatedLetter(i, data, dataSize);
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this->resourcePool.push_back(ResourcePoolEntry(result, virtualFileName));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
GkAnimatedTexture* GkGame::AcquireAnimatedTexture(const wchar_t* virtualFileName, int columnFrames, int rowFrames, int numFrames, float framesPerSecond, int animatedTexture_LoadOrder)
|
||||
{
|
||||
GkAnimatedTexture* result = (GkAnimatedTexture*)this->GetResource(virtualFileName);
|
||||
if (result != NULL)
|
||||
return result;
|
||||
|
||||
void *data;
|
||||
unsigned int dataSize;
|
||||
|
||||
if (!GkFileSystem::LoadFile(virtualFileName, &data, &dataSize))
|
||||
return NULL;
|
||||
result = new GkAnimatedTexture(data, dataSize, columnFrames, rowFrames, numFrames, framesPerSecond, animatedTexture_LoadOrder);
|
||||
delete data;
|
||||
|
||||
this->resourcePool.push_back(ResourcePoolEntry(result, virtualFileName));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
GkAnimatedTexture* GkGame::AcquireAnimatedTextureFromMultipleFiles(const wchar_t* virtualFileName, float framesPerSecond)
|
||||
{
|
||||
GkAnimatedTexture *result = (GkAnimatedTexture*)this->GetResource(virtualFileName);
|
||||
if (result != NULL)
|
||||
return result;
|
||||
|
||||
|
||||
std::vector<GkTexture*> frames;
|
||||
|
||||
void *data;
|
||||
unsigned int dataSize;
|
||||
|
||||
int index = 0;
|
||||
while (GkFileSystem::LoadFile(GkStrings::Format(virtualFileName, GkStrings::IntToString(index, 10, 5).c_str()).c_str(), &data, &dataSize))
|
||||
{
|
||||
GkImage *frameImage = new GkImage();
|
||||
frameImage->LoadFromMemory(data, dataSize);
|
||||
|
||||
GkTexture *frame = new GkTexture();
|
||||
frame->LoadFromImage(frameImage);
|
||||
delete frameImage;
|
||||
|
||||
frames.push_back(frame);
|
||||
|
||||
index++;
|
||||
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
|
||||
int numFrames = frames.size();
|
||||
if (numFrames == 0)
|
||||
return NULL;
|
||||
|
||||
result = new GkAnimatedTexture();
|
||||
result->framesPerSecond = framesPerSecond;
|
||||
result->numFrames = numFrames;
|
||||
result->frames = new GkTexture*[numFrames];
|
||||
for (int i = 0; i < numFrames; i++)
|
||||
{
|
||||
result->frames[i] = frames[i];
|
||||
}
|
||||
|
||||
this->resourcePool.push_back(ResourcePoolEntry(result, virtualFileName));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
GkSoundSource* GkGame::AcquireSoundSource(const wchar_t* virtualFileName)
|
||||
{
|
||||
GkSoundSource* result = (GkSoundSource*)this->GetResource(virtualFileName);
|
||||
if (result != NULL)
|
||||
return result;
|
||||
|
||||
void *data;
|
||||
unsigned int dataSize;
|
||||
|
||||
GkFileSystem::LoadFile(virtualFileName, &data, &dataSize);
|
||||
result = new GkSoundSource();
|
||||
result->LoadFromMemory(data);
|
||||
this->resourcePool.push_back(ResourcePoolEntry(result, virtualFileName));
|
||||
delete data;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
GkGamePage* GkGame::AddGamePage(GkGamePage *gamePage)
|
||||
{
|
||||
this->gamePages.push_back(gamePage);
|
||||
|
||||
if (this->currentGamePage == NULL)
|
||||
this->SetPage(gamePage);
|
||||
|
||||
return gamePage;
|
||||
}
|
||||
|
||||
void GkGame::RemoveGamePage(GkGamePage *gamePage)
|
||||
{
|
||||
int index = -1;
|
||||
for (int i = 0; i < (int)this->gamePages.size(); i++)
|
||||
if (this->gamePages[i] == gamePage)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
for (int i = index; i < (int)this->gamePages.size() - 1; i++)
|
||||
this->gamePages[i] = this->gamePages[i + 1];
|
||||
|
||||
this->gamePages.pop_back();
|
||||
}
|
||||
|
||||
void GkGame::MouseDown(int x, int y)
|
||||
{
|
||||
int numEntities = this->currentGamePage->entities.size();
|
||||
for (int i = numEntities - 1; i >= 0; i--)
|
||||
{
|
||||
GkGameEntity *entity = this->currentGamePage->entities[i];
|
||||
if (entity->IsMouseOver(x, y))
|
||||
{
|
||||
entity->MouseDown(x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GkGame::MouseUp(int x, int y)
|
||||
{
|
||||
int numEntities = this->currentGamePage->entities.size();
|
||||
for (int i = numEntities - 1; i >= 0; i--)
|
||||
{
|
||||
GkGameEntity *entity = this->currentGamePage->entities[i];
|
||||
entity->MouseUp(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void GkGame::NewFrame()
|
||||
{
|
||||
this->timer->Tick();
|
||||
}
|
||||
|
||||
void GkGame::Process()
|
||||
{
|
||||
if (this->currentGamePage != NULL)
|
||||
this->currentGamePage->Process(this);
|
||||
}
|
||||
|
||||
void GkGame::Render()
|
||||
{
|
||||
if (this->currentGamePage != NULL)
|
||||
this->currentGamePage->Render(this);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "..\Graphics\GkGraphicsDevice.h"
|
||||
#include "..\Graphics\GkAnimatedTexture.h"
|
||||
#include "..\Graphics\GkAnimatedFont.h"
|
||||
#include "..\Sound\GkSoundDevice.h"
|
||||
#include "..\Sound\GkSoundSource.h"
|
||||
#include "GkGameTimer.h"
|
||||
#include "GkGamePage.h"
|
||||
#include "..\Base\GkBase.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class GKDLLCLASS GkGamePage;
|
||||
|
||||
struct ResourcePoolEntry
|
||||
{
|
||||
GkBase* resource;
|
||||
wchar_t* id;
|
||||
|
||||
ResourcePoolEntry::ResourcePoolEntry(GkBase *resource, const wchar_t *id);
|
||||
};
|
||||
|
||||
class GKDLLCLASS GkGame
|
||||
{
|
||||
public:
|
||||
GkGraphicsDevice *graphicsDevice;
|
||||
GkSoundDevice *soundDevice;
|
||||
|
||||
GkGameTimer *timer;
|
||||
|
||||
vector<GkGamePage*> gamePages;
|
||||
GkGamePage *currentGamePage;
|
||||
|
||||
vector<ResourcePoolEntry> resourcePool;
|
||||
|
||||
GkGame::GkGame(GkGraphicsDevice *graphicsDevice, GkSoundDevice *soundDevice);
|
||||
virtual GkGame::~GkGame(void);
|
||||
|
||||
void SetPage(GkGamePage *page);
|
||||
GkAnimatedTexture* GkGame::AddAnimatedTexture(GkAnimatedTexture *animatedTexture, const wchar_t* id = 0);
|
||||
void* GkGame::GetResource(const wchar_t* id);
|
||||
bool GkGame::ReleaseResource(const wchar_t* id);
|
||||
GkAnimatedFont* GkGame::AcquireAnimatedFontFromMultipleFiles(const wchar_t* virtualFileName, const wchar_t *charMap, int numFrames = 1);
|
||||
GkAnimatedTexture* GkGame::AcquireAnimatedTexture(const wchar_t* virtualFileName, int columnFrames = 1, int rowFrames = 1, int numFrames = 0, float framesPerSecond = 25.0f, int animatedTexture_LoadOrder = GkAnimatedTexture::LoadOrder_Horizontal);
|
||||
GkAnimatedTexture* GkGame::AcquireAnimatedTextureFromMultipleFiles(const wchar_t* virtualFileName, float framesPerSecond = 25.0f);
|
||||
GkSoundSource* GkGame::AcquireSoundSource(const wchar_t* virtualFileName);
|
||||
GkGamePage* GkGame::AddGamePage(GkGamePage *gamePage);
|
||||
void GkGame::RemoveGamePage(GkGamePage *gamePage);
|
||||
virtual void GkGame::MouseDown(int x, int y);
|
||||
virtual void GkGame::MouseUp(int x, int y);
|
||||
virtual void GkGame::NewFrame();
|
||||
virtual void GkGame::Process();
|
||||
virtual void GkGame::Render();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameEntity.h"
|
||||
|
||||
#include "GkGame.h"
|
||||
|
||||
GkGameEntity::GkGameEntity()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GkGameEntity::~GkGameEntity(void)
|
||||
{
|
||||
}
|
||||
|
||||
void GkGameEntity::MouseDown(int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
void GkGameEntity::MouseUp(int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
void GkGameEntity::Process(GkGame *game)
|
||||
{
|
||||
}
|
||||
|
||||
void GkGameEntity::Draw(GkGame *game)
|
||||
{
|
||||
}
|
||||
|
||||
bool GkGameEntity::IsMouseOver(int x, int y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void GkGameEntity::OnMouseClicked()
|
||||
{
|
||||
}
|
||||
|
||||
bool GkGameEntity::GetBoundaries(int *x1, int *y1, int *x2, int*y2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
class GKDLLCLASS GkGame;
|
||||
|
||||
class GKDLLCLASS GkGameEntity
|
||||
{
|
||||
public:
|
||||
GkGameEntity::GkGameEntity();
|
||||
virtual GkGameEntity::~GkGameEntity(void);
|
||||
|
||||
virtual void GkGameEntity::MouseDown(int x, int y);
|
||||
virtual void GkGameEntity::MouseUp(int x, int y);
|
||||
virtual void GkGameEntity::Process(GkGame *game);
|
||||
virtual void GkGameEntity::Draw(GkGame *game);
|
||||
virtual bool GkGameEntity::IsMouseOver(int x, int y);
|
||||
virtual void GkGameEntity::OnMouseClicked();
|
||||
virtual bool GkGameEntity::GetBoundaries(int *x1, int *y1, int *x2, int*y2);
|
||||
};
|
||||
@@ -0,0 +1,93 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGamePage.h"
|
||||
|
||||
GkGamePage::GkGamePage()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GkGamePage::~GkGamePage(void)
|
||||
{
|
||||
int numEntities = this->entities.size();
|
||||
|
||||
for (int i = 0; i < numEntities; i++)
|
||||
{
|
||||
delete this->entities[i];
|
||||
}
|
||||
}
|
||||
|
||||
void GkGamePage::OnShow(GkGamePage *previous)
|
||||
{
|
||||
}
|
||||
|
||||
void GkGamePage::OnHide(GkGamePage *next)
|
||||
{
|
||||
}
|
||||
|
||||
GkGameEntity* GkGamePage::AddEntity(GkGameEntity *entity)
|
||||
{
|
||||
this->entities.push_back(entity);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
GkGameEntity* GkGamePage::InsertEntity(int position, GkGameEntity *entity)
|
||||
{
|
||||
this->entities.push_back(0);
|
||||
|
||||
for (int i = this->entities.size() - 1; i > position; i--)
|
||||
this->entities[i] = this->entities[i - 1];
|
||||
|
||||
this->entities[position] = entity;
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
bool GkGamePage::RemoveEntity(GkGameEntity *entity)
|
||||
{
|
||||
int numEntities = this->entities.size();
|
||||
|
||||
for (int i = 0; i < numEntities; i++)
|
||||
{
|
||||
if (this->entities[i] == entity)
|
||||
{
|
||||
this->entities[i] = this->entities[numEntities - 1];
|
||||
this->entities.pop_back();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GkGamePage::Process(GkGame *game)
|
||||
{
|
||||
int numEntities = this->entities.size();
|
||||
|
||||
for (int i = 0; i < numEntities; i++)
|
||||
{
|
||||
this->entities[i]->Process(game);
|
||||
}
|
||||
}
|
||||
|
||||
void GkGamePage::Render(GkGame *game)
|
||||
{
|
||||
int numEntities = this->entities.size();
|
||||
|
||||
for (int i = 0; i < numEntities; i++)
|
||||
{
|
||||
this->entities[i]->Draw(game);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "GkGameEntity.h"
|
||||
|
||||
class GKDLLCLASS GkGame;
|
||||
|
||||
class GKDLLCLASS GkGamePage
|
||||
{
|
||||
public:
|
||||
std::vector<GkGameEntity*> entities;
|
||||
|
||||
GkGamePage::GkGamePage();
|
||||
virtual GkGamePage::~GkGamePage(void);
|
||||
|
||||
virtual void OnShow(GkGamePage *previous);
|
||||
virtual void OnHide(GkGamePage *next);
|
||||
|
||||
GkGameEntity* GkGamePage::AddEntity(GkGameEntity *entity);
|
||||
GkGameEntity* GkGamePage::InsertEntity(int position, GkGameEntity *entity);
|
||||
bool GkGamePage::RemoveEntity(GkGameEntity *entity);
|
||||
virtual void GkGamePage::Process(GkGame *game);
|
||||
virtual void GkGamePage::Render(GkGame *game);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameReelModel.h"
|
||||
|
||||
#include "..\OSSpecific\GkOSUtils.h"
|
||||
|
||||
GkGameReelModel::GkGameReelModel(int numItems)
|
||||
{
|
||||
this->numItems = numItems;
|
||||
this->items = new int[this->numItems];
|
||||
|
||||
GkOSUtils::ZeroMem(this->items, this->numItems * sizeof(int));
|
||||
}
|
||||
|
||||
|
||||
GkGameReelModel::~GkGameReelModel(void)
|
||||
{
|
||||
delete[] this->items;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
class GKDLLCLASS GkGameReelModel
|
||||
{
|
||||
public:
|
||||
int numItems;
|
||||
int *items;
|
||||
|
||||
GkGameReelModel(int numItems);
|
||||
virtual ~GkGameReelModel(void);
|
||||
|
||||
virtual int GetSymbol() = 0;
|
||||
virtual void GenerateReel() = 0;
|
||||
virtual void GenerateReelZero() = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameReelsCombinationGenerator.h"
|
||||
|
||||
#include "..\Utils\GkMaths.h"
|
||||
|
||||
GkGameReelsCombinationGenerator::GkGameReelsCombinationGenerator(int numReels, int numReelItems)
|
||||
: GkBaseReelMap(numReels, numReelItems)
|
||||
{
|
||||
this->reels = new GameReelsCombinationGeneratorReel[this->numReels];
|
||||
for (int i = 0; i < this->numReels; i++)
|
||||
{
|
||||
this->reels[i].model = 0;
|
||||
this->reels[i].blocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GkGameReelsCombinationGenerator::~GkGameReelsCombinationGenerator(void)
|
||||
{
|
||||
for (int i = 0; i < this->numReels; i++)
|
||||
{
|
||||
if (this->reels[i].model != 0)
|
||||
delete this->reels[i].model;
|
||||
}
|
||||
|
||||
delete[] this->reels;
|
||||
}
|
||||
|
||||
void GkGameReelsCombinationGenerator::SetReelModel(int reelIndex, GkGameReelModel *reelModel, bool blocked)
|
||||
{
|
||||
this->reels[reelIndex].model = reelModel;
|
||||
this->reels[reelIndex].blocked = blocked;
|
||||
}
|
||||
|
||||
|
||||
void GkGameReelsCombinationGenerator::GenerateReel(int reelIndex)
|
||||
{
|
||||
this->reels[reelIndex].model->GenerateReel();
|
||||
|
||||
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
|
||||
{
|
||||
this->SetSymbol(reelIndex, itemIndex, this->reels[reelIndex].model->items[itemIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameReelsCombinationGenerator::GenerateCombination()
|
||||
{
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
if (!this->reels[reelIndex].blocked)
|
||||
this->GenerateReel(reelIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameReelsCombinationGenerator::GenerateCombinationZero()
|
||||
{
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
if (!this->reels[reelIndex].blocked)
|
||||
{
|
||||
this->reels[reelIndex].model->GenerateReelZero();
|
||||
|
||||
for (int itemIndex = 0; itemIndex < this->numReelItems; itemIndex++)
|
||||
{
|
||||
this->SetSymbol(reelIndex, itemIndex, this->reels[reelIndex].model->items[itemIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
#include "..\Base\GkBaseReelMap.h"
|
||||
#include "GkGameReelModel.h"
|
||||
|
||||
struct GameReelsCombinationGeneratorReel
|
||||
{
|
||||
GkGameReelModel *model;
|
||||
bool blocked;
|
||||
};
|
||||
|
||||
class GKDLLCLASS GkGameReelsCombinationGenerator
|
||||
: public GkBaseReelMap
|
||||
{
|
||||
public:
|
||||
|
||||
GameReelsCombinationGeneratorReel *reels;
|
||||
|
||||
GkGameReelsCombinationGenerator(int numReels, int numReelItems);
|
||||
~GkGameReelsCombinationGenerator(void);
|
||||
|
||||
void SetReelModel(int reelIndex, GkGameReelModel *reelModel, bool blocked = false);
|
||||
|
||||
void GenerateReel(int reelIndex);
|
||||
void GenerateCombination();
|
||||
void GenerateCombinationZero();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameTimer.h"
|
||||
|
||||
#include "..\OSSpecific\GkOSUtils.h"
|
||||
|
||||
GkGameTimer::GkGameTimer(void)
|
||||
{
|
||||
this->counterFrequency = GkOSUtils::GetPerformanceCounterFrequency();
|
||||
|
||||
this->Reset();
|
||||
}
|
||||
|
||||
|
||||
GkGameTimer::~GkGameTimer(void)
|
||||
{
|
||||
}
|
||||
|
||||
void GkGameTimer::Reset()
|
||||
{
|
||||
this->counterTime = GkOSUtils::GetPerformanceCounter();
|
||||
|
||||
this->Tick();
|
||||
}
|
||||
|
||||
float GkGameTimer::Tick()
|
||||
{
|
||||
long long newCounterTime = GkOSUtils::GetPerformanceCounter();
|
||||
|
||||
this->tickTime = (float)((double)(newCounterTime - this->counterTime) / (double)this->counterFrequency);
|
||||
this->counterTime = newCounterTime;
|
||||
|
||||
return this->tickTime;
|
||||
}
|
||||
|
||||
long long GkGameTimer::GetSample()
|
||||
{
|
||||
return GkOSUtils::GetPerformanceCounter();
|
||||
}
|
||||
|
||||
float GkGameTimer::GetSampleTime(long long sample)
|
||||
{
|
||||
return (float)(((double)(GkGameTimer::GetSample() - sample)) / ((double)GkOSUtils::GetPerformanceCounterFrequency()));
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
class GKDLLCLASS GkGameTimer
|
||||
{
|
||||
public:
|
||||
long long counterTime, counterFrequency;
|
||||
|
||||
float tickTime;
|
||||
|
||||
GkGameTimer(void);
|
||||
~GkGameTimer(void);
|
||||
|
||||
void GkGameTimer::Reset();
|
||||
float GkGameTimer::Tick();
|
||||
|
||||
static long long GetSample();
|
||||
static float GetSampleTime(long long sample);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameWinningPotentialsAnalyzer.h"
|
||||
|
||||
GkGameWinningPotentialsAnalyzer::GkGameWinningPotentialsAnalyzer(GkGameWinningsModel *model)
|
||||
: GkGameWinningsAnalyzer(model)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
GkGameWinningPotentialsAnalyzer::~GkGameWinningPotentialsAnalyzer(void)
|
||||
{
|
||||
}
|
||||
|
||||
GameWinning GkGameWinningPotentialsAnalyzer::GetSymbolWinning(int symbolIndex, int lineIndex)
|
||||
{
|
||||
GameWinning reelItem;
|
||||
reelItem.symbolIndex = symbolIndex;
|
||||
reelItem.lineIndex = lineIndex;
|
||||
reelItem.numItems = 0;
|
||||
reelItem.itemsStart = 0;
|
||||
|
||||
GameWinning result = reelItem;
|
||||
|
||||
GameWinningSymbolModel *symbolModel = this->model->GetSymbolModel(symbolIndex);
|
||||
|
||||
bool interrupted = false;
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
int reelSymbolIndex = this->GetLineSymbol(reelIndex, lineIndex);
|
||||
GameWinningSymbolModel *reelSymbolModel = this->model->GetSymbolModel(reelSymbolIndex);
|
||||
|
||||
bool match = GkGameWinningsAnalyzer::SymbolsMatch(symbolIndex, reelSymbolIndex);
|
||||
if (match || !interrupted)
|
||||
{
|
||||
if (reelItem.numItems == 0)
|
||||
{
|
||||
reelItem.itemsStart = reelIndex;
|
||||
reelItem.symbolsFlags = GkGameWinningsModel::SymbolFlag_None;
|
||||
}
|
||||
|
||||
reelItem.numItems++;
|
||||
reelItem.symbolsFlags |= reelSymbolModel->flags;
|
||||
|
||||
if (reelItem.numItems > result.numItems)
|
||||
{
|
||||
result = reelItem;
|
||||
}
|
||||
|
||||
if (!match)
|
||||
interrupted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((symbolModel->flags & GkGameWinningsModel::SymbolFlag_AnyPlace) == 0)
|
||||
break;
|
||||
|
||||
reelItem.numItems = 0;
|
||||
|
||||
interrupted = false;
|
||||
}
|
||||
}
|
||||
|
||||
result.itemsEnd = result.itemsStart + result.numItems - 1;
|
||||
result.winningCoefficient = this->model->GetSymbolCoefficient(result.symbolIndex, result.numItems);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
GameWinning GkGameWinningPotentialsAnalyzer::GetScatterWinning(int symbolIndex)
|
||||
{
|
||||
GameWinning result = GkGameWinningsAnalyzer::GetScatterWinning(symbolIndex);
|
||||
|
||||
if (result.numItems < this->numReels - 1)
|
||||
{
|
||||
result.numItems++;
|
||||
result.winningCoefficient = this->model->GetSymbolCoefficient(result.symbolIndex, result.numItems);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GkGameWinningPotentialsAnalyzer::ReelBelongsToWinningAndSymbol(int reelIndex, int winningIndex)
|
||||
{
|
||||
if (!GkGameWinningsAnalyzer::ReelBelongsToWinning(reelIndex, winningIndex))
|
||||
return false;
|
||||
|
||||
return this->SymbolsMatch(this->winnings.win[winningIndex].symbolIndex, this->GetLineSymbol(reelIndex, this->winnings.win[winningIndex].lineIndex));
|
||||
}
|
||||
|
||||
bool GkGameWinningPotentialsAnalyzer::ContainsActualWin(int winningIndex)
|
||||
{
|
||||
if ((winningIndex < 0) || (winningIndex >= this->winnings.count))
|
||||
return false;
|
||||
|
||||
int actualSequenceLength = 0;
|
||||
for (int reelIndex = this->winnings.win[winningIndex].itemsStart; reelIndex <= this->winnings.win[winningIndex].itemsEnd; reelIndex++)
|
||||
{
|
||||
if (this->ReelBelongsToWinningAndSymbol(reelIndex, winningIndex))
|
||||
actualSequenceLength++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return this->model->GetSymbolCoefficient(this->winnings.win[winningIndex].symbolIndex, actualSequenceLength) != 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
#include "GkGameWinningsAnalyzer.h"
|
||||
|
||||
class GKDLLCLASS GkGameWinningPotentialsAnalyzer :
|
||||
public GkGameWinningsAnalyzer
|
||||
{
|
||||
public:
|
||||
GkGameWinningPotentialsAnalyzer(GkGameWinningsModel *model);
|
||||
virtual ~GkGameWinningPotentialsAnalyzer(void);
|
||||
|
||||
virtual GameWinning GetSymbolWinning(int symbolIndex, int lineIndex);
|
||||
virtual GameWinning GetScatterWinning(int symbolIndex);
|
||||
|
||||
bool ReelBelongsToWinningAndSymbol(int reelIndex, int winningIndex);
|
||||
bool ContainsActualWin(int winningIndex);
|
||||
};
|
||||
@@ -0,0 +1,487 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameWinningsAnalyzer.h"
|
||||
|
||||
#include "..\Utils\GkMaths.h"
|
||||
#include "..\OSSpecific\GkOSUtils.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
// Camparison of reel combinations - combinations may have
|
||||
// A. Exactly the same symbol wins as the compared - equal
|
||||
// B. The same symbol wins from the compared plus more - greater
|
||||
// C. Symbol wins from the compared, but not all or with less symbols - lesser
|
||||
// D. Not all the symbol wins from the compared plus more - different
|
||||
//
|
||||
// Rule set
|
||||
//
|
||||
// Definition: A symbol win is considered a winning of EXACTLY the same symbol and either on EXACTLY the same line OR BEING A SCATTER
|
||||
//
|
||||
// Signs of comparison:
|
||||
// 1.1 Contains all the symbol wins as the compared one
|
||||
// 1.2 Contains symbol wins, that are not present in the compared one
|
||||
//
|
||||
// In addition to that, there might be symbol win(s) with
|
||||
// 2.1 The same number of winning items
|
||||
// 2.2 Greater number of winning items
|
||||
// 2.3 Lesser number of winning items
|
||||
//
|
||||
// Result
|
||||
// Equal - 1.1 and not 1.2 and not 2.2. and not 2.3
|
||||
// Greater - 1.1. and (1.2 or 2.2) and not 2.3
|
||||
// Lesser - (not 1.1 or 2.3) and not 1.2 and not 2.2
|
||||
// Different - otherwise
|
||||
|
||||
|
||||
GkGameWinningsAnalyzer::GkGameWinningsAnalyzer(GkGameWinningsModel *model)
|
||||
: GkBaseReelMap(model->numReels, model->numReelItems)
|
||||
{
|
||||
this->model = model;
|
||||
|
||||
this->comparisonMode = GameWinningAnalyzerComparisonMode_FullComparison;
|
||||
|
||||
this->InitWinningData(&this->winnings);
|
||||
}
|
||||
|
||||
GkGameWinningsAnalyzer::~GkGameWinningsAnalyzer(void)
|
||||
{
|
||||
this->DisposeWinningData(&this->winnings);
|
||||
}
|
||||
|
||||
GameWinning GkGameWinningsAnalyzer::GetSymbolWinning(int symbolIndex, int lineIndex)
|
||||
{
|
||||
GameWinning reelItem;
|
||||
reelItem.symbolIndex = symbolIndex;
|
||||
reelItem.lineIndex = lineIndex;
|
||||
reelItem.numItems = 0;
|
||||
reelItem.itemsStart = 0;
|
||||
|
||||
GameWinning result = reelItem;
|
||||
|
||||
GameWinningSymbolModel *symbolModel = this->model->GetSymbolModel(symbolIndex);
|
||||
|
||||
bool sequenceValid = false;
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
int reelSymbolIndex = this->GetLineSymbol(reelIndex, lineIndex);
|
||||
GameWinningSymbolModel *reelSymbolModel = this->model->GetSymbolModel(reelSymbolIndex);
|
||||
|
||||
if (this->SymbolsMatch(symbolIndex, reelSymbolIndex))
|
||||
{
|
||||
if (symbolIndex == reelSymbolIndex)
|
||||
sequenceValid = true;
|
||||
|
||||
if (reelItem.numItems == 0)
|
||||
{
|
||||
reelItem.itemsStart = reelIndex;
|
||||
reelItem.symbolsFlags = GkGameWinningsModel::SymbolFlag_None;
|
||||
}
|
||||
|
||||
reelItem.numItems++;
|
||||
reelItem.symbolsFlags |= reelSymbolModel->flags;
|
||||
|
||||
if (sequenceValid && (reelItem.numItems > result.numItems))
|
||||
{
|
||||
result = reelItem;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((symbolModel->flags & GkGameWinningsModel::SymbolFlag_AnyPlace) == 0)
|
||||
break;
|
||||
|
||||
sequenceValid = false;
|
||||
reelItem.numItems = 0;
|
||||
}
|
||||
}
|
||||
|
||||
result.itemsEnd = result.itemsStart + result.numItems - 1;
|
||||
result.winningCoefficient = this->model->GetSymbolCoefficient(result.symbolIndex, result.numItems);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GkGameWinningsAnalyzer::SymbolsMatch(int symbolIndex, int testSymbolIndex)
|
||||
{
|
||||
GameWinningSymbolModel *symbolModel = this->model->GetSymbolModel(symbolIndex),
|
||||
*testSymbolModel = this->model->GetSymbolModel(testSymbolIndex);
|
||||
|
||||
return ((testSymbolIndex == symbolIndex) || ((testSymbolModel->flags & GkGameWinningsModel::SymbolFlag_Wild) != 0)) &&
|
||||
((testSymbolModel->flags & symbolModel->exclusionFlags) == 0);
|
||||
}
|
||||
|
||||
GameWinning GkGameWinningsAnalyzer::GetScatterWinning(int symbolIndex)
|
||||
{
|
||||
int scatterNumber = 0;
|
||||
for (int symbolsIndex = 0; symbolsIndex < symbolsIndex; symbolsIndex++)
|
||||
if (this->model->GetSymbolModel(symbolsIndex)->flags & GkGameWinningsModel::SymbolFlag_Scatter)
|
||||
scatterNumber++;
|
||||
|
||||
|
||||
GameWinning result;
|
||||
result.symbolIndex = symbolIndex;
|
||||
result.numItems = 0;
|
||||
result.lineIndex = this->model->numLines + scatterNumber;
|
||||
|
||||
if (scatterNumber >= this->model->numScatters)
|
||||
{
|
||||
result.symbolsFlags = GkGameWinningsModel::SymbolFlag_None;
|
||||
result.winningCoefficient = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
GameWinningSymbolModel *symbolModel = this->model->GetSymbolModel(symbolIndex);
|
||||
|
||||
for (int reelIndex = 0; reelIndex < this->numReels; reelIndex++)
|
||||
{
|
||||
this->model->lines[result.lineIndex].coordinates[reelIndex] = this->FindFirstSymbol(reelIndex, symbolIndex);
|
||||
if (this->model->lines[result.lineIndex].coordinates[reelIndex] != -1)
|
||||
{
|
||||
if (result.numItems == 0)
|
||||
result.itemsStart = reelIndex;
|
||||
|
||||
result.numItems++;
|
||||
result.itemsEnd = reelIndex;
|
||||
}
|
||||
}
|
||||
|
||||
result.symbolsFlags = symbolModel->flags;
|
||||
result.winningCoefficient = this->model->GetSymbolCoefficient(result.symbolIndex, result.numItems);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void GkGameWinningsAnalyzer::AnalyzeWinnings(GkBaseReelMap *reelMap)
|
||||
{
|
||||
if (reelMap != 0)
|
||||
this->SetItems(reelMap);
|
||||
|
||||
this->winnings.count = 0;
|
||||
|
||||
// Analyze line winnings
|
||||
for (int lineIndex = 0; lineIndex < this->model->numLines; lineIndex++)
|
||||
{
|
||||
if (this->model->lines[lineIndex].active)
|
||||
{
|
||||
GameWinning maxLineWin;
|
||||
maxLineWin.winningCoefficient = 0;
|
||||
|
||||
for (int symbolIndex = 0; symbolIndex < this->model->numSymbols; symbolIndex++)
|
||||
{
|
||||
if ((this->model->GetSymbolModel(symbolIndex)->flags & GkGameWinningsModel::SymbolFlag_Scatter) == 0)
|
||||
{
|
||||
GameWinning symbolWin = this->GetSymbolWinning(symbolIndex, lineIndex);
|
||||
if (symbolWin.winningCoefficient != 0)
|
||||
{
|
||||
if ((maxLineWin.winningCoefficient == 0) ||
|
||||
(this->model->CompareSymbolWinnning(symbolWin.symbolIndex, symbolWin.numItems, maxLineWin.symbolIndex, maxLineWin.numItems) > 0))
|
||||
{
|
||||
maxLineWin = symbolWin;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (maxLineWin.winningCoefficient != 0)
|
||||
{
|
||||
this->winnings.win[this->winnings.count++] = maxLineWin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Analyze scatters
|
||||
for (int symbolIndex = 0; symbolIndex < this->model->numSymbols; symbolIndex++)
|
||||
{
|
||||
if ((this->model->GetSymbolModel(symbolIndex)->flags & GkGameWinningsModel::SymbolFlag_Scatter) != 0)
|
||||
{
|
||||
GameWinning symbolWin = this->GetScatterWinning(symbolIndex);
|
||||
if (symbolWin.winningCoefficient != 0)
|
||||
{
|
||||
this->winnings.win[this->winnings.count++] = symbolWin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Calculate total winnigs, total flags and manage items with SymbolFlag_IgnoreWinning
|
||||
this->totalWinning = 0;
|
||||
this->totalFlags = GkGameWinningsModel::SymbolFlag_None;
|
||||
for (int i = 0; i < this->winnings.count; i++)
|
||||
{
|
||||
if (this->winnings.win[i].symbolsFlags & GkGameWinningsModel::SymbolFlag_IgnoreWinning)
|
||||
this->winnings.win[i].winningCoefficient = 0;
|
||||
|
||||
this->totalWinning += this->winnings.win[i].winningCoefficient;
|
||||
this->totalFlags |= this->winnings.win[i].symbolsFlags;
|
||||
}
|
||||
|
||||
this->SortWinnings();
|
||||
}
|
||||
|
||||
int GkGameWinningsAnalyzer::WinningOrder(int winningIndex1, int winningIndex2)
|
||||
{
|
||||
bool win1End = (this->model->GetSymbolModel(this->winnings.win[winningIndex1].symbolIndex)->flags & GkGameWinningsModel::SymbolFlag_AtEnd) != 0;
|
||||
bool win2End = (this->model->GetSymbolModel(this->winnings.win[winningIndex2].symbolIndex)->flags & GkGameWinningsModel::SymbolFlag_AtEnd) != 0;
|
||||
if (win1End && !win2End)
|
||||
return 1;
|
||||
|
||||
if (win2End && !win1End)
|
||||
return -1;
|
||||
|
||||
return GkMaths::Sign(this->winnings.win[winningIndex1].lineIndex - this->winnings.win[winningIndex2].lineIndex);
|
||||
}
|
||||
|
||||
int GkGameWinningsAnalyzer::CompareWinning(int winningIndex1, int winningIndex2)
|
||||
{
|
||||
return GkMaths::Sign(this->winnings.win[winningIndex1].winningCoefficient - this->winnings.win[winningIndex2].winningCoefficient);
|
||||
}
|
||||
|
||||
void GkGameWinningsAnalyzer::SortWinnings()
|
||||
{
|
||||
for (int i = 0; i < this->winnings.count; i++)
|
||||
{
|
||||
int leadingWin = i;
|
||||
for (int j = i + 1; j < this->winnings.count; j++)
|
||||
{
|
||||
if (this->WinningOrder(leadingWin, j) > 0)
|
||||
leadingWin = j;
|
||||
}
|
||||
|
||||
if (leadingWin != i)
|
||||
{
|
||||
GameWinning t = this->winnings.win[i];
|
||||
this->winnings.win[i] = this->winnings.win[leadingWin];
|
||||
this->winnings.win[leadingWin] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameWinningsAnalyzer::MultiplyWinnings(int factor)
|
||||
{
|
||||
for (int i = 0; i < this->winnings.count; i++)
|
||||
this->winnings.win[i].winningCoefficient *= factor;
|
||||
this->totalWinning *= factor;
|
||||
}
|
||||
|
||||
int GkGameWinningsAnalyzer::GetLineSymbol(int reelIndex, int lineIndex)
|
||||
{
|
||||
return this->GetSymbol(reelIndex, model->GetLineSymbolCoordinate(reelIndex, lineIndex));
|
||||
}
|
||||
|
||||
int GkGameWinningsAnalyzer::FindWinning(int symbolIndex, int minSymbols)
|
||||
{
|
||||
for (int i = 0; i < this->winnings.count; i++)
|
||||
if ((this->winnings.win[i].symbolIndex == symbolIndex) && (this->winnings.win[i].numItems >= minSymbols))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool GkGameWinningsAnalyzer::ReelBelongsToWinning(int reelIndex, int winningIndex)
|
||||
{
|
||||
if ((winningIndex < 0) || (winningIndex >= this->winnings.count))
|
||||
return false;
|
||||
|
||||
if (this->winnings.win[winningIndex].symbolsFlags & GkGameWinningsModel::SymbolFlag_Scatter)
|
||||
{
|
||||
if (this->model->lines[this->winnings.win[winningIndex].lineIndex].coordinates[reelIndex] == -1)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((reelIndex < this->winnings.win[winningIndex].itemsStart) || (reelIndex > this->winnings.win[winningIndex].itemsStart + this->winnings.win[winningIndex].numItems - 1))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GkGameWinningsAnalyzer::ReelBelongsToAnyWinning(int reelIndex)
|
||||
{
|
||||
for (int winningIndex = 0; winningIndex < this->winnings.count; winningIndex++)
|
||||
if (this->ReelBelongsToWinning(reelIndex, winningIndex))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GkGameWinningsAnalyzer::ReelItemBelongsToWinning(int reelIndex, int itemIndex, int winningIndex)
|
||||
{
|
||||
if (!this->ReelBelongsToWinning(reelIndex, winningIndex))
|
||||
return false;
|
||||
|
||||
return this->model->lines[this->winnings.win[winningIndex].lineIndex].coordinates[reelIndex] == itemIndex;
|
||||
}
|
||||
|
||||
bool GkGameWinningsAnalyzer::ReelItemBelongsToAnyWinning(int reelIndex, int itemIndex)
|
||||
{
|
||||
for (int winningIndex = 0; winningIndex < this->winnings.count; winningIndex++)
|
||||
if (this->ReelItemBelongsToWinning(reelIndex, itemIndex, winningIndex))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GkGameWinningsAnalyzer::InitWinningData(GameWinnings *data)
|
||||
{
|
||||
data->win = new GameWinning[this->model->numLines + this->model->numScatters];
|
||||
data->count = 0;
|
||||
}
|
||||
|
||||
void GkGameWinningsAnalyzer::DisposeWinningData(GameWinnings *data)
|
||||
{
|
||||
delete[] data->win;
|
||||
data->count = 0;
|
||||
}
|
||||
|
||||
void GkGameWinningsAnalyzer::SaveWinningData(GameWinnings *destination)
|
||||
{
|
||||
destination->count = this->winnings.count;
|
||||
GkOSUtils::CopyMem(destination->win, this->winnings.win, sizeof(GameWinning) * this->winnings.count);
|
||||
}
|
||||
|
||||
WinningDataComparisonResult GkGameWinningsAnalyzer::FindWinning(GameWinning *gameWinning)
|
||||
{
|
||||
for (int i = 0; i < this->winnings.count; i++)
|
||||
{
|
||||
GameWinning *testedWinning = &this->winnings.win[i];
|
||||
|
||||
if ((testedWinning->symbolIndex == gameWinning->symbolIndex) &&
|
||||
((testedWinning->lineIndex == gameWinning->lineIndex) ||
|
||||
((testedWinning->symbolsFlags & GkGameWinningsModel::SymbolFlag_Scatter) != 0) ||
|
||||
(this->comparisonMode == GameWinningAnalyzerComparisonMode_IgnoreLineMatching)))
|
||||
{
|
||||
if (testedWinning->numItems == gameWinning->numItems)
|
||||
return WinningDataComparisonResult_Equivalent;
|
||||
|
||||
if (testedWinning->numItems < gameWinning->numItems)
|
||||
return WinningDataComparisonResult_Lesser;
|
||||
|
||||
if (testedWinning->numItems > gameWinning->numItems)
|
||||
return WinningDataComparisonResult_Greater;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return WinningDataComparisonResult_Different;
|
||||
}
|
||||
|
||||
WinningDataComparisonResult GkGameWinningsAnalyzer::CompareWith(GameWinnings *data)
|
||||
{
|
||||
bool containsLesserWin = false,
|
||||
containsGreaterWin = false;
|
||||
|
||||
int numMatchingWins = 0;
|
||||
|
||||
for (int winIndex = 0; winIndex < data->count; winIndex++)
|
||||
{
|
||||
GameWinning *winning = &data->win[winIndex];
|
||||
|
||||
WinningDataComparisonResult camparedToData = this->FindWinning(winning);
|
||||
|
||||
if (camparedToData == WinningDataComparisonResult_Lesser)
|
||||
containsLesserWin = true;
|
||||
|
||||
if (camparedToData == WinningDataComparisonResult_Greater)
|
||||
containsGreaterWin = true;
|
||||
|
||||
if (camparedToData != WinningDataComparisonResult_Different)
|
||||
numMatchingWins++;
|
||||
}
|
||||
|
||||
bool containsAllDataWins = numMatchingWins == data->count,
|
||||
containsOtherWins = numMatchingWins < this->winnings.count;
|
||||
|
||||
if (containsAllDataWins && !containsOtherWins && !containsLesserWin && !containsGreaterWin)
|
||||
return WinningDataComparisonResult_Equivalent;
|
||||
|
||||
if (containsAllDataWins && (containsOtherWins || containsGreaterWin) && !containsLesserWin)
|
||||
return WinningDataComparisonResult_Greater;
|
||||
|
||||
if ((!containsAllDataWins || containsLesserWin) && !containsOtherWins && !containsGreaterWin)
|
||||
return WinningDataComparisonResult_Lesser;
|
||||
|
||||
|
||||
return WinningDataComparisonResult_Different;
|
||||
}
|
||||
|
||||
int GkGameWinningsAnalyzer::GetWinningReelsCount()
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
for (int reelIndex = 0; reelIndex < this->model->numReels; reelIndex++)
|
||||
if (this->ReelBelongsToAnyWinning(reelIndex))
|
||||
result++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int GkGameWinningsAnalyzer::GetWinningReelsCount(int winningIndex, int startReel, int numReels)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (numReels == -1)
|
||||
numReels = this->model->numReels;
|
||||
|
||||
for (int reelIndex = startReel; reelIndex < startReel + numReels; reelIndex++)
|
||||
if (this->ReelBelongsToWinning(reelIndex, winningIndex))
|
||||
result++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int GkGameWinningsAnalyzer::GetWinningItemReelIndex(int winningItemIndex)
|
||||
{
|
||||
for (int reelIndex = 0; reelIndex < this->model->numReels; reelIndex++)
|
||||
{
|
||||
if (this->ReelBelongsToAnyWinning(reelIndex))
|
||||
{
|
||||
if (winningItemIndex == 0)
|
||||
return reelIndex;
|
||||
|
||||
winningItemIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GkGameWinningsAnalyzer::GetWinningItemReelIndex(int winningItemIndex, int winningIndex)
|
||||
{
|
||||
for (int reelIndex = 0; reelIndex < this->model->numReels; reelIndex++)
|
||||
{
|
||||
if (this->ReelBelongsToWinning(reelIndex, winningIndex))
|
||||
{
|
||||
if (winningItemIndex == 0)
|
||||
return reelIndex;
|
||||
|
||||
winningItemIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GkGameWinningsAnalyzer::GetHighestWinning()
|
||||
{
|
||||
if (this->winnings.count == 0)
|
||||
return -1;
|
||||
|
||||
int result = 0;
|
||||
for (int winIndex = 1; winIndex < this->winnings.count; winIndex++)
|
||||
if (this->CompareWinning(winIndex, result) > 0)
|
||||
result = winIndex;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
#include "..\Base\GkBaseReelMap.h"
|
||||
#include "GkGameWinningsModel.h"
|
||||
|
||||
struct GameWinning
|
||||
{
|
||||
int lineIndex, symbolIndex,
|
||||
itemsStart, itemsEnd, numItems,
|
||||
winningCoefficient;
|
||||
|
||||
unsigned int symbolsFlags;
|
||||
};
|
||||
|
||||
struct GameWinnings
|
||||
{
|
||||
int count;
|
||||
GameWinning *win;
|
||||
};
|
||||
|
||||
enum WinningDataComparisonResult
|
||||
{
|
||||
WinningDataComparisonResult_Different,
|
||||
WinningDataComparisonResult_Equivalent,
|
||||
WinningDataComparisonResult_Greater,
|
||||
WinningDataComparisonResult_Lesser
|
||||
};
|
||||
|
||||
enum GameWinningAnalyzerComparisonMode
|
||||
{
|
||||
GameWinningAnalyzerComparisonMode_FullComparison,
|
||||
GameWinningAnalyzerComparisonMode_IgnoreLineMatching,
|
||||
};
|
||||
|
||||
class GKDLLCLASS GkGameWinningsAnalyzer
|
||||
: public GkBaseReelMap
|
||||
{
|
||||
public:
|
||||
GkGameWinningsModel *model;
|
||||
|
||||
GameWinnings winnings;
|
||||
int totalWinning, totalFlags;
|
||||
|
||||
GameWinningAnalyzerComparisonMode comparisonMode;
|
||||
|
||||
GkGameWinningsAnalyzer(GkGameWinningsModel *model);
|
||||
virtual ~GkGameWinningsAnalyzer(void);
|
||||
|
||||
virtual GameWinning GetSymbolWinning(int symbolIndex, int lineIndex);
|
||||
virtual GameWinning GetScatterWinning(int symbolIndex);
|
||||
virtual void AnalyzeWinnings(GkBaseReelMap *reelMap = 0);
|
||||
virtual bool SymbolsMatch(int symbol1Index, int testSymbolIndex);
|
||||
virtual int WinningOrder(int winningIndex1, int winningIndex2);
|
||||
virtual int CompareWinning(int winningIndex1, int winningIndex2);
|
||||
|
||||
void SortWinnings();
|
||||
void MultiplyWinnings(int factor);
|
||||
int GetLineSymbol(int reelIndex, int lineIndex);
|
||||
|
||||
int FindWinning(int symbolIndex, int minSymbols = 0);
|
||||
bool ReelBelongsToWinning(int reelIndex, int winningIndex);
|
||||
bool ReelBelongsToAnyWinning(int reelIndex);
|
||||
bool ReelItemBelongsToWinning(int reelIndex, int itemIndex, int winningIndex);
|
||||
bool ReelItemBelongsToAnyWinning(int reelIndex, int itemIndex);
|
||||
int GetWinningReelsCount();
|
||||
int GetWinningReelsCount(int winningIndex, int startReel = 0, int numReels = -1);
|
||||
int GetWinningItemReelIndex(int winningItemIndex);
|
||||
int GetWinningItemReelIndex(int winningItemIndex, int winningIndex);
|
||||
int GetHighestWinning();
|
||||
|
||||
void InitWinningData(GameWinnings *data);
|
||||
void DisposeWinningData(GameWinnings *data);
|
||||
void SaveWinningData(GameWinnings *destination);
|
||||
bool IsLessOrEqualThan(GameWinnings *data);
|
||||
WinningDataComparisonResult FindWinning(GameWinning *gameWinning);
|
||||
WinningDataComparisonResult CompareWith(GameWinnings *data);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameWinningsModel.h"
|
||||
|
||||
#include "..\OSSpecific\GkOSUtils.h"
|
||||
#include "..\Utils\GkMaths.h"
|
||||
|
||||
GkGameWinningsModel::GkGameWinningsModel(int numReels, int numReelItems, int numLines, int numSymbols, int numScatters, int numChannels)
|
||||
{
|
||||
this->numReels = numReels;
|
||||
this->numReelItems = numReelItems;
|
||||
this->numLines = numLines;
|
||||
this->numSymbols = numSymbols;
|
||||
this->numScatters = numScatters;
|
||||
this->numChannels = numChannels;
|
||||
this->selectedChannel = 0;
|
||||
|
||||
this->lines = new GameWinningLineModel[this->numLines + numScatters];
|
||||
for (int i = 0; i < this->numLines + this->numScatters; i++)
|
||||
{
|
||||
this->lines[i].active = true;
|
||||
this->lines[i].coordinates = new int[this->numReels];
|
||||
GkOSUtils::ZeroMem(this->lines[i].coordinates, this->numReels * sizeof(int));
|
||||
}
|
||||
|
||||
this->symbols = new GameWinningSymbolModel*[this->numChannels];
|
||||
for (int channel = 0; channel < this->numChannels; channel++)
|
||||
{
|
||||
this->symbols[channel] = new GameWinningSymbolModel[this->numSymbols];
|
||||
for (int symbol = 0; symbol < this->numSymbols; symbol++)
|
||||
{
|
||||
this->symbols[channel][symbol].coefficients = new int[this->numReels];
|
||||
GkOSUtils::ZeroMem(this->symbols[channel][symbol].coefficients, this->numReels * sizeof(int));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GkGameWinningsModel::~GkGameWinningsModel(void)
|
||||
{
|
||||
for (int channel = 0; channel < this->numChannels; channel++)
|
||||
{
|
||||
for (int symbol = 0; symbol < this->numSymbols; symbol++)
|
||||
{
|
||||
delete[] this->symbols[channel][symbol].coefficients;
|
||||
}
|
||||
delete[] this->symbols[channel];
|
||||
}
|
||||
delete[] this->symbols;
|
||||
|
||||
for (int i = 0; i < this->numLines + this->numScatters; i++)
|
||||
{
|
||||
delete[] this->lines[i].coordinates;
|
||||
}
|
||||
delete[] this->lines;
|
||||
}
|
||||
|
||||
void GkGameWinningsModel::SetupLine(int lineIndex, ...)
|
||||
{
|
||||
//GkOSUtils::CopyMem(this->lines[lineIndex], (void*)lineCoordinates, this->numReels * sizeof(int));
|
||||
|
||||
va_list lineCoordinates;
|
||||
va_start(lineCoordinates, lineIndex);
|
||||
for(int i = 0; i < this->numReels; ++i )
|
||||
this->lines[lineIndex].coordinates[i] = va_arg(lineCoordinates, int);
|
||||
va_end(lineCoordinates);
|
||||
}
|
||||
|
||||
void GkGameWinningsModel::SetupSymbol(int symbolIndex, int channelIndex, unsigned int symbolFlags, unsigned int symbolExclusionFlags, ...)
|
||||
{
|
||||
va_list winCoefficients;
|
||||
va_start(winCoefficients, symbolExclusionFlags);
|
||||
for(int i = 0; i < this->numReels; ++i )
|
||||
{
|
||||
this->symbols[channelIndex][symbolIndex].coefficients[i] = va_arg(winCoefficients, int);
|
||||
}
|
||||
va_end(winCoefficients);
|
||||
|
||||
this->symbols[channelIndex][symbolIndex].flags = symbolFlags;
|
||||
this->symbols[channelIndex][symbolIndex].exclusionFlags = symbolExclusionFlags;
|
||||
}
|
||||
|
||||
int GkGameWinningsModel::GetLineSymbolCoordinate(int reelIndex, int lineIndex)
|
||||
{
|
||||
return this->lines[lineIndex].coordinates[reelIndex];
|
||||
}
|
||||
|
||||
GameWinningSymbolModel *GkGameWinningsModel::GetSymbolModel(int symbol)
|
||||
{
|
||||
return &this->symbols[this->selectedChannel][symbol];
|
||||
}
|
||||
|
||||
int GkGameWinningsModel::GetSymbolCoefficient(int symbol, int symbolCount)
|
||||
{
|
||||
if (symbolCount == 0)
|
||||
return 0;
|
||||
|
||||
return this->symbols[this->selectedChannel][symbol].coefficients[symbolCount - 1];
|
||||
}
|
||||
|
||||
int GkGameWinningsModel::CompareSymbolWinnning(int symbol1, int symbol1Count, int symbol2, int symbol2Count)
|
||||
{
|
||||
int coefficientDelta = this->GetSymbolCoefficient(symbol1, symbol1Count) - this->GetSymbolCoefficient(symbol2, symbol2Count);
|
||||
if (coefficientDelta != 0)
|
||||
return GkMaths::Sign(coefficientDelta);
|
||||
|
||||
for (int numSymbols = GkMaths::Max(symbol1Count, symbol2Count); numSymbols <= this->numReels; numSymbols++)
|
||||
{
|
||||
coefficientDelta = this->GetSymbolCoefficient(symbol1, numSymbols) - this->GetSymbolCoefficient(symbol2, numSymbols);
|
||||
if (coefficientDelta != 0)
|
||||
return GkMaths::Sign(coefficientDelta);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\GkDefinitions.h"
|
||||
|
||||
struct GameWinningLineModel
|
||||
{
|
||||
bool active;
|
||||
int *coordinates;
|
||||
};
|
||||
|
||||
struct GameWinningSymbolModel
|
||||
{
|
||||
unsigned int flags, exclusionFlags;
|
||||
int *coefficients;
|
||||
};
|
||||
|
||||
class GKDLLCLASS GkGameWinningsModel
|
||||
{
|
||||
public:
|
||||
static const unsigned int SymbolFlag_None = 0,
|
||||
SymbolFlag_Default = 1 << 0,
|
||||
SymbolFlag_Wild = 1 << 1,
|
||||
SymbolFlag_AnyPlace = 1 << 2, // Line sequence can start from anywhere, not only from the beginning of a line
|
||||
SymbolFlag_IgnoreWinning = 1 << 3,
|
||||
SymbolFlag_AtEnd = 1 << 4,
|
||||
SymbolFlag_Scatter = 1 << 5, // If a symbol is Scatter, it has a line index of numLines and above, and its line's coordinates are set correspondingly on each CalculateWinnings()
|
||||
SymbolFlag_Custom = 1 << 8; // For user - defined flags. User_Defined_Flag = SymbolFlag_Custom << UserFlag_Index
|
||||
|
||||
int numReels, numReelItems, numChannels, selectedChannel;
|
||||
|
||||
int numLines;
|
||||
GameWinningLineModel *lines;
|
||||
|
||||
int numSymbols, numScatters;
|
||||
GameWinningSymbolModel **symbols;
|
||||
|
||||
GkGameWinningsModel(int numReels, int numReelItems, int numLines, int numSymbols, int numScatters = 0, int numChannels = 1);
|
||||
~GkGameWinningsModel(void);
|
||||
|
||||
void SetupLine(int lineIndex, ...);
|
||||
void SetupSymbol(int symbolIndex, int channelIndex, unsigned int symbolFlags, unsigned int symbolExclusionFlags, ...);
|
||||
|
||||
int GetLineSymbolCoordinate(int reelIndex, int lineIndex);
|
||||
GameWinningSymbolModel *GetSymbolModel(int symbol);
|
||||
int GetSymbolCoefficient(int symbol, int symbolCount);
|
||||
int CompareSymbolWinnning(int symbol1, int symbol1Count, int symbol2, int symbol2Count);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameReelRandomModel.h"
|
||||
|
||||
#include "..\..\Utils\GkMaths.h"
|
||||
|
||||
|
||||
GkGameReelRandomModel::GkGameReelRandomModel(int numItems, int numSymbols)
|
||||
:GkGameReelModel(numItems)
|
||||
{
|
||||
this->numSymbols = numSymbols;
|
||||
this->symbols = new GameReelRandomModelSymbol[numSymbols];
|
||||
|
||||
for (int i = 0; i < numSymbols; i++)
|
||||
this->SetupSymbol(i, i);
|
||||
}
|
||||
|
||||
|
||||
GkGameReelRandomModel::~GkGameReelRandomModel(void)
|
||||
{
|
||||
delete[] this->symbols;
|
||||
}
|
||||
|
||||
|
||||
void GkGameReelRandomModel::SetupSymbol(int symbolIndex, int symbolValue, int hitProbability, int maxHits)
|
||||
{
|
||||
this->symbols[symbolIndex].value = symbolValue;
|
||||
this->symbols[symbolIndex].hitProbability = hitProbability;
|
||||
this->symbols[symbolIndex].maxHits = maxHits;
|
||||
|
||||
this->overallProbability = 0;
|
||||
for (int i = 0; i < this->numSymbols; i++)
|
||||
this->overallProbability += this->symbols[i].hitProbability;
|
||||
}
|
||||
|
||||
bool GkGameReelRandomModel::ReplaceReelSymbol(int itemIndex, int symbolIndex, bool forceReplace)
|
||||
{
|
||||
bool autoGenerate = symbolIndex == -1;
|
||||
|
||||
do
|
||||
{
|
||||
if (autoGenerate)
|
||||
{
|
||||
symbolIndex = this->GetSymbolIndex();
|
||||
}
|
||||
|
||||
if ((this->symbols[symbolIndex].maxHits == GkGameReelRandomModel::UnlimitedHits) || (this->symbols[symbolIndex].occurances < this->symbols[symbolIndex].maxHits) || forceReplace)
|
||||
{
|
||||
this->symbols[this->items[itemIndex]].occurances--;
|
||||
this->items[itemIndex] = symbolIndex;
|
||||
this->symbols[symbolIndex].occurances++;
|
||||
return true;
|
||||
}
|
||||
} while (autoGenerate);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int GkGameReelRandomModel::GetSymbolIndex()
|
||||
{
|
||||
int p = GkMaths::Random(this->overallProbability);
|
||||
|
||||
int s = 0;
|
||||
for (int i = 0; i < this->numSymbols; i++)
|
||||
{
|
||||
s += this->symbols[i].hitProbability;
|
||||
if (p < s)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GkGameReelRandomModel::GetSymbol()
|
||||
{
|
||||
int symbolIndex = this->GetSymbolIndex();
|
||||
if (symbolIndex == -1)
|
||||
return -1;
|
||||
else
|
||||
return this->symbols[symbolIndex].value;
|
||||
}
|
||||
|
||||
void GkGameReelRandomModel::GenerateReel()
|
||||
{
|
||||
for (int symbolIndex = 0; symbolIndex < this->numSymbols; symbolIndex++)
|
||||
this->symbols[symbolIndex].occurances = 0;
|
||||
|
||||
|
||||
for (int itemIndex = 0; itemIndex < this->numItems; itemIndex++)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
int symbolIndex = this->GetSymbolIndex();
|
||||
if ((this->symbols[symbolIndex].maxHits == GkGameReelRandomModel::UnlimitedHits) || (this->symbols[symbolIndex].occurances < this->symbols[symbolIndex].maxHits))
|
||||
{
|
||||
this->items[itemIndex] = this->symbols[symbolIndex].value;
|
||||
this->symbols[symbolIndex].occurances++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameReelRandomModel::GenerateReelZero()
|
||||
{
|
||||
this->GenerateReel();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameReelModel.h"
|
||||
|
||||
struct GameReelRandomModelSymbol
|
||||
{
|
||||
int value, hitProbability, maxHits,
|
||||
occurances;
|
||||
};
|
||||
|
||||
class GKDLLCLASS GkGameReelRandomModel :
|
||||
public GkGameReelModel
|
||||
{
|
||||
public:
|
||||
static const int UnlimitedHits = -1;
|
||||
|
||||
int numSymbols;
|
||||
GameReelRandomModelSymbol *symbols;
|
||||
|
||||
int overallProbability;
|
||||
|
||||
GkGameReelRandomModel(int numItems, int numSymbols);
|
||||
~GkGameReelRandomModel(void);
|
||||
|
||||
void SetupSymbol(int symbolIndex, int symbolValue, int hitProbability = 1, int maxHits = GkGameReelRandomModel::UnlimitedHits);
|
||||
bool ReplaceReelSymbol(int itemIndex, int symbolIndex, bool forceReplace);
|
||||
int GetSymbolIndex();
|
||||
|
||||
int GetSymbol();
|
||||
void GenerateReel();
|
||||
void GenerateReelZero();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// GambleKit Copyright (C) 2014 Ivan Donev
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// contact: gamblekit@gmail.com
|
||||
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "GkGameReelStripModel.h"
|
||||
|
||||
#include "..\..\OSSpecific\GkOSUtils.h"
|
||||
#include "..\..\Utils\GkMaths.h"
|
||||
|
||||
GkGameReelStripModel::GkGameReelStripModel(int numItems, int numSymbols, ...)
|
||||
: GkGameReelModel(numItems)
|
||||
{
|
||||
this->numSymbols = numSymbols;
|
||||
this->symbolStrip = new int[this->numSymbols];
|
||||
|
||||
int *parameters = (int*)((int)&numSymbols + 4);
|
||||
for (int i = 0; i < this->numSymbols; i++)
|
||||
this->symbolStrip[i] = parameters[i];
|
||||
|
||||
this->stripPosition = GkMaths::Random(this->numSymbols);
|
||||
}
|
||||
|
||||
|
||||
GkGameReelStripModel::~GkGameReelStripModel(void)
|
||||
{
|
||||
delete[] this->symbolStrip;
|
||||
}
|
||||
|
||||
int GkGameReelStripModel::GetSymbol()
|
||||
{
|
||||
this->stripPosition = (this->stripPosition + 1) % this->numSymbols;
|
||||
return this->symbolStrip[this->stripPosition];
|
||||
}
|
||||
|
||||
void GkGameReelStripModel::GenerateReel()
|
||||
{
|
||||
this->stripPosition = GkMaths::Random(this->numSymbols);
|
||||
|
||||
for (int itemIndex = 0; itemIndex < this->numItems; itemIndex++)
|
||||
{
|
||||
this->items[itemIndex] = this->GetSymbol();
|
||||
}
|
||||
}
|
||||
|
||||
void GkGameReelStripModel::GenerateReelZero()
|
||||
{
|
||||
this->stripPosition = this->numSymbols - this->numItems / 2;
|
||||
|
||||
for (int itemIndex = 0; itemIndex < this->numItems; itemIndex++)
|
||||
{
|
||||
this->items[itemIndex] = this->GetSymbol();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\..\GkDefinitions.h"
|
||||
|
||||
#include "..\GkGameReelModel.h"
|
||||
|
||||
class GKDLLCLASS GkGameReelStripModel :
|
||||
public GkGameReelModel
|
||||
{
|
||||
public:
|
||||
int numSymbols;
|
||||
int *symbolStrip;
|
||||
int stripPosition;
|
||||
|
||||
GkGameReelStripModel(int numItems, int numSymbols, ...);
|
||||
~GkGameReelStripModel(void);
|
||||
|
||||
int GetSymbol();
|
||||
void GenerateReel();
|
||||
void GenerateReelZero();
|
||||
};
|
||||
Reference in new issue
Block a user