sdl-ball/ 0000755 0001750 0001750 00000000000 11132415326 012110 5 ustar dusted dusted sdl-ball/declerations.h 0000644 0001750 0001750 00000002453 11117305744 014746 0 ustar dusted dusted /* ************************************************************************* *
SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk )
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 3 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, see .
* ************************************************************************* */
class effectManager;
#define FX_SPARKS 0
#define FX_FIRE 1
#define FX_TRANSIT 2
#define FX_PARTICLEFIELD 3
#define FX_VAR_TYPE 1
#define FX_VAR_NUM 0
#define FX_VAR_SPEED 2
#define FX_VAR_SPREAD 3
#define FX_VAR_SIZE 4
#define FX_VAR_LIFE 5
#define FX_VAR_GRAVITY 6
#define FX_VAR_COLDET 7
#define FX_VAR_COLOR 8
#define FX_VAR_TEXTURE 9
#define FX_VAR_RECTANGLE 10
sdl-ball/changelog.txt 0000644 0001750 0001750 00000027027 11132414501 014602 0 ustar dusted dusted 0.01
Initial alpha release, highscores are broken, there is a few bugs in the collision detection, and performance is bad.
0.02
Initial highscore support
0.03
Replaced all timer code with two global variables, instead of every object keeping track of its own time which only uses additional resources and makes the game out of sync.
Minor fixes
Fixed the "lives left" text.
Fixed bug in highscores so it only showed up first time
Added settings.cfg and support for loading and saving settings.
0.03b
Fixed bug that made it impossible to change level, added a nonpausing tick variable
Added background to the highscore listing
0.03c
Cleaned up the menu class.
Made highscore listing look better.
0.04
Using lists for effects and balls instead, for more effective management of collision detection.
Optimized a bit here and there.
0.05
Optimizing overall, code cleanup, not drawing the screen every time the simulation runs
implemented global tick variables for frame-age.
implemented aged frames, so the screen is now refreshed in every loop of the engine, major performance boost
game will now write/use settings.cfg to remember settings if available (it will try to create it when a setting is changed in the menu)
particle collision detection is off by default (turn it on in settings.cfg)
fixed missing texture in sound-options
game should now be optimized enough to be playable on most modern machines
removed joystick init from sdl because it is not used
0.05b
fixing non-bug where a ball hits two bricks at the same time, and changing direction because hit detection is done at the first brick, and then at the second brick, it detects the ball as hitting the brick on another surface than what whould see realistic (this is not really a bug, but it looks better.)
removing unused -lglut from makefile, it is not used.
0.05c
Optimizing a bit
Made aim user controlled, using the mousewheel to aim.
Made level editor plugin print out ** Start ** and ** Stop **.
0.06
Added speedometer
Tweaked difficulty settings and speed-increment values
Points are calculated on the average ballspeed, so if the balls are moving faster, more points is given.
Made the game restart when all levels are completed, with a bigger multiplyer on points
Stuff I don't remember
Don't render invisible bricks
0.07
Announced text is in front of menu/dialogs
Announce-class cleanup, fixed bug with messages getting shown wrong if they were right after eachother.
Announce only lifes left and levelchanges. Not powerups.
Removed moving backgrounds.
Added internal fps counter.
Fixed bug in multi-ball powerup that only made it spawn one ball.
Game now restores resolution on exit.
Aim is no longer user-controlled - made game too easy.
Fixed speed bug
Fixing bug that made glass-bricks break on first hit.
0.08
Texture manager can now load jpg images, but only if the filename ends in jpg (case sensitive)
Using jpg background images now.
Clean up bullets on screen when changing level
Changes to levels.txt about random powerups.
Moved powerup properties to a seperate file (data/powerups.txt)
Some powerups are more rare than others
extra life powerup
Remove edge bleeding from ball/paddle-extensions
TTF rendering is VERY heavy.
Using prerendered numbers for the highscore instead.
File data/gfx/highscores/numbers.png and template added
show lives left
Make sure there is at least one explosive powerup in level 4
dont announce lives left since its visible now.
ball tail color is changed instant when "explosive" powerup applies.
rewrote random-powerup code, 4 classes of powerups (most (common) 60%, more 30%, less 10%, least 1%)
initial try to balance powerup spawning.
Make a "random evil powerup" function.
Put a random evil poweups on Doombricks.
0.08b
Found that both P and 3 was assigned to GUN powerup, only P is used now.
Javascript leveleditor added, makes editing levels a lot easier.
Remade level 3 and 11
Added level 20,21
Removed data-changelog.
Thanks to David Wührer for pointing out a (the??) bug in the collision detection.
0.09
bricks can now drop/lift and rotate left or right (moveBoard(brick bricks[], int dir))
Die powerup
Add particle effect to paddle when player dies.
Powerup objects on screen explodes when player looses life.
Added evil powerup that makes board drop down one brick-height when ball hits paddle.
Make 5% chance of getting a powerup default for all levels instead of 10%.
Added "Detonate all explosive bricks" powerup
Added level options for scolling levels, see data/levels.txt for info
Add Explosive brick grow powerup.
Games can now be saved and loaded.
Saving is only available in the beginning of levels, and not in level 1.
Corrected bug that made brick spawn powerup/effects if it is hit twice in one frame.
New (quick/easy) level 1 (moved old level 1 to level 4)
More levels.
0.10
Will choose current resolution if resx or resy is not found in settings.cfg.
Added "All bricks can be destroyed" powerup (PO_EASYBRICK)
Collision detection improved. (ball wont deflect off two sides at the same time, which was annoying!)
Next-level powerup added (player won't get score for bricks that are not hit this level).
Slow/Fast ball poweups wont be added, since there is allready "Small balls"/"Normal balls" and "Big Balls" powerups that do about the same thing.
Aim helper pwerup added (when a ball is on collision course with paddle, a line is drawn to show deflection angle)
Fixed bug that made PO_EXPLOSIVE_GROW happen upon ball collision instead of powerup collision.. xD
Puts user-files (highscore,savegame,settings) in ~/.config/sdl-ball
Added remove rule to Makefile to delete ~/.config/sdl-ball
Only ask for name if player has a high score.
Improved deflection precision.
Added support for padded textures.
Give player aimhelper when theres one brick left.
New powerup icons and other gfx.
0.11
README added.
Removed "flash" at exit that comes from trying to restore resolution even if it is run in windowed mode.
Keyboard control, definable shoot,left and right keys.
Adjustable startspeed and acceleration for keyboard and digital-joysticks. (from settings.cfg)
Adjustable maxspeed for keyboad, digital/analog joysticks and wiimote. (from settings.cfg)
Joystick support, analog is untested (please report if is broken), digital is tested.
Calibration for analog joystick.
Made buttons change in the menu, so one can see if an option is on or off.
WiiMote supported via libusewii see README for info.
Improved collision response (reposition ball outside the brick it hit).
Made it spawn a random powerup if the brick contains one ;)
4 new levels
Padding on paddleBase and gun overlay.
Removed overlay gfx for PO_AIM
It is now possible to control what speed-increase the bricks have, on a per-level basis. (see data/levels.txt)
Corrected bug that made mouseposition offset in a non 4:3 resolution. Thanks to Cids.dk for discovering it.
Initial sound support.
stereo option, to turn off stereo sound.
Produced and found soundeffects which are under a free license (read data/snd/LICENSE.txt)
-- The sound effort is not good, if you are able to create/collect a better set, please do!
-- Maybe they should be more "arcade" style/retro/8bit but I can't do it.
Don't load sounds if sound if disabled, load if enabled.
setting.joyEnabled added.
0.12rc1
Sound is on by default.
3 new levels.
Screenshot function (press s to capture, saves in ~/.config/sdl-ball/screenshots/)
Fixed minor bug, highscore-background datapath was hardcoded.
Added GPL header and real name of author to relevant sourcefiles.
Updated Readme
Faster timeout (now is 20 seconds instead of 30)
If compiled without sound, don't show the sound settings in the menu.
Powerups are a bit larger.
Intro screen with powerup explanations.
Added header to savegamefile (this version is incompatible with older and will override them)
Coins system, Player gets coins for powerups, and can buy powerups for them. (Might need balancing)
Themes (basically do like quake.. If a file is not in the "theme tree" get it from "base") See readme
Moved texture properties to external files so they can change with themes, for bricks
Now possible to have diffrent colors for textureoverlay and particle effects on brick (no more white trail after hitting explosivebricks)
Powerups can have texture overlay color, and their particle color is defined in their texture txt file
0.12rc2
Tweaked some of the powerup animations
Addded easybrick and lasersight to shop.
Tweaked gameplay.
Tweaked powerup prices (gothru should be more expensive than growexplosive)
Game will stop, change level, as soon as the last brick is hit, not after it dissapeared.
Add speed to ball even if go-thru
Fixed bugs in level 6,7 (too many powerups)
Added theme-howto on website
Made border texture square
Removed non-free font files, replaced with the ones from nesworth until better are found.
Updated readme with correct licensing.
Corrected bug that made it impossible to calibrate joystick.
0.12rc3
Tweaked gameplay:
Speed increase from hitting a brick will be reverted to previous value for normal difficulty
Hard difficulty with more agressive speed-increase, higher start-speed, higher max-speed, go-thru increase speed.
Remembers difficulty.
Detonate powerup had same icon as Multiball, fixed now.
0.13:
Changed from "string in a texture" to string-of-quads text rendering.
Changed max-min bounceoff angle from 10-170 to 15-165
Fixed bug that made custom colored bricks invisible.
It now show how many lives you have left AFTER dropping your current ball, instead of before.
Fixed bug that made game paused after having gameover without a highscore.
Removed "Gravity" powerdown.
Added Cash Powerup.
Changed fonts.
Polished stuff..
Shop items are more expensive
Renamed datadir to themes and put the default theme in there, which makes more sense, since all data is in the themes.
Added option to show time (the system time), this wont be available from menu, pres C to enable/disable.
Achieved level saved and shown in higshcore.
FPS (Frames Per Second) option added, default to 120 fps (without vsync), a higher value then screen-refresh is ignored if vsync is on.
Player can only buy a powerup once per level, not per life.
Fixed bug in collision detection
GPL sounds. (made in sfxr, other sounds are most welcome! but they need be GPL!)
More levels.
Added the rest of the background images
0.14:
Changed logo to use a power of two texture (this removed lagging from introscreen, shows logo on some cards)
Fixed crashbug that made it segfault when pressing pressing "next item" and then "buy"
Possible to save game at all times (after level 2).
Pressing a savegame slot when saving will write help, so the user know what to do.
Savegame box always shown, greyed out.
0.15 aka 1.0:
More levels. (50 Levels in total)
Added dio-sound-theme as an optional sound-theme, try it out and give feedback on the sf.net forum
Balls now stop completely when the game is paused.
Added Window manager Icon to the program when it's running.
Added http address to the intro screen.
Disable background if it is not loaded correctly (not found/too large for gfx hw).
Uses $XDG_CONFIG_HOME enviroment variable over $HOME if found.
Updated Makefile accordingly to advice from Christian "idl0r" Ruppert.
Removed "> inc" option from levels.txt
Removed "> up", "> left" and "> right" from levels.txt
1.01:
Added some code to try and handle segfault on resolution change (that might be caused by sdl reporting a void current resolution).
If resolution change fail, the game will quit, and not write the wrong resolution to config.
Planned features:
Some gui way of selecting individual parts of themes.
Stuff that needs doing some time:
Get more liniar increase in difficulty by sorting/adding/removing levels.
sdl-ball/background.cpp 0000644 0001750 0001750 00000011543 11131340150 014726 0 ustar dusted dusted /* ************************************************************************* *
SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk )
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 3 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, see .
* ************************************************************************* */
class backgroundClass {
private:
GLfloat r[4], g[4], b[4], a;
textureClass tex;
bool dir;
bool firstTexture;
public:
backgroundClass()
{
firstTexture=1;
}
void init(textureManager & texMgr)
{
bool l;
//Så vi ikke kommer til at slette texture 0 første gang funktionen bliver kaldt
if(!firstTexture)
glDeleteTextures(1, &tex.prop.texture);
float t = 0.25 * ((float)player.level+1);
if(t <= 1.0)
l=texMgr.load(useTheme("/gfx/bg/1.jpg",setting.gfxTheme), tex);
else if(t <= 2.0)
l=texMgr.load(useTheme("/gfx/bg/2.jpg",setting.gfxTheme), tex);
else if(t <= 3.0)
l=texMgr.load(useTheme("/gfx/bg/3.jpg",setting.gfxTheme), tex);
else if(t <= 4.0)
l=texMgr.load(useTheme("/gfx/bg/4.jpg",setting.gfxTheme), tex);
else if(t <= 5.0)
l=texMgr.load(useTheme("/gfx/bg/5.jpg",setting.gfxTheme), tex);
else if(t <= 6.0)
l=texMgr.load(useTheme("/gfx/bg/6.jpg",setting.gfxTheme), tex);
else if(t <= 7.0)
l=texMgr.load(useTheme("/gfx/bg/7.jpg",setting.gfxTheme), tex);
else if(t <= 8.0)
l=texMgr.load(useTheme("/gfx/bg/8.jpg",setting.gfxTheme), tex);
else if(t <= 9.0)
l=texMgr.load(useTheme("/gfx/bg/9.jpg",setting.gfxTheme), tex);
else if(t <= 10.0)
l=texMgr.load(useTheme("/gfx/bg/10.jpg",setting.gfxTheme), tex);
else if(t <= 11.0)
l=texMgr.load(useTheme("/gfx/bg/11.jpg",setting.gfxTheme), tex);
else if(t <= 12.0)
l=texMgr.load(useTheme("/gfx/bg/12.jpg",setting.gfxTheme), tex);
else if(t <= 13.0)
l=texMgr.load(useTheme("/gfx/bg/13.jpg",setting.gfxTheme), tex);
else if(t <= 14.0)
l=texMgr.load(useTheme("/gfx/bg/14.jpg",setting.gfxTheme), tex);
else if(t <= 15.0)
l=texMgr.load(useTheme("/gfx/bg/15.jpg",setting.gfxTheme), tex);
else if(t <= 16.0)
l=texMgr.load(useTheme("/gfx/bg/16.jpg",setting.gfxTheme), tex);
else if(t <= 17.0)
l=texMgr.load(useTheme("/gfx/bg/17.jpg",setting.gfxTheme), tex);
else if(t <= 18.0)
l=texMgr.load(useTheme("/gfx/bg/18.jpg",setting.gfxTheme), tex);
else if(t <= 19.0)
l=texMgr.load(useTheme("/gfx/bg/19.jpg",setting.gfxTheme), tex);
else if(t <= 20.0)
l=texMgr.load(useTheme("/gfx/bg/20.jpg",setting.gfxTheme), tex);
else if(t <= 21.0)
l=texMgr.load(useTheme("/gfx/bg/21.jpg",setting.gfxTheme), tex);
else if(t <= 22.0)
l=texMgr.load(useTheme("/gfx/bg/22.jpg",setting.gfxTheme), tex);
else if(t <= 23.0)
l=texMgr.load(useTheme("/gfx/bg/23.jpg",setting.gfxTheme), tex);
else if(t <= 24.0)
l=texMgr.load(useTheme("/gfx/bg/24.jpg",setting.gfxTheme), tex);
else if(t <= 25.0)
l=texMgr.load(useTheme("/gfx/bg/25.jpg",setting.gfxTheme), tex);
else
l=texMgr.load(useTheme("/gfx/bg/final.jpg",setting.gfxTheme), tex);
if(!l)
{
setting.showBg=0;
cout << "Backgrounds disabled." << endl;
}
firstTexture=0;
for(int i = 0; i < 4; i++)
{
r[i] = rndflt(1,0);
g[i] = rndflt(1,0);
b[i] = rndflt(1,0);
}
a = 1;
}
void draw()
{
glLoadIdentity();
glTranslatef( 0, 0, -3.0 );
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, tex.prop.texture);
glBegin( GL_QUADS );
glColor4f(r[0],g[0],b[0],a);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.66, 1.25, 0.0f );
glColor4f(r[1],g[1],b[1],a);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.66, 1.25, 0.0f );
glColor4f(r[2],g[2],b[2],a);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.66,-1.25, 0.0f );
glColor4f(r[3],g[3],b[3],a);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.66,-1.25, 0.0f );
glEnd( );
}
};
sdl-ball/LICENSE.txt 0000644 0001750 0001750 00000104513 11117305744 013744 0 ustar dusted dusted GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
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 3 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, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
sdl-ball/effects.cpp 0000644 0001750 0001750 00000037516 11117305744 014254 0 ustar dusted dusted /* ************************************************************************* *
SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk )
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 3 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, see .
* ************************************************************************* */
struct effect_vars {
int type; //Hvilken slags effekt er det?
bool coldet; //er der collision detection på denne?
bool active; //Er denne effekt aktiv
GLfloat col[3]; //Hvilken farve har effekten?
GLfloat speed; //Hvor hurtigt bevæger den sig
GLfloat spread; //Hvor stor er spredningen (i grader)
GLfloat size; //Skalering af elementerne
struct pos rect; //rectangular size (for particleField)
GLfloat gravity; //Hvor stor er tyndgekraften
int num; //Hvor mange elementer er der i den
int life; //hvor mange ms lever den?
textureClass tex; //Texture
int effectId; //unique id for this effect
};
class transit_effect_class {
private:
GLfloat opacity;
public:
int age;
effect_vars vars;
void init()
{
age=0;
opacity = 0.0f;
var.transition_half_done=0;
}
void draw()
{
age += globalTicksSinceLastDraw;
if(age < vars.life/2.0) //første halvdel
{
//Gør solid
opacity += vars.life/500.0*globalMilliTicksSinceLastDraw;
} else {
var.transition_half_done=1;
//Gør trans
opacity -= vars.life/500.0*globalMilliTicksSinceLastDraw;
}
glLoadIdentity();
glDisable( GL_TEXTURE_2D );
glTranslatef(0.0, 0.0, -3.0);
glColor4f( vars.col[0], vars.col[1], vars.col[2], opacity );
glBegin( GL_QUADS );
glVertex3f(-1.66, 1.25, 0.0);
glVertex3f( 1.66, 1.25, 0.0);
glVertex3f( 1.66,-1.25, 0.0);
glVertex3f(-1.66,-1.25, 0.0);
glEnd( );
glEnable( GL_TEXTURE_2D );
}
};
class sparkle {
public:
bool active;
GLfloat size;
GLfloat ang;
int life;
int lifeleft;
pos p,v; //position og vel
effect_vars vars;
GLfloat bounce,f; //bounce og friktion
sparkle()
{
bounce=0;
f=0;
active=1;
}
void draw()
{
if(lifeleft > 0)
{
//sanitize
lifeleft -= globalTicksSinceLastDraw;
//er vi indenfor skærmen?
if(p.x > 1.67 || p.y < -1.7 || p.x < -1.67)
{
active=0;
}
v.y -= vars.gravity*globalMilliTicksSinceLastDraw;
v.y -= bounce*globalMilliTicksSinceLastDraw;
if(v.x < 0)
{
v.x += f*globalMilliTicksSinceLastDraw;
} else {
v.x -= f*globalMilliTicksSinceLastDraw;
}
p.x += v.x * globalMilliTicksSinceLastDraw;
p.y += v.y * globalMilliTicksSinceLastDraw;
glColor4f(vars.col[0], vars.col[1],vars.col[2], (1.0/(float)life)*(float)lifeleft);
GLfloat curSize = size/(float)life * (float)lifeleft;
glBindTexture( GL_TEXTURE_2D, vars.tex.prop.texture );
glBegin( GL_QUADS );
glTexCoord2f(0,0); glVertex3f(p.x-curSize,p.y+curSize, 0.0);
glTexCoord2f(0,1); glVertex3f(p.x+curSize,p.y+curSize, 0.0);
glTexCoord2f(1,1); glVertex3f(p.x+curSize,p.y-curSize, 0.0);
glTexCoord2f(1,0); glVertex3f(p.x-curSize,p.y-curSize, 0.0);
glEnd( );
} else {
active=0;
}
}
void coldet(brick & b)
{
if(p.x > b.posx-b.width && p.x < b.posx+b.width)
{
if(p.y > b.posy-b.height && p.y < b.posy+b.height)
{
//Hvor ramte vi fra?
if(p.y < b.posy && !b.n(3))
{
//bunden
v.y *= -1;
//p.y = b.posy-b.height-0.01;
} else
if(p.y > b.posy && !b.n(2))
{
//toppen
p.y = b.posy+b.height;
if(v.y < 0)
{
v.y *= -1;
v.y /= 2.0;
f += 0.01;
}
} else
if(p.x > b.posx && !b.n(1))
{
//p.x = b.posx+b.width;
//højre
if(v.x < 0)
v.x *= -1;
} else
if(p.x < b.posx && !b.n(0))
{
//p.x = b.posx-b.width;
//venstre
if(v.x > 0)
v.x *= -1;
}
}
}
}
void pcoldet(paddle_class & b)
{
if(p.x > b.posx-b.width && p.x < b.posx+b.width)
{
if(p.y > b.posy-b.height && p.y < b.posy+b.height)
{
//Hvor ramte vi fra?
if(p.y < b.posy)
{
//bunden
p.y = b.posy-b.height;
}
if(p.y > b.posy)
{
//toppen
p.y = b.posy+b.height;
if(v.y < 0)
{
v.y *= -1;
v.y /= 2.0;
f += 0.01;
}
} else
if(p.x > b.posx)
{
p.x = b.posx+b.width;
//højre
if(v.x < 0)
v.x *= -1;
} else
if(p.x < b.posx)
{
p.x = b.posx-b.width;
//venstre
if(v.x > 0)
v.x *= -1;
}
}
}
}
};
class particleFieldClass {
private:
int spawnTimeout; //This is used to spawn sparkles at a random time
sparkle *sparks;
void spawnSpark(int sparkNum);
public:
struct pos p;
struct effect_vars vars;
void init(struct effect_vars varsP, struct pos p);
void draw();
void move(struct pos p);
void coldet(brick & b);
void pcoldet(paddle_class & b);
~particleFieldClass();
};
void particleFieldClass::init(struct effect_vars varsP, struct pos spawnPos)
{
vars=varsP;
spawnTimeout=0;
vars.active=1;
sparks = new sparkle[vars.num];
p=spawnPos;
for(int i=0; i < vars.num; i++)
{
sparks[i].active=1;
sparks[i].vars = vars; //NOTE:remove effect_vars from sparkle class?
spawnSpark(i);
}
}
particleFieldClass::~particleFieldClass()
{
delete[] sparks; //free the sparks
}
void particleFieldClass::spawnSpark(int sparkNum)
{
GLfloat angle=(RAD/vars.num-1)*(rndflt(vars.num,0.0)); //FIXME: Make this elegant: Choose a random angle (in radients)
spawnTimeout = rand()%10;
sparks[sparkNum].life = rand()%vars.life;
sparks[sparkNum].lifeleft = sparks[sparkNum].life;
sparks[sparkNum].v.x = (vars.speed*rndflt(vars.speed*2.0,0.0)) * sin(angle);
sparks[sparkNum].v.y = (vars.speed*rndflt(vars.speed*2.0,0.0)) * cos(angle);
sparks[sparkNum].size = rndflt(vars.size,0);
sparks[sparkNum].p=p;
sparks[sparkNum].p.x += rndflt(vars.rect.x, (vars.rect.x/2.0));
sparks[sparkNum].p.y += rndflt(vars.rect.y, (vars.rect.y/2.0));
sparks[sparkNum].active=1;
}
void particleFieldClass::draw()
{
spawnTimeout -= globalTicksSinceLastDraw;
glLoadIdentity();
glTranslatef(0.0,0.0 , -3.0);
int t=0;
for(int i=0; iinit(vars, p);
break;
}
}
void draw()
{
//find ud af hvor længe der er gået siden sidst
int i;
bool stay=0;
switch(vars.type)
{
case FX_SPARKS:
glLoadIdentity();
glTranslatef(0.0,0.0 , -3.0);
for(i=0; i < vars.num; i++)
{
if(sparks[i].active)
{
sparks[i].draw();
stay=1;
}
}
break;
case FX_TRANSIT:
transit.draw();
if(transit.age <= vars.life)
stay=1;
break;
case FX_PARTICLEFIELD:
pf->draw();
if(pf->vars.active)
stay=1;
break;
}
//Ugley hack, to prevent transit from flickering when spark effects are deleted.
if(var.effectnum != -1 && vars.type != FX_TRANSIT)
stay=1;
if(!stay)
{
vars.active=0;
switch(vars.type)
{
case FX_SPARKS:
delete[] sparks; //Free sparks again ;)
break;
case FX_PARTICLEFIELD:
delete pf; //remove the particlefield
break;
}
}
}
void coldet(brick & b)
{
int i;
if(vars.type == FX_SPARKS)
{
for(i=0; i < vars.num; i++)
{
if(sparks[i].active)
{
sparks[i].coldet(b);
}
}
} else if(vars.type == FX_PARTICLEFIELD)
{
pf->coldet(b);
}
}
void pcoldet(paddle_class & b)
{
int i;
if(vars.type == FX_SPARKS)
{
for(i=0; i < vars.num; i++)
{
if(sparks[i].active)
{
sparks[i].pcoldet(b);
}
}
} else if(vars.type == FX_PARTICLEFIELD)
{
pf->pcoldet(b);
}
}
};
class effectManager {
private:
struct effect_vars vars; //denne kopieres over i den næste effekt der bliver spawned
int effectId; //ever rising number of a spawned effect.
public:
listeffects;
effectManager()
{
effects.clear();
effectId=0;
}
void set(int var, GLfloat val)
{
switch(var)
{
case FX_VAR_SPEED:
vars.speed = val;
break;
case FX_VAR_SPREAD:
vars.spread = val;
break;
case FX_VAR_SIZE:
vars.size = val;
break;
case FX_VAR_GRAVITY:
vars.gravity = val;
}
}
void set(int var, int val)
{
switch(var)
{
case FX_VAR_NUM:
vars.num=val;
break;
case FX_VAR_LIFE:
vars.life=val;
break;
case FX_VAR_TYPE:
vars.type=val;
break;
case FX_VAR_COLDET:
vars.coldet=val;
break;
}
}
void set(int var, GLfloat r, GLfloat g, GLfloat b)
{
switch(var)
{
case FX_VAR_COLOR:
vars.col[0] = r;
vars.col[1] = g;
vars.col[2] = b;
break;
}
}
void set(int var, textureClass tex)
{
switch(var)
{
case FX_VAR_TEXTURE:
vars.tex = tex;
break;
}
}
void set(int var, struct pos p)
{
switch(var)
{
case FX_VAR_RECTANGLE:
vars.rect = p;
break;
}
}
//retunerer effektid så der kan checkes om det er aktivt
int spawn(pos p)
{
effectId++;
effect_class tempEffect;
vars.effectId = effectId;
tempEffect.vars = vars; //kopier det over som er sat op
tempEffect.init(p);
effects.push_back(tempEffect);
return(effectId);
}
void draw()
{
for(list ::iterator it = effects.begin(); it != effects.end(); ++it)
{
it->draw();
if(!it->vars.active)
{
it = effects.erase(it);
}
}
}
void coldet(brick & b)
{
if(b.collide && b.active)
{
for(list ::iterator it = effects.begin(); it != effects.end(); ++it)
{
if(it->vars.coldet)
it->coldet(b);
}
}
}
void pcoldet(paddle_class & b)
{
for(list::iterator it = effects.begin(); it != effects.end(); ++it)
{
if(it->vars.coldet)
it->pcoldet(b);
}
}
int isActive(int id)
{
for(list::iterator it = effects.begin(); it != effects.end(); ++it)
{
if(it->vars.effectId == id && it->vars.active)
{
return(1);
}
}
return(0);
}
void kill(int id)
{
for(list::iterator it = effects.begin(); it != effects.end(); ++it)
{
if(it->vars.effectId)
{
it->vars.active=0;
}
}
}
};
class glAnnounceMessageClass {
private:
int age;
GLfloat zoom,fade;
bool fadedir;
public:
bool active;
int life;
string text;
int font;
glAnnounceMessageClass()
{
active=1;
age=0;
fade=0;
fadedir=0;
zoom=0;
}
void draw()
{
GLfloat s;
zoom += 4000.0/life * globalMilliTicksSinceLastDraw;
if(fadedir)
{
fade -= 4000.0/life * globalMilliTicksSinceLastDraw;
} else {
fade += 4000.0/life * globalMilliTicksSinceLastDraw;
}
glLoadIdentity();
glTranslatef(0.0,0.0,-3.0);
glColor4f(1.0,0.0,0.0,fade);
s=zoom*0.85;
glText->write(text, font, 1, s, 0.0, 0.0);
glColor4f(0.0,1.0,0.0,fade);
s=zoom*0.90;
glText->write(text, font, 1, s, 0.0, 0.0);
glColor4f(0.0,0.0,1.0,fade);
s=zoom*0.95;
glText->write(text, font, 1, s, 0.0, 0.0);
glColor4f(1.0,1.0,1.0,fade);
s=zoom;
glText->write(text, font, 1, s, 0.0, 0.0);
age += globalTicksSinceLastDraw;
if(age > life*0.50)
{
fadedir=1;
}
if(age > life)
active=0;
}
};
#define MAXMSG 10
class glAnnounceTextClass {
private:
int len; //hvor mange mangler vi at vise
list msg;
list::iterator it;
public:
glAnnounceTextClass()
{
len=0;
}
void write(const char *text, int ttl, int font)
{
len++;
msg.resize(len);
it=msg.end();
--it;
it->life=ttl;
it->text=text;
it->font=font;
}
void draw()
{
if(len>0)
{
it=msg.begin();
if(it->active)
{
it->draw();
} else {
msg.erase(it);
len--;
}
}
}
};
sdl-ball/menu.cpp 0000644 0001750 0001750 00000077727 11132414532 013602 0 ustar dusted dusted /* ************************************************************************* *
SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk )
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 3 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, see .
* ************************************************************************* */
struct score {
int score;
string level;
string name;
};
struct score *sortScores(int *rl)
{
ifstream hsList;
string line;
int i=0,t;
int delim[2];
struct score *final=NULL, *temp=NULL;
final = new struct score[1];
hsList.open(privFile.highScoreFile.data());
if(hsList.is_open())
{
while(!hsList.eof())
{
getline(hsList,line);
if(line != "")
{
if(line[0]=='[')
{
delim[0] = line.find(']');
delim[1] = line.find('|', delim[0]+1);
final[i].level=line.substr(0, delim[0]+1);
final[i].level+=" ";
final[i].score = atoi(line.substr(delim[0]+1, delim[1]).data());
final[i].name = line.substr(delim[1]+1);
} else {
final[i].level.clear();
final[i].score = atoi(line.substr(0, line.find('|')).data());
final[i].name = line.substr(line.find('|')+1);
}
temp = new struct score[i+1];
for(t = 0; t < i+1; t++)
{
temp[t] = final[t];
}
delete[] final;
final = new struct score[i+2];
for(t = 0; t < i+1; t++)
{
final[t] = temp[t];
}
delete[] temp;
i++;
}
}
hsList.close();
}
if(i > 20)
*rl=20;
else
*rl=i;
int k;
bool done=0;
bool swaps=0;
temp = new struct score[1];
while(!done)
{
for(k=0; k < i; k++)
{
for(t=0; t < i; t++)
{
if(final[k].score > final[t].score)
{
swaps=1;
temp[0] = final[t];
final[t] = final[k];
final[k] = temp[0];
} else {
swaps=0;
}
}
}
if(swaps == 0)
{
done=1;
}
}
delete[] temp;
return(final);
}
class menuClass {
private:
string saveGameName[6]; //The name of saveGames
int saveGameSlot; //Where player choose to save/load to/from
textureClass tex[5];
GLuint dl;
bool themeChanged; //If the theme has changed change the banner.
vector tI; //Vector of theme info
public:
char highScores[20][255];
menuClass()
{
refreshHighScoreList(); //load the highscore file (if exists)
textureManager texMgr;
dl = glGenLists(4); //Generate displaylists (+0 = background, +1,2 = but
texMgr.load(useTheme("/gfx/menu/menu0.png",setting.gfxTheme), tex[0]);
texMgr.load(useTheme("/gfx/menu/but0.png",setting.gfxTheme), tex[1]);
texMgr.load(useTheme("/gfx/menu/but1.png",setting.gfxTheme), tex[2]);
texMgr.load(useTheme("/gfx/menu/but2.png",setting.gfxTheme), tex[3]);
texMgr.load(useTheme("/gfx/menu/highscorebg.png",setting.gfxTheme), tex[4]);
tI = getThemes(); //Read themes and put them in the vector tI
listSaveGames(saveGameName);
//Baggrund
glNewList(dl, GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, tex[0].prop.texture);
glBegin( GL_QUADS );
glTexCoord2f(0.0f,0.0f);glVertex3f( -1.0, 1.0, 0.0 );
glTexCoord2f(1.0f,0.0f);glVertex3f( 1.0, 1.0, 0.0 );
glTexCoord2f(1.0f,1.0f);glVertex3f( 1.0,-1.0, 0.0 );
glTexCoord2f(0.0f,1.0f);glVertex3f( -1.0,-1.0, 0.0 );
glEnd( );
glEndList( );
//Hvide
glNewList(dl+1, GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, tex[1].prop.texture);
glBegin( GL_QUADS );
glTexCoord2f(0.132f,0.3f); glVertex3f( -0.5, 0.07, 0.0 );
glTexCoord2f(0.87f, 0.3f); glVertex3f( 0.5, 0.07, 0.0 );
glTexCoord2f(0.87f, 0.7f); glVertex3f( 0.5,-0.07, 0.0 );
glTexCoord2f(0.132f,0.7f); glVertex3f( -0.5,-0.07, 0.0 );
glEnd( );
glEndList( );
//Røde
glNewList(dl+2, GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, tex[2].prop.texture);
glBegin( GL_QUADS );
glTexCoord2f(0.132f,0.3f); glVertex3f( -0.5, 0.07, 0.0 );
glTexCoord2f(0.87f, 0.3f); glVertex3f( 0.5, 0.07, 0.0 );
glTexCoord2f(0.87f, 0.7f); glVertex3f( 0.5,-0.07, 0.0 );
glTexCoord2f(0.132f,0.7f); glVertex3f( -0.5,-0.07, 0.0 );
glEnd( );
glEndList( );
//Grøn
glNewList(dl+3, GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, tex[3].prop.texture);
glBegin( GL_QUADS );
glTexCoord2f(0.132f,0.3f); glVertex3f( -0.5, 0.07, 0.0 );
glTexCoord2f(0.87f, 0.3f); glVertex3f( 0.5, 0.07, 0.0 );
glTexCoord2f(0.87f, 0.7f); glVertex3f( 0.5,-0.07, 0.0 );
glTexCoord2f(0.132f,0.7f); glVertex3f( -0.5,-0.07, 0.0 );
glEnd( );
glEndList( );
}
void refreshHighScoreList()
{
struct score *final;
int lines;
final = sortScores(&lines);
//Fill out remaining highscore slots (if any)
for(int t=lines; t < 20; t++)
{
switch(t)
{
case 0:
sprintf(highScores[t], "SDL-BALL v "VERSION );
break;
case 1:
sprintf(highScores[t], "-----------------------");
break;
case 2:
sprintf(highScores[t], "Copyleft GPLv3 2008 Jimmy Christensen");
break;
case 3:
sprintf(highScores[t], "Based on Dx-Ball by Michael P. Welch");
break;
case 4:
sprintf(highScores[t], "Based on Megaball by Ed and Al Mackey");
break;
case 5:
sprintf(highScores[t], "-----------------------");
break;
case 6:
sprintf(highScores[t], "Greetings to everyone!");
break;
default:
sprintf(highScores[t], "SDL-Ball - %i", (t*-1)+20 );
break;
}
}
//Highscores list
for(int t=0; t < lines; t++)
{
sprintf(highScores[t], "%s%i - %s", final[t].level.data(), final[t].score, final[t].name.data());
}
if(lines>0)
delete[] final;
}
void enterSaveGameName(SDL_Event e)
{
if(e.key.keysym.sym != SDLK_RETURN && e.key.keysym.sym != SDLK_ESCAPE)
{
if ( (e.key.keysym.unicode & 0xFF80) == 0 && e.key.keysym.unicode != 0) {
if(e.key.keysym.sym == SDLK_BACKSPACE)
{
if(saveGameName[saveGameSlot].length() > 0)
saveGameName[saveGameSlot].erase(saveGameName[saveGameSlot].length()-1);
} else {
saveGameName[saveGameSlot] += e.key.keysym.unicode;
}
}
} else {
if(e.key.keysym.sym == SDLK_RETURN)
{
//player saved
saveGame(saveGameSlot, saveGameName[saveGameSlot]);
}
var.enterSaveGameName=0;
}
}
void doMenu()
{
int i=0;
glColor4f(1.0, 1.0, 1.0, 1.0);
glLoadIdentity();
glTranslatef(0.0,0.0,-3.0f);
glCallList(dl); //baggrunden
glTranslatef(0.0,-1.0,0.0f);
if(var.menu==1)
{
//Exit
glTranslatef(0.0,0.22,0.0f);
if(var.menuItem==1)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Quit SDL-Ball", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//Settings
glTranslatef(0.0,0.22,0.0f);
if(var.menuItem==2)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Settings", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//highscores
glTranslatef(0.0,0.22,0.0f);
if(var.menuItem==3)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Highscores", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//Save
glTranslatef(0.0,0.22,0.0f);
if(player.level > 0)// && !var.startedPlaying)
{
if(var.menuItem==4)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Save Game", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
} else {
glColor4f(1,1,1,1);
if(var.menuItem==4)
{
glCallList(dl+2);
glColor4f(0.5,0.5,0.5,1);
glText->write("Not in Level 1", FONT_MENU, 1, 1.0, 0.0, -0.005);
} else {
glCallList(dl+1);
glColor4f(0.5,0.5,0.5,1);
glText->write("Save Game", FONT_MENU, 1, 1.0, 0.0, -0.005);
}
glColor4f(1,1,1,1);
}
//Load
glTranslatef(0.0,0.22,0.0f);
if(var.menuItem==5)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Load Game", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//Continue
glTranslatef(0.0,0.22,0.0f);
if(var.menuItem==6)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Continue", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//new game
glTranslatef(0.0,0.22,0.0f);
if(var.menuItem==7)
glCallList(dl+2);
else
glCallList(dl+3);
glColor4f(0,0,0,1);
glText->write("New Game", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
if(var.menuPressed)
{
switch(var.menuItem)
{
case 1: //quit
var.menu=6;
break;
case 2: //settings
var.menu=2;
break;
case 3: //highscores
var.menu=7;
break;
case 4: //Save Game
if(player.level > 0)// && !var.startedPlaying)
var.menu=9;
break;
case 5: //Load game
var.menu=8;
break;
case 6: //resume
resumeGame();
break;
case 7: //new game
var.menu=5;
}
var.menuPressed=0;
}
var.menuNumItems=7;
} else if(var.menu==2)
{
//Settings
//Back
glTranslatef(0.0,0.22,0.0f);
if(var.menuItem==1)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Back", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//settings
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
glCallList(dl+3);
glColor4f(1,1,1,1);
glText->write("Settings", FONT_MENU, 1, 1.0, 0.0, -0.005);
//Video
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==6)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Video", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//sound
glTranslatef(0.0,-0.22,0.0f);
#ifndef NOSOUND
if(var.menuItem==5)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Sound", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
#endif
//Calibrate
glTranslatef(0.0,-0.22,0.0f);
if(SDL_JoystickOpened(0))
{
if(var.menuItem==4)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Calibrate Joystick", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
}
glTranslatef(0.0,-0.22,0.0f);
#ifdef WITH_WIIUSE
if(!var.wiiConnect)
{
if(var.menuItem==3)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Connect WiiMote", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
}
#endif
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==2)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Themes", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
if(var.menuPressed)
{
switch(var.menuItem)
{
case 1:
var.menu=1;
break;
case 6:
var.menu=3;
break;
case 5:
var.menu=4;
break;
case 4:
if(SDL_JoystickOpened(0))
{
var.menuJoyCalStage=0;
var.menu=10;
}
break;
#ifdef WITH_WIIUSE
case 3:
if(!var.wiiConnect)
{
var.menuJoyCalStage=-1;
var.menu=11;
}
break;
#endif
case 2:
var.menu=12;
break;
}
var.menuPressed=0;
}
var.menuNumItems=6;
} else if(var.menu==3)
{
//Video options
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
glCallList(dl+3);
glColor4f(1,1,1,1);
glText->write("Video Options", FONT_MENU, 1, 1.0, 0.0, -0.005);
//Toggle full
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==6)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
if(setting.fullscreen)
glText->write("Fullscreen:On", FONT_MENU, 1, 1.0, 0.0, -0.005);
else
glText->write("Fullscreen:Off", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//Eyecandy
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==5)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
if(setting.eyeCandy)
glText->write("Eyecandy:On", FONT_MENU, 1, 1.0, 0.0, -0.005);
else
glText->write("Eyecandy:Off", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//1600
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==4)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("1600x1200", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//1024
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==3)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("1024x768", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//background
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==2)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
if(setting.showBg)
glText->write("Background:On", FONT_MENU, 1, 1.0, 0.0, -0.005);
else
glText->write("Background:Off", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//Back
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==1)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Back", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
if(var.menuPressed)
{
switch(var.menuItem)
{
case 1:
var.menu=2;
break;
case 2:
if(!setting.showBg)
setting.showBg=1;
else
setting.showBg=0;
writeSettings();
break;
case 3:
setting.resx = 1024;
setting.resy = 768;
#ifndef WIN32
if(initScreen())
#endif
writeSettings();
break;
case 4:
setting.resx = 1600;
setting.resy = 1200;
#ifndef WIN32
if(initScreen())
#endif
writeSettings();
break;
case 5:
if(setting.eyeCandy)
setting.eyeCandy=0;
else
setting.eyeCandy=1;
writeSettings();
break;
case 6:
if(setting.fullscreen)
setting.fullscreen=0;
else
setting.fullscreen=1;
#ifndef WIN32
if(initScreen())
#endif
writeSettings();
break;
}
var.menuPressed=0;
}
var.menuNumItems=6;
} else if(var.menu==4)
{
//Audio
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
glCallList(dl+3);
glColor4f(1,1,1,1);
glText->write("Audio", FONT_MENU, 1, 1.0, 0.0, -0.005);
//Sound on/off
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==6)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
if(setting.sound)
glText->write("Sound:On", FONT_MENU, 1, 1.0, 0.0, -0.005);
else
glText->write("Sound:Off", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//Stereo
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==5)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
if(setting.stereo)
glText->write("Stereo:On", FONT_MENU, 1, 1.0, 0.0, -0.005);
else
glText->write("Stereo:Off", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//Back
glTranslatef(0.0,-0.88,0.0f);
if(var.menuItem==1)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Back", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
if(var.menuPressed)
{
switch(var.menuItem)
{
case 1:
var.menu=2;
break;
case 5:
if(setting.stereo)
setting.stereo=0;
else
setting.stereo=1;
writeSettings();
break;
case 6:
if(setting.sound)
setting.sound=0;
else
setting.sound=1;
soundMan.loadsounds();
writeSettings();
break;
}
var.menuPressed=0;
}
var.menuNumItems=7;
} else if(var.menu==5)
{
//New game?
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
glCallList(dl+3);
glColor4f(0,0,0,1);
glText->write("New Game", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
// glBindTexture(GL_TEXTURE_2D, tex[28].prop.texture);
// glCallList(dl+3);
//Easy
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==6)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,1,0,1);
glText->write("Easy", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
// glBindTexture(GL_TEXTURE_2D, tex[29].prop.texture);
// glCallList(dl+3);
//Normal
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==5)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,1,1);
glText->write("Normal", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
// glBindTexture(GL_TEXTURE_2D, tex[30].prop.texture);
// glCallList(dl+3);
//Hard
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==4)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(1,0,0,1);
glText->write("Hard", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
// glBindTexture(GL_TEXTURE_2D, tex[31].prop.texture);
// glCallList(dl+3);
//Back
glTranslatef(0.0,-0.66,0.0f);
if(var.menuItem==1)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Back", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
// glBindTexture(GL_TEXTURE_2D, tex[32].prop.texture);
// glCallList(dl+3);
if(var.menuPressed)
{
switch(var.menuItem)
{
case 1:
var.menu=1;
break;
case 4: //New game, hard
player.difficulty=HARD;
writeSettings();
resumeGame();
initNewGame();
break;
case 5: //New Game, Normal
player.difficulty=NORMAL;
writeSettings();
resumeGame();
initNewGame();
break;
case 6: //New game, easy
player.difficulty=EASY;
writeSettings();
resumeGame();
initNewGame();
break;
}
var.menuPressed=0;
}
var.menuNumItems=7;
} else if(var.menu==6)
{
//Exit
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
glCallList(dl+2);
glColor4f(0,0,0,1);
glText->write("Exit Game?", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//Yes
glTranslatef(0.0,-0.44,0.0f);
if(var.menuItem==5)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(1,0,0,1);
glText->write("Yes.", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
//Noes!
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==4)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,1,0,1);
glText->write("No way!", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
if(var.menuPressed)
{
switch(var.menuItem)
{
case 4: //no
var.menu=1;
break;
case 5: //Yes
var.quit=1;
break;
}
var.menuPressed=0;
}
var.menuNumItems=5;
} else if(var.menu==7) // highscores
{
//Highscores
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
if(var.menuItem==7)
glCallList(dl+2);
else
glCallList(dl+3);
glColor4f(1,1,1,1);
glText->write("Highscores", FONT_MENU, 1, 1.0, 0.0, -0.005);
glTranslatef(0.0, -0.75, 0.0f);
glBindTexture(GL_TEXTURE_2D, tex[4].prop.texture);
glEnable(GL_TEXTURE_2D);
glColor4f(1.0,1.0,1.0,1.0);
glBegin( GL_QUADS );
glTexCoord2f( 0.0, 0.0 ); glVertex3f( -0.8, 0.63, 0.0 );
glTexCoord2f( 1.0, 0.0 ); glVertex3f( 0.8, 0.63, 0.0 );
glTexCoord2f( 1.0, 1.0 ); glVertex3f( 0.8,-0.63, 0.0 );
glTexCoord2f( 0.0, 1.0 ); glVertex3f( -0.8,-0.63, 0.0 );
glEnd( );
glLoadIdentity();
glTranslatef(0.0, 0.435,-3.0f);
//Find out how many lines we have room for in the box.
int nl= (1.26/glText->getHeight(FONT_MENUHIGHSCORE));
//If theres room for more than 20, only show 20..
nl > 20 ? nl=20 : nl=nl;
for(int i=0; i < nl; i++)
{
glTranslatef(0.0, -glText->getHeight(FONT_MENUHIGHSCORE),0.0f);
glText->write(highScores[i], FONT_MENUHIGHSCORE, 0, 1.0, -0.75, 0.0);
}
if(var.menuPressed)
{
switch(var.menuItem)
{
case 7:
var.menu=1;
break;
}
var.menuPressed=0;
}
} else if(var.menu==8)
{
//Load game
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
if(var.menuItem==8)
glCallList(dl+2);
else
glCallList(dl+3);
glColor4f(1,1,1,1);
glText->write("Load Game", FONT_MENU, 1, 1.0, 0.0, -0.005);
for(int i=0; i < 6; i++)
{
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==6-i)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write(saveGameName[i], FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
}
if(var.menuPressed)
{
if(var.menuItem==7)
{
var.menu=1;
} else if(var.menuItem !=0)
{
loadGame(var.menuItem*-1 +6);
var.menu=0;
resumeGame();
}
var.menuPressed=0;
}
} else if(var.menu == 9)
{
//Save game
//Back
if(var.enterSaveGameName)
{
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
glTranslatef(0.0, 0.12,0.0f);
glColor4f(0,0,0,1);
glText->write("Enter name and press Enter to save. ESC to cancel", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,0,0,1);
}
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
if(var.menuItem==8)
glCallList(dl+2);
else
glCallList(dl+3);
glColor4f(1,1,1,1);
glText->write("Save Game", FONT_MENU, 1, 1.0, 0.0, -0.005);
for(int i=0; i < 6; i++)
{
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==6-i)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write(saveGameName[i], FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
}
if(var.menuPressed)
{
if(var.menuItem==7)
{
var.menu=1;
} else if(var.menuItem !=0)
{
var.enterSaveGameName = 1;
saveGameSlot = (var.menuItem*-1 +6);
saveGameName[saveGameSlot]="";
}
var.menuPressed=0;
}
} else if(var.menu == 10)
{
//Joystick options
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
glCallList(dl+3);
glColor4f(1,1,1,1);
glText->write("Calibrate Joystick", FONT_MENU, 1, 1.0, 0.0, -0.005);
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==6)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
if(setting.joyIsDigital)
glText->write("Digital Joystick", FONT_MENU, 1, 1.0, 0.0, -0.005);
else
glText->write("Analog Joystick", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
glTranslatef(0.0,-0.22,0.0f);
if(!setting.joyIsDigital)
{
if(var.menuItem==5)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
if(var.menuJoyCalStage==0)
glText->write("Start Calibration", FONT_MENU, 1, 1.0, 0.0, -0.005);
else if(var.menuJoyCalStage==1)
glText->write("Center, Push", FONT_MENU, 1, 1.0, 0.0, -0.005);
else if(var.menuJoyCalStage==2)
glText->write("Move Left, Push", FONT_MENU, 1, 1.0, 0.0, -0.005);
else if(var.menuJoyCalStage==3)
glText->write("Move Right, Push", FONT_MENU, 1, 1.0, 0.0, -0.005);
else if(var.menuJoyCalStage==4)
glText->write("Saving...", FONT_MENU, 1, 1.0, 0.0, -0.005);
else if(var.menuJoyCalStage==5)
glText->write("Finished.", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
}
glTranslatef(0.0,-0.22,0.0f);
glTranslatef(0.0,-0.22,0.0f);
glTranslatef(0.0,-0.22,0.0f);
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==1)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Back", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
if(var.menuPressed)
{
switch(var.menuItem)
{
case 1:
var.menu=2;
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
if(!var.menuJoyCalStage)
var.menuJoyCalStage=1;
break;
case 6:
if(setting.joyIsDigital)
setting.joyIsDigital=0;
else
setting.joyIsDigital=1;
writeSettings();
break;
}
var.menuPressed=0;
}
var.menuNumItems=6;
}
#ifdef WITH_WIIUSE
else if(var.menu == 11) //Wiimote
{
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
glCallList(dl+3);
glColor4f(1,1,1,1);
glText->write("Connect WiiMote", FONT_MENU, 1, 1.0, 0.0, -0.005);
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==6 && !var.wiiConnect)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
if(var.menuJoyCalStage==-2)
glText->write("1+2 on WiiMote", FONT_MENU, 1, 1.0, 0.0, -0.005);
else if(var.menuJoyCalStage==-3)
glText->write("WiiMote Connected!", FONT_MENU, 1, 1.0, 0.0, -0.005);
else if(var.menuJoyCalStage==-4)
glText->write("Failed! Try again.", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
glCallList(dl+3);
glTranslatef(0.0,-1.0,0.0);
if(var.menuItem==1)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Back", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
if(var.menuPressed)
{
switch(var.menuItem)
{
case 6:
if(!var.wiiConnect)
{
var.menu=11;
var.menuJoyCalStage=-1;
}
break;
case 1:
var.menu=2;
break;
}
var.menuPressed=0;
}
var.menuNumItems=6;
}
#endif
else if(var.menu == 12) //Theme selector (Main screen)
{
glLoadIdentity();
glTranslatef(0.0, 0.54,-3.0f);
glCallList(dl+3);
if(!themeChanged)
{
glColor4f(0,0,0,1);
glText->write("Themes", FONT_MENU, 1, 1.0, 0.0, -0.005);
} else {
glColor4f(1,0,0,1);
glText->write("Restart to apply", FONT_MENU, 1, 1.0, 0.0, -0.005);
}
glColor4f(1,1,1,1);
int i=0;
for(vector::iterator it=tI.begin(); it < tI.end(); ++it)
{
if(i ==5)
break;
glTranslatef(0.0,-0.22,0.0f);
if(var.menuItem==6-i)
glCallList(dl+2);
else if(it->name.compare(setting.gfxTheme)==0)
glCallList(dl+3);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write(it->name, FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
i++;
}
for(int a=i; a < 6; a++)
{
glTranslatef(0.0,-0.22,0.0f);
}
if(var.menuItem==1)
glCallList(dl+2);
else
glCallList(dl+1);
glColor4f(0,0,0,1);
glText->write("Back", FONT_MENU, 1, 1.0, 0.0, -0.005);
glColor4f(1,1,1,1);
}
if(var.menuPressed)
{
switch(var.menuItem)
{
case 1:
var.menu=2;
break;
}
for(i=0; i < (int)tI.size() && i<5; i++)
{
if(6-i == var.menuItem)
{
setting.gfxTheme = tI.at(i).name;
setting.sndTheme = tI.at(i).name;
setting.lvlTheme = tI.at(i).name;
themeChanged=1;
writeSettings();
}
}
var.menuPressed=0;
}
}
};
sdl-ball/sound.cpp 0000644 0001750 0001750 00000014173 11117305744 013757 0 ustar dusted dusted /* ************************************************************************* *
SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk )
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 3 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, see .
* ************************************************************************* */
#include
struct sampleQueuedItem {
int s,p,num;
};
class soundClass {
private:
#ifndef NOSOUND
//The actual sound samples
Mix_Chunk *sample[SNDSAMPLES];
//List of queued samples
vector q;
void loadSample(const char *SampleName, int sampleNum);
int m; //Secret undocumented variable
#endif
public:
bool init();
void play();
void add(int i, GLfloat x);
void loadsounds();
~soundClass();
};
bool soundClass::init() {
#ifndef NOSOUND
m=0;
int audio_rate = 44100;
Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
int audio_channels = 2;
int audio_buffers = 1024;
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
cout << "Error: Could not open audio device."< pl;
vector::iterator plIt;
bool same=0;
int freeChannel = -1; //The channel we will use for this sample
//Loop through queue and find samples thare are the same, average their position and put in a new vector
for(vector::iterator it = q.begin(); it != q.end(); ++it)
{
//Loop thrugh the playlist to see find out if this allready exist
same=0;
for(plIt=pl.begin(); plIt != pl.end(); ++plIt)
{
if(plIt->s == it->s)
{
same=1;
plIt->num++;
plIt->p += it->p;
}
}
//this sample is not yet in the playlist
if(!same)
{
pl.push_back( *it );
plIt = pl.end();
--plIt;
plIt->num=1;
}
}
q.clear();
//Play the actual samples :)
for(plIt = pl.begin(); plIt != pl.end(); ++plIt)
{
//Find a free channel:
for(int i=0; i < MIX_CHANNELS; i++)
{
if(!Mix_Playing(i))
{
freeChannel=i;
break;
}
}
if(setting.stereo)
{
plIt->p /=plIt->num;
Mix_SetPanning(freeChannel, 255-plIt->p, plIt->p);
}
if(plIt->s == SND_NORM_BRICK_BREAK)
{
switch(m)
{
//Case 0 = SND_NORM_BREAK(a)
case 1:
plIt->s = SND_NORM_BRICK_BREAKB;
break;
case 2:
plIt->s = SND_NORM_BRICK_BREAKC;
break;
case 3:
plIt->s = SND_NORM_BRICK_BREAKD;
break;
case 4:
plIt->s = SND_NORM_BRICK_BREAKE;
break;
}
m++;
if(m==5)
m=0;
}
if(Mix_PlayChannel(freeChannel, sample[plIt->s], 0) == -1)
{
printf("Sample %i: %s\n",plIt->s, Mix_GetError());
}
}
#endif
}
soundClass::~soundClass()
{
#ifndef NOSOUND
for(int i=0; i < SNDSAMPLES; i++)
{
Mix_FreeChunk(sample[i]);
}
Mix_CloseAudio();
#endif
}
sdl-ball/title.cpp 0000644 0001750 0001750 00000020657 11126544536 013760 0 ustar dusted dusted /* ************************************************************************* *
SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk )
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 3 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, see .
* ************************************************************************* */
class powerupDescriptionClass : public moving_object {
public:
powerupDescriptionClass();
textureClass *tex;
void draw();
string name;
string description;
};
powerupDescriptionClass::powerupDescriptionClass()
{
width=0.055;
height=0.055;
}
void powerupDescriptionClass::draw()
{
tex->play();
glBindTexture( GL_TEXTURE_2D, tex->prop.texture);
glColor4f(tex->prop.glTexColorInfo[0],tex->prop.glTexColorInfo[1],tex->prop.glTexColorInfo[2],tex->prop.glTexColorInfo[3]);
glBegin( GL_QUADS );
glTexCoord2f(tex->pos[0],tex->pos[1]);glVertex3f( -width+posx, height+posy, 0.00 ); // øverst venst
glTexCoord2f(tex->pos[2],tex->pos[3]);glVertex3f( width+posx, height+posy, 0.00 ); // øverst højre
glTexCoord2f(tex->pos[4],tex->pos[5]);glVertex3f( width+posx,-height+posy, 0.00 ); // nederst højre
glTexCoord2f(tex->pos[6],tex->pos[7]);glVertex3f( -width+posx,-height+posy, 0.00 ); // nederst venstre
glEnd( );
glColor4f(1.0, 1.0, 1.0, 1.0);
//Write her
glText->write(name, FONT_INTRODESCRIPTION, 0, 1.0, posx+width, posy+(glText->getHeight(FONT_INTRODESCRIPTION)/2.0));
glText->write(description, FONT_INTRODESCRIPTION, 0, 1.0, posx+width, posy-(glText->getHeight(FONT_INTRODESCRIPTION)/2.0));
}
class titleScreenClass {
private:
effectManager *fxMan;
int ticksSinceLastSpawn;
textureManager texMgr;
textureClass texTitle;
textureClass *texPowerups;
GLuint glTitleList;
float rot;
bool rotDir;
powerupDescriptionClass powerUp[MAXPOTEXTURES];
int numHighScores; //Number of highscores to show in the intro
struct pos runnerPos;
menuClass *menu; //Here is the highscore text
int runnerTime;
float runnerVelX,runnerVelY;
int hilight;
bool hilightDir;
int hilightTime;
void readDescriptions(powerupDescriptionClass po[]);
public:
titleScreenClass(effectManager *m, textureClass tp[], menuClass *me);
void draw(int * frameAge, int * maxFrameAge);
};
titleScreenClass::titleScreenClass(effectManager *m, textureClass tp[], menuClass *me)
{
menu = me;
numHighScores=7;
texPowerups = tp;
fxMan = m;
ticksSinceLastSpawn=100;
texMgr.load(useTheme("/gfx/title/title.png",setting.gfxTheme), texTitle);
glTitleList = glGenLists(1);
glNewList(glTitleList, GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, texTitle.prop.texture);
glBegin( GL_QUADS );
for(int i=0; i < 32; i++)
{
glColor4f(1,1,1,0.1);
glTexCoord2f(0.0, 0.0); glVertex3f(-1.2,1.15, 0.005*i );
glTexCoord2f(1.0, 0.0); glVertex3f( 1.2,1.15, 0.005*i );
glColor4f(0,0,1,0.00);
glTexCoord2f(1.0, 1.0); glVertex3f( 1.2, 0.75, 0.005*i );
glTexCoord2f(0.0, 1.0); glVertex3f(-1.2, 0.75, 0.005*i );
}
glEnd( );
glEndList();
for(int ii = 0; ii < 3; ii++)
{
for(int i=0; i < 7; i++)
{
powerUp[i+(7*ii)].tex = &texPowerups[i+(7*ii)];
powerUp[i+(7*ii)].posx = -1.5 + (0.8*ii);
powerUp[i+(7*ii)].posy = -0.35 - (0.135*i);
}
}
readDescriptions(powerUp);
runnerPos.x=0.0;
runnerPos.y=0.66;
runnerVelX = rndflt(2,1)+2;
runnerVelY = rndflt(2,1)+2;
runnerTime=0;
hilight=0;
hilightDir=1;
hilightTime=0;
}
int delta(int a, int b)
{
if(a >= b)
{
return(a-b);
} else {
return(b-a);
}
}
void titleScreenClass::draw(int * frameAge, int * maxFrameAge)
{
pos p,s;
if(*frameAge >= *maxFrameAge)
{
soundMan.play();
if(var.clearScreen)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
glEnable(GL_TEXTURE_2D);
ticksSinceLastSpawn +=globalTicksSinceLastDraw;
if(ticksSinceLastSpawn > 125)
{
s.x = 3.25;
s.y = 0.525;
p.x = 0;
p.y = 1;
ticksSinceLastSpawn=0;
fxMan->set(FX_VAR_TYPE, FX_PARTICLEFIELD);
fxMan->set(FX_VAR_COLDET, 0);
fxMan->set(FX_VAR_LIFE, 1500);
fxMan->set(FX_VAR_NUM, 50);
fxMan->set(FX_VAR_SIZE, 0.01f);
fxMan->set(FX_VAR_SPEED, 0.0f);
fxMan->set(FX_VAR_GRAVITY, 0.0f);
fxMan->set(FX_VAR_RECTANGLE, s);
fxMan->set(FX_VAR_COLOR, 1.0f, 1.0f, 1.0f);
fxMan->spawn(p);
}
fxMan->draw();
int i;
glLoadIdentity();
glTranslatef(0.0, 0.0, -3.0);
for(i=0; i < MAXPOTEXTURES; i++)
{
powerUp[i].draw();
}
runnerTime+=globalTicksSinceLastDraw;
if(runnerTime>10)
{
fxMan->set(FX_VAR_TYPE, FX_SPARKS);
fxMan->set(FX_VAR_COLDET,0);
fxMan->set(FX_VAR_LIFE, 250);
fxMan->set(FX_VAR_NUM, 2);
fxMan->set(FX_VAR_SIZE, 0.09f);
fxMan->set(FX_VAR_SPEED, 0.5f);
fxMan->set(FX_VAR_GRAVITY, -0.4f);
fxMan->set(FX_VAR_COLOR, 1.0f, 0.7f, 0.0f);
fxMan->spawn(runnerPos);
fxMan->set(FX_VAR_COLOR, 1.0f, 0.8f, 0.0f);
fxMan->spawn(runnerPos);
fxMan->set(FX_VAR_COLOR, 1.0f, 0.9f, 0.0f);
fxMan->spawn(runnerPos);
fxMan->set(FX_VAR_COLOR, 1.0f, 1.0f, 0.0f);
fxMan->spawn(runnerPos);
runnerPos.x += runnerVelX*(runnerTime/1000.0);
runnerPos.y += runnerVelY*(runnerTime/1000.0);
if(runnerPos.x > 1.64 && runnerVelX > 0)
{
runnerVelX *= -1;
}
if(runnerPos.x < -1.64 && runnerVelX < 0)
{
runnerVelX *= -1;
}
if(runnerPos.y > 1.24 && runnerVelY > 0)
{
runnerVelY *= -1;
}
if(runnerPos.y < -1.24 && runnerVelY < 0)
{
runnerVelY *= -1;
}
runnerTime=0;
}
hilightTime += globalTicksSinceLastDraw;
if(hilightTime > 50)
{
if(hilightDir)
{
hilight++;
if(hilight == numHighScores*3)//-1)
{
hilight= numHighScores-1;
hilightDir=0;
}
} else {
hilight--;
if(hilight == -numHighScores*2)
{
hilightDir=1;
hilight=0;
}
}
hilightTime=0;
}
glTranslatef(0.0, 0.59, 0.0);
float a;
for(i=0; i < numHighScores; i++)
{
if((hilightDir && i < hilight+1) || (!hilightDir && i > hilight-1))
{
a=1.0-((1.0/(float)(numHighScores*2))*(delta(hilight,i)));
glColor4f(1,1,1,a);
glText->write(menu->highScores[i], FONT_INTROHIGHSCORE, 1, 1.0, 0.0, 0.0);
}
glTranslatef(0.0,-glText->getHeight(FONT_INTROHIGHSCORE),0.0);
}
//Draw the info string with website and version
glColor4f(1,1,0,1);
glText->write("Visit http://sdl-ball.sf.net/ for info, help and updates!", FONT_INTROHIGHSCORE, 1, 1.0, 0,0);
if(!rotDir)
{
rot += 0.01 * globalTicksSinceLastDraw;
if(rot > 40)
{
rotDir=1;
}
} else {
rot -= 0.01 * globalTicksSinceLastDraw;
if(rot < -40)
{
rotDir=0;
}
}
glLoadIdentity();
glTranslatef(0.0,0.0,-3.0);
glRotatef(20, 1,0,0);
glRotatef(rot, 0,1,0);
glCallList(glTitleList);
SDL_GL_SwapBuffers( );
globalTicksSinceLastDraw=0;
globalMilliTicksSinceLastDraw=0;
*frameAge = 0;
}
}
void titleScreenClass::readDescriptions(powerupDescriptionClass po[])
{
ifstream f;
string line;
int p=0;
bool flip=0;
f.open( useTheme("/powerupdescriptions.txt", setting.gfxTheme).data() );
if(f.is_open())
{
while(!f.eof())
{
getline(f, line);
if(!flip)
{
flip=1;
po[p].name=line;
} else {
flip=0;
po[p].description=line;
p++;
}
if(p == MAXPOTEXTURES)
break;
}
f.close();
} else {
cout << "Could not open powerupdescriptions"<