blockattack-1.4.1+ds1.orig/ 0000750 0001750 0001750 00000000000 11536117101 014044 5 ustar pabs pabs blockattack-1.4.1+ds1.orig/changelog141 0000600 0001750 0001750 00000000137 11277747111 016156 0 ustar pabs pabs New in version 1.4.1:
Uses PhysFS for file layer apstraction... at least partial
Theme support
blockattack-1.4.1+ds1.orig/blockattack32.xpm 0000640 0001750 0001750 00000012115 10445102013 017214 0 ustar pabs pabs /* XPM */
static char * blockattack32_xpm[] = {
"32 32 185 2",
" c None",
". c #646415",
"+ c #95952C",
"@ c #96962E",
"# c #A4A449",
"$ c #8D8D1F",
"% c #8E8E1F",
"& c #8E8E21",
"* c #CBCB89",
"= c #B6B61E",
"- c #8E8E20",
"; c #84B55F",
"> c #36A036",
", c #37A037",
"' c #6FBD6F",
") c #A0A01E",
"! c #E6E61E",
"~ c #7AAC55",
"{ c #1F8D1F",
"] c #1F8C1F",
"^ c #2F942F",
"/ c #A1DBA1",
"( c #8C8C1F",
"_ c #C2C21E",
": c #FCFC1F",
"< c #9C9C1E",
"[ c #1F8E1F",
"} c #1EAC1E",
"| c #2B922B",
"1 c #97D797",
"2 c #C0C01E",
"3 c #D9D91E",
"4 c #F2F21F",
"5 c #FFFF1F",
"6 c #E5E51E",
"7 c #D7D71E",
"8 c #A7A71E",
"9 c #1EAB1E",
"0 c #1BF31B",
"a c #1E981E",
"b c #91911F",
"c c #D0D01E",
"d c #FEFE1F",
"e c #F6F61F",
"f c #B2B21E",
"g c #1CE41C",
"h c #1BFF1B",
"i c #1CCA1C",
"j c #CECE1E",
"k c #FDFD1F",
"l c #A8A81E",
"m c #1EB01E",
"n c #1BFE1B",
"o c #1BF81B",
"p c #1E9B1E",
"q c #DCDC1E",
"r c #F5F51E",
"s c #B4B41E",
"t c #1F901F",
"u c #1CE81C",
"v c #1CD01C",
"w c #94941E",
"x c #F2F21E",
"y c #BBBB1E",
"z c #95951F",
"A c #D8D81E",
"B c #D5D51E",
"C c #1DB61D",
"D c #1BF91B",
"E c #1E9F1E",
"F c #A2A21E",
"G c #A5A51E",
"H c #8F8F1F",
"I c #7AB255",
"J c #1BEC1B",
"K c #1CD61C",
"L c #5F5F14",
"M c #74D24C",
"N c #1BFA1B",
"O c #1EA41E",
"P c #660909",
"Q c #702410",
"R c #663E10",
"S c #664010",
"T c #734713",
"U c #9C4526",
"V c #9E6245",
"W c #5FE44D",
"X c #1CDA1C",
"Y c #640808",
"Z c #900C0C",
"` c #A2A16B",
" . c #1BFC1B",
".. c #1EA81E",
"+. c #660808",
"@. c #990D0D",
"#. c #B61010",
"$. c #C91313",
"%. c #C61313",
"&. c #AE1010",
"*. c #940C0C",
"=. c #900B0B",
"-. c #A09562",
";. c #1CDD1C",
">. c #BA1111",
",. c #F41A1A",
"'. c #FF1B1B",
"). c #FE1B1B",
"!. c #E91818",
"~. c #A60F0F",
"{. c #A18063",
"]. c #1E9E1E",
"^. c #1E9D1E",
"/. c #96D696",
"(. c #BD1212",
"_. c #FC1B1B",
":. c #F51A1A",
"<. c #A50E0E",
"[. c #A17A62",
"}. c #1D851D",
"|. c #288E29",
"1. c #4D7F81",
"2. c #303097",
"3. c #5656AB",
"4. c #9C0D0D",
"5. c #F71A1A",
"6. c #E31717",
"7. c #910C0C",
"8. c #AF6F69",
"9. c #0B2C18",
"0. c #142B4A",
"a. c #142C4C",
"b. c #142C4E",
"c. c #193662",
"d. c #1E228D",
"e. c #1F1F8D",
"f. c #262690",
"g. c #C01212",
"h. c #A40E0E",
"i. c #C87878",
"j. c #1E1E8A",
"k. c #1D1DBF",
"l. c #1B1BF8",
"m. c #1D1DC4",
"n. c #252590",
"o. c #8F0C0C",
"p. c #D41515",
"q. c #B41111",
"r. c #1C1CD0",
"s. c #1B1BFF",
"t. c #1C1CD5",
"u. c #D31515",
"v. c #B21010",
"w. c #BA1212",
"x. c #FA1A1A",
"y. c #A00E0E",
"z. c #970C0C",
"A. c #F21919",
"B. c #DA1616",
"C. c #B01010",
"D. c #F91A1A",
"E. c #ED1818",
"F. c #AA0F0F",
"G. c #E71818",
"H. c #FD1B1B",
"I. c #D81616",
"J. c #920C0C",
"K. c #B31111",
"L. c #B11010",
"M. c #9E0E0E",
"N. c #1C1CC9",
"O. c #1B1BFE",
"P. c #1C1CCE",
"Q. c #590707",
"R. c #900D0D",
"S. c #C66060",
"T. c #1F1F90",
"U. c #1E1E9D",
"V. c #1F1F91",
"W. c #460505",
"X. c #4A0606",
"Y. c #5C0808",
"Z. c #121258",
"`. c #151565",
" + c #1A1A73",
" ",
" ",
" . + @ @ @ @ @ @ @ @ @ # ",
" . $ $ $ $ $ % $ $ $ $ & * ",
" . $ $ $ $ $ = $ $ $ $ - ; > > > > > > > > > , ' ",
" . $ $ $ $ ) ! % $ $ $ - ~ { { { ] { { { { { { ^ / ",
" . $ ( ( ( _ : < ( ( ( - ~ { { [ } { { { { { { | 1 ",
" . % 2 3 3 4 5 6 3 7 8 - ~ { { 9 0 a { { { { { | 1 ",
" . $ b c d 5 5 5 e f $ - ~ { [ g h i ] { { { { | 1 ",
" . $ $ % j 5 5 k l $ $ - ~ { m n h o p { { { { | 1 ",
" . $ $ $ q d r 5 s $ $ - ~ t u h h h v { { { { | 1 ",
" . $ $ w x y z A B ( $ - ~ C n h h h D E { { { | 1 ",
" . $ $ F G $ $ % = H $ - I J h h h h h K { { { | 1 ",
" L $ $ $ $ $ $ $ $ $ $ & M n h h h h h N O { { | 1 ",
" P Q R S S S S S S S S S T U V W h h h h h X [ { | 1 ",
" Y Z Z Z Z Z Z Z Z Z Z Z Z Z Z ` h h h h h ...{ | 1 ",
" +.Z Z Z Z @.#.$.%.&.*.Z Z Z =.-. . . . . . .;.[ | 1 ",
" +.Z Z Z >.,.'.'.'.).!.~.Z Z =.{.].].].].].].^.[ | /. ",
" +.Z Z (._.'.'.'.'.'.'.:.<.Z =.[.}.}.}.}.}.}.}.}.|.1.2.3. ",
" +.Z 4.5.'.'.'.'.'.'.'.'.6.7.=.8.9.0.a.b.b.b.b.b.c.d.e.f. ",
" +.Z g.'.'.'.'.'.'.'.'.'._.h.=.i. j.k.l.l.l.l.l.l.l.m.n. ",
" +.o.p.'.'.'.'.'.'.'.'.'.'.q.=.i. j.r.s.s.s.s.s.s.s.t.n. ",
" +.o.u.'.'.'.'.'.'.'.'.'.'.v.=.i. j.r.s.s.s.s.s.s.s.t.n. ",
" +.Z w.'.'.'.'.'.'.'.'.'.x.y.=.i. j.r.s.s.s.s.s.s.s.t.n. ",
" +.Z z.A.'.'.'.'.'.'.'.'.B.Z =.i. j.r.s.s.s.s.s.s.s.t.n. ",
" +.Z Z C.D.'.'.'.'.'.'.E.4.Z =.i. j.r.s.s.s.s.s.s.s.t.n. ",
" +.Z Z Z F.G.H.'.'.x.I.4.Z Z =.i. j.r.s.s.s.s.s.s.s.t.n. ",
" +.Z Z Z Z J.h.K.L.M.Z Z Z Z =.i. j.N.O.O.O.O.O.O.O.P.n. ",
" Q.o.Z Z Z Z Z Z Z Z Z Z Z Z R.S. j.T.U.U.U.U.U.U.U.V.n. ",
" W.X.X.X.X.X.X.X.X.X.X.X.X.Y. Z.`.`.`.`.`.`.`.`.`. + ",
" ",
" "};
blockattack-1.4.1+ds1.orig/README 0000640 0001750 0001750 00000001432 11277746760 014752 0 ustar pabs pabs Thanks for downloading Block Attack - Rise Of the Blocks 1.4.1 for Linux and other Platforms
Version 1.4.1
Theme support and now uses Phys FS for loading files... this is
The game can be compiled by typing make. "scons install" is unfortunatly broken (if you know why then tell me).
If your operating system does not have libenet libaries and you don't want to compile them yourself then change the line "#define NETOWRK=1" to "#define NETOWRK=0" in source/code/block.make
Dependencies:
On Ubunut the required packages are to run are: libsdl1.2debian-all, libsdl-image1.2, libsdl-mixer1.2, libphysfs1 and libenet
To compile: build-essential, libsdl1.2-dev, libsdl-image1.2-dev, libsdl-mixer1.2-dev, libphysfs-dev and libenet-dev
http://blockattack.sf.net
Poul Sander poul@poulsander.com
blockattack-1.4.1+ds1.orig/man/ 0000750 0001750 0001750 00000000000 11536117101 014617 5 ustar pabs pabs blockattack-1.4.1+ds1.orig/man/blockattack.sgml 0000640 0001750 0001750 00000006246 11111344143 017773 0 ustar pabs pabs manpage.1'. You may view
the manual page with: `docbook-to-man manpage.sgml | nroff -man |
less'. A typical entry in a Makefile or Makefile.am is:
manpage.1: manpage.sgml
docbook-to-man $< > $@
The docbook-to-man binary is found in the docbook-to-man package.
Please remember that if you create the nroff version in one of the
debian/rules file targets (such as build), you will need to include
docbook-to-man in your Build-Depends control field.
-->
Goneri">
Le Bouder">
mai 19, 2006">
6">
goneri@rulezlan.org">
BLOCKATTACK">
Debian">
GNU">
GPL">
]>
&dhemail;
&dhfirstname;
&dhsurname;
2006
&dhusername;
&dhdate;
&dhucpackage;
&dhsection;
&dhpackage;
Rise of the Blocks
DESCRIPTION
This manual page documents briefly the
&dhpackage; .
This manual page was written for the &debian; distribution
because the original program does not have a manual page.
.
OPTIONS
These programs don't have specific option.
AUTHOR
This manual page was written by &dhusername; &dhemail; for
the &debian; system (but may be used by others). Permission is
granted to copy, distribute and/or modify this document under
the terms of the &gnu; General Public License, Version 2 any
later version published by the Free Software Foundation.
On Debian systems, the complete text of the GNU General Public
License can be found in /usr/share/common-licenses/GPL.
blockattack-1.4.1+ds1.orig/man/README 0000640 0001750 0001750 00000000126 11111344143 015474 0 ustar pabs pabs to regenerate the manpage:
docbook-to-man blockattack.sgml|gzip -9 > blockattack.6.gz
blockattack-1.4.1+ds1.orig/man/SConscript 0000640 0001750 0001750 00000000247 11111344143 016632 0 ustar pabs pabs #-------------#
# Import Vars #
#-------------#
Import('*')
env.Install ('$destdir/$mandir/man6/','blockattack.6.gz')
env.Alias('install', '$destdir/$mandir/man6/')
blockattack-1.4.1+ds1.orig/source/ 0000750 0001750 0001750 00000000000 11536117101 015344 5 ustar pabs pabs blockattack-1.4.1+ds1.orig/source/code/ 0000750 0001750 0001750 00000000000 11536117101 016256 5 ustar pabs pabs blockattack-1.4.1+ds1.orig/source/code/common.cc 0000640 0001750 0001750 00000017056 11165743143 020100 0 ustar pabs pabs /*
Block Attack - Rise of the Blocks, SDL game, besed on Nintendo's Tetris Attack
Copyright (C) 2008 Poul Sander
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
R�vehjvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
http://blockattack.sf.net
*/
#include "common.h"
#include
//Function to convert numbers to string
string itoa(int num)
{
stringstream converter;
converter << num;
return converter.str();
}
string double2str(double num)
{
stringstream converter;
converter << num;
return converter.str();
}
/**
* str2double parses a string and returns a double with the value of the string.
* if the string is not a double then 0.0 is returned instead of throing an error
* in that way this function will always return a useable value.
*/
double str2double(string str2parse)
{
try{
stringstream converter(str2parse);
double val = 0.0;
converter >> val;
return val;
}catch(ios_base::failure f)
{
return 0.0;
}
}
/**
* str2int parses a string and returns an int with the value of the string.
* if the string is not an int then 0 is returned instead of throing an error
* in that way this function will always return a useable value.
*/
int str2int(string str2parse)
{
try{
stringstream converter(str2parse);
int val = 0;
converter >> val;
return val;
}catch(ios_base::failure f)
{
return 0;
}
}
#ifdef WIN32
//Returns path to "my Documents" in windows:
string getMyDocumentsPath()
{
TCHAR pszPath[MAX_PATH];
//if (SUCCEEDED(SHGetSpecialFolderPath(NULL, pszPath, CSIDL_PERSONAL, FALSE))) {
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, pszPath))) {
// pszPath is now the path that you want
#if DEBUG
cout << "MyDocuments Located: " << pszPath << endl;
#endif
string theResult= pszPath;
return theResult;
}
else
{
cout << "Warning: My Documents not found!" << endl;
string theResult ="";
return theResult;
}
}
#endif
/**
* Returns the path to where all settings must be saved.
* On unix-like systems this is the home-folder under: ~/.gamesaves/GAMENAME
* In Windows it is My Documents/My Games
* Consider changing this for Vista that has a special save games folder
*/
string getPathToSaveFiles()
{
#ifdef __unix__
return (string)getenv("HOME")+(string)"/.gamesaves/"+GAMENAME;
#elif WIN32
return getMyDocumentsPath()+(string)"/My Games/"+GAMENAME;
#else
return ".";
#endif
}
/**
* Takes a number of milliseconds and returns the value in commonTime format.
*/
commonTime TimeHandler::ms2ct(unsigned int milliseconds)
{
commonTime ct;
ct.days = 0;
unsigned int time = milliseconds;
ct.hours = time/(1000*60*60);
time = time % (1000*60*60);
ct.minutes = time/(1000*60);
time = time % (1000*60);
ct.seconds = time/1000;
return ct;
}
commonTime TimeHandler::getTime(string name)
{
commonTime ct;
ct.days = Config::getInstance()->getInt(name+"Days");
ct.hours = Config::getInstance()->getInt(name+"Hours");
ct.minutes = Config::getInstance()->getInt(name+"Minutes");
ct.seconds = Config::getInstance()->getInt(name+"Seconds");
return ct;
}
/**
* Returns the total runtime with toAdd added but without writing it to config file.
* Used for stats
*/
commonTime TimeHandler::peekTime(string name, commonTime toAdd)
{
commonTime ct = getTime(name);
ct.seconds +=toAdd.seconds;
ct.minutes +=ct.seconds/60;
ct.seconds = ct.seconds%60;
ct.minutes += toAdd.minutes;
ct.hours += ct.minutes/60;
ct.minutes = ct.minutes%60;
ct.hours += toAdd.hours;
ct.days += ct.hours/24;
ct.hours = ct.hours%24;
ct.days += toAdd.days;
return ct;
}
/**
* Same as peekTotalTime but writes the time to the config file.
* Should only be called only once! when the program shuts down
*/
commonTime TimeHandler::addTime(string name, commonTime toAdd)
{
commonTime ct = peekTime(name,toAdd);
Config::getInstance()->setInt(name+"Days",ct.days);
Config::getInstance()->setInt(name+"Hours",ct.hours);
Config::getInstance()->setInt(name+"Minutes",ct.minutes);
Config::getInstance()->setInt(name+"Seconds",ct.seconds);
return ct;
}
Config* Config::instance = 0;
Config::Config()
{
configMap.clear();
load();
}
void Config::load()
{
string filename = getPathToSaveFiles()+"/configFile";
ifstream inFile(filename.c_str());
string key;
string previuskey;
char value[MAX_VAR_LENGTH];
if(inFile)
{
while(!inFile.eof())
{
inFile >> key;
if(key==previuskey) //the last entry will be read 2 times if a linebreak is missing in the end
continue;
previuskey = key;
inFile.get(); //Read the space between the key and the content
inFile.getline(value,MAX_VAR_LENGTH);
#if DEBUG
cout << "Config "<< "read: " << key << " with:\"" << value << "\"" << endl;
#endif
configMap[key] = (string)value;
}
inFile.close();
}
}
Config* Config::getInstance()
{
if(Config::instance==0)
{
Config::instance = new Config();
}
return Config::instance;
}
void Config::save()
{
string filename = getPathToSaveFiles()+"/configFile";
ofstream outFile(filename.c_str(),ios::trunc);
if(outFile)
{
map::iterator iter;
for(iter = configMap.begin(); iter != configMap.end(); iter++)
{
outFile << iter->first << " " << iter->second << endl;
}
outFile << "\n"; //The last entry in the file will be read double if a linebreak is missing
//This is checked on load too in case a user changes it himself.
}
outFile.close();
}
bool Config::exists(string varName)
{
//Using that find returns an iterator to the end of the map if not found
return configMap.find(varName) != configMap.end();
}
void Config::setDefault(string varName,string content)
{
if(exists(varName))
return; //Already exists do not change
setString(varName,content);
}
void Config::setString(string varName, string content)
{
configMap[varName] = content;
}
void Config::setInt(string varName, int content)
{
configMap[varName] = itoa(content);
}
void Config::setValue(string varName,double content)
{
configMap[varName] = double2str(content);
}
string Config::getString(string varName)
{
if(exists(varName))
{
return configMap[varName];
}
else
return "";
}
int Config::getInt(string varName)
{
if(exists(varName))
{
return str2int(configMap[varName]);
}
else
return 0;
}
double Config::getValue(string varName)
{
if(exists(varName))
{
return str2double(configMap[varName]);
}
else
return 0.0;
}
blockattack-1.4.1+ds1.orig/source/code/MenuSystem.cc 0000640 0001750 0001750 00000012760 11111344142 020701 0 ustar pabs pabs /*
Block Attack - Rise of the Blocks, SDL game, besed on Nintendo's Tetris Attack
Copyright (C) 2008 Poul Sander
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
R�vehjvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
http://blockattack.sf.net
*/
#include "MenuSystem.h"
#include "common.h"
extern SDL_Surface *mouse;
extern SDL_Surface *backgroundImage;
extern bool highPriority;
int mousex;
int mousey;
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/
inline void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, target, &dest);
}
SDL_Surface* ButtonGfx::marked;
SDL_Surface* ButtonGfx::unmarked;
int ButtonGfx::xsize;
int ButtonGfx::ysize;
TTFont* ButtonGfx::ttf;
void ButtonGfx::setSurfaces(SDL_Surface **marked,SDL_Surface **unmarked)
{
ButtonGfx::marked = *marked;
ButtonGfx::unmarked = *unmarked;
xsize=(*marked)->w;
ysize=(*marked)->h;
}
Button::Button()
{
label = "";
marked = false;
surfaceMarked = SDL_ConvertSurface(ButtonGfx::marked, ButtonGfx::marked->format, SDL_SWSURFACE);
surfaceUnmarked = SDL_ConvertSurface(ButtonGfx::unmarked, ButtonGfx::unmarked->format, SDL_SWSURFACE);
}
Button::~Button()
{
SDL_FreeSurface(surfaceMarked);
SDL_FreeSurface(surfaceUnmarked);
}
Button::Button(const Button& b)
{
label = b.label;
marked = b.marked;
surfaceMarked = SDL_ConvertSurface(ButtonGfx::marked, ButtonGfx::marked->format, SDL_SWSURFACE);
surfaceUnmarked = SDL_ConvertSurface(ButtonGfx::unmarked, ButtonGfx::unmarked->format, SDL_SWSURFACE);
}
void Button::setLabel(string text)
{
label = text;
}
void Button::setAction(void (*action2run)())
{
action = action2run;
}
bool Button::isClicked(int x,int y)
{
if ( x >= this->x && y >= this->y && x<= this->x+ButtonGfx::xsize && y <= this->y + ButtonGfx::ysize)
return true;
else
return false;
}
void Button::doAction()
{
action();
}
void Button::drawTo(SDL_Surface *surface)
{
#if DEBUG
cout << "Painting button: " << label << endl;
#endif
if (marked)
DrawIMG(surfaceMarked,surface,x,y);
else
DrawIMG(surfaceUnmarked,surface,x,y);
//int stringx = x + (ButtonGfx::xsize)/2 - ButtonGfx::ttf->getTextWidth(label)/2;
//int stringy = y + (ButtonGfx::ysize)/2 - ButtonGfx::ttf->getTextHeight()/2;
//ButtonGfx::ttf->writeText(label,surface,stringx,stringy);
}
void Menu::drawSelf()
{
DrawIMG(backgroundImage,screen,0,0);
vector::iterator it;
for(it = buttons.begin();it < buttons.end(); it++)
(*it).drawTo(screen);
exit.drawTo(screen);
DrawIMG(mouse,screen,mousex,mousey);
}
void Menu::performClick(int x,int y)
{
vector::iterator it;
for(it = buttons.begin();it < buttons.end(); it++)
{
Button b = (*it);
if(b.isClicked(x,y))
b.doAction();
}
if(exit.isClicked(x,y))
running = false;
}
void Menu::placeButtons()
{
int nextY = 50;
const int X = 50;
vector::iterator it;
for(it = buttons.begin();it < buttons.end(); it++)
{
(*it).x = X;
(*it).y = nextY;
nextY += 50;
}
exit.x = X;
exit.y = nextY;
}
void Menu::addButton(Button b)
{
buttons.push_back(b);
b.marked = false;
placeButtons();
}
Menu::Menu(SDL_Surface **screen)
{
this->screen = *screen;
buttons = vector(10);
isSubmenu = true;
exit.setLabel("Back");
}
Menu::Menu(SDL_Surface **screen,bool submenu)
{
this->screen = *screen;
buttons = vector(0);
isSubmenu = submenu;
if(isSubmenu)
exit.setLabel("Back");
else
exit.setLabel("Exit");
}
void Menu::run()
{
running = true;
while(running)
{
if (!(highPriority)) SDL_Delay(10);
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) {
running = false;
}
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
running = false;
}
if (event.key.keysym.sym == SDLK_UP)
{
marked--;
if(marked<0)
marked = buttons.size(); //not -1, since exit is after the last element in the list
}
if (event.key.keysym.sym == SDLK_DOWN)
{
marked++;
if(marked>buttons.size())
marked = 0;
}
}
SDL_GetMouseState(&mousex,&mousey);
}
drawSelf();
SDL_Flip(screen);
}
}
blockattack-1.4.1+ds1.orig/source/code/build/ 0000750 0001750 0001750 00000000000 11277746247 017402 5 ustar pabs pabs blockattack-1.4.1+ds1.orig/source/code/BlockGame.hpp 0000640 0001750 0001750 00000241461 11277345404 020637 0 ustar pabs pabs /*
* BlockGame.hpp (this was cut from main.cpp for the overview)
* Copyright (C) 2005 Poul Sander
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Poul Sander
* R�veh�jvej 36, V. 1111
* 2800 Kgs. Lyngby
* DENMARK
* blockattack@poulsander.com
*/
#include "stats.h"
#include "common.h"
#include "mainVars.hpp"
////////////////////////////////////////////////////////////////////////////////
//The BloackGame class represents a board, score, time etc. for a single player/
////////////////////////////////////////////////////////////////////////////////
class BlockGame {
private:
int prevTowerHeight;
bool bGarbageFallLeft;
bool bDraw;
bool bReplaying; //true if we are watching a replay
#if NETWORK
bool bNetworkPlayer; //must recieve packages from the net
bool bDisconnected; //The player has disconnected
#endif
Uint32 nextGarbageNumber;
Uint32 pushedPixelAt;
Uint32 nrPushedPixel, nrFellDown, nrStops;
bool garbageToBeCleared[7][30];
Uint32 lastAImove;
Sint16 AI_LineOffset; //how many lines have changed since command
string strHolder;
Uint32 hangTicks; //How many times have hang been decreased?
//int the two following index 0 may NOT be used (what the fuck did I meen?)
Uint8 chainSize[NUMBEROFCHAINS]; //Contains the chains
bool chainUsed[NUMBEROFCHAINS]; //True if the chain is used
Uint32 nextRandomNumber;
Uint16 rand2() {
nextRandomNumber = nextRandomNumber*1103515245 + 12345;
return ((Uint16)(nextRandomNumber/65536)) % 32768;
}
int firstUnusedChain() {
bool found=false;
int i = 0;
while (!found) {
if (!chainUsed[++i])
found=true;
if (i>NUMBEROFCHAINS-2)
found=true;
}
return i;
}
public:
char name[30];
Uint32 gameStartedAt;
Uint32 gameEndedAfter; //How long did the game last?
int linesCleared;
#if WITH_SDL
SDL_Surface* sBoard;
#endif
int TowerHeight;
BlockGame *garbageTarget;
Sint32 board[7][30];
int stop;
int speedLevel;
int pixels;
int MovesLeft;
bool timetrial, stageClear, vsMode, puzzleMode;
int Level; //Only used in stageClear and puzzle (not implemented)
int stageClearLimit; //stores number of lines user must clear to win
int topx, topy;
int combo;
int chain;
int cursorx; //stores cursor position
int cursory; // -||-
double speed, baseSpeed; //factor for speed. Lower value = faster gameplay
Uint32 score;
bool bGameOver;
bool hasWonTheGame;
int AI_MoveSpeed; //How often will the computer move? milliseconds
bool AI_Enabled;
Replay theReplay; //Stores the replay
Uint32 handicap;
//Constructor
BlockGame(int tx, int ty) {
#if WITH_SDL
tmp = IMG_Load2((char*)"gfx/BackBoard.png");
sBoard = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);
#endif
srand((int)time(NULL));
nrFellDown = 0;
nrPushedPixel = 0;
garbageTarget = this;
nrStops=0;
topx = tx;
topy = ty;
cursorx = 2;
cursory = 3;
stop = 0;
pixels = 0;
score = 0;
bGameOver = false;
bDraw = false;
bReplaying=false; //No replay by default
#if NETWORK
bDisconnected=false;
bNetworkPlayer = false;
#endif
timetrial = false;
stageClear = false;
vsMode = false;
puzzleMode = false;
linesCleared = 0;
AI_Enabled = false;
AI_MoveSpeed=100;
hasWonTheGame = false;
combo=0; //counts
chain=0;
hangTicks = 0;
baseSpeed = 0.5; //All other speeds are relative to this
speed = baseSpeed;
speedLevel = 1;
gameStartedAt = SDL_GetTicks();
gameEndedAfter = 0;
pushedPixelAt = gameStartedAt;
nextGarbageNumber = 10;
handicap=0;
for (int i=0;i<7;i++)
for (int j=0;j<30;j++) {
board[i][j] = -1;
}
for (int i=0;i=garbageStackSize)
return false;
garbageStack[garbageStackUsed][0]=width;
garbageStack[garbageStackUsed][1]=height;
garbageStack[garbageStackUsed][2]=type;
garbageStackUsed++;
return true;
}
bool popGarbage(Uint8 *width, Uint8 *height, Uint8 *type) {
if (garbageStackUsed<1)
return false;
garbageStackUsed--;
*width=garbageStack[garbageStackUsed][0];
*height=garbageStack[garbageStackUsed][1];
*type=garbageStack[garbageStackUsed][2];
return true;
}
#endif
#if WITH_SDL
//Loads BackBoard again if surface format has changed
void convertSurface() {
SDL_FreeSurface(sBoard);
sBoard = SDL_DisplayFormat(backBoard);
}
#endif
//Instead of creating new object new game is called, to prevent memory leaks
void NewGame(int tx, int ty) {
stageButtonStatus = SBdontShow;
bReplaying = false;
#if NETWORK
bNetworkPlayer=false;
bDisconnected =false;
#endif
nrFellDown = 0;
lastNrOfPlayers = 1; //At least one player :-)
nrPushedPixel = 0;
nrStops = 0;
topx = tx;
topy = ty;
cursorx = 2;
cursory = 3;
stop = 0;
pixels = 0;
score = 0;
bGameOver = false;
bDraw = false;
timetrial = false;
stageClear = false;
linesCleared = 0;
hasWonTheGame = false;
vsMode = false;
puzzleMode = false;
combo=0;
chain=0;
AI_Enabled = false;
baseSpeed= 0.5;
speed = baseSpeed;
speedLevel = 1;
gameStartedAt = SDL_GetTicks()+3000;
pushedPixelAt = gameStartedAt;
nextGarbageNumber = 10;
handicap=0;
for (int i=0;i<7;i++)
for (int j=0;j<30;j++) {
board[i][j] = -1;
}
for (int i=0;i -1) {
NewGame(tx, ty);
stageClear = true;
Level = level;
Stats::getInstance()->addOne("PlayedStageLevel"+itoa2(level));
stageClearLimit = 30+(Level%6)*10;
baseSpeed = 0.5/((double)(Level*0.5)+1.0);
speed = baseSpeed;
}
}
void NewPuzzleGame(int level, int tx, int ty) {
if (level>-1) {
NewGame(tx, ty);
puzzleMode = true;
Level = level;
MovesLeft = nrOfMovesAllowed[Level];
for (int i=0;i<6;i++)
for (int j=0;j<12;j++) {
board[i][j+1] = puzzleLevels[Level][i][j];
}
baseSpeed = 100000;
speed = 100000;
//Now push the blines up
for (int i=19;i>0;i--)
for (int j=0;j<6;j++) {
board[j][i] = board[j][i-1];
}
for (int j=0;j<6;j++) {
board[j][0] = rand() % 6;
if (j > 0) {
if (board[j][0] == board[j-1][0])
board[j][0] = rand() % 6;
}
if (board[j][0] == board[j][1])
board[j][0] = 6;
if (board[j][0] == board[j][1])
board[j][0] = 6;
}
}
}
//Replay the current level
void retryLevel()
{
if(puzzleMode)
NewPuzzleGame(Level,topx,topy);
else
if(stageClear)
NewStageGame(Level,topx,topy);
}
//Play the next level
void nextLevel()
{
if(puzzleMode)
{
if(LeveladdOne("VSgamesStarted");
}
//Starts new Vs Game (two Player)
void NewVsGame(int tx, int ty, BlockGame *target, bool AI) {
NewGame(tx, ty);
vsMode = true;
AI_Enabled = AI;
if(!AI)
Stats::getInstance()->addOne("VSgamesStarted");
else
strcpy(name,"CPU\0");
putStartBlocks();
garbageTarget = target;
}
//Go in Demonstration mode, no movement
void Demonstration(bool toggle) {
speed=0;
baseSpeed = 0;
}
//We want to play the replay (must have been loaded beforehand)
void playReplay(int tx, int ty) {
NewGame(tx, ty);
gameStartedAt = SDL_GetTicks();
bReplaying = true; //We are playing, no calculations
#if NETWORK
bNetworkPlayer = false; //Take input from replay file
#endif
}
#if NETWORK
//network play
void playNetwork(int tx, int ty) {
NewGame(tx, ty);
gameStartedAt = SDL_GetTicks();
bReplaying = false; //We are playing, no calculations
bNetworkPlayer = true; //Don't Take input from replay file
emptyGarbageStack();
}
#endif
//Prints "winner" and ends game
void setPlayerWon() {
if (!bGameOver)
{
gameEndedAfter = SDL_GetTicks()-gameStartedAt; //We game ends now!
if(!AI_Enabled && !bReplaying)
{
TimeHandler::addTime("playTime",TimeHandler::ms2ct(gameEndedAfter));
}
}
theReplay.setFinalFrame(getPackage(), 1);
bGameOver = true;
hasWonTheGame = true;
showGame = false;
if (SoundEnabled)Mix_PlayChannel(1, applause, 0);
if(!AI_Enabled && !bReplaying)
{
Stats::getInstance()->addOne("totalWins");
if(garbageTarget->AI_Enabled && !(garbageTarget->bReplaying))
{
//We have defeated an AI
Stats::getInstance()->addOne("defeatedAI"+itoa(garbageTarget->getAIlevel()));
}
}
if(AI_Enabled && !(garbageTarget->AI_Enabled) && garbageTarget->bReplaying==false)
{
//The AI have defeated a human player
Stats::getInstance()->addOne("defeatedByAI"+itoa(getAIlevel()));
}
}
//void SetGameOver();
#if NETWORK
//Sets disconnected:
void setDisconnect() {
bDisconnected = true;
SetGameOver();
}
#endif
//Prints "draw" and ends the game
void setDraw() {
bGameOver = true;
if(!AI_Enabled && !bReplaying)
{
TimeHandler::addTime("playTime",TimeHandler::ms2ct(gameEndedAfter));
}
theReplay.setFinalFrame(getPackage(), 3);
hasWonTheGame = false;
bDraw = true;
showGame = false;
Mix_HaltChannel(1);
if(!AI_Enabled && !bReplaying)
Stats::getInstance()->addOne("totalDraws");
}
//Function to get a boardpackage
boardPackage getPackage() {
boardPackage bp;
if(SDL_GetTicks()= 10000000) //Higher than this means combos (garbage is static, but the stack is static but nothing to do about it)
return true; //They are static
return false; //Return false if no static object found
}
/*
* Generates some blocks so the user don't see a board without blocks
*/
//void putStartBlocks(Uint32);
void putStartBlocks() {
putStartBlocks(time(0));
}
void putStartBlocks(Uint32 n) {
for (int i=0;i<7;i++)
for (int j=0;j<30;j++) {
board[i][j] = -1;
}
nextRandomNumber = n;
int choice = rand2()%3; //Pick a random layout
switch (choice) {
case 0:
//row 0:
board[0][0]=1;
board[1][0]=0;
board[2][0]=4;
board[3][0]=3;
board[4][0]=3;
board[5][0]=5;
//row 1:
board[0][1]=1;
board[1][1]=4;
board[2][1]=2;
board[3][1]=0;
board[4][1]=4;
board[5][1]=5;
//row 2:
board[0][2]=2;
board[1][2]=3;
board[2][2]=0;
board[3][2]=4;
board[4][2]=1;
board[5][2]=1;
//row 3:
board[0][3]=3;
board[1][3]=2;
board[2][3]=3;
board[3][3]=1;
board[4][3]=0;
board[5][3]=4;
//row 4:
board[0][4]=2;
board[1][4]=3;
board[2][4]=3;
board[3][4]=1;
board[4][4]=4;
board[5][4]=0;
//row 5:
board[0][5]=-1;
board[1][5]=5;
board[2][5]=5;
board[3][5]=-1;
board[4][5]=1;
board[5][5]=-1;
break;
case 1:
//row 0:
board[0][0]=3;
board[1][0]=5;
board[2][0]=0;
board[3][0]=0;
board[4][0]=4;
board[5][0]=2;
//row 1:
board[0][1]=3;
board[1][1]=5;
board[2][1]=-1;
board[3][1]=5;
board[4][1]=4;
board[5][1]=2;
//row 2:
board[0][2]=2;
board[1][2]=-1;
board[2][2]=-1;
board[3][2]=4;
board[4][2]=0;
board[5][2]=3;
//row 3:
board[0][3]=2;
board[5][3]=3;
break;
default:
//row 0:
board[0][0]=4;
board[1][0]=5;
board[2][0]=2;
board[3][0]=0;
board[4][0]=1;
board[5][0]=5;
//row 1:
board[0][1]=4;
board[1][1]=5;
board[2][1]=2;
board[3][1]=1;
board[4][1]=0;
board[5][1]=2;
//row 2:
board[0][2]=2;
board[1][2]=4;
board[2][2]=-1;
board[3][2]=0;
board[4][2]=1;
board[5][2]=5;
//row 3:
board[0][3]=4;
board[1][3]=2;
board[2][3]=-1;
board[3][3]=1;
board[4][3]=0;
board[5][3]=2;
//row 4:
board[0][4]=4;
board[1][4]=2;
board[2][4]=-1;
board[3][4]=0;
board[4][4]=1;
board[5][4]=-1;
break;
};
}
//decreases hang for all hanging blocks and wait for waiting blocks
void ReduceStuff() {
Uint32 howMuchHang = (SDL_GetTicks() - FRAMELENGTH*hangTicks)/FRAMELENGTH;
if (howMuchHang>0) {
for (int i=0; i<7; i++)
for (int j=0; j<30; j++) {
if ((board[i][j]/BLOCKHANG)%10==1) {
int hangNumber = (board[i][j]/10)%100;
if (hangNumber<=howMuchHang) {
board[i][j]-=BLOCKHANG;
board[i][j]-=hangNumber*10;
}
else {
board[i][j]-=10*howMuchHang;
}
}
if ((board[i][j]/BLOCKWAIT)%10==1) {
int hangNumber = (board[i][j]/10)%100;
if (hangNumber<=howMuchHang) {
//The blocks must be cleared
board[i][j]-=hangNumber*10;
}
else {
board[i][j]-=10*howMuchHang;
}
}
}
}
hangTicks+=howMuchHang;
}
//Creates garbage using a given wide and height
bool CreateGarbage(int wide, int height) {
#if NETWORK
if (bNetworkPlayer) {
pushGarbage(wide, height, 0);
}
else
#endif
{
if (wide>6) wide = 6;
if (height>12) height = 12;
int startPosition = 12;
while ((!(LineEmpty(startPosition))) || (startPosition == 29))
startPosition++;
if (startPosition == 29) return false; //failed to place blocks
if (29-startPosition999999) nextGarbageNumber = 10;
//bGarbageFallLeft = !(bGarbageFallLeft);
return true;
}
}
//Creates garbage using a given wide and height
bool CreateGreyGarbage() {
#if NETWORK
if (bNetworkPlayer) {
pushGarbage(6, 1, 1);
}
else
#endif
{
int startPosition = 12;
while ((!(LineEmpty(startPosition))) || (startPosition == 29))
startPosition++;
if (startPosition == 29) return false; //failed to place blocks
if (29-startPosition<1) return false; //not enough space
int start, end;
{
start=0;
end=6;
}
for (int i = startPosition; i 999999) nextGarbageNumber = 10;
return true;
}
}
//Clears garbage, must take one the lower left corner!
int GarbageClearer(int x, int y, int number, bool aLineToClear, int chain) {
if ((board[x][y])%1000000 != number) return -1;
if (aLineToClear) {
board[x][y] = rand() % 6;
board[x][y] += 10*HANGTIME+BLOCKHANG+CHAINPLACE*chain;
}
garbageToBeCleared[x][y] = false;
GarbageClearer(x+1, y, number, aLineToClear, chain);
GarbageClearer(x, y+1, number, false, chain);
return 1;
}
//Marks garbage that must be cleared
int GarbageMarker(int x, int y) {
if ((x>6)||(x<0)||(y<0)||(y>29)) return -1;
if (((board[x][y])/1000000 == 1)&&(garbageToBeCleared[x][y] == false)) {
garbageToBeCleared[x][y] = true;
//Float fill
GarbageMarker(x-1, y);
GarbageMarker(x+1, y);
GarbageMarker(x, y-1);
GarbageMarker(x, y+1);
}
return 1;
}
int FirstGarbageMarker(int x, int y) {
if ((x>6)||(x<0)||(y<0)||(y>29)) return -1;
if (((board[x][y])/1000000 == 2)&&(garbageToBeCleared[x][y] == false)) {
for (int i=0;i<6;i++)
garbageToBeCleared[i][y] = true;
}
else
if (((board[x][y])/1000000 == 1)&&(garbageToBeCleared[x][y] == false)) {
garbageToBeCleared[x][y] = true;
//Float fill
GarbageMarker(x-1, y);
GarbageMarker(x+1, y);
GarbageMarker(x, y-1);
GarbageMarker(x, y+1);
}
return 1;
}
//Clear Blocks if 3 or more is alligned (naive implemented)
void ClearBlocks() {
bool toBeCleared[7][30]; //true if blok must be removed
int previus=-1; //the last block checked
int combo=0;
for (int i=0;i<30;i++)
for (int j=0;j<7;j++) {
toBeCleared[j][i] = false;
garbageToBeCleared[j][i] = false;
}
for (int i=0;i<7;i++) {
bool faaling = false;
for (int j=0;j<30;j++) {
if ((faaling)&&(board[i][j]>-1)&&(board[i][j]%10000000<7)) {
board[i][j]+=BLOCKFALL;
}
if ((!faaling)&&((board[i][j]/BLOCKFALL)%10==1))
board[i][j]-=BLOCKFALL;
if (!((board[i][j]>-1)&&(board[i][j]%10000000<7)))
faaling=true;
if (((board[i][j]/1000000)%10==1)||((board[i][j]/1000000)%10==2)||((board[i][j]/BLOCKHANG)%10==1)||((board[i][j]/BLOCKWAIT)%10==1))
faaling = false;
}
}
for (int j=0;j<7;j++) {
previus = -1;
combo=0;
for (int i=1;i<30;i++) {
if ((board[j][i]>-1)&&(board[j][i]%10000000<7)) {
if (board[j][i]%10000000 == previus) {
combo++;
}
else {
if (combo>2)
for (int k = i-combo; k2)
for (int k = i-combo; k-1)&&(board[j][i]%10000000<7))) {
if (board[j][i]%10000000 == previus) {
combo++;
}
else {
if (combo>2)
for (int k = j-combo; k2)
for (int k = j-combo; k2) && (board[j][i]%10000000==6))
garbageTarget->CreateGreyGarbage();
if ((board[j][i]>-1)&&(board[j][i]%10000000<7))
board[j][i]+=BLOCKWAIT+10*FALLTIME;
if (chainSize[board[j][i]/10000000]>chainSize[chain])
chain=board[j][i]/10000000;
combo++;
stop+=140*combo;
score +=10;
if (combo>3)
score+=3*combo; //More points if more cleared simontanously
}
score+=chainSize[chain]*100;
if (chain==0) {
chain=firstUnusedChain();
chainSize[chain]=0;
chainUsed[chain]=true;
}
chainSize[chain]++;
for (int i=0;i<30;i++)
for (int j=0;j<6;j++) {
//if(board[j][i]/10==(BLOCKWAIT+10*FALLTIME)/10)
if (toBeCleared[j][i]) {
board[j][i]=(board[j][i]%10000000)+chain*10000000;
}
}
{ //This is here we add text to screen!
bool dead = false;
for (int i=29;i>=0;i--)
for (int j=0;j<6;j++)
if (toBeCleared[j][i]) {
if (!dead) {
dead=true;
string tempS = itoa(chainSize[chain]);
if (chainSize[chain]>1)
theTextManeger.addText(topx-10+j*bsize, topy+12*bsize-i*bsize, tempS, 1000);
}
}
} //This was there text was added
if (vsMode)
switch (combo) {
case 0:
case 1:
case 2:
case 3:
break;
case 4:
garbageTarget->CreateGarbage(3, 1);
break;
case 5:
garbageTarget->CreateGarbage(4, 1);
break;
case 6:
garbageTarget->CreateGarbage(5, 1);
break;
case 7:
garbageTarget->CreateGarbage(6, 1);
break;
case 8:
garbageTarget->CreateGarbage(4, 1);
garbageTarget->CreateGarbage(4, 1);
break;
case 9:
garbageTarget->CreateGarbage(5, 1);
garbageTarget->CreateGarbage(4, 1);
break;
case 10:
garbageTarget->CreateGarbage(5, 1);
garbageTarget->CreateGarbage(5, 1);
break;
case 11:
garbageTarget->CreateGarbage(6, 1);
garbageTarget->CreateGarbage(5, 1);
break;
case 12:
garbageTarget->CreateGarbage(6, 1);
garbageTarget->CreateGarbage(6, 1);
break;
case 13:
garbageTarget->CreateGarbage(5, 1);
garbageTarget->CreateGarbage(5, 1);
garbageTarget->CreateGarbage(4, 1);
break;
default:
garbageTarget->CreateGarbage(5, 1);
garbageTarget->CreateGarbage(5, 1);
garbageTarget->CreateGarbage(4, 1);
break;
}
for (int i=0;i<30;i++)
for (int j=0;j<6;j++)
if (garbageToBeCleared[j][i]) {
GarbageClearer(j, i, board[j][i]%1000000, true, chain); //Clears the blocks and all blocks connected to it.
}
chain=0;
//Break chains (if a block is stable it is resetted to (chain == 0)):
for (int i=0;i<7;i++) {
bool faaling = false; //In the beginning we are NOT falling
for (int j=0;j<30;j++) {
if ((faaling)&&(board[i][j]>-1)&&(board[i][j]<7)) {
board[i][j]+=BLOCKFALL;
}
if ((!faaling)&&((board[i][j]/BLOCKFALL)%10==1))
board[i][j]-=BLOCKFALL;
if ((!faaling)&&(board[i][j]>0)&&(board[i][j]/10000000!=0)&&((board[i][j]/BLOCKWAIT)%10!=1)&&((board[i][j]/BLOCKHANG)%10!=1)) {
if (chainSize[board[i][j]/10000000]>chainSize[chain])
chain=board[i][j]/10000000;
board[i][j]=board[i][j]%10000000;
}
if (!((board[i][j]>-1)&&(board[i][j]<7)))
faaling=true;
if (((board[i][j]/1000000)%10==1)||((board[i][j]/BLOCKHANG)%10==1)||((board[i][j]/BLOCKWAIT)%10==1))
faaling = false;
}
}
//Create garbage as a result
//if((vsMode)&&(chainSize[chain]>1)) garbageTarget->CreateGarbage(6,chainSize[chain]-1);
//Calculate chain
chain=0;
for (int i=0; i<6;i++)
for (int j=0; j<30;j++) {
if (chainSize[board[i][j]/10000000]>chain)
chain=chainSize[board[i][j]/10000000];
}
//Make space in table for more things
if (chain==0)
for (int i=0;i1)) garbageTarget->CreateGarbage(6, chainSize[i]-1);
if ((SoundEnabled)&&(chainSize[i]>4))Mix_PlayChannel(1, applause, 0);
if(chainSize[i]>1 && !puzzleMode && !AI_Enabled)
Stats::getInstance()->addOne((string)"chainX"+itoa(chainSize[i]));
chainUsed[i]=false;
}
} //ClearBlocks
//prints "Game Over" and ends game
void SetGameOver() {
if (!bGameOver) {
gameEndedAfter = SDL_GetTicks()-gameStartedAt; //We game ends now!
if(!AI_Enabled && !bReplaying)
{
TimeHandler::addTime("playTime",TimeHandler::ms2ct(gameEndedAfter));
}
}
if(bReplaying)
{
bReplaying = false;
}
else
{
strncpy(theReplay.name,name,30);
}
theReplay.setFinalFrame(getPackage(), 0);
bGameOver = true;
showGame = false;
if(stageClear)
stageButtonStatus = SBstageClear;
}
//Moves all peaces a spot down if possible
int FallBlock(int x, int y, int number) {
if (y == 0) return -1;
if (x>0)
if (board[x-1][y] == number)
return -1;
int i=x;
bool canFall = true;
//checks a line of a garbage block and see if something is under it
while ((board[i][y] == number)&&(canFall)&&(i<6)) {
if (board[i][y-1] != -1) canFall = false;
i++;
}
if (canFall) {
//cout << "Now falling" << endl;
for (int j = x;j12) ||(((pixels==bsize)||(pixels==0)) && (cursory<11))))
cursory++;
if ((way == 'S') && (cursory>0))
cursory--;
if ((way == 'W') && (cursorx>0))
cursorx--;
if ((way == 'E') && (cursorx<4))
cursorx++;
}
}
//switches the two blocks at the cursor position, unless game over
void SwitchAtCursor() {
if ((board[cursorx][cursory+1]<7) && (board[cursorx+1][cursory+1]<7) && (!bGameOver) && ((!puzzleMode)||(MovesLeft>0)) && (gameStartedAt0)) MovesLeft--;
}
//Generates a new line and moves the field one block up (restart puzzle mode)
void PushLine() {
//If not game over, not high tower and not puzzle mode
if ((!bGameOver) && TowerHeight<13 && (!puzzleMode) && (gameStartedAt0;i--)
for (int j=0;j<6;j++) {
board[j][i] = board[j][i-1];
}
for (int j=0;j<6;j++) {
board[j][0] = rand2() % 4;
if (j > 0) {
if (board[j][0] == board[j-1][0])
board[j][0] = rand2() % 6;
}
if (board[j][0] == board[j][1])
board[j][0] = rand2() % 6;
if (board[j][0] == board[j][1])
board[j][0] = rand2() % 6;
while ((j>0)&&(board[j][0]==board[j-1][0]))
board[j][0] = rand2() % 6;
}
score+=1;
MoveCursor('N');
if (vsMode) {
if (rand2()%6==1)
board[rand2()%6][0]=6;
}
pixels = 0;
stop=0;
pushedPixelAt = SDL_GetTicks();
linesCleared++;
AI_LineOffset++;
nrPushedPixel=(int)((double)(pushedPixelAt-gameStartedAt)/(1000.0*speed));
if(!AI_Enabled && !bReplaying)
{
Stats::getInstance()->addOne("linesPushed");
}
} //if !bGameOver
//Restart Puzzle mode
if (puzzleMode && !bGameOver) {
//Reloads level
MovesLeft = nrOfMovesAllowed[Level];
for (int i=0;i<6;i++)
for (int j=0;j<12;j++) {
board[i][j+1] = puzzleLevels[Level][i][j];
}
score=0;
bGameOver=false;
showGame = true;
}
if ((TowerHeight>12) && (!puzzleMode)&&(!bGameOver)&&(chain==0)) {
if ((!vsMode)&&(theTopScoresEndless.isHighScore(score))&&(!AI_Enabled)) {
if (SoundEnabled)Mix_PlayChannel(1, applause, 0);
theTopScoresEndless.addScore(name, score);
cout << "New high score!" << endl;
}
SetGameOver();
}
}//PushLine
//Pushes a single pixel, so it appears to scrool
void PushPixels() {
nrPushedPixel++;
if ((pixels < bsize) && TowerHeight<13) {
pixels++;
}
else
PushLine();
if (pixels>bsize)
pixels=0;
}
//See how high the tower is, saved in integer TowerHeight
/*void FindTowerHeight()
* {
* /*
* This function needs to be corrected, if an empty line appears towerheight become to low!
* /
* bool found = false;
* bool notNew = false;
* TowerHeight = 0;
* for(int i=0; i<19;i++)
* //while(!found)
* {
* found = true;
* for(int j=0;j<6;j++)
* if(board[j][i] != -1)
* found = false;
* if((!found) && (notNew))
* notNew =false;
* if((found)&&(!notNew))
* {
* TowerHeight=i;
* notNew = true;
* }
* }
* TowerHeight--;
* }*/
//See how high the tower is, saved in integer TowerHeight
void FindTowerHeight() {
/*
* Old implementation, used until I find the bug in the other.
* This function has a bug in stage clear! if an empty line appears.
*/
prevTowerHeight = TowerHeight;
bool found = false;
TowerHeight = 0;
while (!found) {
found = true;
for (int j=0;j<6;j++)
if (board[j][TowerHeight] != -1)
found = false;
TowerHeight++;
}
TowerHeight--;
}
///////////////////////////////////////////////////////////////////////////
/////////////////////////// AI starts here! ///////////////////////////////
///////////////////////////////////////////////////////////////////////////
//First the helpet functions:
int nrOfType(int line, int type) {
// cout << "Start_ nrOfType" << endl;
int counter = 0;
for (int i=0; i<6; i++)
if (board[i][line]==type)counter++;
return counter;
}
int AIcolorToClear;
int AIlineToClear;
//See if a combo can be made in this line
int horiInLine(int line) {
//cout << "Start_ hori in line" << endl;
int nrOfType[7] = {0, 0, 0, 0, 0, 0, 0};
int iTemp;
int max = 0;
for (int i=0; i<6; i++) {
iTemp = board[i][line];
if ((iTemp>-1)&&(iTemp<7))
nrOfType[iTemp]++;
}
for (int j=0; j<7; j++) {
if (nrOfType[j]>max) {
max = nrOfType[j];
AIcolorToClear = j;
}
}
return max;
}
bool horiClearPossible() {
//cout << "Start_ horiclear possible" << endl;
int i=13;
bool solutionFound = false;
do{
if (horiInLine(i)>2) {
AI_LineOffset = 0;
AIlineToClear = i;
solutionFound = true;
}
i--;
}while ((!solutionFound)&&(i>0));
return solutionFound;
}
//the Line Has Unmoveable Objects witch might stall the AI
bool lineHasGarbage(int line) {
for (int i=0;i<6;i++)
if (board[i][line]>1000000)
return true;
return false;
}
//Types 0..6 in line
inline int nrOfRealTypes(int line) {
//cout << "Start_ nrOfReal" << endl;
int counter = 0;
for (int i=0; i<6; i++)
if ((board[i][line]>-1)&&(board[i][line]<7))counter++;
return counter;
}
//See if there is a tower
bool ThereIsATower() {
//cout << "Start_ there is a tower" << endl;
bool bThereIsATower = false; //Unless proven otherwise!
bool topReached = false; //If we have reached the top
int lineNumber = 0;
bool emptySpacesFound = false;
do {
if ((emptySpacesFound) && (nrOfRealTypes(lineNumber)>0)&&(nrOfType(lineNumber, -1)>0)) {
AIlineToClear = lineNumber;
if (lineHasGarbage(lineNumber))
return false;
else
bThereIsATower = true;
}
else
emptySpacesFound=false;
if ((!emptySpacesFound)&&(nrOfType(lineNumber, -1)>0))
emptySpacesFound = true;
if (lineNumber<12)
lineNumber++;
else
topReached = true;
}while ((!bThereIsATower)&&(!topReached));
//if(bThereIsATower)
//cout << "There is actually a tower" << endl;
return bThereIsATower;
}
double firstInLine1(int line) {
for (int i=0;i<6;i++)
if ((board[i][line]>-1)&&(board[i][line]<7))
return (double)i;
return 3.0;
}
//returns the first coordinate of the block of type
double firstInLine(int line, int type) {
for (int i=0;i<6;i++)
if (board[i][line]==type)
return (double)i;
return 3.0;
}
//There in the line shall we move
int closestTo(int line, int place) {
if ((int)firstInLine1(line)>place)
return (int)firstInLine1(line)-1;
for (int i=place;i>=0;i--) {
if ((board[i][line]>-1)&&(board[i][line]<7))
return i;
}
AIstatus=0;
return place;
}
//The AI will remove a tower
inline void AI_ClearTower() {
// cout << "AI: ClearTower, line: " << AIlineToClear << endl;
int place = (int)firstInLine(AIlineToClear-1, -1); //Find an empty field to frop a brick into
int xplace = closestTo(AIlineToClear, place); //Find the brick to drop in it
if (cursory+1AIlineToClear)
MoveCursor('S');
else
if (cursorxxplace)
MoveCursor('W');
else
SwitchAtCursor();
if (!ThereIsATower())
AIstatus = 0;
}
//The AI will try to clear block horisontally
void AI_ClearHori() {
// cout << "AI: ClearHori";
int lowestLine = AIlineToClear;
//AIcolorToClear
bool found =true;
/*for(int i; (i<12)&&(!found);i++)
* {
* if(horiInLine(i)>2)
* {
* int lowestLine = i;
* found = true;
* }
* }*/
for (int i=0;i<7;i++) {
if (nrOfType(lowestLine, i)>2)
AIcolorToClear = i;
}
if (found) {
if (cursory>lowestLine-1)
MoveCursor('S');
else if (cursory2) {
int left=0, right=0;
if (board[0][lowestLine]==AIcolorToClear) left++;
if (board[1][lowestLine]==AIcolorToClear) left++;
if (board[2][lowestLine]==AIcolorToClear) left++;
if (board[3][lowestLine]==AIcolorToClear) right++;
if (board[4][lowestLine]==AIcolorToClear) right++;
if (board[5][lowestLine]==AIcolorToClear) right++;
int xplace = 0;
if (leftleft";
int count=0;
for (int i=0;(i<4)&&(count<1);i++)
if ((board[i][lowestLine]==AIcolorToClear)&&((i==0)||(board[i+1][lowestLine]!=AIcolorToClear))) {
count++;
xplace = i;
}
}
else {
// cout << ", left>=right";
int count=0;
for (int i=3;(i<=5)&&(count<1);i++)
if ((board[i][lowestLine]==AIcolorToClear)&&(board[i-1][lowestLine]!=AIcolorToClear)) {
count++;
xplace = --i;
}
}
//cout << ", xplace: " << xplace;
if (cursorxxplace)
MoveCursor('W');
else
if (cursorx==xplace)
SwitchAtCursor();
else
AIstatus = 0;
}
else
AIstatus = 0;
}
else
AIstatus = 0;
//cout << endl; //for debugging
}
//Test if vertical clear is possible
inline bool veriClearPossible() {
bool found=false;
int colors[7] = {0, 0, 0, 0, 0, 0, 0};
for (int i=12;(i>0)&&(!found);i--) {
for (int j=0;j<7;j++) {
if (nrOfType(i, j)==0)
colors[j]=0;
else
if (++colors[j]>2) {
AIcolorToClear = j;
AIlineToClear = i;
found=true;
}
}
}
return found;
}
//There in the line shall we move
int closestTo(int line, int type, int place) {
if ((int)firstInLine(line, type)>place)
return (int)firstInLine(line, type)-1;
for (int i=place;i>=0;i--) {
if (board[i][line]==type)
return i;
}
AIstatus=0;
return place;
}
//The AI will try to clear blocks vertically
inline void AI_ClearVertical() {
// cout << "AI: ClearVeri";
//First we find the place there we will align the bricks
int placeToCenter = (int)(firstInLine(AIlineToClear, AIcolorToClear)/3.0+firstInLine(AIlineToClear+1, AIcolorToClear)/3.0+firstInLine(AIlineToClear+2, AIcolorToClear)/3.0);
int unlimitedLoop=0;
while (((board[placeToCenter][AIlineToClear]>1000000)||(board[placeToCenter][AIlineToClear+1]>1000000)||(board[placeToCenter][AIlineToClear+2]>1000000))&&(unlimitedLoop<10)) {
unlimitedLoop++;
placeToCenter++;
if (placeToCenter>5)
placeToCenter=0;
}
if(unlimitedLoop>9) {
AIstatus = 0;
}
//cout << ", ptc: " << placeToCenter << ", line: " << AIlineToClear << ", cy: " << cursory;
if (cursory+1>AIlineToClear+2) {
// cout << ", cursory>line+2";
MoveCursor('S');
}
if (cursory+1closestTo(AIlineToClear, AIcolorToClear, placeToCenter))
MoveCursor('W');
else
if (cursorxclosestTo(AIlineToClear+1, AIcolorToClear, placeToCenter))
MoveCursor('W');
else
if (cursorxclosestTo(AIlineToClear+2, AIcolorToClear, placeToCenter))
MoveCursor('W');
else
if (cursorx5) right = -1;
else right = board[j+1][i];
if (i>28) over = -1;
else over = board[j][i+1];
if (i<1) under = -1;
else under = board[j][i-1];
if ((left == number)&&(right == number)&&(over == number)&&(under == number))
DrawIMG(garbageFill, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left != number)&&(right == number)&&(over == number)&&(under == number))
DrawIMG(garbageL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left == number)&&(right != number)&&(over == number)&&(under == number))
DrawIMG(garbageR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left == number)&&(right == number)&&(over != number)&&(under == number))
DrawIMG(garbageT, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left == number)&&(right == number)&&(over == number)&&(under != number))
DrawIMG(garbageB, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left != number)&&(right == number)&&(over != number)&&(under == number))
DrawIMG(garbageTL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left != number)&&(right == number)&&(over == number)&&(under != number))
DrawIMG(garbageBL, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left == number)&&(right != number)&&(over != number)&&(under == number))
DrawIMG(garbageTR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left == number)&&(right != number)&&(over == number)&&(under != number))
DrawIMG(garbageBR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left == number)&&(right != number)&&(over != number)&&(under != number))
DrawIMG(garbageMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left == number)&&(right == number)&&(over != number)&&(under != number))
DrawIMG(garbageM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
if ((left != number)&&(right == number)&&(over != number)&&(under != number))
DrawIMG(garbageML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
}
if ((board[j][i]/1000000)%10==2) {
if (j==0)
DrawIMG(garbageGML, sBoard, j*bsize, bsize*12-i*bsize-pixels);
else
if (j==5)
DrawIMG(garbageGMR, sBoard, j*bsize, bsize*12-i*bsize-pixels);
else
DrawIMG(garbageGM, sBoard, j*bsize, bsize*12-i*bsize-pixels);
}
}
const int j = 0;
int garbageSize=0;
for (int i=0;i<20;i++) {
if ((board[j][i]/1000000)%10==1) {
int left, right, over, under;
int number = board[j][i];
if (j<1) left = -1;
else left = board[j-1][i];
if (j>5) right = -1;
else right = board[j+1][i];
if (i>28) over = -1;
else over = board[j][i+1];
if (i<1) under = -1;
else under = board[j][i-1];
if (((left != number)&&(right == number)&&(over != number)&&(under == number))&&(garbageSize>0)) {
DrawIMG(smiley[board[j][i]%4], sBoard, 2*bsize, 12*bsize-i*bsize-pixels+(bsize/2)*garbageSize);
}
if (!((left != number)&&(right == number)&&(over == number)&&(under == number))) //not in garbage
{
garbageSize=0;
}
else {
//cout << "In garbage" << endl;
garbageSize++;
}
}
}
for (int i=0;i<6;i++)
if (board[i][0]!=-1)
DrawIMG(transCover, sBoard, i*bsize, 12*bsize-pixels); //Make the appering blocks transperant
}
//Paints the bricks gotten from a replay/net package
void SimplePaintBricks() {
/*
* We will need to mark the blocks that must have a bomb, we will here need to see, what is falling
*/
bool bbomb[6][13]; //has a bomb on it!
bool falling[6][13]; //this is falling
bool getReady[6][13]; //getReady
for (int i=0;i<6;i++)
for (int j=0;j<13;j++) {
bbomb[i][j]=false; //All false by default
falling[i][j]=false;
if (board[i][j]>29)
getReady[i][j]=true;
else
getReady[i][j]=false;
}
//See that is falling
for (int i=0;i<6;i++) {
bool rowFalling = false;
for (int j=0;j<13;j++) {
if (rowFalling)
falling[i][j]=true;
if ((!rowFalling)&&(board[i][j]%30==-1))
rowFalling = true;
if ((rowFalling)&&(board[i][j]%30>6))
rowFalling = false;
if (getReady[i][j]) {
falling[i][j]=true; //getReady is the same as falling
rowFalling = false;
}
}
}
//Now looking at rows:
for (int i=0;i<6;i++) {
int count = 0;
int color = -1;
for (int j=1;j<13;j++) {
if ((board[i][j]%30==color)&&(!falling[i][j]))
count++;
else
if (falling[i][j]) {
count = 0;
}
else {
color=board[i][j]%30;
count=1;
}
if ((count>2)&&(color>-1)&&(color)<7) {
bbomb[i][j]=true;
bbomb[i][j-1]=true;
bbomb[i][j-2]=true;
}
}
}
//now looking for lines
for (int i=1;i<13;i++) {
int count = 0;
int color = -1;
for (int j=0;j<6;j++) {
if ((board[j][i]%30==color)&&(!falling[j][i]))
count++;
else
if (falling[j][i]) {
count = 0;
}
else {
color=board[j][i]%30;
count=1;
}
if ((count>2)&&(color>-1)&&(color<7)) {
bbomb[j][i]=true;
bbomb[j-1][i]=true;
bbomb[j-2][i]=true;
}
}
}
for (int i=0;((i<13)&&(i<30));i++)
for (int j=0;j<6;j++) {
if ((board[j][i]%10 != -1) && (board[j][i]%30 < 7)) {
DrawIMG(bricks[board[j][i]%10], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
if (bbomb[j][i])
DrawIMG(bomb[(SDL_GetTicks()/BOMBTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
if (getReady[j][i])
DrawIMG(ready[(SDL_GetTicks()/READYTIME)%2], sBoard, j*bsize, 12*bsize-i*bsize-pixels);
}
if (board[j][i]%30>6) {
if (board[j][i]%30==7)
DrawIMG(garbageR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==9)
DrawIMG(garbageML, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==10)
DrawIMG(garbageMR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==11)
DrawIMG(garbageTR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==12)
DrawIMG(garbageTL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==13)
DrawIMG(garbageBL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==14)
DrawIMG(garbageBR, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==15)
DrawIMG(garbageM, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==16)
DrawIMG(garbageFill, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==17)
DrawIMG(garbageT, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==18)
DrawIMG(garbageB, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==19)
DrawIMG(garbageL, sBoard, j*bsize, 12*bsize-i*bsize-pixels); //good
if (board[j][i]%30==20)
switch(j) {
case 0:
DrawIMG(garbageGML, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
break;
case 5:
DrawIMG(garbageGMR, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
break;
default:
DrawIMG(garbageGM, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
}
//cout << "IS: " << board[j][i] << endl;
}
}
int garbageSize=0;
for (int i=0;i<20;i++) {
if ((board[0][i]%30==12)&&(garbageSize>0)) {
DrawIMG(smiley[0], sBoard, 2*bsize, bsize-i*bsize-pixels+(bsize/2)*garbageSize);
}
if (board[0][i]%30!=19) //not in garbage
{
garbageSize=0;
}
else {
//cout << "In garbage" << endl;
garbageSize++;
}
}
}
int lastCounter;
//Draws everything
void DoPaintJob() {
DrawIMG(backBoard, sBoard, 0, 0);
#if NETWORK
if ((!bReplaying)&&(!bNetworkPlayer))
#else
if (!bReplaying)
#endif
PaintBricks();
else
SimplePaintBricks();
if (stageClear) DrawIMG(blackLine, sBoard, 0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1);
if (puzzleMode&&(!bGameOver)) {
//We need to write nr. of moves left!
strHolder = "Moves left: " + itoa(MovesLeft);
SFont_Write(sBoard, fBlueFont, 5, 5, strHolder.c_str());
}
if(puzzleMode && stageButtonStatus == SBpuzzleMode)
{
DrawIMG(bRetry,sBoard, cordRetryButton.x, cordRetryButton.y);
if(LevelgameStartedAt+10000)&&(!bGameOver))
{
int currentCounter = (SDL_GetTicks()-(int)gameStartedAt)/1000;
if(currentCounter!=lastCounter)
{
if(currentCounter>115 && currentCounter<120)
Mix_PlayChannel(1,counterChunk,0);
}
lastCounter = currentCounter;
}
else
{
if( (0==lastCounter) && (SoundEnabled)&&(!NoSound))
{
Mix_PlayChannel(1,counterFinalChunk,0);
}
lastCounter = -1;
}
}
if ((bGameOver)&&(!editorMode))
if (hasWonTheGame)DrawIMG(iWinner, sBoard, 0, 5*bsize);
else if (bDraw) DrawIMG(iDraw, sBoard, 0, 5*bsize);
else
DrawIMG(iGameOver, sBoard, 0, 5*bsize);
}
#endif
//Updates evrything, if not called nothing happends
void Update() {
Uint32 tempUInt32;
Uint32 nowTime = SDL_GetTicks(); //We remember the time, so it doesn't change during this call
if (bReplaying) {
setBoard(theReplay.getFrameSec((Uint32)(nowTime-gameStartedAt)));
strncpy(name,theReplay.name,30);
if (theReplay.isFinnished((Uint32)(nowTime-gameStartedAt)))
switch (theReplay.getFinalStatus()) {
case 1: //Winner
bGameOver = true;
hasWonTheGame = true;
break;
case 2: //Looser
case 4: //GameOver
bGameOver = true;
break;
case 3: //draw
bGameOver =true;
bDraw = true;
break;
default:
bGameOver = true;
//Nothing
break;
};
}
#if NETWORK
if ((!bReplaying)&&(!bNetworkPlayer)) {
#else
if (!bReplaying) {
#endif
FindTowerHeight();
if ((linesCleared-TowerHeight>stageClearLimit) && (stageClear) && (!bGameOver)) {
stageCleared[Level] = true;
if(stageScores[Level](&tempBool), sizeof(bool));
}
for (int i=0;i(&tempUInt32), sizeof(Uint32));
}
for (int i=0;i(&tempUInt32), sizeof(Uint32));
}
outfile.close();
}
setPlayerWon();
stageButtonStatus = SBstageClear;
}
if ((TowerHeight>12)&&(prevTowerHeight<13)&&(!puzzleMode)) {
//if (SoundEnabled) Mix_PlayChannel(1, heartBeat, 0);
stop+=1000;
}
if ((TowerHeight>12)&&(!puzzleMode)&&(!bGameOver)) {
bNearDeath = true;
}
while (nowTime>nrStops*40+gameStartedAt) //Increase stops, till we reach nowTime
{
if (stop>0) {
stop = stop-20;
if (stop<=0) nrPushedPixel=(int)((nowTime-gameStartedAt)/(1000.0*speed));
}
if (stop<0)
stop = 0;
nrStops++;
}
//If we have static content, we don't raise at all!
if (hasStaticContent())
stop++;
if ((puzzleMode)&&(!bGameOver)&&BoardEmpty()) {
if (!singlePuzzle) {
if(puzzleCleared[Level]==false)
Stats::getInstance()->addOne("puzzlesSolved");
puzzleCleared[Level] = true;
ofstream outfile;
stageButtonStatus = SBpuzzleMode;
outfile.open(puzzleSavePath.c_str(), ios::binary |ios::trunc);
if (!outfile) {
cout << "Error writing to file: " << puzzleSavePath << endl;
}
else {
for (int i=0;i(&tempBool), sizeof(bool));
}
outfile.close();
}
}
setPlayerWon();
}
//increse speed:
if ((nowTime>gameStartedAt+20000*speedLevel)&&(speedLevel <99)&&(!bGameOver))
{
speed = (baseSpeed*0.9)/((double)speedLevel*0.5);
speedLevel++;
nrPushedPixel=(int)((double)(nowTime-gameStartedAt)/(1000.0*speed));
}
//To prevent the stack from raising a lot then we stop a chain (doesn't work anymore)
if (chain>0)
stop+=1;
//Raises the stack
if ((nowTime>gameStartedAt+nrPushedPixel*1000*speed) && (!bGameOver)&&(!stop))
while ((nowTime>gameStartedAt+nrPushedPixel*1000*speed)&&(!(puzzleMode)))
PushPixels();
if (!bGameOver)ClearBlocks();
/*************************************************************
Ai stuff
**************************************************************/
if (bGameOver) {
AIstatus = 0; //Enusres that AI is resetted
}
else
if (AI_Enabled)
if (lastAImove+AI_MoveSpeedgameStartedAt+nrFellDown*140) && (!bGameOver)) FallDown();
if ((nowTimegameStartedAt+2*60*1000)) {
SetGameOver();
if(!NoSound && SoundEnabled)Mix_PlayChannel(1,counterFinalChunk,0);
if ((theTopScoresTimeTrial.isHighScore(score))&&(!AI_Enabled)) {
theTopScoresTimeTrial.addScore(name, score);
//new highscore
//Also check if it is better than the best result so far.
string checkFilename = getPathToSaveFiles() + "/bestTTresult";
ifstream inFile(checkFilename.c_str());
Uint32 bestResult = 3000; //Never accept a best result under 3000
if(inFile)
{
inFile >> bestResult;
inFile.close();
}
if(score>bestResult)
{
string bestFile = getPathToSaveFiles() + "/bestTT";
theReplay.saveReplay(bestFile);
ofstream outFile(checkFilename.c_str(),ios::trunc);
if(outFile)
outFile << score;
}
}
}
}
if ((!bGameOver)&&(!bReplaying)&&(nowTime>gameStartedAt))
{
//cout << nowTime << " bigger than " << gameStartedAt << endl;
theReplay.setFrameSecTo(nowTime-gameStartedAt, getPackage());
}
DoPaintJob();
}
}; //class BlockGame
////////////////////////////////////////////////////////////////////////////////
///////////////////////// BlockAttack class end ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
blockattack-1.4.1+ds1.orig/source/code/joypad.h 0000640 0001750 0001750 00000003411 11111344142 017711 0 ustar pabs pabs /*
joypad.h - Enables joypad support
Copyright (C) 2005 Poul Sander
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
Rvehjvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
*/
//headerfile joypad.h
#include
#include
#include
#define NRofPADS 4
#define NRofBUTTONS 12
using namespace std;
struct Joypad_status{
bool padLeft[NRofPADS];
bool padRight[NRofPADS];
bool padUp[NRofPADS];
bool padDown[NRofPADS];
bool button[NRofBUTTONS];
};
//Contains the init code
bool Joypad_init();
//How many joypads are availble?
#define Joypad_number SDL_NumJoysticks()
//Open a joystick
#define Joypad_open(X) SDL_JoystickOpen(X)
//Returns the status of the joypad
Joypad_status Joypad_getStatus(SDL_Joystick);
class Joypad{
private:
SDL_Joystick *joystick;
static int Joy_count;
public:
bool up,down,left,right,but1,but2;
bool upREL,downREL,leftREL,rightREL,but1REL,but2REL;
bool working;
Joypad();
~Joypad();
void update();
};
blockattack-1.4.1+ds1.orig/source/code/uploadReplay.h 0000640 0001750 0001750 00000002630 11111344142 021066 0 ustar pabs pabs /*
Block Attack - Rise of the Blocks, SDL game, besed on Nintendo's Tetris Attack
Copyright (C) 2008 Poul Sander
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
R�vehjvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
http://blockattack.sf.net
*/
//
// File: uploadReplay.h
// Author: poul
//
// Created on 26. februar 2008, 00:12
//
#ifndef _UPLOADREPLAY_H
#define _UPLOADREPLAY_H
#define HIGHSCORESERVER http://localhost/~poul/blockattackHighscores/result/
#include
#include "SDL.h"
using namespace std;
SDL_mutex *mutDownload,*mutUpload;
bool uploadReplay_canUpload();
void uploadReplay_upload();
class OnlineHighscores
{
};
#endif /* _UPLOADREPLAY_H */
blockattack-1.4.1+ds1.orig/source/code/ttfont.cc 0000640 0001750 0001750 00000005240 11111344142 020101 0 ustar pabs pabs /*
Block Attack - Rise of the Blocks, SDL game, besed on Nintendo's Tetris Attack
Copyright (C) 2008 Poul Sander
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
R�vehjvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
http://blockattack.sf.net
*/
#include "ttfont.h"
//extern SDL_Surface *tmp;
//#define CONVERTA(n) tmp = SDL_DisplayFormatAlpha(n); SDL_FreeSurface(n); n = tmp
TTFont::TTFont()
{
font = NULL;
actualInstance = false;
}
int TTFont::count = 0;
TTFont::TTFont(TTF_Font *f)
{
if(!(TTF_WasInit()))
{
//Init TTF for the first time
TTF_Init();
}
if(f == NULL)
cout << "Font was null!" << endl;
actualInstance = false; //We have not yet copied to final location
font = f;
}
TTFont::~TTFont()
{
if(!actualInstance)
return;
cout << "Closing a font" << endl;
TTF_CloseFont(font);
font = NULL;
count--;
if(count==0)
TTF_Quit();
}
//Copy constructor, you cannot copy an actual instance
TTFont::TTFont(const TTFont &t)
{
if(t.font == NULL || t.actualInstance)
{
font = NULL;
actualInstance = false;
}
else
{
font = t.font;
actualInstance = true;
count++;
}
}
int TTFont::getTextHeight()
{
return TTF_FontHeight(font);
}
int TTFont::getTextWidth(string text)
{
int width = 0;
if(TTF_SizeText(font,text.c_str(),&width,NULL)!=0)
cout << "Failed to get text width!" << endl;
return width;
}
void TTFont::writeText(string text, SDL_Surface *target, int x, int y)
{
SDL_Surface *text_surface;
SDL_Color color={255,255,255};
if(!(text_surface=TTF_RenderText_Solid(font,text.c_str(), color)))
{
cout << "Error writing text: " << TTF_GetError() << endl;
}
else
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(text_surface,NULL,target,&dest);
SDL_FreeSurface(text_surface);
}
}
blockattack-1.4.1+ds1.orig/source/code/win.make 0000640 0001750 0001750 00000004732 11125714525 017730 0 ustar pabs pabs GAMEDIR=../../Game/
BINARY=$(GAMEDIR)blockattack.exe
CC=i586-mingw32msvc-gcc
CPP=i586-mingw32msvc-g++
BASE_CFLAGS=-c $(shell sdl-config --cflags)
BASE_LIBS=$(shell sdl-config --libs) -lSDL_image -lSDL_mixer -lSDL_ttf
#For developement only
ifndef DEBUG
DEBUG=1
endif
ifndef NETWORK
NETWORK=1
endif
#Never use the apstract fs, it is not implemented and just linking it breaks on some systems
ifndef USE_ABSTRACT_FS
USE_ABSTRACT_FS=0
endif
#Compile with debug information or optimized.
ifeq ($(DEBUG),1)
BASE_CFLAGS += -g -DDEBUG=1
else
BASE_CFLAGS += -O4
endif
ifeq ($(NETWORK),1)
BASE_CFLAGS += -DNETWORK=1
BASE_LIBS += -lenet
else
BASE_CFLAGS += -DNETWORK=0
endif
ifeq ($(USE_ABSTRACT_FS),1)
BASE_CFLAGS += -DUSE_ABSTRACT_FS=1
BASE_LIBS += -lphysfs
else
BASE_CFLAGS += -DUSE_ABSTRACT_FS=0
endif
$(BINARY): winbuild/main.o winbuild/highscore.o winbuild/SFont.o winbuild/ReadKeyboard.o winbuild/joypad.o winbuild/listFiles.o winbuild/replay.o winbuild/common.o winbuild/stats.o winbuild/uploadReplay.o
$(CPP) -O -o $(BINARY) winbuild/main.o winbuild/highscore.o winbuild/SFont.o winbuild/ReadKeyboard.o winbuild/joypad.o winbuild/listFiles.o winbuild/replay.o winbuild/common.o winbuild/stats.o $(BASE_LIBS)
#-lphysfs
winbuild/main.o: main.cpp BlockGame.hpp mainVars.hpp common.h
$(CPP) $(BASE_CFLAGS) main.cpp -o winbuild/main.o
winbuild/highscore.o: highscore.h highscore.cpp
$(CPP) $(BASE_CFLAGS) highscore.cpp -o winbuild/highscore.o
winbuild/SFont.o: SFont.h SFont.c
$(CC) $(BASE_CFLAGS) SFont.c -o winbuild/SFont.o
winbuild/ReadKeyboard.o: ReadKeyboard.h ReadKeyboard.cpp
$(CPP) $(BASE_CFLAGS) ReadKeyboard.cpp -o winbuild/ReadKeyboard.o
winbuild/joypad.o: joypad.h joypad.cpp
$(CPP) $(BASE_CFLAGS) joypad.cpp -o winbuild/joypad.o
winbuild/listFiles.o: listFiles.h listFiles.cpp
$(CPP) $(BASE_CFLAGS) listFiles.cpp -o winbuild/listFiles.o
winbuild/replay.o: replay.h replay.cpp
$(CPP) $(BASE_CFLAGS) replay.cpp -o winbuild/replay.o
winbuild/stats.o: stats.h stats.cc
$(CPP) $(BASE_CFLAGS) stats.cc -o winbuild/stats.o
winbuild/common.o: common.h common.cc
$(CPP) $(BASE_CFLAGS) common.cc -o winbuild/common.o
winbuild/uploadReplay.o: uploadReplay.cc uploadReplay.h
$(CPP) $(BASE_CFLAGS) uploadReplay.cc -o winbuild/uploadReplay.o
#winbuild/MenuSystem.o: MenuSystem.cc MenuSystem.h
# $(CPP) $(BASE_CFLAGS) MenuSystem.cc -o winbuild/MenuSystem.o
#winbuild/ttfont.o: ttfont.h ttfont.cc
# $(CPP) $(BASE_CFLAGS) ttfont.cc -o winbuild/ttfont.o
run: $(BINARY)
clean:
rm winbuild/*o
blockattack-1.4.1+ds1.orig/source/code/README 0000640 0001750 0001750 00000002012 11111344142 017126 0 ustar pabs pabs Thanks for downloading Block Attack - Rise Of the Blocks 1.3.2 for Linux and other Platforms
Version 1.3.2
scons must be present on the system to compile. (There is a make file but it is mostly for development and unpriviliged compiling, NEVER use "make install"!)
To build:
scons
scons install (as root)
The game can be ran by double clicking "starter" in the "Game" directory. (Only if build with the make file)
If it doesn't work (because your distro uses an old stdc++ file, is not Linux or you are running 64 bit you will need to compile)
If you get errors you might need certain packages on your system.
Dependencies:
On Ubunut the required packages are to run are: libsdl1.2debian-all, libsdl-image1.2, libsdl-mixer1.2 and libenet
To compile: build-essential, libsdl1.2-dev, libsdl-image1.2-dev, libsdl-mixer1.2-dev and libenet-dev
By default the game is now placed in: /usr/local/bin/blockattack
This means that it can be runned by just typing "blockattack"
http://blockattack.sf.net
Poul Sander poul@poulsander.com
blockattack-1.4.1+ds1.orig/source/code/replay.h 0000640 0001750 0001750 00000006152 11165743143 017741 0 ustar pabs pabs /*
replay.h
Copyright (C) 2005 Poul Sander
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
R�veh�jvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
*/
//headerfile for replay.h
/*
replay is used to save a replay, there is saved 10 moves per second, should be
able to give a realistic replay
*/
//constants - 3000 is 5 minutes
#define FRAMESPERSEC 10
#include "SDL.h"
#include
#include
#include
#include
using namespace std;
//board_package, stores a board can be used for network play and replay
struct boardPackage //92 bytes
{
Uint32 time; //game time
Uint8 brick[6][13];
Uint8 pixels; //pixels pushed
Uint8 cursorX; //Cursor coordinate
Uint8 cursorY; // -||-
Uint32 score;
Uint8 speed;
Uint8 chain;
Uint8 result; //0=none,1=gameOver,2=winner,4=draw
};
class Replay{
private:
//Our replay is stored in an array of TOTALFRAMES length
//boardPackage bps[TOTALFRAMES];
vector bps;
//The final package is not set to any specific time
boardPackage finalPack;
//We store number of frames, so we know how long to read the array
Uint32 nrOfFrames;
//An enumerator, so we know how it ends! (should be removed then boardPackage is the 92 byte version)
enum { gameOver=0, winner, looser, draw } theResult;
//If we are loaded from a file, then we are read only
bool isLoaded;
public:
//Store player name
char name[30];
Replay(); //Constructor
Replay(const Replay& r); //Copy constructor
Uint32 getNumberOfFrames(); //Returns number of frames
void setFrameSecTo(Uint32,boardPackage); //Sets frame at a given time to the package
void setFinalFrame(boardPackage,int); //Sets the final package
boardPackage getFrameSec(Uint32); //Gets a frame to a time
boardPackage getFinalFrame(); //Gets the last frame, that must remain
int getFinalStatus(); //Return the result: winner, looser, draw or gameOver
bool isFinnished(Uint32); //Returns true if we are done
//Ok, I'll ignore this for some time, and just save to file, if however, we ever use a dynamic saving structure, we are fucked
bool saveReplay(string); //Saves a replay
bool saveReplay(string,Replay p2); //saves a replay, plus another replay given as a parameter
bool loadReplay(string); //laods a replay
bool loadReplay2(string); //loads the second part of the replay file, if it exists, returns false otherwise
};
blockattack-1.4.1+ds1.orig/source/code/ttfont.h 0000640 0001750 0001750 00000003161 11165743143 017760 0 ustar pabs pabs /*
Block Attack - Rise of the Blocks, SDL game, besed on Nintendo's Tetris Attack
Copyright (C) 2008 Poul Sander
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
R�vehjvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
http://blockattack.sf.net
*/
//
// File: ttfont.hpp.h
// Author: poul
//
// Created on 25. december 2007, 13:52
//
#ifndef _TTFONT_H
#define _TTFONT_H
#include
#include
#include
#include "SDL.h"
//#include "SDL_ttf.h" //To use True Type Fonts in SDL
using namespace std;
class TTFont
{
private:
static int count; //The total number of instances
TTF_Font *font;
bool actualInstance;
public:
TTFont();
TTFont(TTF_Font *f);
TTFont(const TTFont &t);
~TTFont();
int getTextWidth(string text);
int getTextHeight();
void writeText(string text, SDL_Surface *target, int x, int y);
};
#endif /* _TTFONT_H */
blockattack-1.4.1+ds1.orig/source/code/SFont.c 0000640 0001750 0001750 00000012242 11111344142 017451 0 ustar pabs pabs /* SFont: a simple font-library that uses special .pngs as fonts
Copyright (C) 2003 Karl Bartel
License: GPL or LGPL (at your choice)
WWW: http://www.linux-games.com/sfont/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Karl Bartel
Cecilienstr. 14
12307 Berlin
GERMANY
karlb@gmx.net
*/
#include
#include
#include
#include "SFont.h"
static long GetPixel(SDL_Surface *Surface, Sint32 X, Sint32 Y)
{
Uint8 *bits;
Uint32 Bpp;
assert(X>=0);
assert(Xw);
Bpp = Surface->format->BytesPerPixel;
bits = ((Uint8 *)Surface->pixels)+Y*Surface->pitch+X*Bpp;
// Get the pixel
switch(Bpp) {
case 1:
return *((Uint8 *)Surface->pixels + Y * Surface->pitch + X);
break;
case 2:
return *((Uint16 *)Surface->pixels + Y * Surface->pitch/2 + X);
break;
case 3: { // Format/endian independent
Uint8 r, g, b;
r = *((bits)+Surface->format->Rshift/8);
g = *((bits)+Surface->format->Gshift/8);
b = *((bits)+Surface->format->Bshift/8);
return SDL_MapRGB(Surface->format, r, g, b);
}
break;
case 4:
return *((Uint32 *)Surface->pixels + Y * Surface->pitch/4 + X);
break;
}
return -1;
}
SFont_Font* SFont_InitFont(SDL_Surface* Surface)
{
int x = 0, i = 0;
Uint32 pixel;
SFont_Font* Font;
Uint32 pink;
if (Surface == NULL)
return NULL;
Font = (SFont_Font *) malloc(sizeof(SFont_Font));
Font->Surface = Surface;
SDL_LockSurface(Surface);
pink = SDL_MapRGB(Surface->format, 255, 0, 255);
while (x < Surface->w) {
if (GetPixel(Surface, x, 0) == pink) {
Font->CharPos[i++]=x;
while((x < Surface->w) && (GetPixel(Surface, x, 0)== pink))
x++;
Font->CharPos[i++]=x;
}
x++;
}
Font->MaxPos = x-1;
pixel = GetPixel(Surface, 0, Surface->h-1);
SDL_UnlockSurface(Surface);
SDL_SetColorKey(Surface, SDL_SRCCOLORKEY, pixel);
return Font;
}
void SFont_FreeFont(SFont_Font* FontInfo)
{
SDL_FreeSurface(FontInfo->Surface);
free(FontInfo);
}
void SFont_Write(SDL_Surface *Surface, const SFont_Font *Font,
int x, int y, const char *text)
{
const char* c;
int charoffset;
SDL_Rect srcrect, dstrect;
if(text == NULL)
return;
// these values won't change in the loop
srcrect.y = 1;
dstrect.y = y;
srcrect.h = dstrect.h = Font->Surface->h - 1;
for(c = text; *c != '\0' && x <= Surface->w ; c++) {
charoffset = ((int) (*c - 33)) * 2 + 1;
// skip spaces and nonprintable characters
if (*c == ' ' || charoffset < 0 || charoffset > Font->MaxPos) {
x += Font->CharPos[2]-Font->CharPos[1];
continue;
}
srcrect.w = dstrect.w =
(Font->CharPos[charoffset+2] + Font->CharPos[charoffset+1])/2 -
(Font->CharPos[charoffset] + Font->CharPos[charoffset-1])/2;
srcrect.x = (Font->CharPos[charoffset]+Font->CharPos[charoffset-1])/2;
dstrect.x = x - (int)(Font->CharPos[charoffset]
- Font->CharPos[charoffset-1])/2;
SDL_BlitSurface(Font->Surface, &srcrect, Surface, &dstrect);
x += Font->CharPos[charoffset+1] - Font->CharPos[charoffset];
}
}
int SFont_TextWidth(const SFont_Font *Font, const char *text)
{
const char* c;
int charoffset=0;
int width = 0;
if(text == NULL)
return 0;
for(c = text; *c != '\0'; c++) {
charoffset = ((int) *c - 33) * 2 + 1;
// skip spaces and nonprintable characters
if (*c == ' ' || charoffset < 0 || charoffset > Font->MaxPos) {
width += Font->CharPos[2]-Font->CharPos[1];
continue;
}
width += Font->CharPos[charoffset+1] - Font->CharPos[charoffset];
}
return width;
}
int SFont_TextHeight(const SFont_Font* Font)
{
return Font->Surface->h - 1;
}
void SFont_WriteCenter(SDL_Surface *Surface, const SFont_Font *Font,
int y, const char *text)
{
SFont_Write(Surface, Font, Surface->w/2 - SFont_TextWidth(Font, text)/2,
y, text);
}
blockattack-1.4.1+ds1.orig/source/code/winbuild/ 0000750 0001750 0001750 00000000000 11277746240 020111 5 ustar pabs pabs blockattack-1.4.1+ds1.orig/source/code/replay.cpp 0000640 0001750 0001750 00000021076 11165743143 020276 0 ustar pabs pabs /*
replay.cpp
Copyright (C) 2005 Poul Sander
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
R�veh�jvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
*/
/*
Handles replay
*/
#include
#include "replay.h"
Replay::Replay()
{
nrOfFrames=0;
isLoaded = false;
}
Replay::Replay(const Replay& r)
{
bps = r.bps;
finalPack = r.finalPack;
nrOfFrames = r.nrOfFrames;
isLoaded = r.isLoaded;
theResult = r.theResult;
strncpy(name,r.name,sizeof(name));
}
Uint32 Replay::getNumberOfFrames()
{
return nrOfFrames;
}
void Replay::setFrameSecTo(Uint32 miliseconds, boardPackage bp)
{
if (isLoaded)
return;
int framesToSet = (miliseconds*FRAMESPERSEC)/1000;
for (int i=nrOfFrames;i(&version),sizeof(Uint32)); //Fileversion
Uint8 nrOfReplays = 1;
saveFile.write(reinterpret_cast(&nrOfReplays),sizeof(Uint8)); //nrOfReplaysIn File
saveFile.write(reinterpret_cast(&nrOfFrames),sizeof(Uint32)); //Nr of frames in file
for (int i=0; i(&bp),sizeof(bp));
}
saveFile.write(reinterpret_cast(&finalPack),sizeof(finalPack));
saveFile.write(reinterpret_cast(&theResult),sizeof(theResult));
saveFile.write(reinterpret_cast(&name),sizeof(name));
saveFile.close();
return true;
}
else
{
return false;
}
}
bool Replay::saveReplay(string filename,Replay p2)
{
//Saving as fileversion 3
cout << "Saving as version 3 save file (2 players)" << endl;
ofstream saveFile;
saveFile.open(filename.c_str(),ios::binary|ios::trunc);
if (saveFile)
{
Uint32 version = 3;
boardPackage bp;
saveFile.write(reinterpret_cast(&version),sizeof(Uint32)); //Fileversion
Uint8 nrOfReplays = 2;
saveFile.write(reinterpret_cast(&nrOfReplays),sizeof(Uint8)); //nrOfReplaysIn File
saveFile.write(reinterpret_cast(&nrOfFrames),sizeof(Uint32)); //Nr of frames in file
for (int i=0; i(&bp),sizeof(bp));
}
saveFile.write(reinterpret_cast(&finalPack),sizeof(finalPack));
saveFile.write(reinterpret_cast(&theResult),sizeof(theResult));
saveFile.write(reinterpret_cast(&name),sizeof(name));
///Player 2 starts here!!!!!!!!!!!!!!!!!!!!!!
saveFile.write(reinterpret_cast(&p2.nrOfFrames),sizeof(Uint32)); //Nr of frames in file
for (int i=0; (i(&bp),sizeof(bp));
}
saveFile.write(reinterpret_cast(&p2.finalPack),sizeof(finalPack));
saveFile.write(reinterpret_cast(&p2.theResult),sizeof(theResult));
saveFile.write(reinterpret_cast(&p2.name),sizeof(name));
saveFile.close();
return true;
}
else
{
return false;
}
}
bool Replay::loadReplay(string filename)
{
isLoaded = true;
ifstream loadFile;
loadFile.open(filename.c_str(),ios::binary);
if (loadFile)
{
Uint32 version;
loadFile.read(reinterpret_cast(&version),sizeof(Uint32));
switch (version)
{
case 3:
cout << "Loading a version 3 save game" << endl;
Uint8 nrOfPlayers;
boardPackage bp;
loadFile.read(reinterpret_cast(&nrOfPlayers),sizeof(Uint8));
loadFile.read(reinterpret_cast(&nrOfFrames),sizeof(Uint32));
bps.clear();
for (int i=0; (i(&bp),sizeof(bp));
bps.push_back(bp);
}
loadFile.read(reinterpret_cast(&finalPack),sizeof(finalPack));
loadFile.read(reinterpret_cast(&theResult),sizeof(theResult));
loadFile.read(reinterpret_cast(&name),sizeof(name));
break;
default:
cout << "Unknown version" << endl;
return false;
};
loadFile.close();
cout << "Loaded 1 player" << endl;
}
else
{
cout << "File not found or couldn't open: " << filename << endl;
return false;
}
}
bool Replay::loadReplay2(string filename)
{
isLoaded = true;
ifstream loadFile;
loadFile.open(filename.c_str(),ios::binary);
if (loadFile)
{
Uint32 version;
loadFile.read(reinterpret_cast(&version),sizeof(Uint32));
switch (version)
{
case 3:
Uint8 nrOfPlayers;
boardPackage bp;
loadFile.read(reinterpret_cast(&nrOfPlayers),sizeof(Uint8));
if (nrOfPlayers<2)
{
loadFile.close();
cout << "Only one player in replay" << endl;
return false;
}
cout << "loading player 2" << endl;
loadFile.read(reinterpret_cast(&nrOfFrames),sizeof(Uint32));
for (int i=0; (i(&bp),sizeof(bp));
//bps.push_back(bp); We have already read player 1 with another function
}
loadFile.read(reinterpret_cast(&finalPack),sizeof(finalPack));
loadFile.read(reinterpret_cast(&theResult),sizeof(theResult));
loadFile.read(reinterpret_cast(&name),sizeof(name));
loadFile.read(reinterpret_cast(&nrOfFrames),sizeof(Uint32));
bps.reserve(nrOfFrames);
for (int i=0; (i(&bp),sizeof(bp));
bps.push_back(bp);
}
loadFile.read(reinterpret_cast(&finalPack),sizeof(finalPack));
loadFile.read(reinterpret_cast(&theResult),sizeof(theResult));
loadFile.read(reinterpret_cast(&name),sizeof(name));
break;
default:
cout << "Unknown version: " << version << endl;
return false;
};
loadFile.close();
}
else
{
cout << "File not found or couldn't open: " << filename << endl;
return false;
}
}
blockattack-1.4.1+ds1.orig/source/code/physfs_stream.hpp 0000640 0001750 0001750 00000034632 11205333766 021701 0 ustar pabs pabs /*
physfs_stream.hpp
Copyright (C) 2009 Poul Sander
Copied from Warzone 2100
http://svn.gna.org/viewcvs/warzone/branches/sound/lib/sound/general/physfs_stream.hpp?rev=3623
Copyright (C) 2007 Warzone Resurrection Project
Copyright (C) 2007 Giel van Schijndel
Originally part of SuperTux:
http://svn.berlios.de/svnroot/repos/supertux/trunk/supertux/src/physfs/physfs_stream.cpp revision 4176
Copyright (C) 2006 Matthias Braun
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
R�veh�jvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
*/
#ifndef __INCLUDED_PHYSFS_STREAM_HPP__
#define __INCLUDED_PHYSFS_STREAM_HPP__
#define BUF_SIZE 1024
#include
#include
#include
#include
/*Compared to Warzone 2100 boost:array has been replaced by vector to limit
the compile requirements*/
#include
/** This an implementation of "File-based streams" as described in the
* ISO/IEC 14882:1998(E) C++ Standard in chapter 27 "Input/output library",
* section 8 "File-based streams". This implementation however uses PhysicsFS
* instead of the C-library's FILE functions. Also this implementation lacks
* an implementation of basic_fstream because PhysicsFS does not support
* opening a file both for reading as well as writing.
*
* This header contains similar classes and typedefs as does. Both
* similar in names as well as operation, the main difference is that these
* classes do _not_ reside in namespace std.
*/
namespace PhysFS
{
/** Typedefinitions mandated by the C++ standard in section 27.8.1
*/
template >
class physfs_filebuf;
typedef physfs_filebuf filebuf;
typedef physfs_filebuf wfilebuf;
template >
class physfs_ifstream;
typedef physfs_ifstream ifstream;
typedef physfs_ifstream wifstream;
template >
class physfs_ofstream;
typedef physfs_ofstream ofstream;
typedef physfs_ofstream wofstream;
/** This class implements a C++ streambuf object for physfs files.
* So that you can use normal istream and ostream operations on them.
* This class is similar to std::basic_filebuf as defined in
* section 27.8.1.1, except in name.
*/
template
class physfs_filebuf : public std::basic_streambuf<_CharT, _Traits>
{
public:
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef std::basic_streambuf<_CharT, _Traits> __streambuf_type;
typedef physfs_filebuf<_CharT, _Traits> __filebuf_type;
physfs_filebuf() :
_file(0)
{
_buf.resize(BUF_SIZE);
}
virtual ~physfs_filebuf()
{
close();
}
bool is_open() const throw()
{
return (_file != 0);
}
__filebuf_type* open(const char* fileName, std::ios_base::openmode mode)
{
// Return failure if this file buf is open already
if (is_open() != false)
return 0;
// Return failure if we are requested to open a file in an unsupported mode
if (!(mode & std::ios_base::binary) ||
(mode & std::ios_base::in &&
mode & std::ios_base::out))
return 0;
// Open the file
if (mode & std::ios_base::out &&
mode & std::ios_base::app)
{
_file = PHYSFS_openAppend(fileName);
_writeStream = true;
}
else if (mode & std::ios_base::out)
{
_file = PHYSFS_openWrite(fileName);
_writeStream = true;
}
else if (mode & std::ios_base::in)
{
_file = PHYSFS_openRead(fileName);
_writeStream = false;
}
else
{
return 0;
}
if (!_file)
return 0;
if (mode & std::ios_base::ate &&
mode & std::ios_base::in)
{
if (!PHYSFS_seek(_file, PHYSFS_fileLength(_file)))
{
close();
return 0;
}
}
return this;
}
__filebuf_type* close()
{
// Return failure if this file buf is closed already
if (is_open() == false)
return 0;
sync();
if (!PHYSFS_close(_file))
{
return 0;
}
_file = 0;
return this;
}
protected:
// Read stuff:
virtual int_type underflow()
{
if (!is_open() || _writeStream)
return traits_type::eof();
if(PHYSFS_eof(_file))
{
return traits_type::eof();
}
PHYSFS_sint64 objectsRead = PHYSFS_read(_file, &*_buf.begin(), sizeof(char_type), BUF_SIZE);
if(objectsRead <= 0)
{
return traits_type::eof();
}
char_type* xend = (static_cast (objectsRead) == BUF_SIZE) ? &*_buf.end() : &_buf[objectsRead];
setg(&*_buf.begin(), &*_buf.begin(), xend);
return traits_type::to_int_type(_buf.front());
}
virtual pos_type seekpos(pos_type pos, std::ios_base::openmode)
{
if (!is_open() || _writeStream)
return pos_type(off_type(-1));
if(PHYSFS_seek(_file, static_cast (pos)) == 0)
{
return pos_type(off_type(-1));
}
// the seek invalidated the buffer
setg(&*_buf.begin(), &*_buf.begin(), &*_buf.begin());
return pos;
}
virtual pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode mode)
{
if (!is_open() || _writeStream)
return pos_type(off_type(-1));
off_type pos = off;
switch (dir)
{
case std::ios_base::beg:
break;
case std::ios_base::cur:
{
PHYSFS_sint64 ptell = PHYSFS_tell(_file);
pos_type buf_tell = static_cast (ptell) - static_cast (__streambuf_type::egptr() - __streambuf_type::gptr());
if(off == 0)
{
return buf_tell;
}
pos += static_cast (buf_tell);
break;
}
case std::ios_base::end:
pos = static_cast (PHYSFS_fileLength(_file)) - pos;
break;
default:
//assert(!"invalid seekdirection");
return pos_type(off_type(-1));
}
return seekpos(static_cast (pos), mode);
}
// Write stuff:
virtual int_type overflow(int_type c = traits_type::eof())
{
if (!is_open() || !_writeStream)
return traits_type::eof();
size_t size = __streambuf_type::pptr() - __streambuf_type::pbase();
if(size == 0)
return 0;
PHYSFS_sint64 res = PHYSFS_write(_file, __streambuf_type::pbase(), sizeof(char_type), size);
if(res <= 0)
return traits_type::eof();
if(!traits_type::eq_int_type(c, traits_type::eof()))
{
PHYSFS_sint64 res = PHYSFS_write(_file, &c, sizeof(char_type), 1);
if(res <= 0)
return traits_type::eof();
}
char_type* xend = (static_cast (res) == BUF_SIZE) ? &*_buf.end() : &_buf[res];
setp(&*_buf.begin(), xend);
return 0;
}
virtual int sync()
{
if (!is_open() || !_writeStream)
return -1;
return overflow(traits_type::eof());
}
virtual std::streamsize showmanyc()
{
if (!is_open() || _writeStream)
return -1;
PHYSFS_sint64 fileSize = PHYSFS_fileLength(_file);
return static_cast (fileSize);
}
private:
PHYSFS_file* _file;
bool _writeStream;
vector _buf;
};
/** This class implements a C++ istream object for physfs files.
* This class is similar to std::basic_ifstream as defined in
* section 27.8.1.5, except in name.
*/
template
class physfs_ifstream : public std::basic_istream<_CharT, _Traits>
{
public:
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef physfs_filebuf<_CharT, _Traits> __filebuf_type;
typedef std::basic_istream<_CharT, _Traits> __istream_type;
physfs_ifstream() throw() :
__istream_type(&_sb)
{
}
explicit physfs_ifstream(const char* fileName, std::ios_base::openmode mode = std::ios_base::binary) :
__istream_type(&_sb)
{
open(fileName, mode);
}
const __filebuf_type* rdbuf() const throw()
{
return &_sb;
}
__filebuf_type* rdbuf() throw()
{
return &_sb;
}
bool is_open() const throw()
{
return rdbuf()->is_open();
}
void open(const char* fileName, std::ios_base::openmode mode = std::ios_base::binary)
{
if (!rdbuf()->open(fileName, mode | std::ios_base::in))
{
__istream_type::setstate(std::ios_base::failbit);
}
}
void close()
{
if (!rdbuf()->close())
{
__istream_type::setstate(std::ios_base::failbit);
}
}
private:
__filebuf_type _sb;
};
/** This class implements a C++ ostream object for physfs files.
* This class is similar to std::basic_ofstream as defined in
* section 27.8.1.8, except in name.
*/
template
class physfs_ofstream : public std::basic_ostream<_CharT, _Traits>
{
public:
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef physfs_filebuf<_CharT, _Traits> __filebuf_type;
typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
physfs_ofstream() throw() :
__ostream_type(&_sb)
{
}
explicit physfs_ofstream(const char* fileName, std::ios_base::openmode mode = std::ios_base::binary) :
__ostream_type(&_sb)
{
open(fileName, mode);
}
const __filebuf_type* rdbuf() const throw()
{
return &_sb;
}
__filebuf_type* rdbuf() throw()
{
return &_sb;
}
bool is_open() const throw()
{
return rdbuf()->is_open();
}
void open(const char* fileName, std::ios_base::openmode mode = std::ios_base::binary)
{
if (!rdbuf()->open(fileName, mode | std::ios_base::out))
{
__ostream_type::setstate(std::ios_base::failbit);
}
}
void close()
{
if (!rdbuf()->close())
{
__ostream_type::setstate(std::ios_base::failbit);
}
}
private:
__filebuf_type _sb;
};
}
#endif // __INCLUDED_PHYSFS_STREAM_HPP__
blockattack-1.4.1+ds1.orig/source/code/SFont.h 0000640 0001750 0001750 00000005732 11111344142 017464 0 ustar pabs pabs /* SFont: a simple font-library that uses special bitmaps as fonts
Copyright (C) 2003 Karl Bartel
License: GPL or LGPL (at your choice)
WWW: http://www.linux-games.com/sfont/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Karl Bartel
Cecilienstr. 14
12307 Berlin
GERMANY
karlb@gmx.net
*/
/************************************************************************
* SFONT - SDL Font Library by Karl Bartel *
* *
* All functions are explained below. For further information, take a *
* look at the example files, the links at the SFont web site, or *
* contact me, if you problem isn' addressed anywhere. *
* *
************************************************************************/
#ifndef SFONT_H
#define SFONT_H
#include
#ifdef __cplusplus
extern "C" {
#endif
// Delcare one variable of this type for each font you are using.
// To load the fonts, load the font image into YourFont->Surface
// and call InitFont( YourFont );
typedef struct {
SDL_Surface *Surface;
int CharPos[512];
int MaxPos;
} SFont_Font;
// Initializes the font
// Font: this contains the suface with the font.
// The Surface must be loaded before calling this function
SFont_Font* SFont_InitFont (SDL_Surface *Font);
// Frees the font
// Font: The font to free
// The font must be loaded before using this function.
void SFont_FreeFont(SFont_Font* Font);
// Blits a string to a surface
// Destination: the suface you want to blit to
// text: a string containing the text you want to blit.
void SFont_Write(SDL_Surface *Surface, const SFont_Font *Font, int x, int y,
const char *text);
// Returns the width of "text" in pixels
int SFont_TextWidth(const SFont_Font* Font, const char *text);
// Returns the height of "text" in pixels (which is always equal to Font->Surface->h)
int SFont_TextHeight(const SFont_Font* Font);
// Blits a string to Surface with centered x position
void SFont_WriteCenter(SDL_Surface *Surface, const SFont_Font* Font, int y,
const char *text);
#ifdef __cplusplus
}
#endif
#endif /* SFONT_H */
blockattack-1.4.1+ds1.orig/source/code/AUTHORS 0000640 0001750 0001750 00000000666 11277345404 017352 0 ustar pabs pabs Block Attack - Rise of the Blocks by
Poul Sander
http://blockattack.sf.net
Gonéri Le Bouder
Done some work for making it work with SHAREDIR and all Scons scripts
Contains SFont - SDL Font Library by
Karl Bartel
Jordà Polo
Two patches
A lot of the 1.4.0 graphics is by
Iwan Gabovitch aka qubodup
Detailed auther information regarding media can be found in the blockattack.data zip-file
blockattack-1.4.1+ds1.orig/source/code/mainVars.hpp 0000640 0001750 0001750 00000027051 11165743143 020566 0 ustar pabs pabs /*
mainVars.hpp
Copyright (C) 2007 Poul Sander
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
R�veh�jvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
*/
//Make sure it is only included once
#ifndef _MAINVARS_HPP
#define _MAINVARS_HPP
//main variables and constants
//Some definitions
//The game is divided in frames. FALLTIME means the blocks will fall one block every FRAMELENGTH*FALLTIME millisecond
#define FRAMELENGTH 50
#define HANGTIME 40
#define FALLTIME 20
//Don't change the following, they are fundamental and later some functions are hardcoded
#define BLOCKFALL 10000
#define BLOCKWAIT 100000
#define BLOCKHANG 1000
#define GARBAGE 1000000
#define CHAINPLACE 10000000
#define NUMBEROFCHAINS 100
//Animation lengths:
#define READYTIME 500
#define BOMBTIME 200
#define CURSORTIME 200
using namespace std; //remove it if you dare...
char sharedir[] = SHAREDIR;
//All graphic in the game (as pointers):
SDL_Surface *background; //Stores background
SDL_Surface *backgroundImage; //Stores the background image
int backgroundImageW, backgroundImageH; //size of background image
SDL_Surface *backBoard; //Stores the background to the board
SDL_Surface *b1player;
SDL_Surface *b2players;
SDL_Surface *bVsMode;
SDL_Surface *bVsModeConfig; //Added in 1.4.0
SDL_Surface *bStageClear;
SDL_Surface *bPuzzle;
SDL_Surface *bNewGame; //The New Game botton
SDL_Surface *bEndless; //Endless button (sub to new)
SDL_Surface *bTimeTrial; //Time trial button (sub to new)
SDL_Surface *bOptions; //The Options botton
//new in 1.1.1
SDL_Surface *bConfigure; //The configure button
SDL_Surface *bSelectPuzzle; //The Select Puzzle Button
SDL_Surface *bBack; //The "Back" button
SDL_Surface *bForward; //The "forward" button
//new in 1.1.1 end
//new in 1.1.2
SDL_Surface *iChainBack;
//new in 1.1.2 end (nota that iSmallFont has also been added)
//new in 1.2.0
SDL_Surface *bReplay;
SDL_Surface *bSave;
SDL_Surface *bLoad;
#if NETWORK
SDL_Surface *bNetwork;
SDL_Surface *bConnect;
SDL_Surface *bHost;
#endif
//new in 1.2.0 end
SDL_Surface *bHighScore; //The High Score botton
SDL_Surface *bExit; //The Exit botton
SDL_Surface *blackLine; //The seperator in stage clear
SDL_Surface *stageBobble; //The bobble instage clear
SDL_Surface *screen; //The whole screen;
SDL_Surface *iGameOver; //The gameOver image
SDL_Surface *iWinner; //the "winner" image
SDL_Surface *iDraw; //the "draw" image
SDL_Surface *iLoser; //the "loser" image
//Animations:
SDL_Surface *cursor[2]; //The animated cursor
SDL_Surface *bomb[2]; //Bomb then the bricks should blow
SDL_Surface *ready[2]; //Before the blocks fall
SDL_Surface *explosion[4]; //Then a block explodes
//Animations end
SDL_Surface *counter[3]; //Counts down from 3
SDL_Surface *bricks[7]; //The bricks, saved in an array of pointers
SDL_Surface *crossover; //Cross the bricks that will be cleared soon
SDL_Surface *balls[7]; //The balls (the small ones that jump around)
SDL_Surface *iBlueFont; //Contains the blue font used
SDL_Surface *iSmallFont; //Small font used for the chain text
SDL_Surface *optionsBack;
SDL_Surface *changeButtonsBack;
SDL_Surface *dialogBox;
//SDL_Surface *fileDialogBox; //Manual entering of filename, new in 1.1.1, obsolute in 1.1.2
SDL_Surface *bOn;
SDL_Surface *bOff;
SDL_Surface *bChange;
SDL_Surface *b1024;
SDL_Surface *iLevelCheck; //To the level select screen
SDL_Surface *iLevelCheckBox;
SDL_Surface *iCheckBoxArea;
SDL_Surface *boardBackBack;
SDL_Surface *garbageTL; //the Garbage Blocks
SDL_Surface *garbageT;
SDL_Surface *garbageTR;
SDL_Surface *garbageR;
SDL_Surface *garbageBR;
SDL_Surface *garbageB;
SDL_Surface *garbageBL;
SDL_Surface *garbageL;
SDL_Surface *garbageFill;
SDL_Surface *garbageM;
SDL_Surface *garbageML;
SDL_Surface *garbageMR;
SDL_Surface *smiley[4];
SDL_Surface *garbageGM;
SDL_Surface *garbageGML;
SDL_Surface *garbageGMR;
SDL_Surface *transCover; //The transperant block, covers the upcomming
#if LEVELEDITOR
SDL_Surface *bCreateFile;
SDL_Surface *bDeletePuzzle;
SDL_Surface *bLoadFile;
SDL_Surface *bMoveBack;
SDL_Surface *bMoveDown;
SDL_Surface *bMoveForward;
SDL_Surface *bMoveLeft;
SDL_Surface *bMoveRight;
SDL_Surface *bMoveUp;
SDL_Surface *bNewPuzzle;
SDL_Surface *bSaveFileAs;
SDL_Surface *bSavePuzzle;
SDL_Surface *bSaveToFile;
SDL_Surface *bTestPuzzle;
#endif
SDL_Surface *bTheme;
SDL_Surface *bSkip;
SDL_Surface *bRetry;
SDL_Surface *bNext;
//SDL_Surface *menuMarked;
//SDL_Surface *menuUnmarked;
//end new in 1.4.0
SDL_Surface *mouse; //The mouse cursor
SDL_Surface *tmp; //a temporary surface to use DisplayFormat
SFont_Font *fBlueFont; //Stores the blue font (SFont)
SFont_Font *fSmallFont; //Stores the small font (SFont)
//TTFont ttfont; //Stores the TTF font (TTFSDL)
Mix_Music *bgMusic; //backgroundMusic
Mix_Music *highbeatMusic; //Background music with higher beat
Mix_Chunk *boing; //boing sound when clearing
Mix_Chunk *applause; //Applause, then the player is good
Mix_Chunk *photoClick; //clickSound
Mix_Chunk *typingChunk; //When writing
Mix_Chunk *counterChunk; //When counting down
Mix_Chunk *counterFinalChunk;
Highscore theTopScoresEndless; //Stores highscores for endless
Highscore theTopScoresTimeTrial; //Stores highscores for timetrial
bool bMouseUp; //true if the mouse(1) is unpressed
bool bMouseUp2; //true if the mouse(2) is unpressed
bool bNewGameOpen; //show sub menues
bool bOptionsOpen; //Show OptionsMenu (Configure and Select Puzzle)
bool b1playerOpen; //show submenu
bool b2playersOpen; //show submenu
bool bReplayOpen; //Show replay menu
#if NETWORK
bool bNetworkOpen; //Show the network menu
#endif
bool showGame; //the game is active don't show highscores/options
bool showOptions; //true if options is open
bool bScreenLocked; //Don't take input or allow any mouse interaction! Used for dialogbox and warningbox
bool showDialog;
bool NoSound; //if true, absolutely no sound will be played, can be set from the commandline
//prevents crash on systems without a soundcard
bool MusicEnabled; //true if background music is enabled
bool SoundEnabled; //true if sound effects is enabled
bool bNearDeath; //Play music faster or louder while tru
bool bNearDeathPrev; //Near death status last time checked.
bool bFullscreen; //true if game is running fullscreen
bool puzzleLoaded; //true if the puzzle levels have been loaded
bool drawBalls; //if true balls are drawed to the screen, this might lower framerate too much
bool standardBackground;
bool highPriority;
bool editorMode = false;
bool editorModeTest = false;
//Things for network play:
#if NETWORK
bool networkPlay;
bool networkActive;
Uint8 nrOfNetworkPlayers; //Up to 4 players (inkl. self)
bool playerAlive[4];
//sockets here
#define SERVERPORT 41780
#define CLIENTPORT 41781
char serverAddress[30];
#endif
//should be automatically disabled if framerate to low (isn't implemented and wont be soon/ever):
//const int ballsFpsEnable = 30; //If framerate higher -> enable balls
//const int ballsFpsDisable = 10; //If framerate lower -> disable balls
//other ball constants:
const double gravity = 200.8; //acceleration
const double startVelocityY = 50.0;
const double VelocityX = 50.0;
const int ballSize = 16;
const double minVelocity = 200.0;
//global settings (reset everytime the game starts)
Uint8 player1Speed=0;
Uint8 player2Speed=0;
bool player1AI=false; //Is AI enabled?
bool player2AI=false; //Is AI enabled for player 2 (opponent in single player)
Uint8 player1AIlevel=3; //What level is AI? 0 min, 6 max
Uint8 player2AIlevel=3;
const Uint8 AIlevels=7; //7 possible levels: 0..6
Uint8 player1handicap=0;
Uint8 player2handicap=0;
unsigned long int currentTime; //contains the current time, so we don't call SDL_GetTickets() too often...
int xsize = 1024;
int ysize = 768;
int bsize = 50;
//Stores the players names (way to long, but at least no buffer overflows (max length is 16 for display reasons))
char player1name[30];
char player2name[30];
//paths
string stageClearSavePath;
string puzzleSavePath;
string puzzleName; //The filename of
const int nrOfStageLevels = 50; //number of stages in stage Clear
const int maxNrOfPuzzleStages = 50; //Maximum number of puzzle stages
vector stageCleared(nrOfStageLevels); //vector that tells if a stage is cleared
vector stageTimes(nrOfStageLevels); //For statistical puposes
vector stageScores(nrOfStageLevels); //--||--
vector puzzleCleared(maxNrOfPuzzleStages); //vector that tells if puzzle cleared
vector nrOfMovesAllowed(maxNrOfPuzzleStages); //Moves to clear
int puzzleLevels[maxNrOfPuzzleStages][6][12]; //Contains board layout;
int nrOfPuzzles; //How many are there actually?
//Old mouse position:
int oldMousex, oldMousey;
//Old Stage Clear Buble
int oldBubleX, oldBubleY;
//bool doublebuf = false; //if true, screen is double buffered
char forceredraw; //If 1: always redraw, if 2: rarely redraw
bool singlePuzzle = false; //if true we are just in a little 300x600 window
int singlePuzzleNr = 0;
string singlePuzzleFile;
#if DEBUG
//frame counter (fps)
unsigned long int Frames, Ticks;
char FPS[10];
#endif
int lastNrOfPlayers; //1 if 1 player and 2 if vs. mode
//keySetup
int player1keys, player2keys;
bool mouseplay1=false; //The mouse works on the play field
bool mouseplay2=false; //Same for player2
bool joyplay1=false; //Player one uses the joypad
bool joyplay2=false; //Player two uses the joypad
//Stores the controls
struct control
{
SDLKey up;
SDLKey down;
SDLKey left;
SDLKey right;
SDLKey change;
SDLKey push;
};
control keySettings[3]; //array to hold the controls (default and two custom)
#define KEYMENU_MAXWITH 4
#define KEYMENU_MAXDEPTH 7
//The following struct holds variables relevant to selecting menu items with
//keyboard/joypad.
struct KeyMenu_t
{
unsigned long canBeActivatedTime; //Time that the KeyMenu can be activated by pressing a button
bool activated; //The keymenu is activated
//Here comes the coordinates to the key we are howering.
int x;
int y;
bool menumap[KEYMENU_MAXWITH][KEYMENU_MAXDEPTH];
};
KeyMenu_t keymenu;
enum stageButton {SBdontShow, SBstageClear, SBpuzzleMode};
stageButton stageButtonStatus = SBdontShow;
const int buttonXsize = 120;
const int buttonYsize = 40;
struct ButtonCords
{
int x;
int y;
int xsize;
int ysize;
};
ButtonCords cordNextButton = {
cordNextButton.x = 3*bsize+(3*bsize-buttonXsize)/2,
cordNextButton.y = 10*bsize,
cordNextButton.xsize = buttonXsize,
cordNextButton.ysize = buttonYsize
};
ButtonCords cordRetryButton = {
cordRetryButton.x = (3*bsize-buttonXsize)/2,
cordRetryButton.y = 10*bsize,
cordRetryButton.xsize = buttonXsize,
cordRetryButton.ysize = buttonYsize
};
#endif
blockattack-1.4.1+ds1.orig/source/code/listFiles.cpp 0000640 0001750 0001750 00000010410 11277345404 020730 0 ustar pabs pabs /*
listFiles.cpp
Copyright (C) 2005 Poul Sander
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Poul Sander
R�veh�jvej 36, V. 1111
2800 Kgs. Lyngby
DENMARK
blockattack@poulsander.com
*/
/*
listFiles.cpp
*/
#include "listFiles.h"
/*ListFiles::ListFiles()
{
}
ListFiles::~ListFiles()
{
}*/
void ListFiles::setDirectory(string directory)
{
for (int i=0;id_name;
if (!isInList(name) && name[0]!='.' )
{
nrOfFiles++;
filenames[nrOfFiles] = name;
}
}
closedir(DirectoryPointer);
#endif
startFileNr=FIRST_FILE;
//Put code here
}
bool ListFiles::isInList(string name)
{
for (int i=0;(i<=nrOfFiles);i++)
{
if (0==strcmp(name.c_str(),filenames[i].c_str()))
{
return true;
}
}
return false;
}
void ListFiles::setDirectory2(string dic)
{
#if defined(__unix__)
DIR *DirectoryPointer;
struct dirent *dp;
//cout << "Will look in: " << dic << endl;
DirectoryPointer = opendir(dic.c_str());
if(!DirectoryPointer)
return;
while ((dp=readdir(DirectoryPointer))&&(nrOfFilesd_name;
if (!isInList(name) && name != "." && name != "..")
{
nrOfFiles++;
filenames[nrOfFiles] = name;
}
}
closedir(DirectoryPointer);
startFileNr=FIRST_FILE;
#endif
}
string ListFiles::getFileName(int nr)
{
if (startFileNr+nrFIRST_FILE)
startFileNr = startFileNr-10;
if (startFileNr