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:
Amrit Panesar committed 2015-05-06 10:18:39 -07:00
1 parent 40ac78074b
commit 39ee821f54
174 files changed
+13356 -80

No files matched your search

@@ -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;
}
}
}
@@ -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);
};
@@ -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);
};
@@ -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);
};