CRM32Pro SDK  v5.22
SpacePong.h


SpacePong header - A little pong clone game

/*--------------------------------------------
SpacePong Minigame - Roberto Prieto
Copyright (C) 2001-2011 MegaStorm Systems
--------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Roberto Prieto
contact@megastormsystems.com
http://www.megastormsystems.com
Used software licenses, including the one for this game, are located
at /licenses directory. Please, include them on your distributions.
------------------------------------------------------------------------
SpacePong Minigame, a pong clone with 3 different game modes:
- Auto demo mode
- 1 player
- 2 players (on the same computer)
- 2D environment at 800x600
- Graphics, sounds and musics using DPF
Supported platforms:
- Any Windows x86 or x86-64 version.
- Any Linux x86 or x86-64 distribution.
- MacOS X 10.x x86 or x86-64.
Thanks to Worvast for the new in-game graphics.
Changelog: Check history.txt
------------------------------------------------------------------------ */
// ---Defines---
#define PONG_VERSION "SpacePong v2.02"
#define GFX_RESOURCE "gfx.dpf"
#define MUS_RESOURCE "audio.dpf"
#define Y_POSITION_1 568
#define Y_POSITION_2 16
#define Y_SIZE_PADDER 16
#define X_SIZE_BALL 16
#define Y_SIZE_BALL 16
#define LEFT_BAR 151
#define RIGHT_BAR 648
#define UP_LIMIT -8
#define DOWN_LIMIT 600
#define MAX_BALL_SPEED 2.0f
#define MODE_COMPUTER 0
#define MODE_1PLAYER 2
#define MODE_2PLAYER 4
#define MODE_2NET 8
#define GAME_TIME 0
#define GAME_GOAL 2
#define GAME_NORMAL 4
#define PADDER_ACEL 1.0f
#define PADDER_MAXSPEED 8.0f
#define PONG_ENTRY 0
#define PONG_LOOP 1
#define PONG_QUIT 2
#define PONG_ENDMATCH 3
// ---Structs---
struct _sBall
{
float x,y;
float sx,sy; // Specific speed per coordinate
float speed; // Global speed (it is going up each padder hit)
} sBall;
struct _sPadder
{
float x,y;
float speed;
short size,random;
} sPadder[2];
struct _sGameDat
{
Uint32 iWinP1;
Uint32 iWinP2;
char iModo;
char iTipo;
} sGameDat;
// ---Global vars---
SDL_Rect rRect;
SDL_Surface *sGameBg, *sRestoreBg[2];
SDL_Surface *sMenuBg, *sMenuTitle, *sMenuInfo;
Uint32 iAux = 0;
Uint32 cCursor;
Uint32 bExitID, bPlayer1ID, bPlayer2ID;
Uint32 bTimeID, bGoalID, bNormalID, bAutoID, bID;
char sCad[10];
// ---Music and sound handles---
int music_menu;
int music_game;
int click, click2, thunder;
int p1, p2, pared, gol, end;
// ---Prototypes---
void LoadAudio();
void FreeAudio();
void LoadGraphics();
void FreeGraphics();
void RenderInGame(int bLogicUpdate);
void RenderInMenu(int bLogicUpdate);
void InitBall(int);
void AIPadder(int);
void PadderHitBall(int);
void GameLoop(void);
void DrawInterfaz(int);
void InfoEngine(int);
// ---Macros---
#define SET_SPEED(a,b)\
{ \
if(b==1) sPadder[a].speed+=PADDER_ACEL; \
else sPadder[a].speed-=PADDER_ACEL; \
if(b==1) { if(sPadder[a].speed<0.0f) sPadder[a].speed+=PADDER_ACEL*2; } \
else { if(sPadder[a].speed>0.0f) sPadder[a].speed-=PADDER_ACEL*2; } \
}