- It is now possible to have avatars associated to each Deck
- Added SFX
- Added Music files
- Possibility to choose your opponent
- Opponents' difficulty is measured according to their number of victories against a given deck
This commit is contained in:
wagic.the.homebrew
2008-11-24 09:24:47 +00:00
parent a9e70c0bdc
commit 3721247bee
69 changed files with 734 additions and 259 deletions
+30 -18
View File
@@ -15,7 +15,10 @@ AIPlayer::AIPlayer(MTGPlayerCards * _deck, string file): Player(_deck, file){
AIPlayer::~AIPlayer(){
if (potentialMana) delete potentialMana;
SAFE_DELETE(stats);
if (stats){
stats->save();
delete stats;
}
}
MTGCardInstance * AIPlayer::chooseCard(TargetChooser * tc, MTGCardInstance * source, int random){
for (int i = 0; i < game->hand->nb_cards; i++){
@@ -392,24 +395,29 @@ AIStats * AIPlayer::getStats(){
return stats;
}
AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, MTGPlayerCards * oponents_deck){
int nbdecks = 0;
int found = 1;
while (found){
found = 0;
char buffer[512];
sprintf(buffer, "Res/ai/baka/deck%i.txt",nbdecks+1);
std::ifstream file(buffer);
if(file){
found = 1;
file.close();
nbdecks++;
AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, MTGPlayerCards * oponents_deck, int deckid){
if (!deckid){
int nbdecks = 0;
int found = 1;
while (found){
found = 0;
char buffer[512];
sprintf(buffer, "Res/ai/baka/deck%i.txt",nbdecks+1);
std::ifstream file(buffer);
if(file){
found = 1;
file.close();
nbdecks++;
}
}
if (!nbdecks) return NULL;
deckid = 1 + rand() % (nbdecks);
}
if (!nbdecks) return NULL;
int deckid = 1 + rand() % (nbdecks);
char deckFile[512];
sprintf(deckFile, "Res/ai/baka/deck%i.txt",deckid);
char avatarFile[512];
sprintf(avatarFile, "ai/baka/avatars/avatar%i.jpg",deckid);
char deckFileSmall[512];
sprintf(deckFileSmall, "ai_baka_deck%i",deckid);
#if defined (WIN32) || defined (LINUX)
@@ -420,7 +428,7 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, MTGPlayerCa
int deck_cards_ids[100];
int nb_elements = readfile_to_ints(deckFile, deck_cards_ids);
MTGPlayerCards * deck = NEW MTGPlayerCards(collection,deck_cards_ids, nb_elements);
AIPlayerBaka * baka = NEW AIPlayerBaka(deck,deckFileSmall);
AIPlayerBaka * baka = NEW AIPlayerBaka(deck,deckFileSmall, avatarFile);
return baka;
}
@@ -460,8 +468,12 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * potentialMana, const c
return nextCardToPlay;
}
AIPlayerBaka::AIPlayerBaka(MTGPlayerCards * _deck, char * file): AIPlayer(_deck,file){
mAvatarTex = JRenderer::GetInstance()->LoadTexture("ai/baka/avatar.jpg", TEX_TYPE_USE_VRAM);
AIPlayerBaka::AIPlayerBaka(MTGPlayerCards * _deck, char * file, char * avatarFile): AIPlayer(_deck,file){
if (fileExists(avatarFile)){
mAvatarTex = JRenderer::GetInstance()->LoadTexture(avatarFile, TEX_TYPE_USE_VRAM);
}else{
mAvatarTex = JRenderer::GetInstance()->LoadTexture("ai/baka/avatar.jpg", TEX_TYPE_USE_VRAM);
}
if (mAvatarTex)
mAvatar = NEW JQuad(mAvatarTex, 0, 0, 35, 50);
initTimer();
-1
View File
@@ -61,7 +61,6 @@ void AIStats::updateStats(){
damage = ((Damage * )as->getNext(damage,ACTION_DAMAGE, RESOLVED_OK));
}
stats.sort(compare_aistats);
save();
}
bool AIStats::isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCountsForTrue ){
+10
View File
@@ -7,6 +7,7 @@
#include "../include/GameObserver.h"
#include "../include/Damage.h"
#include "../include/ManaCost.h"
#include "../include/GameOptions.h"
/*
NextGamePhase requested by user
@@ -85,6 +86,15 @@ int Spell::resolve(){
GameObserver * game = GameObserver::GetInstance();
//TODO Remove target if it's not targettable anymore
source->controller()->game->putInPlay(source);
//Play SFX
if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME] > 0){
JSample * sample = source->getSample();
if (sample){
JSoundSystem::GetInstance()->PlaySample(sample);
}
}
AbilityFactory af;
af.addAbilities(game->mLayers->actionLayer()->getMaxId(), this);
return 1;
+16 -8
View File
@@ -59,6 +59,7 @@ void CardGui::alternateRender(MTGCard * card, JLBFont * mFont, JQuad ** manaIcon
ManaCost * manacost = card->getManaCost();
int nbicons = 0;
for (int i = 1; i < MTG_NB_COLORS - 1; i++){
int cost = manacost->getCost(i);
for (int j=0; j < cost; j++){
v.x = (width/2 - 20 - 16*nbicons)*scale;
@@ -74,13 +75,13 @@ void CardGui::alternateRender(MTGCard * card, JLBFont * mFont, JQuad ** manaIcon
v.y = ((-height/2) + 14) * scale;
v.Rotate(rotation);
sprintf(buf,"%i",cost);
mFont->SetColor(ARGB(255,255,255,255));
mFont->DrawString(buf,x+v.x,y+v.y);
}
if (!card->formattedTextInit){
std::string s(card->getText());
std::string::size_type found=s.find_first_of("{}");
while (found!=string::npos)
{
s[found]='/';
@@ -201,9 +202,7 @@ void CardGui::Update(float dt){
PlayGuiObject::Update(dt);
}
void CardGui::RenderBig(float xpos, float ypos){
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = card->getQuad();
void CardGui::RenderBig(float xpos, float ypos, int alternate){
if (xpos == -1){
xpos = 300;
if (x > SCREEN_WIDTH / 2)
@@ -211,10 +210,19 @@ void CardGui::RenderBig(float xpos, float ypos){
}
if(ypos == -1)
ypos = 20;
if (quad){
quad->SetColor(ARGB(220,255,255,255));
renderer->RenderQuad(quad, xpos , ypos , 0.0f,0.9f,0.9f);
}else{
if (!alternate){
JRenderer * renderer = JRenderer::GetInstance();
JQuad * quad = card->getQuad();
if (quad){
quad->SetColor(ARGB(220,255,255,255));
renderer->RenderQuad(quad, xpos , ypos , 0.0f,0.9f,0.9f);
}else{
alternate = 1;
}
}
if (alternate){
MTGCard * mtgcard = card->model;
JLBFont * font = GameApp::CommonRes->GetJLBFont("graphics/magic");
CardGui::alternateRender(mtgcard, font, NULL, xpos + 90 , ypos + 130, 0.0f,0.9f);
+98
View File
@@ -0,0 +1,98 @@
#include "../include/debug.h"
#include "../include/DeckStats.h"
#include "../include/Player.h"
DeckStats * DeckStats::mInstance = NULL;
int DeckStat::percentVictories(){
if (nbgames == 0) return 50;
return (100 * victories / nbgames);
}
DeckStats * DeckStats::GetInstance(){
if (!mInstance) mInstance = NEW DeckStats();
return mInstance;
}
void DeckStats::cleanStats(){
map<string,DeckStat *>::iterator it;
for (it = stats.begin(); it != stats.end(); it++){
delete(it->second);
}
stats.clear();
}
DeckStats::~DeckStats(){
cleanStats();
}
int DeckStats::percentVictories(string opponentsFile){
map<string,DeckStat *>::iterator it = stats.find(opponentsFile);
if (it == stats.end()){
return 50;
}else{
return (it->second->percentVictories());
}
}
void DeckStats::load(Player * player){
char filename[512];
sprintf(filename, "Res/player/stats/%s.txt",player->deckFile.c_str());
load(filename);
}
void DeckStats::load(const char * filename){
cleanStats();
std::ifstream file(filename);
std::string s;
if(file){
while(std::getline(file,s)){
string deckfile = s;
std::getline(file,s);
int games = atoi(s.c_str());
std::getline(file,s);
int victories = atoi(s.c_str());
stats[deckfile] = NEW DeckStat(games,victories);
}
file.close();
}
}
void DeckStats::save(Player * player){
char filename[512];
sprintf(filename, "Res/player/stats/%s.txt",player->deckFile.c_str());
save(filename);
}
void DeckStats::save(const char * filename){
std::ofstream file(filename);
char writer[512];
if (file){
map<string,DeckStat *>::iterator it;
for (it = stats.begin(); it != stats.end(); it++){
sprintf(writer,"%s\n", it->first.c_str());
file<<writer;
sprintf(writer,"%i\n", it->second->nbgames);
file<<writer;
sprintf(writer,"%i\n", it->second->victories);
file<<writer;
}
file.close();
}
}
void DeckStats::saveStats(Player *player, Player *opponent, GameObserver * game){
int victory = 1;
if (game->gameOver == player) victory = 0;
load(player);
map<string,DeckStat *>::iterator it = stats.find(opponent->deckFile);
if (it == stats.end()){
stats[opponent->deckFile] = NEW DeckStat(1,victory);
}else{
it->second->victories+=victory;
it->second->nbgames+=1;
}
save(player);
}
+5 -1
View File
@@ -15,7 +15,7 @@
#include "../include/GameStateDuel.h"
#include "../include/GameStateOptions.h"
#include "../include/GameStateShop.h"
#include "../include/DeckStats.h"
const char * const GameState::menuTexts[]= {"--NEW--","Deck 1", "Deck 2", "Deck 3", "Deck 4", "Deck 5", "Deck 6"} ;
JResourceManager* GameApp::CommonRes = NEW JResourceManager();
@@ -179,6 +179,10 @@ void GameApp::Destroy()
if (Subtypes::subtypesList) delete Subtypes::subtypesList;
if (MtgSets::SetsList) delete MtgSets::SetsList;
SAFE_DELETE(music);
delete(DeckStats::GetInstance());
LOG("==Destroying GameApp Successful==");
}
+113 -39
View File
@@ -3,6 +3,8 @@
#include "../include/utils.h"
#include "../include/AIPlayer.h"
#include "../include/PlayerData.h"
#include "../include/DeckStats.h"
#ifdef TESTSUITE
#include "../include/TestSuiteAI.h"
@@ -16,6 +18,7 @@ GameStateDuel::GameStateDuel(GameApp* parent): GameState(parent) {
game = NULL;
deckmenu = NULL;
opponentMenu = NULL;
menu = NULL;
#ifdef TESTSUITE
testSuite = NULL;
@@ -43,6 +46,7 @@ void GameStateDuel::Start()
mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
mFont->SetBase(0); // using 2nd font
opponentMenuFont = NEW JLBFont("graphics/f3",16);
menu = NEW SimpleMenu(11,this,mFont,SCREEN_WIDTH/2-100,20,200);
@@ -79,16 +83,22 @@ void GameStateDuel::Start()
}
void GameStateDuel::loadPlayer(int playerId, int decknb){
if (decknb){ //Human Player
char deckFile[255];
sprintf(deckFile, "Res/player/deck%i.txt",decknb);
char deckFileSmall[255];
sprintf(deckFileSmall, "player_deck%i",decknb);
int deck_cards_ids[100];
int nb_elements = readfile_to_ints(deckFile, deck_cards_ids);
deck[playerId] = NEW MTGPlayerCards(mParent->collection,deck_cards_ids, nb_elements);
mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFileSmall);
void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
if (decknb){
if (!isAI){ //Human Player
char deckFile[255];
sprintf(deckFile, "Res/player/deck%i.txt",decknb);
char deckFileSmall[255];
sprintf(deckFileSmall, "player_deck%i",decknb);
int deck_cards_ids[100];
int nb_elements = readfile_to_ints(deckFile, deck_cards_ids);
deck[playerId] = NEW MTGPlayerCards(mParent->collection,deck_cards_ids, nb_elements);
mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFileSmall);
}else{ //AI Player, chose deck
AIPlayerFactory playerCreator;
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection,NULL,decknb);
deck[playerId] = mPlayers[playerId]->game;
}
}else{
AIPlayerFactory playerCreator;
mPlayers[playerId] = playerCreator.createAIPlayer(mParent->collection,NULL);
@@ -127,15 +137,21 @@ void GameStateDuel::End()
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Ending GamestateDuel\n");
#endif
GameObserver::EndInstance();
game = NULL;
SAFE_DELETE(deckmenu);
JRenderer::GetInstance()->EnableVSync(false);
if (mPlayers[0] && mPlayers[1]) mPlayers[0]->End();
GameObserver::EndInstance();
game = NULL;
for (int i = 0; i < 2; i++){
SAFE_DELETE(mPlayers[i]);
SAFE_DELETE(deck[i]);
}
SAFE_DELETE(menu);
SAFE_DELETE(opponentMenu);
SAFE_DELETE(opponentMenuFont);
#ifdef TESTSUITE
SAFE_DELETE(testSuite);
#endif
@@ -176,8 +192,43 @@ void GameStateDuel::Update(float dt)
}
else{
loadPlayer(1);
mGamePhase = DUEL_PLAY;
if (mParent->players[0] == PLAYER_TYPE_HUMAN){
if (!opponentMenu){
opponentMenu = NEW SimpleMenu(13,this,opponentMenuFont,10,10,SCREEN_WIDTH/2,"choose Opponent");
opponentMenu->Add(0,"Random");
nbAIDecks = 0;
int found = 1;
while (found){
found = 0;
char buffer[512];
char aiSmallDeckName[512];
char deckDesc[512];
sprintf(buffer, "Res/ai/baka/deck%i.txt",nbAIDecks+1);
if(fileExists(buffer)){
found = 1;
nbAIDecks++;
sprintf(aiSmallDeckName, "ai_baka_deck%i",nbAIDecks);
DeckStats * stats = DeckStats::GetInstance();
stats->load(mPlayers[0]);
int percentVictories = stats->percentVictories(string(aiSmallDeckName));
string difficulty;
if (percentVictories < 34){
difficulty = "(hard)";
}else if (percentVictories < 67){
difficulty = "";
}else{
difficulty = "(easy)";
}
sprintf(deckDesc, "Deck %i %s",nbAIDecks, difficulty.c_str());
opponentMenu->Add(nbAIDecks,deckDesc);
}
}
}
opponentMenu->Update(dt);
}else{
loadPlayer(1);
mGamePhase = DUEL_PLAY;
}
}
}else if (mGamePhase == DUEL_PLAY){
@@ -259,14 +310,17 @@ void GameStateDuel::Render()
}else{
int winner = 2;
if (game->gameOver !=mPlayers[0]){
winner = 1;
winner = 1;
}
sprintf(buffer, "Player %i wins (%i)", winner, p0life );
}
mFont->DrawString(buffer, 10, 150);
}else if (mGamePhase == DUEL_CHOOSE_DECK1 || mGamePhase == DUEL_CHOOSE_DECK2){
if (deckmenu)
if (opponentMenu){
opponentMenu->Render();
}else if (deckmenu){
deckmenu->Render();
}
}else if (mGamePhase == ERROR_NO_DECK){
mFont->DrawString("NO DECK AVAILABLE,",0,SCREEN_HEIGHT/2);
mFont->DrawString("PRESS CIRCLE TO GO TO THE DECK EDITOR!",0,SCREEN_HEIGHT/2 + 20);
@@ -278,30 +332,50 @@ void GameStateDuel::Render()
void GameStateDuel::ButtonPressed(int controllerId, int controlId)
{
switch (controlId)
{
case 1:
case 2:
case 3:
case 4:
case 5:
{
if (mGamePhase == DUEL_CHOOSE_DECK1){
loadPlayer(0,controlId);
mGamePhase = DUEL_CHOOSE_DECK2;
}else{
loadPlayer(1,controlId);
mGamePhase = DUEL_PLAY;
}
break;
}
case 12:
mParent->SetNextState(GAME_STATE_MENU);
break;
switch (controllerId){
case 13:
mGamePhase = DUEL_PLAY;
break;
}
{
switch(controlId){
case 0:
loadPlayer(1);
mGamePhase = DUEL_PLAY;
break;
default:
loadPlayer(1,controlId,1);
mGamePhase = DUEL_PLAY;
break;
}
break;
}
default:
{
switch (controlId)
{
case 1:
case 2:
case 3:
case 4:
case 5:
{
if (mGamePhase == DUEL_CHOOSE_DECK1){
loadPlayer(0,controlId);
mGamePhase = DUEL_CHOOSE_DECK2;
}else{
loadPlayer(1,controlId);
mGamePhase = DUEL_PLAY;
}
break;
}
case 12:
mParent->SetNextState(GAME_STATE_MENU);
break;
case 13:
mGamePhase = DUEL_PLAY;
break;
}
}
}
}
+25 -8
View File
@@ -17,12 +17,15 @@ GameStateOptions::~GameStateOptions() {
void GameStateOptions::Start()
{
timer = 0;
mState = SHOW_OPTIONS;
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
optionsList = NEW OptionsList();
if (GameApp::HasMusic) optionsList->Add(NEW OptionItem(OPTIONS_MUSICVOLUME, "Music volume", 100, 10));
optionsList->Add(NEW OptionItem(OPTIONS_SFXVOLUME, "SFX volume", 100, 10));
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170,SCREEN_WIDTH-120);
optionsMenu->Add(1, "Save & Back to Main Menu");
@@ -41,6 +44,8 @@ void GameStateOptions::End()
void GameStateOptions::Update(float dt)
{
timer+= dt;
if (mState == SHOW_OPTIONS){
if (mEngine->GetButtonClick(PSP_CTRL_START)){
mState = SHOW_OPTIONS_MENU;
@@ -59,17 +64,18 @@ void GameStateOptions::Render()
{
//Erase
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
optionsList->Render();
const char * const CreditsText[] = {
"Wagic, The Homebrew ?! by WilLoW",
"This is a work in progress and it contains bugs, deal with it",
"updates on http://www.wololo.net/wagic",
"Many thanks to Abrasax and J for their help in this release",
"",
"Developped with the JGE++ Library",
"http://jge.khors.com",
"Developped with the JGE++ Library (http://jge.khors.com)",
"",
"this freeware app is not endorsed by Wizards of the Coast, Inc",
"",
"SFX From www.soundsnap.com",
};
@@ -80,24 +86,35 @@ void GameStateOptions::Render()
};
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/magic");
mFont->SetColor(ARGB(255,200,200,200));
mFont->SetScale(0.80);
for (int i = 0; i < 8; i++){
mFont->DrawString(CreditsText[i],SCREEN_WIDTH/2, 40 +18*i,JGETEXT_CENTER);
mFont->SetScale(1.0);
float startpos = 272 - timer * 10;
float pos = startpos;
for (int i = 0; i < 10; i++){
pos = startpos +20*i;
if (pos > -20){
mFont->DrawString(CreditsText[i],SCREEN_WIDTH/2,pos ,JGETEXT_CENTER);
}
}
if (GameApp::HasMusic){
for (int i = 0; i < 3; i++){
mFont->DrawString(MusicText[i],SCREEN_WIDTH/2, 40 +18*(8+i),JGETEXT_CENTER);
pos = startpos +20*(10+i);
if (pos > -20){
mFont->DrawString(MusicText[i],SCREEN_WIDTH/2, pos,JGETEXT_CENTER);
}
}
}
if (pos < -20) timer = 0;
mFont->SetScale(1.f);
if (mState == SHOW_OPTIONS_MENU){
optionsMenu->Render();
}
optionsList->Render();
}
+12 -4
View File
@@ -26,14 +26,19 @@ void GameStateShop::Start()
{
menu = NULL;
mFont = GameApp::CommonRes->GetJLBFont("graphics/magic");
mStage = STAGE_SHOP_SHOP;
bgTexture = JRenderer::GetInstance()->LoadTexture("graphics/shop.jpg", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(bgTexture, 0, 0, 400, 280); // Create background quad for rendering.
backTexture = JRenderer::GetInstance()->LoadTexture("sets/back.jpg", TEX_TYPE_USE_VRAM);
mBack = NEW JQuad(backTexture, 0, 0, 200, 285); // Create background quad for rendering.
JRenderer::GetInstance()->ResetPrivateVRAM();
JRenderer::GetInstance()->EnableVSync(true);
int sets[500];
int nbsets = 0;
for (int i = 0; i < MtgSets::SetsList->nb_items; i++){
@@ -48,6 +53,9 @@ void GameStateShop::Start()
setId = (rand() % MtgSets::SetsList->nb_items);
}
JQuad * mBackThumb = GameApp::CommonRes->GetQuad("back_thumb");
shop = NULL;
shop = NEW ShopItems(10, this, mFont, 10, 10, mParent->collection, setId);
sprintf(starterBuffer, "%s Starter (60 cards)",MtgSets::SetsList->values[setId].c_str());
sprintf(boosterBuffer, "%s Booster (15 cards)",MtgSets::SetsList->values[setId].c_str());
@@ -63,9 +71,9 @@ void GameStateShop::Start()
void GameStateShop::End()
{
JRenderer::GetInstance()->EnableVSync(false);
if (shop)
SAFE_DELETE(shop);
SAFE_DELETE(shop);
SAFE_DELETE(mBack);
SAFE_DELETE(backTexture);
if(bgTexture)
SAFE_DELETE(bgTexture);
if(mBg)
@@ -115,11 +123,11 @@ void GameStateShop::ButtonPressed(int controllerId, int controlId)
{
switch (controllerId){
case 10:
shop->pricedialog(controlId);
if (shop) shop->pricedialog(controlId);
break;
case 11:
if (controlId == 12){
shop->saveAll();
if (shop) shop->saveAll();
mParent->SetNextState(GAME_STATE_MENU);
}else{
mStage = STAGE_SHOP_SHOP;
+1 -1
View File
@@ -8,7 +8,7 @@ using namespace std;
#include <windows.h>
#endif
void Logger::Log(char * text){
void Logger::Log(const char * text){
ofstream file (LOG_FILE,ios_base::app);
if (file){
file << text;
+41
View File
@@ -8,6 +8,7 @@
#include "../include/MTGCardInstance.h"
#include "../include/CardDescriptor.h"
#include "../include/Counters.h"
#include "../include/Subtypes.h"
MTGCardInstance::MTGCardInstance(): MTGCard(), Damageable(0){
LOG("==Creating MTGCardInstance==");
@@ -33,6 +34,7 @@ MTGCardInstance::~MTGCardInstance(){
LOG("==Deleting MTGCardInstance Succesfull==");
}
void MTGCardInstance::initMTGCI(){
sample = "";
model=NULL;
lifeOrig = 0;
doDamageTest = 0;
@@ -405,3 +407,42 @@ int MTGCardInstance::protectedAgainst(MTGCardInstance * card){
}
return 0;
}
/* Choose a sound sample to associate to that card */
JSample * MTGCardInstance::getSample(){
if (!sample.size()){
for (int i = nb_types-1; i>0; i--){
string type = Subtypes::subtypesList->find(types[i]);
type = "sound/sfx/" + type + ".wav";
#ifdef WIN32
OutputDebugString(type.c_str());
#endif
if (fileExists(type.c_str())){
sample = string(type);
break;
}
}
}
if (!sample.size()){
for (int i = 0; i < NB_BASIC_ABILITIES; i++){
if (!basicAbilities[i]) continue;
string type = MTGBasicAbilities[i];
type = "sound/sfx/" + type + ".wav";
if (fileExists(type.c_str())){
sample = type;
break;
}
}
}
if (!sample.size()){
string type = Subtypes::subtypesList->find(types[0]);
type = "sound/sfx/" + type + ".wav";
if (fileExists(type.c_str())){
sample = type;
}
}
if (sample.size()) return SampleCache::GetInstance()->getSample(sample);
return NULL;
}
+1 -1
View File
@@ -77,7 +77,7 @@ int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
card->setType( "Artifact");
card->setColor(MTG_COLOR_ARTIFACT);
if (value.c_str()[8] == ' ' && value.c_str()[9] == 'C')
card->setSubtype("Creature");
card->setSubtype("Creature");
break;
case 'E':
card->setType( "Enchantment");
+10 -2
View File
@@ -1,6 +1,7 @@
#include "../include/debug.h"
#include "../include/MTGGameZones.h"
#include "../include/Player.h"
#include "../include/GameOptions.h"
#if defined (WIN32) || defined (LINUX)
#include <time.h>
@@ -90,9 +91,16 @@ void MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone * from, MTGGa
if (from->removeCard(card)){
to->addCard(card);
card->changedZoneRecently = 1.f;
//if (to == graveyard){
card->reset();
//}
if (GameOptions::GetInstance()->values[OPTIONS_SFXVOLUME] > 0){
if (to == graveyard){
if (card->isACreature()){
JSample * sample = SampleCache::GetInstance()->getSample("sound/sfx/graveyard.wav");
if (sample) JSoundSystem::GetInstance()->PlaySample(sample);
}
}
}
}
}
+1 -1
View File
@@ -95,7 +95,7 @@ void MTGGuiHand::Render(){
}
if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render();
if (showBigCards) ((CardGui *)mObjects[mCurr])->RenderBig(10);
if (showBigCards) ((CardGui *)mObjects[mCurr])->RenderBig(10,-1,showBigCards-1);
}
}
}
+3 -2
View File
@@ -361,8 +361,9 @@ void MTGGuiPlay::Render(){
if (mCount && mObjects[mCurr] != NULL){
mObjects[mCurr]->Render();
if (hasFocus && mCurr >= offset && showBigCards)
((CardGui *)mObjects[mCurr])->RenderBig();
if (hasFocus && mCurr >= offset && showBigCards && last_user_move > BIG_CARD_RENDER_TIME){
((CardGui *)mObjects[mCurr])->RenderBig(-1,-1,showBigCards-1);
}
}
if (mGlitterAlpha < 0){
+1
View File
@@ -31,6 +31,7 @@ void OptionItem::Render(){
mFont->SetColor(ARGB(255,255,255,255));
}
JRenderer * renderer = JRenderer::GetInstance();
renderer->FillRoundRect(x-5,y-2,SCREEN_WIDTH -x - 5,20,2,ARGB(150,50,50,50));
mFont->DrawString(displayValue.c_str(),x,y);
char buf[512];
sprintf(buf, "%i", value);
+8 -2
View File
@@ -4,7 +4,7 @@
#include "../include/PlayGuiObject.h"
#include "../include/GameObserver.h"
bool PlayGuiObjectController::showBigCards = true;
int PlayGuiObjectController::showBigCards = 1;
int PlayGuiObjectController::getClosestItem(int direction){
return getClosestItem(direction, 35);
@@ -177,6 +177,7 @@ void PlayGuiObjectController::Update(float dt){
void PlayGuiObjectController::CheckUserInput(float dt){
last_user_move +=dt;
if (!mCount)
return;
if (game != NULL){
@@ -193,6 +194,8 @@ void PlayGuiObjectController::CheckUserInput(float dt){
if (mEngine->GetButtonState(PSP_CTRL_LEFT))
{
last_user_move = 0;
if (KeyRepeated(PSP_CTRL_LEFT, dt))
{
int n = getClosestItem(DIR_LEFT);
@@ -205,6 +208,7 @@ void PlayGuiObjectController::CheckUserInput(float dt){
}
else if (mEngine->GetButtonState(PSP_CTRL_RIGHT))
{
last_user_move = 0;
if (KeyRepeated(PSP_CTRL_RIGHT, dt))
{
int n = getClosestItem(DIR_RIGHT);
@@ -217,6 +221,7 @@ void PlayGuiObjectController::CheckUserInput(float dt){
}
else if (mEngine->GetButtonState(PSP_CTRL_UP))
{
last_user_move = 0;
if (KeyRepeated(PSP_CTRL_UP, dt))
{
int n = getClosestItem(DIR_UP);
@@ -229,6 +234,7 @@ void PlayGuiObjectController::CheckUserInput(float dt){
}
else if (mEngine->GetButtonState(PSP_CTRL_DOWN))
{
last_user_move = 0;
if (KeyRepeated(PSP_CTRL_DOWN, dt))
{
int n = getClosestItem(DIR_DOWN);
@@ -239,7 +245,7 @@ void PlayGuiObjectController::CheckUserInput(float dt){
}
}
}else if (mEngine->GetButtonClick(PSP_CTRL_TRIANGLE)){
showBigCards = !showBigCards;
showBigCards = (++showBigCards) %3;
}
else{
+6 -1
View File
@@ -1,7 +1,7 @@
#include "../include/debug.h"
#include "../include/Player.h"
#include "../include/GameObserver.h"
#include "../include/DeckStats.h"
Player::Player(MTGPlayerCards * _deck, string file): Damageable(20){
@@ -14,6 +14,11 @@ Player::Player(MTGPlayerCards * _deck, string file): Damageable(20){
type_as_damageable = DAMAGEABLE_PLAYER;
}
/*Method to call at the end of a game, before all objects involved in the game are destroyed */
void Player::End(){
DeckStats::GetInstance()->saveStats(this, opponent(),GameObserver::GetInstance());
}
Player::~Player(){
if (manaPool) delete manaPool;
if (mAvatarTex) delete mAvatarTex;
+20 -4
View File
@@ -2,7 +2,7 @@
#include "../include/SimpleMenu.h"
#include "../include/SimpleMenuItem.h"
SimpleMenu::SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int y, int width, const char * _title): JGuiController(id, listener){
SimpleMenu::SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int y, int width, const char * _title, int _maxItems): JGuiController(id, listener){
mHeight = 0;
mWidth = width;
mX = x;
@@ -15,6 +15,8 @@ SimpleMenu::SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int
}else{
displaytitle = 0;
}
startId = 0;
maxItems = _maxItems;
}
void SimpleMenu::Render(){
@@ -25,10 +27,24 @@ void SimpleMenu::Render(){
renderer->FillRoundRect(mX+2,mY+2,mWidth - 4,mHeight-4,10,ARGB(255,62,62,62));
if (displaytitle)
mFont->DrawString(title.c_str(), mX+10, mY+10);
JGuiController::Render();
for (int i = startId; i < startId + maxItems ; i++){
if (i > mCount-1) break;
((SimpleMenuItem * )mObjects[i])->RenderWithOffset(-20*startId);
}
}
void SimpleMenu::Update(float dt){
JGuiController::Update(dt);
if (mCurr > startId + maxItems-1){
startId = mCurr - maxItems +1;
}else if (mCurr < startId){
startId = mCurr;
}
}
void SimpleMenu::Add(int id, const char * text){
JGuiController::Add(NEW SimpleMenuItem(id, mFont, text, mWidth/2 + mX + 10, mY + 10 + mHeight, (mCount == 0)));
mHeight += 20;
int y = mCount*20;
if (displaytitle) y+=20;
JGuiController::Add(NEW SimpleMenuItem(id, mFont, text, mWidth/2 + mX + 10, mY + 10 + y, (mCount == 0)));
if (mCount <= maxItems) mHeight += 20;
}
+10 -4
View File
@@ -2,10 +2,10 @@
#include "../include/SimpleMenuItem.h"
SimpleMenuItem::SimpleMenuItem(int id, JLBFont *font, const char* text, int x, int y, bool hasFocus): JGuiObject(id), mFont(font), mText(text), mX(x), mY(y)
SimpleMenuItem::SimpleMenuItem(int id, JLBFont *font, const char* text, int x, int y, bool hasFocus): JGuiObject(id), mFont(font), mX(x), mY(y)
{
mText = text;
mHasFocus = hasFocus;
mScale = 1.0f;
@@ -20,7 +20,7 @@ SimpleMenuItem::SimpleMenuItem(int id, JLBFont *font, const char* text, int x, i
}
void SimpleMenuItem::Render()
void SimpleMenuItem::RenderWithOffset(float yOffset)
{
mFont->SetScale(mScale);
@@ -29,10 +29,16 @@ void SimpleMenuItem::Render()
{
mFont->SetColor(ARGB(255,255,255,0));
}
mFont->DrawString(mText, mX, mY, JGETEXT_CENTER);
mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER);
mFont->SetScale(1.0f);
}
void SimpleMenuItem::Render()
{
RenderWithOffset(0);
}
void SimpleMenuItem::Update(float dt)
{
if (mScale < mTargetScale)
+9
View File
@@ -43,3 +43,12 @@ int Subtypes::find(const char * subtype){
return (find(value));
}
/*This will be slow... */
string Subtypes::find(int id){
map<string,int>::iterator it;
for (it = values.begin(); it != values.end(); it++){
if (it->second == id) return it->first;
}
return NULL;
}
+34
View File
@@ -117,3 +117,37 @@ CardTexture::~CardTexture(){
LOG("CardTexture Object deletion Succesful");
}
SampleCache * SampleCache::mInstance = NULL;
SampleCache * SampleCache::GetInstance(){
if (!mInstance) mInstance = NEW SampleCache();
return mInstance;
}
JSample * SampleCache::getSample(string filename){
map<string,JSample *>::iterator it = cache.find(filename);
if (it == cache.end()){
if (cache.size() >10) cleanCache(); //Poor man's limit
JSample * sample = JSoundSystem::GetInstance()->LoadSample(filename.c_str());
if (!sample && fileExists(filename.c_str())){ //Out of Ram ??
cleanCache();
sample = JSoundSystem::GetInstance()->LoadSample(filename.c_str());
}
return sample;
}else{
return (it->second);
}
}
void SampleCache::cleanCache(){
map<string,JSample *>::iterator it;
for (it = cache.begin(); it != cache.end(); it++){
delete(it->second);
}
cache.clear();
}
SampleCache::~SampleCache(){
cleanCache();
}
+17
View File
@@ -142,3 +142,20 @@ int readfile_to_ints(const char * filename, int * out_buffer){
return count;
}
int fileExists(const char * filename){
std::ifstream fichier(filename);
if(fichier){
fichier.close();
return 1;
}
char alternateFilename[512];
sprintf(alternateFilename, "Res/%s",filename);
std::ifstream fichier2(alternateFilename);
if(fichier2){
fichier2.close();
return 1;
}
return 0;
}