This commit is contained in:
wagic.the.homebrew
2008-11-02 09:50:16 +00:00
commit d45e3b101b
726 changed files with 179125 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _IAPLAYER_H
#define _IAPLAYER_H
#include "Player.h"
#define INFO_NBCREATURES 0
#define INFO_CREATURESPOWER 1
class AIStats;
class AIPlayer: public Player{
protected:
MTGCardInstance * nextCardToPlay;
ManaCost * potentialMana;
void tapLandsForMana(ManaCost * potentialMana, ManaCost * cost);
int checkInterrupt();
int combatDamages();
int chooseAttackers();
int chooseBlockers();
int effectBadOrGood(MTGCardInstance * card);
int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0);
AIStats * getStats();
public:
virtual int displayStack(){return 0;}
AIStats * stats;
ManaCost * getPotentialMana();
AIPlayer(MTGPlayerCards * _deck, char * deckFile);
virtual ~AIPlayer();
virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
virtual int chooseTarget(TargetChooser * tc = NULL);
virtual int Act();
int isAI(){return 1;};
};
class AIPlayerBaka: public AIPlayer{
protected:
int oldGamePhase;
int timer;
MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type);
public:
AIPlayerBaka(MTGPlayerCards * _deck, char * deckFile);
virtual int Act();
void initTimer();
};
class AIPlayerFactory{
public:
AIPlayer * createAIPlayer(MTGAllCards * collection, MTGPlayerCards * oponents_deck);
};
#endif
+42
View File
@@ -0,0 +1,42 @@
#ifndef _AISTATS_H_
#define _AISTATS_H_
#define STATS_PLAYER_MULTIPLIER 15
#define STATS_CREATURE_MULTIPLIER 10
#define STATS_AURA_MULTIPLIER 9
#include <list>
#include <string>
using std::list;
using std::string;
class Player;
class MTGCardInstance;
class MTGCard;
class Damage;
class AIStat{
public:
int source; //MTGId of the card
int value;
int occurences;
bool direct;
AIStat(int _source, int _value, int _occurences, bool _direct):source(_source), value(_value),occurences(_occurences),direct(_direct){};
};
class AIStats{
public:
Player * player;
string filename;
list<AIStat *> stats;
AIStats(Player * _player, char * filename);
~AIStats();
void updateStats();
void load(char * filename);
void save();
AIStat * find(MTGCard * card);
bool isInTop(MTGCardInstance * card,int max, bool tooSmallCountsForTrue = true );
void updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, float multiplier = 1.0);
};
#endif
+48
View File
@@ -0,0 +1,48 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _ACTIONELEMENT_H_
#define _ACTIONELEMENT_H_
#include <JGui.h>
#define INACTIVE 0
#define ACTION_REQUESTED 1
#define ACTIVE 2
class MTGCardInstance;
class Targetable;
class TargetChooser;
class ActionElement: public JGuiObject{
protected:
int activeState;
public:
TargetChooser * tc;
int currentPhase;
int newPhase;
int modal;
int waitingForAnswer;
void RenderMessageBackground(float y0, int height);
int getActivity();
virtual void Update(float dt){};
virtual void Render(){};
virtual int testDestroy(){return 0;};
virtual int destroy(){return 0;};
virtual void CheckUserInput(float dt){};
ActionElement(int id);
virtual int isReactingToTargetClick(Targetable * card);
virtual int reactToTargetClick(Targetable * card);
virtual int isReactingToClick(MTGCardInstance * card){return 0;};
virtual int reactToClick(MTGCardInstance * card){return 0;};
virtual const char * getMenuText(){return "Ability";};
};
#endif
+39
View File
@@ -0,0 +1,39 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _ACTIONLAYER_H_
#define _ACTIONLAYER_H_
#include "GuiLayers.h"
#include "ActionElement.h"
#include "SimpleMenu.h"
class GuiLayer;
class Targetable;
class ActionLayer: public GuiLayer, public JGuiListener{
public:
Targetable * menuObject;
SimpleMenu * abilitiesMenu;
virtual void Render();
virtual void Update(float dt);
int unstopableRenderInProgress();
void CheckUserInput(float dt);
ActionLayer(int id, GameObserver* _game):GuiLayer(id, _game){ menuObject = NULL; abilitiesMenu = NULL;};
int isWaitingForAnswer();
int isReactingToTargetClick(Targetable * card);
int reactToTargetClick(Targetable * card);
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int isModal();
void setMenuObject(Targetable * object);
void ButtonPressed(int controllerid, int controlid);
TargetChooser * getCurrentTargetChooser();
};
#endif
+151
View File
@@ -0,0 +1,151 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _SPELLSTACK_H_
#define _SPELLSTACK_H_
#define MAX_SPELL_TARGETS 10
#define ACTION_SPELL 10
#define ACTION_DAMAGE 11
#define ACTION_DAMAGES 12
#define ACTION_NEXTGAMEPHASE 13
#define ACTION_DRAW 14
#define ACTION_PUTINGRAVEYARD 15
#define ACTION_ABILITY 16
#define NOT_RESOLVED -2
#define RESOLVED_OK 1
#define RESOLVED_NOK -1
#include "../include/PlayGuiObject.h"
#include "GuiLayers.h"
#include "../include/TargetsList.h"
#include "../include/Targetable.h"
class GuiLayer;
class PlayGuiObject;
class MTGCardInstance;
class GameObserver;
class Player;
class Damageable;
class MTGAbility;
class Targetable;
class DamageStack;
class ManaCost;
#define ACTIONSTACK_STANDARD 0
#define ACTIONSTACK_TARGET 1
class Interruptible: public PlayGuiObject, public Targetable{
public:
int state, display;
MTGCardInstance * source;
virtual void Entering(){mHasFocus = true;};
virtual bool Leaving(u32 key){mHasFocus = false;return true;};
virtual bool ButtonPressed(){return true;};
virtual int resolve(){return 0;};
virtual void Render(){};
int typeAsTarget(){return TARGET_STACKACTION;};
Interruptible(int id,bool hasFocus = false):PlayGuiObject(id,40,x,y,hasFocus){state=NOT_RESOLVED;display=0;source=NULL;};
};
class NextGamePhase: public Interruptible {
public:
int resolve();
void Render();
NextGamePhase(int id);
};
class Spell: public Interruptible, public TargetsList {
protected:
public:
ManaCost * cost;
Spell(MTGCardInstance* _source);
Spell(int id, MTGCardInstance* _source, Targetable * _targets[], int _nbtargets, ManaCost * _cost);
~Spell();
int resolve();
void Render();
};
class StackAbility: public Interruptible {
public:
MTGAbility * ability;
int resolve();
void Render();
StackAbility(int id, MTGAbility * _ability);
};
class PutInGraveyard: public Interruptible {
public:
MTGCardInstance * card;
int removeFromGame;
int resolve();
void Render();
PutInGraveyard(int id, MTGCardInstance * _card);
};
class DrawAction: public Interruptible {
public:
int nbcards;
Player * player;
int resolve();
void Render();
DrawAction(int id, Player * _player, int _nbcards);
};
class ActionStack :public GuiLayer{
protected:
int interruptDecision[2];
int timer;
int currentState;
int mode;
int checked;
void unpackDamageStacks();
void unpackDamageStack(DamageStack * ds);
void repackDamageStacks();
public:
int setIsInterrupting(Player * player);
int count( int type = 0 , int state = 0 , int display = -1);
Interruptible * getPrevious(Interruptible * next, int type = 0, int state = 0 , int display = -1);
int getPreviousIndex(Interruptible * next, int type = 0, int state = 0 , int display = -1);
Interruptible * getNext(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
int getNextIndex(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
void Fizzle(Interruptible * action);
Interruptible * _(int id);
void cancelInterruptOffer(int cancelMode = 1);
void endOfInterruption();
Interruptible * getLatest(int state);
Player * askIfWishesToInterrupt;
int garbageCollect();
int addAction(Interruptible * interruptible);
int addSpell(MTGCardInstance* card, Targetable * targets[], int nbtargets, ManaCost * mana);
int AddNextGamePhase();
int addPutInGraveyard(MTGCardInstance * card);
int addDraw(Player * player, int nbcards = 1);
int addDamage(MTGCardInstance * _source, Damageable * target, int _damage);
int addAbility(MTGAbility * ability);
void Update(float dt);
void CheckUserInput(float dt);
virtual void Render();
ActionStack(int id, GameObserver* _game);
int resolve();
int CombatDamages();
int CombatDamages(int firststrike);
int has(Interruptible * action);
};
#endif
File diff suppressed because it is too large Load Diff
+53
View File
@@ -0,0 +1,53 @@
#ifndef _BLOCKER_H_
#define _BLOCKER_H_
#define MAX_BLOCKERS 64 // Currently needs to be equal to MAX_GUI_OBJECTS in JGE/JGui.h.
#include "MTGAbility.h"
class ManaCost;
class GameObserver;
class MTGAbility;
class Blocker : public MTGAbility {
protected:
ManaCost * manaCost;
int currentPhase;
void init(ManaCost * _cost);
public:
virtual ManaCost * untapManaCost(){return manaCost;};
virtual int unblock(){return 1;};
Blocker(int id, MTGCardInstance * card, ManaCost * _cost);
Blocker(int id, MTGCardInstance * card);
Blocker(int id, MTGCardInstance * card, MTGCardInstance *_target, ManaCost * _cost);
~Blocker();
virtual void Update(float dt);
virtual int destroy();
};
class Blockers {
protected:
int cursor;
int blockers[MAX_BLOCKERS];
GameObserver * game;
public:
Blockers();
~Blockers();
int Add (Blocker * ability);
int Remove (Blocker * ability);
int init();
Blocker * next();
int rewind();
int isEmpty();
};
#include "ManaCost.h"
#include "GameObserver.h"
#endif
+22
View File
@@ -0,0 +1,22 @@
/*
A Filter/Mask system for Card Instances to find cards matching specific settings such as color, type, etc...
*/
#ifndef _CARDDESCRIPTOR_H_
#define _CARDDESCRIPTOR_H_
#include "MTGCardInstance.h"
#include "MTGGameZones.h"
class CardDescriptor: public MTGCardInstance{
protected:
public:
int init();
CardDescriptor();
MTGCardInstance * match(MTGCardInstance * card);
MTGCardInstance * match(MTGGameZone * zone);
MTGCardInstance * nextmatch(MTGGameZone * zone, MTGCardInstance * previous);
};
#endif
+32
View File
@@ -0,0 +1,32 @@
#ifndef _CARD_DISPLAY_H_
#define _CARD_DISPLAY_H_
#include "../include/PlayGuiObjectController.h"
class TargetChooser;
class MTGGameZone;
class MTGCardInstance;
class CardDisplay:public PlayGuiObjectController{
public:
int x, y , start_item, nb_displayed_items;
TargetChooser * tc;
JGuiListener * listener;
CardDisplay();
CardDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, TargetChooser * _tc = NULL, int _nb_displayed_items = 7 );
void AddCard(MTGCardInstance * _card);
void rotateLeft();
void rotateRight();
void CheckUserInput(float dt);
void Render();
void init(MTGGameZone * zone);
};
class DefaultTargetDisplay:CardDisplay{
public:
DefaultTargetDisplay(int id, GameObserver* _game, int _x, int _y, JGuiListener * _listener, int _nb_displayed_items );
~DefaultTargetDisplay();
};
#endif
+30
View File
@@ -0,0 +1,30 @@
/* Graphical representation of a Card Instance, used in game */
#ifndef _CARD_GUI_H_
#define _CARD_GUI_H_
#include <JGui.h>
#include "PlayGuiObject.h"
#include "MTGCardInstance.h"
#include <hge/hgeparticle.h>
class MTGCardInstance;
class PlayGuiObject;
class CardGui: public PlayGuiObject{
protected:
hgeParticleSystem * mParticleSys;
int alpha;
public:
MTGCardInstance * card;
CardGui(int id, MTGCardInstance * _card, float desiredHeight, float _x=0, float _y=0, bool hasFocus = false);
virtual void Render();
virtual void Update(float dt);
void RenderBig(float x=-1, float y = -1);
static void alternateRender(MTGCard * card, JLBFont * mFont, JQuad ** manaIcons, float x, float y, float rotation= 0, float scale=1);
~CardGui();
};
#endif
+14
View File
@@ -0,0 +1,14 @@
#ifndef _CONSTRAINTRESOLVER_H_
#define _CONSTRAINTRESOLVER_H_
#include "GameObserver.h"
#include "MTGCardInstance.h"
class ConstraintResolver {
protected:
public:
static int untap(GameObserver * game, MTGCardInstance * card);
};
#endif
+43
View File
@@ -0,0 +1,43 @@
#ifndef _COUNTERS_H_
#define _COUNTERS_H_
#include <string>
using std::string;
class MTGCardInstance;
/* One family of counters. Ex : +1/+1 */
class Counter{
public :
string name;
int nb;
int power, toughness;
MTGCardInstance * target;
Counter(MTGCardInstance * _target, int _power, int _toughness);
Counter(MTGCardInstance * _target, const char * _name,int _power = 0 , int _toughness = 0 );
int init(MTGCardInstance * _target,const char * _name, int _power, int _toughness);
bool sameAs(const char * _name, int _power, int _toughness);
bool cancels(int _power, int _toughness);
int added();
int removed();
};
/* Various families of counters attached to an instance of a card */
class Counters{
public:
int mCount;
Counter * counters[10];
MTGCardInstance * target;
Counters(MTGCardInstance * _target);
~Counters();
int addCounter(const char * _name,int _power = 0, int _toughness = 0);
int addCounter(int _power, int _toughness);
int removeCounter(const char * _name,int _power = 0, int _toughness = 0);
int removeCounter(int _power, int _toughness);
Counter * hasCounter(const char * _name,int _power = 0, int _toughness = 0);
Counter * hasCounter(int _power, int _toughness);
Counter * getNext(Counter * previous = NULL);
};
#endif
+58
View File
@@ -0,0 +1,58 @@
#ifndef _DAMAGE_H_
#define _DAMAGE_H_
#include <JGui.h>
#include "GuiLayers.h"
#include "ActionStack.h"
class GuiLayer;
class JGuiObject;
class MTGCardInstance;
class GameObserver;
#define DAMAGEABLE_MTGCARDINSTANCE 0
#define DAMAGEABLE_PLAYER 1
class Damageable {
protected:
public:
int life;
int type_as_damageable;
Damageable(int _life){life=_life;};
int getLife(){return life;};
virtual int dealDamage(int damage){life-=damage;return life;};
virtual int afterDamage(){return 0;}
virtual JQuad * getIcon(){return NULL;};
};
class Damage: public Interruptible {
protected:
void init(MTGCardInstance * _source, Damageable * _target, int _damage);
public:
Damageable * target;
MTGCardInstance * source;
int damage;
void Render();
Damage(int id, MTGCardInstance* _source, Damageable * _target);
Damage(int id, MTGCardInstance* _source, Damageable * _target, int _damage);
int resolve();
};
class DamageStack :public GuiLayer, public Interruptible{
protected:
int currentState;
public:
int resolve();
void Render();
int CombatDamages();//Deprecated ?
int CombatDamages(int strike);
DamageStack(int id, GameObserver* _game);
};
#endif
@@ -0,0 +1,38 @@
#ifndef _DAMAGERESOLVERLAYER_H_
#define _DAMAGERESOLVERLAYER_H_
#include "../include/PlayGuiObjectController.h"
class MTGCardInstance;
class DamagerDamaged;
class DamageStack;
class DamageResolverLayer:public PlayGuiObjectController{
protected:
int trampleDamage();
public:
int buttonOk;
int currentPhase;
int remainingDamageSteps;
Player * currentChoosingPlayer;
DamageStack * damageStack;
DamagerDamaged * currentSource;
DamageResolverLayer(int id, GameObserver* _game);
int init();
int initResolve();
Player * whoSelectsDamagesDealtBy(MTGCardInstance * card);
int addAutoDamageToOpponents(MTGCardInstance * card);
int addIfNotExists(MTGCardInstance * card, Player * selecter);
int addDamager(MTGCardInstance * card, Player * selecter);
DamagerDamaged * findByCard(MTGCardInstance * card);
int canStopDealDamages();
int resolveDamages();
int isOpponent(DamagerDamaged * a, DamagerDamaged * b);
void nextPlayer();
virtual void Update(float dt);
virtual void CheckUserInput(float dt);
virtual void Render();
};
#endif
+30
View File
@@ -0,0 +1,30 @@
#ifndef _DAMAGERDAMAGED_H_
#define _DAMAGERDAMAGED_H_
#include "../include/CardGui.h"
class Player;
class DamagerDamaged:public CardGui{
public:
Player * damageSelecter;
int mCount;
Damage * damages[10];
int damageToDeal;
int dealOneDamage(DamagerDamaged * target);
int addDamage(int damage, DamagerDamaged * source);
int removeDamagesTo(DamagerDamaged * target);
int removeDamagesFrom(DamagerDamaged * source);
int sumDamages();
int hasLethalDamage();
DamagerDamaged(CardGui * cardg, Player * _damageSelecter, bool _hasFocus);
~DamagerDamaged();
void Render(Player * currentPlayer);
};
#endif
+48
View File
@@ -0,0 +1,48 @@
#ifndef _DECKDATAWRAPPER_H_
#define _DECKDATAWRAPPER_H_
#include "../include/MTGDefinitions.h"
#include "../include/MTGCard.h"
#include <map>
#include <string>
using std::map;
using std::string;
class MTGDeck;
class Cmp1 { // compares cards by their name
public:
bool operator()(MTGCard * card1, MTGCard * card2) {
if (!card2) return true;
if (!card1) return false;
string name1 = card1->name;
string name2 = card2->name;
int result = name1.compare(name2);
if (!result) return card1->getMTGId() < card2->getMTGId();
return ( result < 0);
}
};
class DeckDataWrapper{
public:
int colors[MTG_NB_COLORS+1];
int currentColor;
map<MTGCard *, int,Cmp1> cards;
int currentposition;
MTGDeck * parent;
DeckDataWrapper(MTGDeck * deck);
~DeckDataWrapper();
int Add(MTGCard * card);
int Remove(MTGCard * card);
MTGCard * getNext(MTGCard * previous = NULL, int color = -1);
MTGCard * getPrevious(MTGCard * next = NULL, int color = -1);
void updateCounts(MTGCard * card = NULL, int removed = 0);
void updateCurrentPosition(MTGCard * currentCard,int color = -1);
int getCount(int color = -1);
void save();
};
#endif
+34
View File
@@ -0,0 +1,34 @@
#ifndef _DUELLAYERS_H_
#define _DUELLAYERS_H_
#include "GuiLayers.h"
class MTGGuiHand;
class MTGGuiPlay;
class ActionLayer;
class ActionStack;
class DamageResolverLayer;
class DuelLayers: public GuiLayers{
public:
ActionLayer * actionLayer();
MTGGuiHand * handLayer();
MTGGuiPlay * playLayer();
ActionStack * stackLayer();
DamageResolverLayer * combatLayer();
void init();
};
#include "ActionLayer.h"
#include "GameObserver.h"
#include "MTGGamePhase.h"
#include "MTGGuiHand.h"
#include "MTGGuiPlay.h"
#include "ActionStack.h"
#include "Damage.h"
#endif
+88
View File
@@ -0,0 +1,88 @@
/*
* Wagic, The Homebrew ?! is licensed under the BSD license
* See LICENSE in the Folder's root
* http://wololo.net/wagic/
*/
#ifndef _GAMEAPP_H_
#define _GAMEAPP_H_
#include "../include/Logger.h"
#include <JApp.h>
#include <JGE.h>
#include <JSprite.h>
#include <JLBFont.h>
#include <hge/hgeparticle.h>
#include <JResourceManager.h>
#include "../include/GameState.h"
#include "../include/MTGDeck.h"
#include "../include/MTGCard.h"
#include "../include/MTGGameZones.h"
#include "../include/TexturesCache.h"
#define MAX_STATE 6
#define PLAYER_TYPE_CPU 0
#define PLAYER_TYPE_HUMAN 1
#define PLAYER_TYPE_TESTSUITE 2
class MTGAllCards;
class TexturesCache;
class GameApp: public JApp
{
private:
bool mShowDebugInfo;
int mScreenShotCount;
GameState* mCurrentState;
GameState* mNextState;
GameState* mGameStates[MAX_STATE];
public:
int players[2];
MTGAllCards * collection;
TexturesCache * cache;
GameApp();
virtual ~GameApp();
virtual void Create();
virtual void Destroy();
virtual void Update();
virtual void Render();
virtual void Pause();
virtual void Resume();
void LoadGameStates();
void SetNextState(int state);
static JResourceManager * CommonRes;
static hgeParticleSystem * Particles[6];
static int HasMusic;
};
#endif
+89
View File
@@ -0,0 +1,89 @@
#ifndef _GAMEOBSERVER_H_
#define _GAMEOBSERVER_H_
#include "Player.h"
#include "MTGAbility.h"
#include "DuelLayers.h"
#include "MTGCardInstance.h"
#include "PlayGuiObject.h"
#include "DuelLayers.h"
#include "TargetChooser.h"
#define MAX_GAME_OBSERVERS 500
class MTGGamePhase;
class MTGAbility;
class MTGCardInstance;
class CardGui;
class Player;
class TargetChooser;
class GameObserver{
protected:
int reaction;
static GameObserver * mInstance;
MTGCardInstance * cardWaitingForTargets;
int nbPlayers;
int currentPlayerId;
int currentRound;
int targetListIsSet(MTGCardInstance * card);
public:
int cancelCurrentAction();
int currentGamePhase;
int oldGamePhase;
TargetChooser * targetChooser;
DuelLayers * mLayers;
Player * gameOver;
Player * players[2]; //created outside
MTGGamePhase * gamePhaseManager; //Created Outside ?
TargetChooser * getCurrentTargetChooser();
void stackObjectClicked(Interruptible * action);
void cardClick(MTGCardInstance * card,Targetable * _object = NULL );
int enteringPhase(int phase);
int getCurrentGamePhase();
void userRequestNextGamePhase();
void nextGamePhase();
void cleanupPhase();
void nextPlayer();
static void Init(Player * _players[], int _nbplayers);
static GameObserver * GetInstance();
static void EndInstance();
Player * currentPlayer;
Player * currentActionPlayer;
Player * isInterrupting;
Player * opponent();
Player * currentlyActing();
GameObserver(Player * _players[], int _nbplayers);
~GameObserver();
void setGamePhaseManager(MTGGamePhase * _phases);
void stateEffects();
void eventOccured();
void addObserver(MTGAbility * observer);
void removeObserver(ActionElement * observer);
void startGame(int shuffle = 1, int draw = 1);
void nextStep();
void untapPhase();
void draw();
int canPutInPlay(MTGCardInstance * card);
void putInPlay(MTGCardInstance * card);
int isInPlay(MTGCardInstance * card);
int isACreature(MTGCardInstance * card);
int tryToTapOrUntap(MTGCardInstance * card);
int checkManaCost(MTGCardInstance * card);
void Update(float dt);
void Render();
void ButtonPressed(int, PlayGuiObject*);
};
#endif
+24
View File
@@ -0,0 +1,24 @@
#ifndef _GAME_OPTIONS_H_
#define _GAME_OPTIONS_H_
#define MAX_OPTIONS 50
#define OPTIONS_MUSICVOLUME 0
#define OPTIONS_INTERRUPTATENDOFPHASE_OFFSET 1
#define OPTIONS_SAVEFILE "Res/settings/options.txt"
class GameOptions {
public:
int values[MAX_OPTIONS];
static GameOptions * GetInstance();
static void Destroy();
int save();
int load();
private:
GameOptions();
~GameOptions();
static GameOptions* mInstance;
};
#endif
+46
View File
@@ -0,0 +1,46 @@
#ifndef _GAME_STATE_H_
#define _GAME_STATE_H_
#define FADING_SPEED 350.0f
class JGE;
#include <JSoundSystem.h>
enum _gameSates
{
GAME_STATE_MENU,
GAME_STATE_DUEL,
GAME_STATE_DECK_VIEWER,
GAME_STATE_SHOP,
GAME_STATE_OPTIONS
};
class GameApp;
class GameState
{
protected:
GameApp* mParent;
JGE* mEngine;
public:
static const char * const menuTexts[];
GameState(GameApp* parent);
virtual ~GameState() {}
virtual void Create() {}
virtual void Destroy() {}
virtual void Start() {}
virtual void End() {}
virtual void Update(float dt) = 0;
virtual void Render() = 0;
};
#endif
+790
View File
@@ -0,0 +1,790 @@
#ifndef _GAME_STATE_DECK_VIEWER_H_
#define _GAME_STATE_DECK_VIEWER_H_
#include <math.h>
#include <iostream>
#include <JGE.h>
#include "GameState.h"
#include "SimpleMenu.h"
#include "../include/CardGui.h"
#include "../include/GameOptions.h"
#include "../include/PriceList.h"
#include "../include/PlayerData.h"
#include "../include/DeckDataWrapper.h"
#define NO_USER_ACTIVITY_HELP_DELAY 10
#define NO_USER_ACTIVITY_SHOWCARD_DELAY 0.1
#define STAGE_WAITING 2
#define STAGE_TRANSITION_LEFT 1
#define STAGE_TRANSITION_RIGHT 0
#define STAGE_TRANSITION_UP 3
#define STAGE_TRANSITION_DOWN 4
#define STAGE_ONSCREEN_MENU 5
#define STAGE_WELCOME 6
#define STAGE_MENU 7
#define ALL_COLORS -1
#define ROTATE_LEFT 1;
#define ROTATE_RIGHT 0;
class GameStateDeckViewer: public GameState, public JGuiListener
{
private:
JQuad * mIcons[7];
JQuad * pspIcons[8];
JTexture * pspIconsTexture;
float last_user_activity;
float onScreenTransition;
float mRotation;
float mSlide;
int mAlpha;
int mStage;
int colorFilter;
JMusic * bgMusic;
JTexture * backTex;
JQuad * backQuad;
SimpleMenu * welcome_menu;
JLBFont * mFont;
bool showing_user_deck;
JLBFont * menuFont;
SimpleMenu * menu;
SimpleMenu * sellMenu;
PriceList* pricelist;
PlayerData * playerdata;
int price;
DeckDataWrapper * displayed_deck;
DeckDataWrapper * myDeck;
DeckDataWrapper * myCollection;
MTGCard * currentCard;
MTGCard * cardIndex[7];
int hudAlpha;
public:
GameStateDeckViewer(GameApp* parent): GameState(parent) {
bgMusic = NULL;
}
virtual ~GameStateDeckViewer() {
SAFE_DELETE(bgMusic);
}
void rotateCards(int direction){
int maxCards=displayed_deck->getCount(colorFilter);
if (maxCards==0)
return;
int left = direction;
if (left){
MTGCard * currentCard = displayed_deck->getNext(cardIndex[6],colorFilter);
for (int i = 1; i<7; i++){
cardIndex[i-1] = cardIndex[i];
}
cardIndex[6] = currentCard;
}else{
MTGCard * currentCard = displayed_deck->getPrevious(cardIndex[0],colorFilter);
for (int i = 5; i>=0; i--){
cardIndex[i+1] = cardIndex[i];
}
cardIndex[0] = currentCard;
}
displayed_deck->updateCurrentPosition(cardIndex[2],colorFilter);
}
void loadIndexes(MTGCard * current = NULL){
for (int i = 0; i < 7; i++){
cardIndex[i] = NULL;
}
MTGCard * _current = current;
_current = displayed_deck->getNext(NULL,colorFilter);
for (int i = 0; i < 7; i++){
cardIndex[i] = _current;
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf,"Loadindexes[%i] is NULL\n", i);
if(_current) sprintf(buf, "LoadIndexes[%i] : %s\n", i, _current->getName());
OutputDebugString(buf);
#endif
_current = displayed_deck->getNext(_current,colorFilter);
}
displayed_deck->updateCurrentPosition(cardIndex[2],colorFilter);
}
void switchDisplay(){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Switching display");
#endif
if (displayed_deck == myCollection){
displayed_deck = myDeck;
}else{
displayed_deck = myCollection;
}
currentCard = NULL;
loadIndexes();
}
virtual void Start()
{
hudAlpha = 0;
pricelist = NEW PriceList("Res/settings/prices.dat",mParent->collection);
playerdata = NEW PlayerData(mParent->collection);
sellMenu = NULL;
myCollection = NEW DeckDataWrapper(NEW MTGDeck("Res/player/collection.dat", mParent->cache,mParent->collection));
displayed_deck = myCollection;
myDeck = NULL;
menuFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont = GameApp::CommonRes->GetJLBFont("graphics/magic");
menu = NEW SimpleMenu(11,this,menuFont,SCREEN_WIDTH/2-100,20,200);
menu->Add(11,"Save");
menu->Add(12,"Back to main menu");
menu->Add(13, "Cancel");
//icon images
mIcons[MTG_COLOR_ARTIFACT] = GameApp::CommonRes->GetQuad("c_artifact");
mIcons[MTG_COLOR_LAND] = GameApp::CommonRes->GetQuad("c_land");
mIcons[MTG_COLOR_WHITE] = GameApp::CommonRes->GetQuad("c_white");
mIcons[MTG_COLOR_RED] = GameApp::CommonRes->GetQuad("c_red");
mIcons[MTG_COLOR_BLACK] = GameApp::CommonRes->GetQuad("c_black");
mIcons[MTG_COLOR_BLUE] = GameApp::CommonRes->GetQuad("c_blue");
mIcons[MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green");
for (int i=0; i < 7; i++){
mIcons[i]->SetHotSpot(16,16);
}
pspIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/iconspsp.png", TEX_TYPE_USE_VRAM);
for (int i=0; i < 8; i++){
pspIcons[i] = NEW JQuad(pspIconsTexture, i*32, 0, 32, 32);
pspIcons[i]->SetHotSpot(16,16);
}
backTex = JRenderer::GetInstance()->LoadTexture("sets/back.jpg", TEX_TYPE_USE_VRAM);
backQuad = NEW JQuad(backTex, 0, 0, 200, 285); // Create quad for rendering.
//menuFont = NEW JLBFont("graphics/f3",16);
menuFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
welcome_menu = NEW SimpleMenu(10,this,menuFont,20,20,200);
char buffer[100];
for (int i=1; i < 6; i++){
sprintf(buffer, "Res/player/deck%i.txt",i);
std::ifstream file(buffer);
if(file){
welcome_menu->Add(i, GameState::menuTexts[i]);
file.close();
}else{
welcome_menu->Add(i, GameState::menuTexts[0]);
}
}
welcome_menu->Add(10, "Cancel");
if (GameApp::HasMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){
if (!bgMusic) bgMusic = JSoundSystem::GetInstance()->LoadMusic("sound/track1.mp3");
if (bgMusic){
JSoundSystem::GetInstance()->PlayMusic(bgMusic, true);
}
}
colorFilter = ALL_COLORS;
mStage = STAGE_WELCOME;
mRotation = 0;
mSlide = 0;
mAlpha = 255;
//mEngine->ResetPrivateVRAM();
//mEngine->EnableVSync(true);
currentCard = NULL;
loadIndexes(currentCard);
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
onScreenTransition = 0;
}
virtual void End()
{
//mEngine->EnableVSync(false);
if (bgMusic) JSoundSystem::GetInstance()->StopMusic(bgMusic);
SAFE_DELETE(backTex);
SAFE_DELETE(backQuad);
SAFE_DELETE(welcome_menu);
SAFE_DELETE(menu);
SAFE_DELETE(pspIconsTexture);
for (int i=0; i < 8; i++){
delete pspIcons[i];
}
SAFE_DELETE(myCollection);
SAFE_DELETE(myDeck);
SAFE_DELETE(pricelist);
SAFE_DELETE(playerdata);
}
void addRemove(MTGCard * card){
if (!card) return;
if (displayed_deck->Remove(card)){
if (displayed_deck == myCollection){
myDeck->Add(card);
}else{
myCollection->Add(card);
}
}
//loadIndexes(cardIndex[0]);
}
int Remove(MTGCard * card){
if (!card) return 0;
int result = displayed_deck->Remove(card);
loadIndexes(currentCard);
return result;
}
virtual void Update(float dt)
{
hudAlpha = 255-(last_user_activity * 500);
if (hudAlpha < 0) hudAlpha = 0;
if (sellMenu){
sellMenu->Update(dt);
return;
}
if (mStage == STAGE_WAITING || mStage == STAGE_ONSCREEN_MENU){
if (mEngine->GetButtonState(PSP_CTRL_LEFT)){
last_user_activity = 0;
currentCard = displayed_deck->getNext(currentCard,colorFilter);
mStage = STAGE_TRANSITION_LEFT;
}
else if (mEngine->GetButtonState(PSP_CTRL_RIGHT))
{
last_user_activity = 0;
currentCard = displayed_deck->getPrevious(currentCard,colorFilter);
mStage = STAGE_TRANSITION_RIGHT;
}
else if (mEngine->GetButtonState(PSP_CTRL_UP))
{
last_user_activity = 0;
mStage = STAGE_TRANSITION_UP;
colorFilter --;
if (colorFilter < -1) colorFilter = MTG_COLOR_LAND;
}
else if (mEngine->GetButtonState(PSP_CTRL_DOWN))
{
last_user_activity = 0;
mStage = STAGE_TRANSITION_DOWN;
colorFilter ++;
if (colorFilter > MTG_COLOR_LAND) colorFilter =-1;
}
else if (mEngine->GetButtonClick(PSP_CTRL_TRIANGLE) && last_user_activity > 0.2)
{
last_user_activity = 0;
switchDisplay();
}
else if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE))
{
last_user_activity = 0;
addRemove(cardIndex[2]);
}
else if (mEngine->GetButtonClick(PSP_CTRL_CROSS))
{
last_user_activity = 0;
SAFE_DELETE(sellMenu);
char buffer[4096];
MTGCard * card = cardIndex[2];
if (card){
int rnd = (rand() % 20);
price = pricelist->getPrice(card->getMTGId()) / 2;
price = price - price * (rnd -10)/100;
sprintf(buffer,"%s : %i credits",card->getName(),price);
sellMenu = NEW SimpleMenu(2,this,mFont,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,270,buffer);
sellMenu->Add(20,"Yes");
sellMenu->Add(21,"No");
}
}
else if (mEngine->GetButtonClick(PSP_CTRL_SQUARE))
{
if (last_user_activity < NO_USER_ACTIVITY_HELP_DELAY){
last_user_activity = NO_USER_ACTIVITY_HELP_DELAY + 1;
}else{
last_user_activity = 0;
mStage = STAGE_WAITING;
}
}
else if (mEngine->GetButtonClick(PSP_CTRL_START))
{
mStage = STAGE_MENU;
}
else{
if (last_user_activity > NO_USER_ACTIVITY_HELP_DELAY){
if (mStage != STAGE_ONSCREEN_MENU){
mStage = STAGE_ONSCREEN_MENU;
onScreenTransition = 1;
}else{
if (onScreenTransition >0){
onScreenTransition-= 0.05f;
}else{
onScreenTransition = 0;
}
}
}else{
last_user_activity+= dt;
}
}
}else if (mStage == STAGE_TRANSITION_RIGHT || mStage == STAGE_TRANSITION_LEFT) {
//mAlpha = 128;
if (mStage == STAGE_TRANSITION_RIGHT){
mRotation -= 0.05f;
}else if(mStage == STAGE_TRANSITION_LEFT){
mRotation += 0.05f;
}
if (fabs(mRotation) > 1.0f){
rotateCards(mStage);
mRotation = 0;
mStage = STAGE_WAITING;
}
}else if (mStage == STAGE_TRANSITION_DOWN || mStage == STAGE_TRANSITION_UP){
if (mStage == STAGE_TRANSITION_DOWN){
mSlide -= 0.05f;
if (mSlide < -1.0f){
loadIndexes(currentCard);
mSlide = 1;
}else if (mSlide > 0 && mSlide < 0.05){
mStage = STAGE_WAITING;
mSlide = 0;
}
}else if (mStage == STAGE_TRANSITION_UP){
mSlide += 0.05f;
if (mSlide > 1.0f){
loadIndexes(currentCard);
mSlide = -1;
}else if (mSlide < 0 && mSlide > -0.05){
mStage = STAGE_WAITING;
mSlide = 0;
}
}
}else if (mStage == STAGE_WELCOME){
welcome_menu->Update(dt);
}else if (mStage == STAGE_MENU){
menu->Update(dt);
}
}
void renderOnScreenBasicInfo(){
char buffer[30], buffer2[30];
float y = 0;
JRenderer::GetInstance()->FillRoundRect(SCREEN_WIDTH-125,y-5,110,15,5,ARGB(128,0,0,0));
sprintf(buffer, "DECK: %i", myDeck->getCount());
mFont->DrawString(buffer, SCREEN_WIDTH-120 , y);
if (colorFilter != ALL_COLORS){
sprintf(buffer2, "( %i)", myDeck->getCount(colorFilter));
mFont->DrawString(buffer2, SCREEN_WIDTH-55 , y);
JRenderer::GetInstance()->RenderQuad(mIcons[colorFilter], SCREEN_WIDTH-42 , y + 6 , 0.0f,0.5,0.5);
}
}
void renderSlideBar(){
int currentPos = displayed_deck->currentposition;
int total = displayed_deck->getCount(colorFilter);
int filler = 15;
int y = SCREEN_HEIGHT-25;
int bar_size = SCREEN_WIDTH - 2*filler;
int cursor_pos = bar_size * currentPos / total;
JRenderer * r = JRenderer::GetInstance();
r->FillRoundRect(filler + 5,y+5,bar_size,0,3,ARGB(hudAlpha/2,0,0,0));
r->DrawLine(filler+cursor_pos + 5 ,y+5,filler+cursor_pos + 5,y+10,ARGB(hudAlpha/2,0,0,0));
r->FillRoundRect(filler,y,bar_size,0,3,ARGB(hudAlpha/2,128,128,128));
//r->FillCircle(filler+cursor_pos + 3 ,SCREEN_HEIGHT - 15 + 3,6,ARGB(255,128,128,128));
r->DrawLine(filler+cursor_pos,y,filler+cursor_pos,y+5,ARGB(hudAlpha,255,255,255));
char buffer[256];
string deckname = "Collection";
if (displayed_deck == myDeck){
deckname = "Deck";
}
sprintf(buffer,"%s - %i/%i", deckname.c_str(),currentPos, total);
mFont->SetColor(ARGB(hudAlpha,255,255,255));
mFont->DrawString(buffer,SCREEN_WIDTH/2, y+5,JGETEXT_CENTER);
mFont->SetColor(ARGB(255,255,255,255));
}
void renderDeckBackground(){
int max1 = 0;
int maxC1 = 4;
int max2 = 0;
int maxC2 = 4;
for (int i= 0; i< MTG_NB_COLORS -1; i++){
int value = myDeck->getCount(i);
if (value > max1){
max2 = max1;
maxC2 = maxC1;
max1 = value;
maxC1 = i;
}else if (value > max2){
max2 = value;
maxC2 = i;
}
}
if (max2 < max1/2){
maxC2 = maxC1;
}
int _a[6] = {255, 255, 255,255,255,255};
int _r[6] = {75, 0, 0, 255,50,255};
int _g[6] = {30, 255, 0, 0, 50,255};
int _b[6] = {20, 0, 255,0, 50,255};
PIXEL_TYPE colors[] =
{
ARGB(255,_r[maxC1],_g[maxC1],_b[maxC1]),
ARGB(255,_r[maxC1],_g[maxC1],_b[maxC1]),
ARGB(255,_r[maxC2],_g[maxC2],_b[maxC2]),
ARGB(255,_r[maxC2],_g[maxC2],_b[maxC2]),
};
JRenderer::GetInstance()->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,colors);
}
void renderOnScreenMenu(){
mFont->SetColor(ARGB(255,255,255,255));
JRenderer * r = JRenderer::GetInstance();
float pspIconsSize = 0.5;
float leftTransition = onScreenTransition*84;
float rightTransition = onScreenTransition*204;
float leftPspX = 40 - leftTransition;
float leftPspY = SCREEN_HEIGHT/2 - 30 ;
float rightPspX = SCREEN_WIDTH-100 + rightTransition;
float rightPspY = SCREEN_HEIGHT/2 - 30 ;
//FillRects
r->FillRect(0-(onScreenTransition*84),0,84,SCREEN_HEIGHT,ARGB(128,0,0,0));
r->FillRect(SCREEN_WIDTH-204+(onScreenTransition*204),0,200,SCREEN_HEIGHT,ARGB(128,0,0,0));
//LEFT PSP CIRCLE render
r->FillCircle(leftPspX,leftPspY,40,ARGB(128,50,50,50));
r->RenderQuad(pspIcons[0],leftPspX, leftPspY - 20,0,pspIconsSize,pspIconsSize);
r->RenderQuad(pspIcons[1],leftPspX, leftPspY + 20,0,pspIconsSize,pspIconsSize);
r->RenderQuad(pspIcons[2],leftPspX - 20, leftPspY,0,pspIconsSize,pspIconsSize);
r->RenderQuad(pspIcons[3],leftPspX + 20, leftPspY,0,pspIconsSize,pspIconsSize);
mFont->DrawString("Prev.", leftPspX - 35, leftPspY-15);
mFont->DrawString("Next", leftPspX + 15, leftPspY-15);
mFont->DrawString("card", leftPspX - 35, leftPspY);
mFont->DrawString("card", leftPspX + 15, leftPspY);
mFont->DrawString("Next color", leftPspX - 33, leftPspY - 35);
mFont->DrawString("Prev. color", leftPspX -33 , leftPspY +25);
//RIGHT PSP CIRCLE render
r->FillCircle(rightPspX+(onScreenTransition*204),rightPspY,40,ARGB(128,50,50,50));
r->RenderQuad(pspIcons[4],rightPspX+20, rightPspY,0,pspIconsSize,pspIconsSize);
r->RenderQuad(pspIcons[5],rightPspX, rightPspY - 20,0,pspIconsSize,pspIconsSize);
r->RenderQuad(pspIcons[6],rightPspX-20, rightPspY,0,pspIconsSize,pspIconsSize);
r->RenderQuad(pspIcons[7],rightPspX, rightPspY + 20,0,pspIconsSize,pspIconsSize);
if (displayed_deck == myCollection){
mFont->DrawString("Add card", rightPspX + 20, rightPspY-15);
mFont->DrawString("Display Deck", rightPspX - 35, rightPspY - 40);
}else{
mFont->DrawString("Remove card", rightPspX + 20, rightPspY-15);
mFont->DrawString("Display Collection", rightPspX - 35, rightPspY - 40);
}
mFont->DrawString("Deck info", rightPspX - 70 , rightPspY-15);
mFont->DrawString("Sell card", rightPspX - 30 , rightPspY+20);
//Bottom menus
mFont->DrawString("menu", SCREEN_WIDTH-35 +rightTransition, SCREEN_HEIGHT-15);
//Your Deck Information
char buffer[300];
int nb_letters = 0;
for (int j=0; j<MTG_NB_COLORS;j++){
int value = myDeck->getCount(j);
if (value > 0){
sprintf(buffer, "%i", value);
mFont->DrawString(buffer, SCREEN_WIDTH-190+rightTransition + nb_letters*13, SCREEN_HEIGHT/2 + 40);
r->RenderQuad(mIcons[j],SCREEN_WIDTH-197+rightTransition + nb_letters*13 , SCREEN_HEIGHT/2 + 46,0,0.5,0.5);
if (value > 9){nb_letters += 3;}else{nb_letters+=2;}
}
}
int value = myDeck->getCount();
sprintf(buffer, "Your Deck: %i cards", value);
mFont->DrawString(buffer, SCREEN_WIDTH-200+rightTransition, SCREEN_HEIGHT/2 + 25);
//TODO, put back !
/*int nbCreatures = myDeck->countByType("Creature");
int nbSpells = myDeck->countByType("Instant") + myDeck->countByType("Enchantment") + myDeck->countByType("Sorcery");
sprintf(buffer, "Creatures: %i - Spells: %i", nbCreatures, nbSpells);
mFont->DrawString(buffer, SCREEN_WIDTH-200+rightTransition, SCREEN_HEIGHT/2 + 55);
*/
mFont->DrawString("You are currently viewing your", SCREEN_WIDTH-200+rightTransition, 5);
if (displayed_deck == myCollection){
mFont->DrawString("collection. Press TRIANGLE", SCREEN_WIDTH-200+rightTransition, 20);
mFont->DrawString("to switch to your deck", SCREEN_WIDTH-200+rightTransition, 35);
}else{
mFont->DrawString("deck. Press TRIANGLE to", SCREEN_WIDTH-200+rightTransition, 20);
mFont->DrawString("switch to your collection", SCREEN_WIDTH-200+rightTransition, 35);
}
}
virtual void renderCard(int id, float rotation){
MTGCard * card = cardIndex[id];
float max_scale = 0.96;
float min_scale = 0.2;
float x_center_0 = 180;
float right_border = SCREEN_WIDTH - 20 ;
float x_center = x_center_0 + cos((rotation + 8 - id)*M_PI/12)*(right_border-x_center_0);
float scale = max_scale/ 1.12 * cos((x_center-x_center_0)*1.5/(right_border - x_center_0) ) + 0.2 * max_scale * cos (cos((x_center-x_center_0)*0.15/(right_border - x_center_0) ));
float x = x_center - 100*scale;
float y = (SCREEN_HEIGHT - 285*scale)/2 + SCREEN_HEIGHT*mSlide*(scale+0.2);
int alpha = (int) (255 * (scale + 1.0 - max_scale));
if (!card){
/*int scaleBackup = mFont->GetScale();
mFont->SetScale(scale);
mFont->DrawString("empty slot", x, y);
mFont->SetScale(scaleBackup);*/
return;
}
JQuad * quad = backQuad;
int showName = 1;
if (mParent->cache->isInCache(card) || last_user_activity > (abs(2-id) + 1)* NO_USER_ACTIVITY_SHOWCARD_DELAY){
quad = card->getQuad(mParent->cache);
showName = 0;
}
if (quad){
int quadAlpha = alpha;
if ( !displayed_deck->cards[card]) quadAlpha /=2;
quad->SetColor(ARGB(mAlpha,quadAlpha,quadAlpha,quadAlpha));
JRenderer::GetInstance()->RenderQuad(quad, x , y , 0.0f,scale,scale);
if (showName){
char buffer[4096];
sprintf(buffer, "%s", card->getName());
int scaleBackup = mFont->GetScale();
mFont->SetScale(1*scale);
mFont->DrawString(buffer,x,y);
mFont->SetScale(scaleBackup);
}
}else{
CardGui::alternateRender(card, mFont, mIcons, x_center, y + 142.5*scale, 0, scale);
}
if (last_user_activity < 3){
int fontAlpha = alpha;
float qtY = y + 0 * scale;
float qtX = x + 120*scale;
char buffer[4096];
sprintf(buffer, "x%i", displayed_deck->cards[card]);
JLBFont * font = menuFont;
int scaleBackup = font->GetScale();
font->SetScale(1*scale);
font->SetColor(ARGB(fontAlpha/2,0,0,0));
JRenderer::GetInstance()->FillRect(qtX, qtY,32*scale,20*scale,ARGB(fontAlpha/2,0,0,0));
font->DrawString(buffer, qtX + 2, qtY + 2);
font->SetColor(ARGB(fontAlpha,255,255,255));
font->DrawString(buffer, qtX, qtY);
font->SetScale(scaleBackup);
font->SetColor(ARGB(255,255,255,255));
}
}
virtual void renderCard (int id){
renderCard(id, 0);
}
virtual void Render()
{
// void RenderQuad(JQuad* quad, float xo, float yo, float angle=0.0f, float xScale=1.0f, float yScale=1.0f);
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
if(displayed_deck == myDeck){
renderDeckBackground();
}
int order[3] = {1,2,3};
if (mRotation < 0.5 && mRotation > -0.5){
order[1]=3;
order[2]=2;
}else if (mRotation < -0.5){
order[0] = 3;
order[2] = 1;
}
renderCard(6,mRotation);
renderCard(5,mRotation);
renderCard(4,mRotation);
renderCard(0,mRotation);
for (int i =0; i< 3; i++){
renderCard(order[i],mRotation);
}
if (displayed_deck->getCount(colorFilter)>0){
renderSlideBar();
}else{
int scaleBackup = mFont->GetScale();
mFont->SetScale(2);
mFont->DrawString("No Card", SCREEN_WIDTH/2, SCREEN_HEIGHT/2,JGETEXT_CENTER);
mFont->SetScale(scaleBackup);
}
if (mStage == STAGE_ONSCREEN_MENU){
renderOnScreenMenu();
}else if (mStage == STAGE_WELCOME){
welcome_menu->Render();
}else{
renderOnScreenBasicInfo();
if (sellMenu) sellMenu->Render();
}
if (mStage == STAGE_MENU){
menu->Render();
}
}
int loadDeck(int deckid){
SAFE_DELETE(myCollection);
myCollection = NEW DeckDataWrapper(NEW MTGDeck("Res/player/collection.dat", mParent->cache,mParent->collection));
displayed_deck = myCollection;
char filename[4096];
sprintf(filename, "Res/player/deck%i.txt", deckid);
SAFE_DELETE(myDeck);
myDeck = NEW DeckDataWrapper(NEW MTGDeck(filename, mParent->cache,mParent->collection));
MTGCard * current = myDeck->getNext();
while (current){
int howmanyinDeck = myDeck->cards[current];
for (int i = 0; i < howmanyinDeck; i++){
int deleted = myCollection->Remove(current);
if (!deleted){
myDeck->Remove(current);
}
}
current = myDeck->getNext(current);
}
return 1;
}
virtual void ButtonPressed(int controllerId, int controlId)
{
switch (controlId)
{
case 1:
case 2:
case 3:
case 4:
case 5:
loadDeck(controlId);
mStage = STAGE_WAITING;
break;
case 10:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 11:
myDeck->save();
playerdata->save();
pricelist->save();
mStage = STAGE_WAITING;
break;
case 12:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 13:
mStage = STAGE_WAITING;
break;
case 20:
{
MTGCard * card = cardIndex[2];
if (card){
int rnd = (rand() % 20);
price = price - (rnd * price)/100;
playerdata->credits += price;
pricelist->setPrice(card->getMTGId(),price*2);
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "CARD'S NAME : %s", card->getName());
OutputDebugString(buf);
#endif
playerdata->collection->remove(card->getMTGId());
Remove(card);
}
}
case 21:
SAFE_DELETE(sellMenu);
break;
}
}
};
#endif
+55
View File
@@ -0,0 +1,55 @@
#ifndef _GAME_STATE_DUEL_H_
#define _GAME_STATE_DUEL_H_
#include "../include/GameState.h"
#include "_includeAll.h"
#include "../include/SimpleMenu.h"
#define DUEL_START 0
#define DUEL_END 1
#define DUEL_CHOOSE_DECK1 2
#define DUEL_CHOOSE_DECK2 3
#define ERROR_NO_DECK 4
#define DUEL_PLAY 5
#define DUEL_MENU 6
#ifdef TESTSUITE
class TestSuite;
#endif
class GameStateDuel: public GameState, public JGuiListener
{
private:
#ifdef TESTSUITE
TestSuite * testSuite;
#endif
int mGamePhase;
Player * mCurrentPlayer;
Player * mPlayers[2];
MTGPlayerCards * deck[2];
GameObserver * game;
SimpleMenu * deckmenu;
SimpleMenu * menu;
JLBFont* mFont;
void loadPlayer(int playerId, int decknb = 0);
public:
GameStateDuel(GameApp* parent);
virtual ~GameStateDuel();
#ifdef TESTSUITE
void loadTestSuitePlayers();
#endif
virtual void ButtonPressed(int ControllerId, int ControlId);
virtual void Start();
virtual void End();
virtual void Update(float dt);
virtual void Render();
};
#endif
+432
View File
@@ -0,0 +1,432 @@
#ifndef _GAME_STATE_MENU_H_
#define _GAME_STATE_MENU_H_
#include <JGui.h>
#include <dirent.h>
#include "GameState.h"
#include "MenuItem.h"
#include "SimpleMenu.h"
#include "../include/GameOptions.h"
#define STATE_MENU 0
#define STATE_SUBMENU 1
#define STATE_LOADING_MENU 2
#define STATE_LOADING_CARDS 3
#define STATE_FIRST_TIME 4
#define STATE_WARNING 5
#define GAME_VERSION "WTH?! 0.2.1 - by WilLoW"
#define ALPHA_WARNING 0
class GameStateMenu: public GameState, public JGuiListener
{
private:
JGuiController* mGuiController;
SimpleMenu* subMenuController;
JLBFont* mFont;
JQuad * mIcons[10];
JTexture * mIconsTexture;
JTexture * bgTexture;
JQuad * mBg;
float mCreditsYPos;
int currentState;
JMusic * bgMusic;
int mVolume;
char nbcardsStr[400];
DIR *mDip;
struct dirent *mDit;
char mCurrentSetName[10];
char mCurrentSetFileName[512];
int mReadConf;
public:
GameStateMenu(GameApp* parent): GameState(parent)
{
mGuiController = NULL;
subMenuController = NULL;
mIconsTexture = NULL;
bgMusic = NULL;
}
virtual ~GameStateMenu()
{
}
virtual void Create()
{
mDip = NULL;
mReadConf = 0;
mCurrentSetName[0] = 0;
mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM);
bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/menutitle.png", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(bgTexture, 10, 0, 220, 80); // Create background quad for rendering.
mBg->SetHotSpot(105,32);
//load all the icon images
int n = 0;
for (int i=0;i<5;i++)
{
for (int j=0;j<2;j++)
{
mIcons[n] = NEW JQuad(mIconsTexture, 10 + i*32, j*32, 32, 32);
mIcons[n]->SetHotSpot(16,16);
n++;
}
}
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
//mFont->SetBase(0); // using 2nd font
mGuiController = NEW JGuiController(100, this);
//mGuiController->SetShadingBackground(10, 45, 80, 100, ARGB(255,0,0,0));
if (mGuiController)
{
mGuiController->Add(NEW MenuItem(1, mFont, "Play", 80, SCREEN_HEIGHT/2, mIcons[8], mIcons[9],"graphics/particle1.psi",GameApp::CommonRes->GetQuad("particles"), true));
mGuiController->Add(NEW MenuItem(2, mFont, "Deck Editor", 160, SCREEN_HEIGHT/2, mIcons[2], mIcons[3],"graphics/particle2.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(3, mFont, "Shop", 240, SCREEN_HEIGHT/2, mIcons[0], mIcons[1],"graphics/particle3.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(4, mFont, "Options", 320, SCREEN_HEIGHT/2, mIcons[6], mIcons[7],"graphics/particle4.psi",GameApp::CommonRes->GetQuad("particles")));
mGuiController->Add(NEW MenuItem(5, mFont, "Exit", 400, SCREEN_HEIGHT/2, mIcons[4], mIcons[5],"graphics/particle5.psi",GameApp::CommonRes->GetQuad("particles")));
}
currentState = STATE_LOADING_CARDS;
}
virtual void Destroy()
{
if (mGuiController)
delete mGuiController;
if (subMenuController)
delete subMenuController;
if (mIconsTexture)
delete mIconsTexture;
for (int i = 0; i < 10 ; i++){
delete mIcons[i];
}
if (mBg) delete mBg;
SAFE_DELETE (bgMusic);
}
virtual void Start(){
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
if (GameApp::HasMusic && !bgMusic && GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME] > 0){
bgMusic = JSoundSystem::GetInstance()->LoadMusic("sound/track0.mp3");
}
if (bgMusic){
mVolume = 0;
JSoundSystem::GetInstance()->SetVolume(mVolume);
JSoundSystem::GetInstance()->PlayMusic(bgMusic, true);
}
}
/* Retrieves the next set subfolder automatically
*/
int nextCardSet(){
int found = 0;
if (!mDip){
mDip = opendir("Res/sets/");
}
while (!found && (mDit = readdir(mDip))){
sprintf(mCurrentSetFileName, "Res/sets/%s/_cards.dat", mDit->d_name);
std::ifstream file(mCurrentSetFileName);
if(file){
sprintf(mCurrentSetName, "%s", mDit->d_name);
file.close();
found = 1;
}
}
if (!mDit) {
closedir(mDip);
mDip = NULL;
}
return found;
}
virtual void End()
{
//mEngine->EnableVSync(false);
if (bgMusic)
{
JSoundSystem::GetInstance()->StopMusic(bgMusic);
}
JRenderer::GetInstance()->EnableVSync(false);
}
virtual void Update(float dt)
{
if (bgMusic && mVolume < 2*GameOptions::GetInstance()->values[OPTIONS_MUSICVOLUME]){
mVolume++;
JSoundSystem::GetInstance()->SetVolume(mVolume/2);
}
if (currentState == STATE_LOADING_CARDS){
if (mReadConf){
mParent->collection->load(mCurrentSetFileName, mCurrentSetName);
}else{
mReadConf = 1;
}
if (!nextCardSet()){
//How many cards total ?
sprintf(nbcardsStr, "Database: %i cards", mParent->collection->totalCards());
//Check for first time comer
std::ifstream file("Res/player/collection.dat");
if(file){
file.close();
currentState = STATE_WARNING;
}else{
currentState = STATE_FIRST_TIME;
}
}
}else if (currentState == STATE_FIRST_TIME){
//Give the player cards from the set for which we have the most variety
int setId = 0;
int maxcards = 0;
for (int i=0; i< MtgSets::SetsList->nb_items; i++){
int value = mParent->collection->countBySet(i);
if (value > maxcards){
maxcards = value;
setId = i;
}
}
createUsersFirstDeck(setId);
currentState = STATE_WARNING;
}else if (currentState == STATE_WARNING){
if (!ALPHA_WARNING){
currentState = STATE_MENU;
}else{
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) currentState = STATE_MENU;
}
}else{
if (currentState == STATE_MENU && mGuiController!=NULL)
mGuiController->Update(dt);
if (currentState == STATE_SUBMENU){
if( subMenuController != NULL){
subMenuController->Update(dt);
}else{
subMenuController = NEW SimpleMenu(102, this,mFont, 50,170,SCREEN_WIDTH-120);
if (subMenuController){
subMenuController->Add(11,"1 Player");
subMenuController->Add(12, "2 Players");
subMenuController->Add(13,"Demo");
subMenuController->Add(14, "Cancel");
#ifdef TESTSUITE
subMenuController->Add(666, "Test Suite");
#endif
}
}
}
}
if (currentState == STATE_WARNING && !ALPHA_WARNING) currentState = STATE_MENU;
}
void createUsersFirstDeck(int setId){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "setID: %i", setId);
OutputDebugString(buf);
#endif
MTGDeck *mCollection = NEW MTGDeck("Res/player/collection.dat", mParent->cache, mParent->collection);
//10 lands of each
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Forest")){
mCollection->addRandomCards(10, -1,RARITY_L,"Forest");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Plains")){
mCollection->addRandomCards(10, -1,RARITY_L,"Plains");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Swamp")){
mCollection->addRandomCards(10, -1,RARITY_L,"Swamp");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Mountain")){
mCollection->addRandomCards(10, -1,RARITY_L,"Mountain");
}
if (!mCollection->addRandomCards(10, setId,RARITY_L,"Island")){
mCollection->addRandomCards(10, -1,RARITY_L,"Island");
}
#if defined (WIN32) || defined (LINUX)
OutputDebugString("1\n");
#endif
//Starter Deck
mCollection->addRandomCards(3, setId,RARITY_R,NULL);
mCollection->addRandomCards(9, setId,RARITY_U,NULL);
mCollection->addRandomCards(48, setId,RARITY_C,NULL);
#if defined (WIN32) || defined (LINUX)
OutputDebugString("2\n");
#endif
//Boosters
for (int i = 0; i< 2; i++){
mCollection->addRandomCards(1, setId,RARITY_R);
mCollection->addRandomCards(3, setId,RARITY_U);
mCollection->addRandomCards(11, setId,RARITY_C);
}
mCollection->save();
delete mCollection;
}
virtual void Render()
{
JRenderer * renderer = JRenderer::GetInstance();
renderer->ClearScreen(ARGB(0,0,0,0));
if (currentState == STATE_LOADING_CARDS){
char text[512];
sprintf(text, "LOADING SET: %s", mCurrentSetName);
mFont->DrawString(text,SCREEN_WIDTH/2,SCREEN_HEIGHT/2,JGETEXT_CENTER);
}else{
PIXEL_TYPE colors[] =
{
ARGB(255,17,17,17),
ARGB(255,17,17,17),
ARGB(255,62,62,62),
ARGB(255,62,62,62)
};
renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,colors);
renderer->RenderQuad(mBg, SCREEN_WIDTH/2 , 50);
if (mGuiController!=NULL)
mGuiController->Render();
mFont->SetScale(0.7);
mFont->SetColor(ARGB(128,255,255,255));
mFont->DrawString(GAME_VERSION, SCREEN_WIDTH-10,SCREEN_HEIGHT-15,JGETEXT_RIGHT);
mFont->DrawString(nbcardsStr,10, SCREEN_HEIGHT-15);
mFont->SetScale(1.f);
mFont->SetColor(ARGB(255,255,255,255));
if (currentState == STATE_SUBMENU && subMenuController != NULL){
subMenuController->Render();
}
if (currentState == STATE_WARNING){
renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(128,0,0,0));
mFont->DrawString("IMPORTANT NOTE" ,SCREEN_WIDTH/2,10,JGETEXT_CENTER);
mFont->DrawString("This is an alpha version with lots of bugs.",SCREEN_WIDTH/2,35,JGETEXT_CENTER);
mFont->DrawString("It WILL crash your psp" ,SCREEN_WIDTH/2,50,JGETEXT_CENTER);
mFont->DrawString("If you use it anyway, your feedback is welcome" ,SCREEN_WIDTH/2,65,JGETEXT_CENTER);
mFont->DrawString("This freeware game is NOT published or endorsed" ,SCREEN_WIDTH/2,110,JGETEXT_CENTER);
mFont->DrawString("by Wizard of the Coast, Inc." ,SCREEN_WIDTH/2,125,JGETEXT_CENTER);
mFont->DrawString("Infos & updates at http://wololo.net/wagic/" ,SCREEN_WIDTH/2,170,JGETEXT_CENTER);
mFont->DrawString("PRESS CIRCLE TO CONTINUE OR HOME TO QUIT" ,SCREEN_WIDTH/2,210,JGETEXT_CENTER);
}
}
}
virtual void ButtonPressed(int controllerId, int controlId)
{
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf, "cnotrollerId: %i", controllerId);
OutputDebugString(buf);
#endif
switch (controllerId){
case 101:
createUsersFirstDeck(controlId);
currentState = STATE_MENU;
SAFE_DELETE(subMenuController);
break;
default:
switch (controlId)
{
case 1:
currentState = STATE_SUBMENU;
break;
case 2:
mParent->SetNextState(GAME_STATE_DECK_VIEWER);
break;
case 3:
mParent->SetNextState(GAME_STATE_SHOP);
break;
case 4:
mParent->SetNextState(GAME_STATE_OPTIONS);
break;
case 5:
mEngine->End();
break;
case 11:
mParent->players[0] = PLAYER_TYPE_HUMAN;
mParent->players[1] = PLAYER_TYPE_CPU;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 12:
mParent->players[0] = PLAYER_TYPE_HUMAN;
mParent->players[1] = PLAYER_TYPE_HUMAN;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 13:
mParent->players[0] = PLAYER_TYPE_CPU;
mParent->players[1] = PLAYER_TYPE_CPU;
mParent->SetNextState(GAME_STATE_DUEL);
break;
case 14:
currentState = STATE_MENU;
delete subMenuController;
subMenuController = NULL;
break;
#ifdef TESTSUITE
case 666:
mParent->players[0] = PLAYER_TYPE_TESTSUITE;
mParent->players[1] = PLAYER_TYPE_TESTSUITE;
mParent->SetNextState(GAME_STATE_DUEL);
break;
#endif
}
break;
}
}
};
#endif
+34
View File
@@ -0,0 +1,34 @@
#ifndef _GAME_STATE_OPTIONS_H_
#define _GAME_STATE_OPTIONS_H_
#include <JGui.h>
#include "../include/GameState.h"
#define SHOW_OPTIONS 1
#define SHOW_OPTIONS_MENU 2
class GameApp;
class OptionsList;
class SimpleMenu;
class GameStateOptions: public GameState, public JGuiListener
{
public:
SimpleMenu * optionsMenu;
int mState;
OptionsList * optionsList;
GameStateOptions(GameApp* parent);
virtual ~GameStateOptions();
virtual void Start();
virtual void End();
virtual void Update(float dt);
virtual void Render();
void ButtonPressed(int controllerId, int ControlId);
};
#endif
+46
View File
@@ -0,0 +1,46 @@
#ifndef _GAME_STATE_SHOP_H_
#define _GAME_STATE_SHOP_H_
#include <JGE.h>
#include "../include/GameState.h"
#include "../include/SimpleMenu.h"
#include "../include/ShopItem.h"
#define STATE_BUY 1
#define STATE_SELL 2
#define STAGE_SHOP_MENU 3
#define STAGE_SHOP_SHOP 4
class GameStateShop: public GameState, public JGuiListener
{
private:
ShopItems * shop;
JLBFont * mFont;
JQuad * mBg;
JTexture * bgTexture;
JQuad * mBack;
JTexture * backTexture;
SimpleMenu * menu;
int mStage;
char starterBuffer[128], boosterBuffer[128];
int setId;
public:
GameStateShop(GameApp* parent);
virtual ~GameStateShop();
virtual void Start();
virtual void End();
virtual void Create();
virtual void Destroy();
virtual void Update(float dt);
virtual void Render();
virtual void ButtonPressed(int controllerId, int controlId);
};
#endif
+39
View File
@@ -0,0 +1,39 @@
#ifndef _GROUPOFCARDS_H_
#define _GROUPOFCARDS_H_
#include "GameObserver.h"
#include "MTGCardInstance.h"
#define FILTER_SUBTYPE 1
#define GROUP_LIMIT 10
class GroupOfCards{
protected:
GameObserver * game;
public:
GroupOfCards(GameObserver * _game);
//virtual ~GroupOfCards();
virtual int includes(MTGCardInstance * card){return 0;};
};
class GroupOfCreatures:public GroupOfCards{
protected:
int filter;
int filterValue;
public:
GroupOfCreatures(GameObserver * _game, int _filter, int _filterValue);
int includes(MTGCardInstance * card);
};
class GroupOfSpecificCards:public GroupOfCards{
protected:
int nb_cards;
MTGCardInstance * cards[GROUP_LIMIT];
public:
int includes(MTGCardInstance * card);
GroupOfSpecificCards(GameObserver * _game, MTGCardInstance * _creatures[], int _nb_creatures);
GroupOfSpecificCards(GameObserver * _game, MTGCardInstance * card);
};
#endif
+6
View File
@@ -0,0 +1,6 @@
#ifndef _GROUPOFCREATURES_H_
#define _GROUPOFCREATURES_H_
class Group
#endif
+13
View File
@@ -0,0 +1,13 @@
#ifndef _GUI_CARDS_CONTROLLER_H_
#define _GUI_CARDS_CONTROLLER_H_
#include "PlayGuiObjectController.h"
class GuiCardsController : public PlayGuiObjectController{
public:
GuiCardsController(int id, GameObserver* _game):PlayGuiObjectController(id, _game){};
};
#endif
+58
View File
@@ -0,0 +1,58 @@
#ifndef _GUI_LAYERS_H_
#define _GUI_LAYERS_H_
#define MAX_GUI_LAYERS 6
#define DIR_DOWN 1
#define DIR_UP 2
#define DIR_LEFT 3
#define DIR_RIGHT 4
#include <JGui.h>
class GameObserver;
class Player;
class GuiLayer: public JGuiController{
protected:
int modal;
GameObserver * game;
public:
virtual void resetObjects();
int hasFocus;
int getMaxId();
void RenderMessageBackground(float x0, float y0, float width, int height);
void RenderMessageBackground(float y0, int height);
GuiLayer(int id, GameObserver* _game);
virtual int isModal();
void setModal(int _modal);
virtual ~GuiLayer();
virtual void Update(float dt);
virtual void CheckUserInput(float dt){};
virtual int unstopableRenderInProgress(){return 0;};
int getIndexOf(JGuiObject * object);
JGuiObject * getByIndex (int index);
virtual void Render(){JGuiController::Render();};
int empty(){
if (mCount) return 0;
return 1;
};
};
class GuiLayers{
protected:
int nbitems;
GuiLayer * objects[MAX_GUI_LAYERS];
public:
GuiLayers();
void Update(float dt, Player * player);
void Render();
void Add(GuiLayer * layer);
void Remove();
int unstopableRenderInProgress();
~GuiLayers();
};
#endif
+20
View File
@@ -0,0 +1,20 @@
#ifndef _LOGGER_H
#define _LOGGER_H_
#ifdef DOLOG
#define LOG(x) Logger::Log(x);
#else
#define LOG(x)
#endif
#define LOG_FILE "Res/debug.txt"
class Logger{
public:
static void Log(char * text);
};
#endif
+117
View File
@@ -0,0 +1,117 @@
#ifndef _MTGABILITY_H_
#define _MTGABILITY_H_
class MTGCardInstance;
class GameObserver;
class Spell;
class Damageable;
class PlayGuiObject;
class TargetChooser;
class ManaCost;
class MTGGameZone;
class Player;
#include "ActionElement.h"
#include <string>
#include <map>
using std::string;
using std::map;
#define BAKA_EFFECT_GOOD 10
#define BAKA_EFFECT_BAD 11
class AbilityFactory{
private:
int destroyAllFromTypeInPlay(const char * type, MTGCardInstance * source, int bury = 0);
int putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p);
public:
int magicText(int id, Spell * spell, MTGCardInstance * card = NULL);
void addAbilities(int _id, Spell * spell);
};
class MTGAbility: public ActionElement{
protected:
char menuText[25];
Damageable * target;
GameObserver * game;
public:
MTGCardInstance * source;
MTGAbility(int id, MTGCardInstance * card);
MTGAbility(int id, MTGCardInstance * _source, Damageable * _target);
virtual int testDestroy();
virtual ~MTGAbility();
virtual void Render(){};
virtual int isReactingToClick(MTGCardInstance * card){return 0;};
virtual int reactToClick(MTGCardInstance * card){return 0;};
virtual void Update(float dt){};
virtual int fireAbility();
virtual int resolve(){return 0;};
};
class TriggeredAbility:public MTGAbility{
public:
TriggeredAbility(int id, MTGCardInstance * card);
TriggeredAbility(int id, MTGCardInstance * _source, Damageable * _target);
virtual void Update(float dt);
virtual void Render(){};
virtual int trigger()=0;
virtual int resolve() = 0;
};
class ActivatedAbility:public MTGAbility{
public:
ManaCost * cost;
int playerturnonly;
int needsTapping;
ActivatedAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
virtual int reactToClick(MTGCardInstance * card);
virtual int isReactingToClick(MTGCardInstance * card);
virtual int reactToTargetClick(Targetable * object);
virtual int resolve() = 0;
virtual ~ActivatedAbility();
};
class TargetAbility:public ActivatedAbility{
public:
TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1);
virtual void Update(float dt);
virtual int reactToClick(MTGCardInstance * card);
virtual int reactToTargetClick(Targetable * object);
virtual void Render();
};
class InstantAbility:public MTGAbility{
public:
int init;
virtual void Update(float dt);
virtual int testDestroy();
InstantAbility(int _id, MTGCardInstance * source);
InstantAbility(int _id, MTGCardInstance * source,Damageable * _target);
virtual int resolve(){return 0;};
};
/* State based effects. This class works ONLY for InPlay and needs to be extended for other areas of the game !!! */
class ListMaintainerAbility:public MTGAbility{
public:
map<MTGCardInstance *,bool> cards;
ListMaintainerAbility(int _id):MTGAbility(_id,NULL){};
ListMaintainerAbility(int _id, MTGCardInstance *_source):MTGAbility(_id, _source){};
ListMaintainerAbility(int _id, MTGCardInstance *_source,Damageable * _target):MTGAbility(_id, _source, _target){};
virtual void Update(float dt);
virtual int canBeInList(MTGCardInstance * card) = 0;
virtual int added(MTGCardInstance * card) = 0;
virtual int removed(MTGCardInstance * card) = 0;
virtual int destroy();
};
#include "MTGCardInstance.h"
#endif
+119
View File
@@ -0,0 +1,119 @@
#ifndef _MTGCARD_H_
#define _MTGCARD_H_
#define MTGCARD_NAME_SIZE 30
#define MTGCARD_TEXT_SIZE 300
#define MTG_IMAGE_WIDTH 200
#define MTG_IMAGE_HEIGHT 285
#define MAX_TYPES_PER_CARD 10
#include "ManaCost.h"
class TexturesCache;
#include <string>
#include <vector>
using namespace std;
class MTGCard {
protected:
int mtgid;
TexturesCache * mCache;
ManaCost manaCost;
char rarity;
char image_name[MTGCARD_NAME_SIZE];
int init();
public:
string text;
string name;
int colors[MTG_NB_COLORS];
int basicAbilities[NB_BASIC_ABILITIES];
vector<string> formattedText;
string magicText;
int alias;
string spellTargetType;
int formattedTextInit;
int power;
int toughness;
int setId;
static const char * const Colors_To_Text[];
int nb_types;
int types[MAX_TYPES_PER_CARD];
MTGCard();
MTGCard(TexturesCache * cache, int set_id);
MTGCard(MTGCard * source);
JQuad * getQuad(TexturesCache * cache);
JQuad * getQuad(int type=1);
JQuad * getThumb();
void setColor(int _color, int removeAllOthers = 0);
int getColor();
int hasColor(int _color);
const char * colorToString();
void setMTGId(int id);
int getMTGId();
int getId();
int has(int ability);
char getRarity();
void setRarity(char _rarity);
const char * getSetName();
//void setImageName( char * value);
char * getImageName ();
void setText( string value);
const char * getText();
void addMagicText(string value);
void setName( string value);
const char * getName();
void addType(char * type_text);
void addType(int id);
void setType(const char * type_text);
void setSubtype( string value);
int removeType(string value, int removeAll = 0);
int removeType(int value, int removeAll = 0);
int hasSubtype(int _subtype);
int hasSubtype(const char * _subtype);
int hasSubtype(string _subtype);
int hasType(int _type);
int hasType(const char * type);
void setManaCost(string value);
ManaCost * getManaCost();
int isACreature();
void setPower(int _power);
int getPower();
void setToughness(int _toughness);
int getToughness();
};
#endif
+102
View File
@@ -0,0 +1,102 @@
#ifndef _MTG_CARD_INSTANCE_H_
#define _MTG_CARD_INSTANCE_H_
#include "MTGCard.h"
#include "MTGGameZones.h"
#include "MTGAbility.h"
#include "TexturesCache.h"
#include "ManaCost.h"
#include "Blocker.h"
#include "Damage.h"
#include "Targetable.h"
class MTGCardInstance;
class MTGPlayerCards;
class MTGAbility;
class MTGCard;
class TexturesCache;
class ManaCost;
class Blockers;
class CardDescriptor;
class Counters;
class MTGCardInstance: public MTGCard, public Damageable, public Targetable {
protected:
int untapping;
int nb_damages;
int lifeOrig;
Blockers * blockers;
MTGPlayerCards * belongs_to;
MTGAbility * UntapBlockers[10];
void unband();
MTGCardInstance * getNextPartner();
void initMTGCI();
public:
MTGGameZone * getCurrentZone();
int doDamageTest;
int summoningSickness;
// The recommended method to test for summoning Sickness !
int hasSummoningSickness();
int changeController(Player * newcontroller);
MTGCardInstance * defenser;
float changedZoneRecently;
Player * owner;
Counters * counters;
int typeAsTarget(){return TARGET_CARD;}
int attacker;
MTGCardInstance * banding; // If belongs to a band when attacking
MTGCardInstance * target;
int tapped;
void addType(int type);
int canBlock();
int canBlock(MTGCardInstance * opponent);
int canAttack();
int afterDamage();
void setUntapping();
int isUntapping();
int has(int ability);
int cleanup();
int reset();
int isAttacker();
MTGCardInstance * isDefenser();
int toggleDefenser(MTGCardInstance * opponent);
int toggleAttacker();
MTGCard * model;
MTGCardInstance();
MTGCardInstance(MTGCard * card, MTGPlayerCards * _belongs_to);
Blockers * getBlockers();
void regenerate();
Player * controller();
JQuad * getIcon();
int initAttackersDefensers();
MTGCardInstance * getNextOpponent(MTGCardInstance * previous=NULL);
int nbOpponents();
~MTGCardInstance();
int addToToughness(int value);
int setToughness(int value);
CardDescriptor * protections[10];
int nbprotections;
int addProtection(CardDescriptor * cd);
int removeProtection(CardDescriptor *cd, int erase = 0);
int protectedAgainst(MTGCardInstance * card);
// in game
int isTapped();
void untap();
void tap();
int isInPlay();
void resetAllDamage();
};
#endif
+91
View File
@@ -0,0 +1,91 @@
#ifndef _MTGDECK_H_
#define _MTGDECK_H_
#define MTG_ERROR -1
#include "../include/MTGDefinitions.h"
#include "../include/GameApp.h"
#include "../include/TexturesCache.h"
#include <string>
using std::string;
class GameApp;
class MTGCard;
#define MAX_SETS 30
class MtgSets{
protected:
public:
int nb_items;
string values[MAX_SETS];
public:
static MtgSets * SetsList;
MtgSets();
int Add(const char * subtype);
};
class MTGAllCards {
protected:
int conf_read_mode;
int conf_fd;
char * conf_buffer;
int read_cursor;
int colorsCount[MTG_NB_COLORS];
int total_cards;
GameApp * parent;
void init();
void initCounters();
public:
TexturesCache * mCache;
MTGCard * _(int i);
MTGCard * collection[TOTAL_NUMBER_OF_CARDS];
MTGAllCards();
~MTGAllCards();
MTGAllCards(TexturesCache * cache);
void destroyAllCards();
MTGAllCards(const char * config_file, const char * set_name);
MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache);
MTGCard * getCardById(int id);
int load(const char * config_file, const char * setName, int autoload = 1);
int countByType(const char * _type);
int countByColor(int color);
int countBySet(int setId);
int readConfLine(int set_id);
int totalCards();
int randomCardId();
private:
int processConfLine(char* file, MTGCard* card);
};
class MTGDeck:public MTGAllCards{
protected:
string filename;
MTGAllCards * allcards;
public:
MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards);
int addRandomCards(int howmany, int setId = -1, int rarity = -1, const char * subtype = NULL);
int add(int cardid);
int remove(int cardid);
int removeAll();
int add(MTGCard * card);
int remove(MTGCard * card);
int save();
};
#endif
+151
View File
@@ -0,0 +1,151 @@
#ifndef _MTGDEFINITION_H_
#define _MTGDEFINITION_H_
#define TOTAL_NUMBER_OF_CARDS 4000
#define MTG_NB_COLORS 7
#define MTG_COLOR_ARTIFACT 0
#define MTG_COLOR_GREEN 1
#define MTG_COLOR_BLUE 2
#define MTG_COLOR_RED 3
#define MTG_COLOR_BLACK 4
#define MTG_COLOR_WHITE 5
#define MTG_COLOR_LAND 6
static char MTGColorChars[] = {'x','g','u','r','b','w','l'};
static int _r[7] = {75, 20, 20, 200,50,255,128};
static int _g[7] = {30, 140, 30, 15, 50,255,128};
static int _b[7] = {20, 0, 140,15, 50,255,128};
#define MTG_UNCOLORED 0
#define MTG_FOREST 1
#define MTG_ISLAND 2
#define MTG_MOUNTAIN 3
#define MTG_SWAMP 4
#define MTG_PLAIN 5
#define MTG_TYPE_CREATURE 10
#define MTG_TYPE_ARTIFACT 11
#define MTG_TYPE_ENCHANTMENT 12
#define MTG_TYPE_SORCERY 13
#define MTG_TYPE_LAND 14
#define MTG_TYPE_INSTANT 15
#define MTG_PHASE_UNTAP 0
#define MTG_PHASE_UPKEEP 1
#define MTG_PHASE_DRAW 2
#define MTG_PHASE_FIRSTMAIN 3
#define MTG_PHASE_COMBATBEGIN 4
#define MTG_PHASE_COMBATATTACKERS 5
#define MTG_PHASE_COMBATBLOCKERS 6
#define MTG_PHASE_COMBATDAMAGE 7
#define MTG_PHASE_COMBATEND 8
#define MTG_PHASE_SECONDMAIN 9
#define MTG_PHASE_ENDOFTURN 10
#define MTG_PHASE_EOT 10
#define MTG_PHASE_CLEANUP 11
#define TRAMPLE 0
#define FORESTWALK 1
#define ISLANDWALK 2
#define MOUNTAINWALK 3
#define SWAMPWALK 4
#define PLAINSWALK 5
#define FLYING 6
#define FIRSTSTRIKE 7
#define DOUBLESTRIKE 8
#define FEAR 9
#define FLASH 10
#define HASTE 11
#define LIFELINK 12
#define REACH 13
#define SHROUD 14
#define VIGILANCE 15
#define DEFENSER 16
#define BANDING 17
#define PROTECTIONGREEN 18
#define PROTECTIONBLUE 19
#define PROTECTIONRED 20
#define PROTECTIONBLACK 21
#define PROTECTIONWHITE 22
#define UNBLOCKABLE 23
#define WITHER 24
#define PERSIST 25
#define RETRACE 26
#define EXALTED 27
#define LEGENDARY 28
#define NB_BASIC_ABILITIES 29
static const char * MTGBasicAbilities[] = {
"trample",
"forestwalk",
"islandwalk",
"mountainwalk",
"swampwalk",
"plainwalk",
"flying",
"first strike",
"double strike",
"fear",
"flash",
"haste",
"lifelink",
"reach",
"shroud",
"vigilance",
"defender",
"banding",
"protection from green",
"protection from blue",
"protection from red",
"protection from black",
"protection from white",
"unblockable",
"wither",
"persist",
"retrace",
"exalted",
"legendary"
};
#define RARITY_M 'M'
#define RARITY_R 'R'
#define RARITY_U 'U'
#define RARITY_C 'C'
#define RARITY_L 'L'
#define MAIN_FONT 0
#define MAGIC_FONT 1
static const char *MTGPhaseNames[] =
{
"Untap",
"Upkeep",
"Draw",
"Main phase 1",
"Combat begins",
"Attackers",
"Blockers",
"Combat damage",
"Combat ends",
"Main phase 2",
"End of turn",
"cleanup"
};
#endif
+24
View File
@@ -0,0 +1,24 @@
#ifndef _MTGGAMEPHASE_H_
#define _MTGGAMEPHASE_H_
#include "ActionElement.h"
#include "GameObserver.h"
#include <JGui.h>
#include <JLBFont.h>
class MTGGamePhase: public ActionElement {
protected:
float animation;
int currentState;
JLBFont * mFont;
public:
MTGGamePhase(int id);
virtual void Render();
virtual void Update(float dt);
void CheckUserInput(float dt);
};
#endif
+93
View File
@@ -0,0 +1,93 @@
#ifndef _MTGGAMEZONES_H_
#define _MTGGAMEZONES_H_
#include "MTGDeck.h"
#include "MTGCardInstance.h"
#define MTG_MAX_PLAYER_CARDS 100
class MTGAllCards;
class MTGCardInstance;
class Player;
class MTGGameZone {
protected:
Player * owner;
public:
MTGCardInstance * cards[MTG_MAX_PLAYER_CARDS];
int nb_cards;
MTGGameZone();
~MTGGameZone();
void shuffle();
virtual MTGCardInstance * draw();
void addCard(MTGCardInstance * card);
void debugPrint();
MTGCardInstance * removeCard(MTGCardInstance * card);
MTGCardInstance * hasCard(MTGCardInstance * card);
void cleanupPhase();
int countByType(const char * value);
int hasType(const char * value);
void setOwner(Player * player);
MTGCardInstance * lastCardDrawn;
};
class MTGLibrary: public MTGGameZone {
public:
// MTGLibrary();
void shuffleTopToBottom(int nbcards);
MTGCardInstance * draw();
};
class MTGGraveyard: public MTGGameZone {
public:
// MTGGraveyard();
};
class MTGHand: public MTGGameZone {
public:
};
class MTGStack: public MTGGameZone {
public:
};
class MTGInPlay: public MTGGameZone {
public:
//MTGInPlay();
void untapAll();
MTGCardInstance * getNextAttacker(MTGCardInstance * previous);
MTGCardInstance * getNextDefenser(MTGCardInstance * previous, MTGCardInstance * attacker);
int nbDefensers( MTGCardInstance * attacker);
int nbPartners(MTGCardInstance * attacker);
};
class MTGPlayerCards {
protected:
void init();
public:
MTGLibrary * library;
MTGGraveyard * graveyard;
MTGHand * hand;
MTGInPlay * inPlay;
MTGStack * stack;
MTGAllCards * collection;
MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize);
~MTGPlayerCards();
void initGame(int shuffle = 1, int draw = 1);
void setOwner(Player * player);
void discardRandom(MTGGameZone * from);
void drawFromLibrary();
void showHand();
void putInGraveyard(MTGCardInstance * card);
void putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGameZone * to);
void putInPlay(MTGCardInstance * card);
int isInPlay(MTGCardInstance * card);
};
#endif
+34
View File
@@ -0,0 +1,34 @@
#ifndef _MTGGUIHAND_H_
#define _MTGGUIHAND_H_
#include "GuiCardsController.h"
#include "Player.h"
#include "GameObserver.h"
#define HAND_SHOW_ANIMATION 1
#define HAND_HIDE_ANIMATION 2
#define HAND_SHOW 3
#define HAND_HIDE 4
class Player;
class GuiCardscontroller;
class MTGGuiHand: public GuiCardsController{
protected:
int currentId[2];
Player * currentPlayer;
int mShowHand;
float mAnimState;
JLBFont * mFont;
public:
MTGGuiHand(int id, GameObserver * _game);
void Update(float dt);
void CheckUserInput(float dt);
virtual void Render();
void updateCards();
};
#endif
+57
View File
@@ -0,0 +1,57 @@
#ifndef _MTGGUIPLAY_H_
#define _MTGGUIPLAY_H_
#define MAX_ATTACKERS 20
#include "PlayGuiObjectController.h"
#include "Player.h"
class Player;
class GameObserver;
class CardGui;
class MTGGuiPlay: public PlayGuiObjectController {
protected:
int offset;
Player * currentPlayer;
MTGCardInstance * cardsGrid[SCREEN_WIDTH/5][SCREEN_HEIGHT/5];
int nb_creatures;
int nb_spells;
int nb_lands;
int cards_x_limit;
JQuad * phaseIcons[24];
JQuad * mGlitter;
int mGlitterAlpha;
float mGlitterX, mGlitterY;
JTexture * mPhaseBarTexture;
JQuad * mIcons[7];
JTexture * mIconsTexture;
JTexture * mBgTex;
JQuad * mBg;
JTexture * mBgTex2;
JQuad * mBg2;
int alphaBg[4];
void RenderPhaseBar();
void RenderPlayerInfo(int player);
JLBFont* mFont;
void AddPlayersGuiInfo();
void initCardsDisplay();
void setCardPosition(CardGui * cardg, int player, int playerTurn, int spellMode);
void setTargettingCardPosition(CardGui * cardg, int player, int playerTurn);
void adjustCardPosition(CardGui * cardg);
public:
CardGui * getByCard(MTGCardInstance * card);
MTGGuiPlay(int id, GameObserver * game);
~MTGGuiPlay();
void Update(float dt);
void CheckUserInput(float dt);
virtual void Render();
void updateCards();
};
#endif
+120
View File
@@ -0,0 +1,120 @@
/* Default observers/Abilities that are added to the game for a standard Magic Game
*/
#ifndef _MTGRULES_H_
#define _MTGRULES_H_
#include "../include/MTGAbility.h"
#include "../include/Counters.h"
class MTGAttackRule:public MTGAbility{
public:
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int testDestroy();
MTGAttackRule(int _id);
const char * getMenuText(){return "Attacker";}
};
class MTGBlockRule:public MTGAbility{
public:
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int testDestroy();
MTGBlockRule(int _id);
const char * getMenuText(){return "Blocker";}
};
/* Persist Rule */
class MTGPersistRule:public ListMaintainerAbility{
public:
MTGPersistRule(int _id):ListMaintainerAbility(_id){};
virtual void Update(float dt){
map<MTGCardInstance *,bool>::iterator it;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCardInstance * card = ((*it).first);
Player * p = card->controller();
if (p->game->graveyard->hasCard(card)){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 1 !\n");
#endif
p->game->putInZone(card, p->game->graveyard, p->game->hand);
Spell * spell = NEW Spell(card);
p->game->putInZone(card, p->game->hand, p->game->stack);
spell->resolve();
delete spell;
#if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 2 !\n");
#endif
card->counters->addCounter(-1,-1);
#if defined (WIN32) || defined (LINUX)
OutputDebugString("persist passed test 3 !\n");
#endif
}
}
ListMaintainerAbility::Update(dt);
}
int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[PERSIST] && !card->counters->hasCounter(-1,-1) ){
#if defined (WIN32) || defined (LINUX)
OutputDebugString("yay, persist !\n");
#endif
return 1;
}
return 0;
}
int added(MTGCardInstance * card){return 1;}
int removed(MTGCardInstance * card){return 0;}
int testDestroy(){return 0;}
};
/*
* Rule 420.5e (Legend Rule)
* If two or more legendary permanents with the same name are in play, all are put into their
* owners' graveyards. This is called the "legend rule." If only one of those permanents is
* legendary, this rule doesn't apply.
*/
class MTGLegendRule:public ListMaintainerAbility{
public:
MTGLegendRule(int _id):ListMaintainerAbility(_id){};
int canBeInList(MTGCardInstance * card){
if (card->basicAbilities[LEGENDARY]){
return 1;
}
return 0;
}
int added(MTGCardInstance * card){
map<MTGCardInstance *,bool>::iterator it;
int destroy = 0;
for ( it=cards.begin() ; it != cards.end(); it++ ){
MTGCardInstance * comparison = (*it).first;
if (comparison!= card && !strcmp(comparison->getName(), card->getName())){
comparison->owner->game->putInGraveyard(comparison);
destroy = 1;
}
}
if (destroy){
card->owner->game->putInGraveyard(card);
}
return 1;
}
int removed(MTGCardInstance * card){return 0;}
int testDestroy(){return 0;}
};
#endif
+44
View File
@@ -0,0 +1,44 @@
#ifndef _MANACOST_H_
#define _MANACOST_H_
#include "../include/utils.h"
#include "../include/MTGDefinitions.h"
class ManaCostHybrid;
class ManaCost{
protected:
int cost[MTG_NB_COLORS+1];
ManaCostHybrid * hybrids[10];
int nbhybrids;
public:
static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL);
void init();
void x();
ManaCost(int _cost[], int nb_elems);
ManaCost();
~ManaCost();
ManaCost(ManaCost * _manaCost);
void copy (ManaCost * _manaCost);
int getConvertedCost();
string toString();
int getCost(int color);
int getMainColor();
int hasColor(int color);
int remove (int color, int value);
int add(int color, int value);
int addHybrid(int c1, int v1, int c2, int v2);
int tryToPayHybrids(ManaCostHybrid * _hybrids[], int _nbhybrids, int diff[]);
void randomDiffHybrids(ManaCost * _cost, int diff[]);
int add(ManaCost * _cost);
int pay (ManaCost * _cost);
//return 1 if _cost can be paid with current data, 0 otherwise
int canAfford(ManaCost * _cost);
int isPositive();
ManaCost * Diff(ManaCost * _cost);
};
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef _MANACOST_HYBRID_H_
#define _MANACOST_HYBRID_H_
class ManaCostHybrid{
public:
int color1;
int color2;
int value1;
int value2;
ManaCostHybrid();
int hasColor(int color);
ManaCostHybrid(int c1,int v1,int c2,int v2);
void init(int c1,int v1,int c2,int v2);
int getConvertedCost();
};
#endif
+43
View File
@@ -0,0 +1,43 @@
#ifndef _MENU_ITEM_H
#define _MENU_ITEM_H
#include <JLBFont.h>
#include <JGui.h>
#include <hge/hgeparticle.h>
#define SCALE_SELECTED 1.2f
#define SCALE_NORMAL 1.0f
class hgeParticleSystem;
class MenuItem: public JGuiObject
{
private:
bool mHasFocus;
JLBFont *mFont;
const char* const mText;
int mX;
int mY;
int updatedSinceLastRender;
float lastDt;
float mScale;
float mTargetScale;
JQuad * onQuad;
JQuad * offQuad;
hgeParticleSystem* mParticleSys;
public:
MenuItem(int id, JLBFont *font, const char* text, int x, int y, JQuad * _off, JQuad * _on, const char * particle, JQuad * particleQuad, bool hasFocus = false);
~MenuItem();
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
};
#endif
+40
View File
@@ -0,0 +1,40 @@
#ifndef _OPTION_ITEM_H_
#define _OPTION_ITEM_H_
#include <JGui.h>
#include <string>
using std::string;
class OptionItem:public JGuiObject{
public:
string displayValue;
int id, value;
int hasFocus;
int maxValue, increment;
float x, y;
OptionItem(int id, string _displayValue, int _maxValue = 1, int _increment = 1);
~OptionItem();
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving();
void setData();
virtual void updateValue(){value+=increment; if (value>maxValue) value=0;};
};
class OptionsList{
public:
OptionItem * options[20];
int nbitems;
int current;
OptionsList();
~OptionsList();
void Render();
void Update(float dt);
void Add(OptionItem * item);
void save();
};
#endif
+78
View File
@@ -0,0 +1,78 @@
/*
A class for all interactive objects in the play area (cards, avatars, etc...)
*/
#ifndef _PLAYGUIOBJECT_H_
#define _PLAYGUIOBJECT_H_
#define GUI_AVATAR 1
#define GUI_CARD 2
#define GUI_GRAVEYARD 3
#define GUI_LIBRARY 4
#include <JGui.h>
class MTGGameZone;
class Player;
class CardDisplay;
class PlayGuiObject: public JGuiObject, public JGuiListener{
protected:
public:
int wave;
float mHeight;
float defaultHeight;
bool mHasFocus;
int x;
int y;
int type;
virtual void Entering(){mHasFocus = true;};
virtual bool Leaving(u32 key){mHasFocus = false;return true;};
virtual bool ButtonPressed(){return true;};
virtual void Render(){};
virtual void Update(float dt);
PlayGuiObject(int id, float desiredHeight,float _x, float _y, bool hasFocus);
virtual void ButtonPressed(int controllerId, int controlId){};
virtual ~PlayGuiObject(){};
};
class GuiAvatar: public PlayGuiObject{
protected:
int avatarRed;
int currentLife;
public:
Player * player;
virtual void Render();
GuiAvatar(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * _player);
};
class GuiGameZone: public PlayGuiObject{
protected:
MTGGameZone * zone;
public:
CardDisplay * cd;
int showCards;
virtual void Render();
virtual void Update(float dt);
GuiGameZone(int id, float desiredHeight,float _x, float _y, bool hasFocus,MTGGameZone * _zone);
~GuiGameZone();
virtual void ButtonPressed(int controllerId, int controlId);
void toggleDisplay();
};
class GuiGraveyard: public GuiGameZone{
public:
GuiGraveyard(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
};
class GuiLibrary: public GuiGameZone{
public:
GuiLibrary(int id, float desiredHeight,float _x, float _y, bool hasFocus,Player * player);
};
#endif
@@ -0,0 +1,21 @@
#ifndef _PLAYGUIOBJECTCONTROLLER_H_
#define _PLAYGUIOBJECTCONTROLLER_H_
#include "GuiLayers.h"
class PlayGuiObjectController : public GuiLayer{
protected:
int getClosestItem(int direction);
int getClosestItem(int direction, float tolerance);
static bool showBigCards;
public:
virtual void Update(float dt);
virtual void CheckUserInput(float dt);
PlayGuiObjectController(int id, GameObserver* _game):GuiLayer(id, _game){};
virtual void Render(){GuiLayer::Render();};
};
#endif
+50
View File
@@ -0,0 +1,50 @@
#ifndef _PLAYER_H_
#define _PLAYER_H_
#include <JGE.h>
#include "ManaCost.h"
#include "MTGGameZones.h"
#include "Damage.h"
#include "Targetable.h"
class MTGPlayerCards;
class MTGInPlay;
class Player: public Damageable, public Targetable{
protected:
ManaCost * manaPool;
public:
int typeAsTarget(){return TARGET_PLAYER;}
virtual int displayStack(){return 1;}
JTexture * mAvatarTex;
JQuad * mAvatar;
int canPutLandsIntoPlay;
MTGPlayerCards * game;
int testLife();
int afterDamage();
Player(MTGPlayerCards * _deck, char * deckFile);
virtual ~Player();
void unTapPhase();
MTGInPlay * inPlay();
ManaCost * getManaPool();
int manaBurn();
void cleanupPhase();
virtual int Act(){return 0;};
virtual int isAI(){return 0;};
Player * opponent();
int getId();
JQuad * getIcon();
string deckFile;
};
class HumanPlayer: public Player{
public:
HumanPlayer(MTGPlayerCards * _deck, char * _deckFile);
};
#endif
+18
View File
@@ -0,0 +1,18 @@
#ifndef _PLAYER_DATA_H_
#define _PLAYER_DATA_H_
#define PLAYER_SAVEFILE "Res/player/data.dat"
#include "../include/MTGDeck.h"
class PlayerData{
protected:
public:
int credits;
MTGDeck * collection;
PlayerData(MTGAllCards * allcards);
~PlayerData();
int save();
};
#endif
+31
View File
@@ -0,0 +1,31 @@
#ifndef _PRICELIST_H_
#define _PRICELIST_H_
#include<string>
#include "../include/MTGDefinitions.h"
#include "../include/MTGDeck.h"
#include <stdio.h>
class Price{
public:
int cardid;
int price;
Price(int _cardid, int _price);
};
class PriceList{
private:
MTGAllCards * collection;
string filename;
Price * prices[TOTAL_NUMBER_OF_CARDS];
int nbprices;
public:
PriceList(const char * file, MTGAllCards * _collection);
~PriceList();
int save();
int getPrice(int cardId);
int setPrice(int cardId, int price);
};
#endif
+71
View File
@@ -0,0 +1,71 @@
#ifndef _SHOP_ITEM_H
#define _SHOP_ITEM_H
#include <JGui.h>
#include <JLBFont.h>
#include "SimpleMenu.h"
#include "MTGDeck.h"
#include "../include/PriceList.h"
#include "../include/PlayerData.h"
#include "../include/CardDisplay.h"
#include <string>
using std::string;
class ShopItem:public JGuiObject{
private:
bool mHasFocus;
JLBFont *mFont;
string mText;
int mX;
int mY;
JQuad * quad;
JQuad * thumb;
float mScale;
float mTargetScale;
public:
int quantity;
MTGCard * card;
int price;
ShopItem(int id, JLBFont * font, int _cardid, int x, int y, bool hasFocus, MTGAllCards * collection, int _price);
ShopItem(int id, JLBFont * font, char* text, JQuad * _quad, JQuad * _thumb,int x, int y, bool hasFocus, int _price);
~ShopItem();
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
const char * getText();
};
class ShopItems:public JGuiController,public JGuiListener{
private:
PlayerData * playerdata;
PriceList * pricelist;
int mX, mY, mHeight;
JLBFont* mFont;
MTGAllCards * collection;
SimpleMenu * dialog;
int showPriceDialog;
int setId;
MTGCardInstance * displayCards[100];
CardDisplay * display;
void safeDeleteDisplay();
public:
ShopItems(int id, JGuiListener* listener, JLBFont* font, int x, int y, MTGAllCards * _collection, int setId);
~ShopItems();
void Render();
virtual void Update(float dt);
void Add(int cardid);
void Add(char * text, JQuad * quad, JQuad * thumb,int _price);
void pricedialog(int id, int mode=1);
virtual void ButtonPressed(int controllerId, int controlId);
void savePriceList();
void saveAll();
};
#endif
+24
View File
@@ -0,0 +1,24 @@
/*
A class for very simple menus structure
*/
#ifndef _SIMPLEMENU_H_
#define _SIMPLEMENU_H_
#include <JGui.h>
#include <JLBFont.h>
#include <string>
class SimpleMenu:public JGuiController{
private:
int mHeight, mWidth, mX, mY;
JLBFont* mFont;
std::string title;
int displaytitle;
public:
SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int y, int width, const char * _title = NULL);
void Render();
void Add(int id, const char * Text);
};
#endif
+37
View File
@@ -0,0 +1,37 @@
#ifndef _SIMPLEMENU_ITEM_H
#define _SIMPLEMENU_ITEM_H
#include <JLBFont.h>
#include <JGui.h>
#define SCALE_SELECTED 1.2f
#define SCALE_NORMAL 1.0f
class SimpleMenuItem: public JGuiObject
{
private:
bool mHasFocus;
JLBFont *mFont;
const char* mText;
int mX;
int mY;
float mScale;
float mTargetScale;
public:
SimpleMenuItem(int id, JLBFont *font, const char* text, int x, int y, bool hasFocus = false);
virtual void Render();
virtual void Update(float dt);
virtual void Entering();
virtual bool Leaving(u32 key);
virtual bool ButtonPressed();
};
#endif
+25
View File
@@ -0,0 +1,25 @@
#ifndef _SUBTYPES_H_
#define _SUBTYPES_H_
#define MAX_SUBTYPES 1000
#include <string>
using std::string;
class Subtypes{
protected:
int nb_items;
string values[MAX_SUBTYPES];
public:
static Subtypes * subtypesList;
Subtypes();
int offset;
int Add(const char * subtype);
int find(const char * subtype);
int Add(string subtype);
int find(string subtype);
};
#endif
+129
View File
@@ -0,0 +1,129 @@
#ifndef _TARGETCHOOSER_H_
#define _TARGETCHOOSER_H_
#define TARGET_NOK 0
#define TARGET_OK 1
#define TARGET_OK_FULL 2
#define TARGET_OK_NOT_READY 3
#include <JGE.h>
#include "../include/TargetsList.h"
#include "../include/ActionStack.h"
#include <string>
using std::string;
class MTGCardInstance;
class MTGGameZone;
class Player;
class Damageable;
class Targetable;
class TargetChooser: public TargetsList {
protected:
int forceTargetListReady;
public:
TargetChooser(MTGCardInstance * card = NULL, int _maxtargets = -1);
MTGCardInstance * source; //Optionnal source, used for protection from...
int maxtargets; //Set to -1 for "unlimited"
int ForceTargetListReady();
int targetsReadyCheck();
virtual int addTarget(Targetable * target);
virtual int canTarget(Targetable * _target);
virtual int full(){if (maxtargets != -1 && cursor>=maxtargets) {return 1;} else{return 0;}};
virtual int ready(){return cursor;};
int targetListSet();
};
class TargetChooserFactory{
public:
TargetChooser * createTargetChooser(string s, MTGCardInstance * card);
TargetChooser * createTargetChooser(MTGCardInstance * card);
};
class TargetZoneChooser:public TargetChooser{
public:
MTGGameZone * zones[6];
int nbzones;
int init(MTGGameZone ** _zones, int _nbzones);
TargetZoneChooser(MTGCardInstance * card = NULL, int _maxtargets = 1);
TargetZoneChooser(MTGGameZone ** _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * _card);
};
class CreatureTargetChooser:public TargetZoneChooser{
public:
int maxpower;
CreatureTargetChooser(MTGGameZone ** _zones, int _nbzones,MTGCardInstance * card = NULL, int _maxtargets = 1);
CreatureTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1);
virtual int canTarget(Targetable * _card);
};
class DamageableTargetChooser:public CreatureTargetChooser{
public:
DamageableTargetChooser(MTGGameZone ** _zones, int _nbzones,MTGCardInstance * card = NULL, int _maxtargets = 1):CreatureTargetChooser( _zones,_nbzones, card, _maxtargets){};
DamageableTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1):CreatureTargetChooser(card, _maxtargets){};
virtual int canTarget(Targetable * target);
};
class PlayerTargetChooser:public TargetChooser{
public:
PlayerTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1):TargetChooser(card, _maxtargets){};
virtual int canTarget(Targetable * target);
};
class TypeTargetChooser:public TargetZoneChooser{
public:
int nbtypes;
int types[10];
TypeTargetChooser(const char * _type, MTGCardInstance * card = NULL, int _maxtargets = 1);
TypeTargetChooser(const char * _type, MTGGameZone ** _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1);
void addType(int type);
void addType(const char * type);
virtual int canTarget(Targetable * targe);
};
class SpellTargetChooser:public TargetChooser{
public:
int color;
SpellTargetChooser( MTGCardInstance * card = NULL,int _color = -1, int _maxtargets = 1 );
virtual int canTarget(Targetable * target);
};
class SpellOrPermanentTargetChooser:public TargetZoneChooser{
public:
int color;
SpellOrPermanentTargetChooser(MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1);
virtual int canTarget(Targetable * target);
};
class DamageTargetChooser:public TargetChooser{
public:
int color;
int state;
DamageTargetChooser( MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1, int state = NOT_RESOLVED);
virtual int canTarget(Targetable * target);
};
class DamageOrPermanentTargetChooser:public TargetZoneChooser{
public:
int color;
DamageOrPermanentTargetChooser(MTGCardInstance * card = NULL,int _color = -1 , int _maxtargets = 1);
virtual int canTarget(Targetable * target);
};
#endif
+13
View File
@@ -0,0 +1,13 @@
#ifndef _TARGETABLE_H_
#define _TARGETABLE_H_
#define TARGET_CARD 1
#define TARGET_PLAYER 2
#define TARGET_STACKACTION 3
class Targetable{
public:
virtual int typeAsTarget() = 0;
};
#endif
+34
View File
@@ -0,0 +1,34 @@
#ifndef _TARGETSLIST_H_
#define _TARGETSLIST_H_
#define MAX_TARGETS 20
class Targetable;
class MTGCardInstance;
class Player;
class Damageable;
class Spell;
class Interruptible;
class Damage;
class TargetsList{
public:
int cursor;
TargetsList();
TargetsList(Targetable * _targets[], int nbtargets);
Targetable* targets[MAX_TARGETS];
int alreadyHasTarget(Targetable * target);
int removeTarget(Targetable * _card);
int toggleTarget(Targetable * _card);
virtual int addTarget(Targetable * _target);
MTGCardInstance * getNextCardTarget(MTGCardInstance * previous = 0);
Player * getNextPlayerTarget(Player * previous = 0);
Damageable * getNextDamageableTarget(Damageable * previous = 0);
Interruptible * getNextInterruptible(Interruptible * previous, int type);
Spell * getNextSpellTarget(Spell * previous = 0);
Damage * getNextDamageTarget(Damage * previous = 0);
Targetable * getNextTarget(Targetable * previous, int type);
void initTargets(){cursor = 0;};
};
#endif
+84
View File
@@ -0,0 +1,84 @@
#ifndef _TESTSUITE_AI_H_
#define _TESTSUITE_AI_H_
#define MAX_TESTSUITE_ACTIONS 100
#define MAX_TESTUITE_CARDS 100
#include "../include/AIPlayer.h"
class TestSuiteActions{
public:
int nbitems;
string actions[MAX_TESTSUITE_ACTIONS];
void add(string action);
TestSuiteActions();
void cleanup();
};
class TestSuitePlayerZone{
public:
int cards[MAX_TESTUITE_CARDS];
int nbitems;
void add(int cardid);
TestSuitePlayerZone();
void cleanup();
};
class TestSuitePlayerData{
public:
int life;
ManaCost * manapool;
TestSuitePlayerZone zones[5];
TestSuitePlayerData();
~TestSuitePlayerData();
void cleanup();
};
class TestSuiteState{
public:
int phase;
void parsePlayerState(int playerId, string s);
TestSuiteState();
TestSuitePlayerData playerData[2];
void cleanup();
};
class TestSuite{
public:
int currentAction;
TestSuiteState initState;
TestSuiteState endState;
TestSuiteActions actions;
string files[128];
int nbfiles;
int currentfile;
void load(const char * filename);
TestSuite(const char * filename);
void initGame();
int assertGame();
MTGPlayerCards * buildDeck(MTGAllCards * collection, int playerId);
string getNextAction();
int phaseStrToInt(string s);
MTGCardInstance * getCardByMTGId(int mtgid);
Interruptible * getActionByMTGId(int mtgid);
int loadNext();
void cleanup();
int Log(const char * text);
};
class TestSuiteAI:public AIPlayer{
public:
TestSuite * suite;
int timer;
TestSuiteAI(MTGAllCards * collection,TestSuite * suite, int playerId);
virtual int Act();
virtual int displayStack(){return 1;}
};
#endif
+58
View File
@@ -0,0 +1,58 @@
#ifndef _TEXTURES_CACHE_H
#define _TEXTURES_CACHE_H
#define MAX_CACHE_OBJECTS 100
#define CACHE_SIZE_PIXELS 1000000
#define CACHE_CARD 1
#define CACHE_THUMB 2
#include <JGE.h>
#include <JTypes.h>
#include "MTGDeck.h"
class MTGCard;
class CardTexture{
protected:
int mtgid;
JTexture* tex;
JQuad* quad;
public:
int lastTime;
int type;
int nbpixels;
int getId();
JQuad * getQuad();
CardTexture(MTGCard * card, int type);
~CardTexture();
};
class TexturesCache{
protected:
int lastTime;
int nb_textures;
int delete_previous;
int totalsize;
CardTexture * cache[MAX_CACHE_OBJECTS];
public:
int isInCache(MTGCard * card, int type=CACHE_CARD);
TexturesCache();
~TexturesCache();
int getOldestQuad();
void removeQuad(int id);
int cleanup();
int getCacheById(int id, int type=CACHE_CARD);
JQuad * getQuad(MTGCard * card, int type=CACHE_CARD);
JQuad * getThumb(MTGCard * card){return getQuad(card, CACHE_THUMB);};
};
#endif
+43
View File
@@ -0,0 +1,43 @@
#ifndef _INCLUDEALL_H_
#define _INCLUDEALL_H_
class MTGPlayerCards;
class MTGCardInstance;
class MTGCard;
class GameObserver;
class TexturesCache;
class MTGAbility;
class Player;
class CardGui;
class ActionElement;
class DuelLayers;
class MTGInPlay;
class MTGGamePhase;
#include "CardGui.h"
#include "GuiLayers.h"
#include "GuiCardsController.h"
#include "MTGGuiPlay.h"
#include "MTGGuiHand.h"
#include "ManaCost.h"
#include "TexturesCache.h"
#include "MTGAbility.h"
#include "MTGGameZones.h"
#include "ActionElement.h"
#include "ActionLayer.h"
#include "MTGGamePhase.h"
#include "DuelLayers.h"
#include "GameObserver.h"
#include "MTGDeck.h"
#include "Player.h"
#endif
+5
View File
@@ -0,0 +1,5 @@
#ifndef _ALLTARGETCHOOSERS_H_
#define _ALLTARGETCHOOSERS_H_
#endif
+19
View File
@@ -0,0 +1,19 @@
#ifndef _DEBUG_H_
#define _DEBUG_H_
#ifdef _DEBUG
#define NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define TESTSUITE 1
#else
#define NEW new
#endif
#ifdef LINUX
#ifdef _DEBUG
#define OutputDebugString(val) (std::cerr << val);
#else
#define OutputDebugString(val)
#endif
#endif
#endif
+50
View File
@@ -0,0 +1,50 @@
#ifndef _UTILS_H_
#define _UTILS_H_
#include <JGE.h>
#if defined (WIN32) || defined (LINUX)
#else
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspiofilemgr.h>
#include <pspdebug.h>
#include <psputility.h>
#include <pspgu.h>
#include <psprtc.h>
#endif
#include <math.h>
#include <stdio.h>
#include <string>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#define BUFSIZE 600
using std::string;
template <typename T, size_t N>
char ( &_ArraySizeHelper( T (&array)[N] ))[N];
#define countof( array ) (sizeof( _ArraySizeHelper( array ) ))
int lowercase(string source);
int substr_copy(char *source, char *target, int start, int len);
int append_str(char * s1, char * s2, char * target);
int filesize(const char * filename);
int read_file (const char * filename, char * buffer, int filesize);
int readline (char * in_buffer, char * out_buffer, int cursor);
int readfile_to_ints(const char * filename, int * out_buffer);
#endif