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 megastorm@ono.com http://www.megastormsystems.com ------------------------------------------------------------------------ SpacePong Minigame - CRM32Pro SDK example 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 - Platform: Win32 / Linux / MacOS X 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 //!< Padder acceleration #define PADDER_MAXSPEED 8.0f //!< Maximum padder speed #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) CRM32Pro_CSprite *spr; } sBall; struct _sPadder { float x,y; float speed; short size,random; CRM32Pro_CSprite *spr; } 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; CRM32Pro_CFont *fFont; 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; } \ }
1.7.1