// Frogger a game by PhilVaz // Full Screen GDI game // October 20, 2006 // INCLUDES /////////////////////////////////////////////// #define WIN32_LEAN_AND_MEAN #include // include all the windows headers #include // include useful macros #include // for DirectSound #include // for rand functions #include #include #include // include DirectSound #include "dsutil.h" // for LoadSoundBuffer() #include "Frogger.h" // sounds and bitmap resources // DEFINES //////////////////////////////////////////////// // defines for windows #define WINDOW_CLASS_NAME "WINCLASS1" #define WINDOW_WIDTH 800 // size of game window #define WINDOW_HEIGHT 600 #define GAME_SPEED 15 // speed of game (increase to go slower) #define GAME_STATE_DEMO_INIT 0 // demo initialization state #define GAME_STATE_DEMO_RUN 1 // demo running state #define GAME_STATE_GAME_INIT 2 // game initialization state #define GAME_STATE_GAME_RUN 3 // game running state #define GAME_STATE_GAME_RESET 4 // game reset state (new level) #define GAME_STATE_GAME_PAUSE 5 // game pause state (no movement) #define MAX_CARS 50 #define MAX_PARTICLES 250 #define MAX_BUGS 10 #define LEVEL_PAUSE 80 #define FROG_SPEED 3 // speed of frog, 6=fast, 3=normal #define FROG_DELAY 2 // delay between anim frames, 1=fast, 2=normal #define FROG_RIGHT 1 // for frog road goal (left or right) #define FROG_LEFT 2 // to switch F = 3 - F #define DIFFICULTY_EASY 0 #define DIFFICULTY_HARD 1 #define XLANE1 60 // slower lane (car down) #define XLANE2 135 // faster lane (car down) #define XLANE3 215 // faster lane (car up) #define XLANE4 288 // slower lane (car up) #define XLANE5 432 // slower lane (car down) #define XLANE6 506 // faster lane (car down) #define XLANE7 588 // faster lane (car up) #define XLANE8 660 // slower lane (car up) // MACROS ///////////////////////////////////////////////// #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) // GLOBALS //////////////////////////////////////////////// HWND game_window = NULL; // global game window handle HINSTANCE game_instance = NULL; // global game instance handle HDC game_dc = NULL; // global device context (for GDI) handle // for back (double) buffering HDC back_dc = NULL; HBITMAP back_bmp = NULL; HBITMAP old_bmp = NULL; RECT back_rect = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; LPDIRECTSOUND game_sound_main = NULL; // global direct sound object LPDIRECTSOUNDBUFFER game_sound_theme = NULL; LPDIRECTSOUNDBUFFER game_sound_frog01 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog02 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog03 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog04 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog05 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog06 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog07 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog08 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog09 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog10 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog11 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog12 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog13 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog14 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog15 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog16 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog17 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog18 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog19 = NULL; LPDIRECTSOUNDBUFFER game_sound_frog20 = NULL; LPDIRECTSOUNDBUFFER game_sound_horn1 = NULL; LPDIRECTSOUNDBUFFER game_sound_horn2 = NULL; LPDIRECTSOUNDBUFFER game_sound_horn3 = NULL; LPDIRECTSOUNDBUFFER game_sound_horn4 = NULL; LPDIRECTSOUNDBUFFER game_sound_horn5 = NULL; LPDIRECTSOUNDBUFFER game_sound_move1 = NULL; LPDIRECTSOUNDBUFFER game_sound_move2 = NULL; LPDIRECTSOUNDBUFFER game_sound_move3 = NULL; LPDIRECTSOUNDBUFFER game_sound_move4 = NULL; LPDIRECTSOUNDBUFFER game_sound_move5 = NULL; LPDIRECTSOUNDBUFFER game_sound_siren1 = NULL; LPDIRECTSOUNDBUFFER game_sound_siren2 = NULL; LPDIRECTSOUNDBUFFER game_sound_siren3 = NULL; LPDIRECTSOUNDBUFFER game_sound_beep1 = NULL; LPDIRECTSOUNDBUFFER game_sound_beep2 = NULL; LPDIRECTSOUNDBUFFER game_sound_beep3 = NULL; LPDIRECTSOUNDBUFFER game_sound_beep4 = NULL; LPDIRECTSOUNDBUFFER game_sound_beep5 = NULL; LPDIRECTSOUNDBUFFER game_sound_buzz = NULL; LPDIRECTSOUNDBUFFER game_sound_lick1 = NULL; LPDIRECTSOUNDBUFFER game_sound_lick2 = NULL; LPDIRECTSOUNDBUFFER game_sound_lick3 = NULL; LPDIRECTSOUNDBUFFER game_sound_splat1 = NULL; LPDIRECTSOUNDBUFFER game_sound_splat2 = NULL; LPDIRECTSOUNDBUFFER game_sound_splat3 = NULL; bool sound_ok; // whether DirectSound init ok int last_frog_sound; // to keep sound different DEVMODE game_screen; // global for full screen mode // global pens and brush HPEN white_pen = CreatePen(PS_SOLID, 2, RGB(255,255,255)); HPEN black_pen = CreatePen(PS_SOLID, 2, RGB(0,0,0)); HBRUSH white_brush = CreateSolidBrush(RGB(255,255,255)); HBRUSH black_brush = CreateSolidBrush(RGB(0,0,0)); // global joystick variables bool joy_ok; // whether joystick found ok UINT joy_num; // number of joys JOYINFO joy_info; // joy init info UINT joy_ID; // joy ID JOYCAPS joy_caps; // joy capture info RECT joy_trip; // joy trip info DWORD joy_xcenter; // joy x axis center DWORD joy_ycenter; // joy y axis center // joy directions (1=true, 0=false) int joy_left, joy_right, joy_up, joy_down, joy_but1, joy_but2, joy_but3, joy_but4; // global game variables int game_state = GAME_STATE_DEMO_INIT; // start in demo state char text[80]; // for display text output int game_score = 0; int game_level = 1; int game_difficulty = DIFFICULTY_EASY; int xlimit = WINDOW_WIDTH - 60; // BMP limits for x and y int ylimit = WINDOW_HEIGHT - 80; int frogs_left; // frog players left int frog_goal; // frog road goal (1=right, 2=left) int level_countdown = 0; // pause time between levels // BITMAP graphics for frog animations and cars HBITMAP hfrogbmp[64]; // 64 total frames of animation for player BITMAP frogbmp[64]; HBITMAP hcarbmp[10]; // 5 cars, facing up and down BITMAP carbmp[10]; HBITMAP hhighwaybmp; BITMAP highwaybmp; HBITMAP hbugbmp; BITMAP bugbmp; HDC bmp_dc = NULL; // temp dc for bitmap // particle direction X (sin) and Y (-cos) float xdir[32] = {0.0f, 0.1951f, 0.3827f, 0.5556f, 0.7071f, 0.8315f, 0.9239f, 0.9808f, 1.0f, 0.9808f, 0.9239f, 0.8315f, 0.7071f, 0.5556f, 0.3827f, 0.1951f, 0.0f, -0.1951f, -0.3827f, -0.5556f, -0.7071f, -0.8315f, -0.9239f, -0.9808f, -1.0f, -0.9808f, -0.9239f, -0.8315f, -0.7071f, -0.5556f, -0.3827f, -0.1951f}; float ydir[32] = {-1.0f, -0.9808f, -0.9239f, -0.8315f, -0.7071f, -0.5556f, -0.3827f, -0.1951f, 0.0f, 0.1951f, 0.3827f, 0.5556f, 0.7071f, 0.8315f, 0.9239f, 0.9808f, 1.0f, 0.9808f, 0.9239f, 0.8315f, 0.7071f, 0.5556f, 0.3827f, 0.1951f, 0.0f, -0.1951f, -0.3827f, -0.5556f, -0.7071f, -0.8315f, -0.9239f, -0.9808f}; typedef struct { int x; // x y top-left of frog player int y; int speed; // current speed int pos; // animation position (0 to 15) int face; // facing (0=right, 16=left, 32=up, 48=down) int count; // count between frames int wait; // time to hold for speed increase (after eating bug) } FROG_STRUCT; FROG_STRUCT Player; typedef struct { bool alive; // TRUE = exist, FALSE = not int type; // 1 to 3 = cars, 4 = police, 5 = firetruck int x; // x y top-left int y; int xm; // x move (not used), y move int ym; int count; // not used? } CAR_STRUCT; CAR_STRUCT Cars[MAX_CARS]; typedef struct { bool alive; // TRUE = exist, FALSE = not int x; // x y top-left int y; int count; // countdown to disappear } BUG_STRUCT; BUG_STRUCT Bugs[MAX_BUGS]; typedef struct { bool alive; // TRUE = exist, FALSE = not float x; // x y center float y; float xm; float ym; int count; // count of particle, keep on screen then fade out } PARTICLE_STRUCT; PARTICLE_STRUCT Particles[MAX_PARTICLES]; // FUNCTIONS ////////////////////////////////////////////// void GameInit(); // game initialization, go full screen etc void GameMain(); // game main loop and processing void GameQuit(); // game quit and clean up void DisplayScore(); // display text score/level bottom of screen void DrawHighway(); void SetPlayer(); void MovePlayer(); void SetCars(); void MoveCars(); void InsertCar(); void InsertParticles(int, int, int); // particle explosion at x,y of type t void MoveParticles(); void MoveBugs(); void InsertBug(); bool SoundInit(); void SoundQuit(); void PlayRandomMoveSound(); // background sounds void PlayRandomBackSound(); bool JoyInit(); void JoyQuit(); void JoyStatus(); void CheckCollisions(); // Check for all potential Collisions void ResetAll(); // Reset (clear) all cars, particles, etc // WINPROC //////////////////////////////////////////////// LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { // this is the main message handler of the system HDC hdc; // handle to a device context PAINTSTRUCT ps; // used in WM_PAINT switch(msg) // what is the message { case WM_CREATE: { // do initialization stuff here return(0); // return success } break; case WM_PAINT: { hdc = BeginPaint(hwnd, &ps); // validate the window EndPaint(hwnd, &ps); return(0); // return success } break; case WM_DESTROY: { PostQuitMessage(0); // kill the application, sends a WM_QUIT message return(0); // return success } break; default:break; } // end switch // process any default messages return (DefWindowProc(hwnd, msg, wparam, lparam)); } // end WinProc // WINMAIN //////////////////////////////////////////////// int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; // this will hold the class we create HWND hwnd; // generic window handle MSG msg; // generic message // save the game instance handle game_instance = hinstance; // first fill in the window class structure // WHEN DONE ADD // LoadIcon(game_instance, MAKEINTRESOURCE(ICON_VAZGAMES)) winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WinProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(game_instance, MAKEINTRESOURCE(ICON_VAZGAMES)); winclass.hIconSm = LoadIcon(game_instance, MAKEINTRESOURCE(ICON_VAZGAMES)); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; // register the window class if (!RegisterClassEx(&winclass)) return(0); // create the window if (!(hwnd = CreateWindowEx(NULL, // extended style WINDOW_CLASS_NAME, // class "Frogger", // title WS_POPUP | WS_VISIBLE, // use POPUP for full screen 0,0, // initial game window x,y WINDOW_WIDTH, // initial game width WINDOW_HEIGHT, // initial game height NULL, // handle to parent NULL, // handle to menu hinstance, // instance of this application NULL))) // extra creation parms return(0); // save the game window handle game_window = hwnd; GameInit(); // game initialization function called here // enter main event loop using PeekMessage() to retrieve messages while(TRUE) { // get initial tick count to keep game speed constant DWORD start_tick = GetTickCount(); // is there a message in queue, if so get it if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys TranslateMessage(&msg); // send the message to WinProc DispatchMessage(&msg); } // end if // if we're not in pause state, erase the back buffer if (game_state != GAME_STATE_GAME_PAUSE) FillRect(back_dc, &back_rect, white_brush); GameMain(); // game main processing function called here // copy back buffer to front buffer BitBlt(game_dc, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, back_dc, 0, 0, SRCCOPY); // check for key and send quit game if (KEYDOWN(VK_ESCAPE)) SendMessage (hwnd, WM_CLOSE, 0, 0); // wait until we hit correct game speed frame rate while ((GetTickCount() - start_tick) < GAME_SPEED); } // end while GameQuit(); // game quit function and clean up before exit called here return(msg.wParam); // return to Windows } // end WinMain // BEGIN GAME CODE //////////////////////////////////////// /////////////////////////////////////////////////////////// // // GAME INITIALIZATION // /////////////////////////////////////////////////////////// void GameInit() { int i; // for loop srand(GetTickCount()); // seed the random numbers // temporary change to full screen mode ZeroMemory(&game_screen, sizeof(game_screen)); // clear out size of DEVMODE struct game_screen.dmSize = sizeof(game_screen); game_screen.dmPelsWidth = WINDOW_WIDTH; game_screen.dmPelsHeight = WINDOW_HEIGHT; game_screen.dmBitsPerPel = 16; game_screen.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; ChangeDisplaySettings(&game_screen, CDS_FULLSCREEN); game_dc = GetDC(game_window); // get the GDI device context // for back (double) buffering back_dc = CreateCompatibleDC(game_dc); back_bmp = CreateCompatibleBitmap(game_dc, WINDOW_WIDTH, WINDOW_HEIGHT); old_bmp = (HBITMAP)SelectObject(back_dc, back_bmp); ShowCursor(FALSE); bmp_dc = CreateCompatibleDC(game_dc); // load the BMP frog player resources hfrogbmp[0] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG00), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[0], sizeof(frogbmp[0]), &frogbmp[0]); hfrogbmp[1] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG01), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[1], sizeof(frogbmp[1]), &frogbmp[1]); hfrogbmp[2] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG02), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[2], sizeof(frogbmp[2]), &frogbmp[2]); hfrogbmp[3] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG03), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[3], sizeof(frogbmp[3]), &frogbmp[3]); hfrogbmp[4] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG04), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[4], sizeof(frogbmp[4]), &frogbmp[4]); hfrogbmp[5] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG05), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[5], sizeof(frogbmp[5]), &frogbmp[5]); hfrogbmp[6] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG06), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[6], sizeof(frogbmp[6]), &frogbmp[6]); hfrogbmp[7] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG07), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[7], sizeof(frogbmp[7]), &frogbmp[7]); hfrogbmp[8] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG08), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[8], sizeof(frogbmp[8]), &frogbmp[8]); hfrogbmp[9] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG09), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[9], sizeof(frogbmp[9]), &frogbmp[9]); hfrogbmp[10] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG10), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[10], sizeof(frogbmp[10]), &frogbmp[10]); hfrogbmp[11] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG11), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[11], sizeof(frogbmp[11]), &frogbmp[11]); hfrogbmp[12] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG12), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[12], sizeof(frogbmp[12]), &frogbmp[12]); hfrogbmp[13] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG13), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[13], sizeof(frogbmp[13]), &frogbmp[13]); hfrogbmp[14] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG14), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[14], sizeof(frogbmp[14]), &frogbmp[14]); hfrogbmp[15] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG15), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[15], sizeof(frogbmp[15]), &frogbmp[15]); hfrogbmp[16] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG16), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[16], sizeof(frogbmp[16]), &frogbmp[16]); hfrogbmp[17] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG17), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[17], sizeof(frogbmp[17]), &frogbmp[17]); hfrogbmp[18] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG18), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[18], sizeof(frogbmp[18]), &frogbmp[18]); hfrogbmp[19] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG19), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[19], sizeof(frogbmp[19]), &frogbmp[19]); hfrogbmp[20] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG20), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[20], sizeof(frogbmp[20]), &frogbmp[20]); hfrogbmp[21] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG21), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[21], sizeof(frogbmp[21]), &frogbmp[21]); hfrogbmp[22] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG22), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[22], sizeof(frogbmp[22]), &frogbmp[22]); hfrogbmp[23] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG23), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[23], sizeof(frogbmp[23]), &frogbmp[23]); hfrogbmp[24] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG24), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[24], sizeof(frogbmp[24]), &frogbmp[24]); hfrogbmp[25] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG25), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[25], sizeof(frogbmp[25]), &frogbmp[25]); hfrogbmp[26] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG26), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[26], sizeof(frogbmp[26]), &frogbmp[26]); hfrogbmp[27] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG27), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[27], sizeof(frogbmp[27]), &frogbmp[27]); hfrogbmp[28] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG28), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[28], sizeof(frogbmp[28]), &frogbmp[28]); hfrogbmp[29] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG29), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[29], sizeof(frogbmp[29]), &frogbmp[29]); hfrogbmp[30] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG30), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[30], sizeof(frogbmp[30]), &frogbmp[30]); hfrogbmp[31] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG31), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[31], sizeof(frogbmp[31]), &frogbmp[31]); hfrogbmp[32] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG32), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[32], sizeof(frogbmp[32]), &frogbmp[32]); hfrogbmp[33] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG33), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[33], sizeof(frogbmp[33]), &frogbmp[33]); hfrogbmp[34] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG34), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[34], sizeof(frogbmp[34]), &frogbmp[34]); hfrogbmp[35] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG35), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[35], sizeof(frogbmp[35]), &frogbmp[35]); hfrogbmp[36] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG36), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[36], sizeof(frogbmp[36]), &frogbmp[36]); hfrogbmp[37] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG37), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[37], sizeof(frogbmp[37]), &frogbmp[37]); hfrogbmp[38] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG38), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[38], sizeof(frogbmp[38]), &frogbmp[38]); hfrogbmp[39] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG39), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[39], sizeof(frogbmp[39]), &frogbmp[39]); hfrogbmp[40] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG40), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[40], sizeof(frogbmp[40]), &frogbmp[40]); hfrogbmp[41] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG41), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[41], sizeof(frogbmp[41]), &frogbmp[41]); hfrogbmp[42] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG42), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[42], sizeof(frogbmp[42]), &frogbmp[42]); hfrogbmp[43] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG43), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[43], sizeof(frogbmp[43]), &frogbmp[43]); hfrogbmp[44] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG44), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[44], sizeof(frogbmp[44]), &frogbmp[44]); hfrogbmp[45] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG45), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[45], sizeof(frogbmp[45]), &frogbmp[45]); hfrogbmp[46] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG46), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[46], sizeof(frogbmp[46]), &frogbmp[46]); hfrogbmp[47] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG47), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[47], sizeof(frogbmp[47]), &frogbmp[47]); hfrogbmp[48] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG48), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[48], sizeof(frogbmp[48]), &frogbmp[48]); hfrogbmp[49] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG49), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[49], sizeof(frogbmp[49]), &frogbmp[49]); hfrogbmp[50] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG50), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[50], sizeof(frogbmp[50]), &frogbmp[50]); hfrogbmp[51] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG51), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[51], sizeof(frogbmp[51]), &frogbmp[51]); hfrogbmp[52] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG52), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[52], sizeof(frogbmp[52]), &frogbmp[52]); hfrogbmp[53] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG53), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[53], sizeof(frogbmp[53]), &frogbmp[53]); hfrogbmp[54] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG54), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[54], sizeof(frogbmp[54]), &frogbmp[54]); hfrogbmp[55] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG55), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[55], sizeof(frogbmp[55]), &frogbmp[55]); hfrogbmp[56] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG56), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[56], sizeof(frogbmp[56]), &frogbmp[56]); hfrogbmp[57] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG57), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[57], sizeof(frogbmp[57]), &frogbmp[57]); hfrogbmp[58] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG58), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[58], sizeof(frogbmp[58]), &frogbmp[58]); hfrogbmp[59] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG59), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[59], sizeof(frogbmp[59]), &frogbmp[59]); hfrogbmp[60] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG60), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[60], sizeof(frogbmp[60]), &frogbmp[60]); hfrogbmp[61] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG61), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[61], sizeof(frogbmp[61]), &frogbmp[61]); hfrogbmp[62] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG62), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[62], sizeof(frogbmp[62]), &frogbmp[62]); hfrogbmp[63] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_FROG63), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hfrogbmp[63], sizeof(frogbmp[63]), &frogbmp[63]); // load the BMP car resources hcarbmp[0] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_CAR1D), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hcarbmp[0], sizeof(carbmp[0]), &carbmp[0]); hcarbmp[1] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_CAR1U), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hcarbmp[1], sizeof(carbmp[1]), &carbmp[1]); hcarbmp[2] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_CAR2D), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hcarbmp[2], sizeof(carbmp[2]), &carbmp[2]); hcarbmp[3] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_CAR2U), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hcarbmp[3], sizeof(carbmp[3]), &carbmp[3]); hcarbmp[4] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_CAR3D), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hcarbmp[4], sizeof(carbmp[4]), &carbmp[4]); hcarbmp[5] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_CAR3U), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hcarbmp[5], sizeof(carbmp[5]), &carbmp[5]); hcarbmp[6] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_CAR4D), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hcarbmp[6], sizeof(carbmp[6]), &carbmp[6]); hcarbmp[7] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_CAR4U), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hcarbmp[7], sizeof(carbmp[7]), &carbmp[7]); hcarbmp[8] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_CAR5D), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hcarbmp[8], sizeof(carbmp[8]), &carbmp[8]); hcarbmp[9] = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_CAR5U), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hcarbmp[9], sizeof(carbmp[9]), &carbmp[9]); // load the BMP highway background hhighwaybmp = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_HIGHWAY), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hhighwaybmp, sizeof(highwaybmp), &highwaybmp); // load the BMP bug hbugbmp = (HBITMAP)LoadImage(game_instance, MAKEINTRESOURCE(BMP_BUG), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); GetObject(hbugbmp, sizeof(bugbmp), &bugbmp); // Initialize DirectSound sound_ok = SoundInit(); // Initialize Joystick joy_ok = JoyInit(); // reset particles (only done once) for (i = 0; i < MAX_PARTICLES; i++) Particles[i].alive = FALSE; } // END OF GameInit /////////////////////////////////////////////////////////// // // GAME MAIN LOOP AND PROCESSING // /////////////////////////////////////////////////////////// void GameMain() { switch(game_state) { case GAME_STATE_DEMO_INIT: { ResetAll(); SetCars(); frog_goal = FROG_RIGHT; game_state = GAME_STATE_DEMO_RUN; } break; case GAME_STATE_DEMO_RUN: { DrawHighway(); MoveCars(); MoveBugs(); MoveParticles(); DisplayScore(); // check for play opening song if (KEYDOWN(VK_SPACE) || KEYDOWN(49)) { game_level = 1; game_state = GAME_STATE_GAME_INIT; game_difficulty = DIFFICULTY_EASY; if (sound_ok) IDirectSoundBuffer_Play(game_sound_theme,0,0,NULL); } if (KEYDOWN(50)) { game_level = 1; game_state = GAME_STATE_GAME_INIT; game_difficulty = DIFFICULTY_HARD; if (sound_ok) IDirectSoundBuffer_Play(game_sound_theme,0,0,NULL); } } break; case GAME_STATE_GAME_INIT: { // reset scores, level, player to initial values game_score = 0; frogs_left = 5; level_countdown = LEVEL_PAUSE; ResetAll(); SetPlayer(); SetCars(); game_state = GAME_STATE_GAME_RUN; } break; case GAME_STATE_GAME_RUN: { DrawHighway(); MoveCars(); MoveBugs(); MovePlayer(); MoveParticles(); CheckCollisions(); DisplayScore(); // if 'p' key pressed, set state to GAME_PAUSE if (KEYDOWN(80)) game_state = GAME_STATE_GAME_PAUSE; } break; case GAME_STATE_GAME_RESET: { game_level++; level_countdown = LEVEL_PAUSE; game_state = GAME_STATE_GAME_RUN; } break; case GAME_STATE_GAME_PAUSE: { // if key pressed resume game if (KEYDOWN(VK_SPACE)) game_state = GAME_STATE_GAME_RUN; } break; } // end switch } // END OF GameMain /////////////////////////////////////////////////////////// // // GAME QUIT AND CLEAN UP // /////////////////////////////////////////////////////////// void GameQuit() { int i; SoundQuit(); // turn off DirectSound and release buffers JoyQuit(); // release Joystick // delete the pens and brushes DeleteObject(white_pen); DeleteObject(black_pen); DeleteObject(white_brush); DeleteObject(black_brush); // RELEASE/DELETE ALL BITMAPS HERE for (i=0; i<64; i++) DeleteObject(hfrogbmp[i]); for (i=0; i<10; i++) DeleteObject(hcarbmp[i]); DeleteObject(hhighwaybmp); DeleteObject(hbugbmp); DeleteDC(bmp_dc); // release the back buffer SelectObject(back_dc, old_bmp); DeleteObject(back_bmp); DeleteDC(back_dc); // release the device context (for GDI) from the game window ReleaseDC(game_window, game_dc); // return to original display settings ChangeDisplaySettings(NULL,NULL); } // END OF GameQuit ///////////////////////////////////////////////////////// // display text score/level/frogs bottom of screen ///////////////////////////////////////////////////////// void DisplayScore() { SetTextColor(back_dc, RGB(0,0,0)); // black text color SetBkColor(back_dc, RGB(255,255,255)); // white background sprintf(text,"SCORE = %d", game_score); TextOut(back_dc, 80, 580, text, strlen(text)); sprintf(text,"LEVEL = %d", game_level); TextOut(back_dc, 210, 580, text, strlen(text)); sprintf(text,"FROGS = %d", frogs_left); TextOut(back_dc, 340, 580, text, strlen(text)); sprintf(text,"Frogger a game by PhilVaz (c) 2006"); TextOut(back_dc, 470, 580, text, strlen(text)); if (game_state == GAME_STATE_DEMO_RUN) { sprintf(text,"Cross Lanes of Traffic -- Avoid Cars -- Eat Bugs -- Press or 1=Easy 2=Hard to Start Game"); TextOut(back_dc, 80, 565, text, strlen(text)); } // end of if } // END OF DisplayScore ///////////////////////////////////////////////////////// // draw/refresh the highway ///////////////////////////////////////////////////////// void DrawHighway() { // select and blit the highway (no transparency required since it is background) SelectObject(bmp_dc, hhighwaybmp); BitBlt(back_dc, 0, 0, 800, 580, bmp_dc, 0, 0, SRCCOPY); } // END OF DrawHighway ///////////////////////////////////////////////////////// // set the frog player ///////////////////////////////////////////////////////// void SetPlayer() { // set initial position and animation of frog player bitmap Player.x = 1; if (frog_goal == FROG_LEFT) Player.x = 740; Player.y = 300; Player.speed = FROG_SPEED; Player.pos = 0; // start at first animation position Player.face = 32; // start facing up Player.count = FROG_DELAY; // set countdown between animation frames Player.wait = 0; // clear speed up wait time } // END OF SetPlayer ///////////////////////////////////////////////////////// // move/update the frog player once ///////////////////////////////////////////////////////// void MovePlayer() { // check for level countdown = pause time between levels if (level_countdown > 0) { level_countdown--; } // end if else { JoyStatus(); // get joystick movement if (Player.wait > 0) Player.wait--; if (KEYDOWN(VK_RIGHT) || joy_right) { Player.count--; if (Player.count == 0) { Player.face = 0; Player.pos++; if (Player.pos > 15) { Player.pos = 0; PlayRandomMoveSound(); } Player.x += Player.speed; if (Player.wait > 0) Player.x += Player.speed; if (Player.x > xlimit) Player.x = xlimit; Player.count = FROG_DELAY; if (Player.wait > 0) Player.count--; } // end countdown } // end else if moving right else if (KEYDOWN(VK_LEFT) || joy_left) { Player.count--; if (Player.count == 0) { Player.face = 16; Player.pos++; if (Player.pos > 15) { Player.pos = 0; PlayRandomMoveSound(); } Player.x -= Player.speed; if (Player.wait > 0) Player.x -= Player.speed; if (Player.x < 1) Player.x = 1; Player.count = FROG_DELAY; if (Player.wait > 0) Player.count--; } // end countdown } // end else if moving left else if (KEYDOWN(VK_UP) || joy_up) { Player.count--; if (Player.count == 0) { Player.face = 32; Player.pos++; if (Player.pos > 15) { Player.pos = 0; PlayRandomMoveSound(); } Player.y -= Player.speed; if (Player.wait > 0) Player.y -= Player.speed; if (Player.y < 1) Player.y = 1; Player.count = FROG_DELAY; if (Player.wait > 0) Player.count--; } // end countdown } // end else if moving up else if (KEYDOWN(VK_DOWN) || joy_down) { Player.count--; if (Player.count == 0) { Player.face = 48; Player.pos++; if (Player.pos > 15) { Player.pos = 0; PlayRandomMoveSound(); } Player.y += Player.speed; if (Player.wait > 0) Player.y += Player.speed; if (Player.y > ylimit) Player.y = ylimit; Player.count = FROG_DELAY; if (Player.wait > 0) Player.count--; } // end countdown } // end else if moving down } // end else // display BMP to back buffer SelectObject(bmp_dc, hfrogbmp[Player.pos + Player.face]); if (Player.face < 17) TransparentBlt(back_dc, Player.x, Player.y, 86, 52, bmp_dc, 0, 0, 86, 52, RGB(255,255,255)); else TransparentBlt(back_dc, Player.x, Player.y, 52, 86, bmp_dc, 0, 0, 52, 86, RGB(255,255,255)); PlayRandomBackSound(); // play a random background noise if ((Player.x == 1) && (frog_goal == FROG_LEFT)) { game_score += 1000; frog_goal = FROG_RIGHT; if (sound_ok) IDirectSoundBuffer_Play(game_sound_beep3,0,0,NULL); game_state = GAME_STATE_GAME_RESET; } if ((Player.x > (xlimit - 10)) && (frog_goal == FROG_RIGHT)) { game_score += 500; frog_goal = FROG_LEFT; if (sound_ok) IDirectSoundBuffer_Play(game_sound_beep5,0,0,NULL); } } // END OF MovePlayer ////////////////////////////////////////////// // set the cars based on level ////////////////////////////////////////////// void SetCars() { int i, n, r, t, s; // numbers of initial cars, random lanes, type of car, speed int c; // car overlap check n = (rand()%3) + 5; // number of cars begins from 5 to 7 for (i = 0; i < n; i++) { Cars[i].alive = TRUE; t = (rand()%3) + 1; // car type 1 to 3 Cars[i].type = t; s = (rand()%5) + 2; // speed 2 to 6 for slow if (game_difficulty == DIFFICULTY_EASY) s = (rand()%3) + 1; r = (rand()%8) + 1; // one of eight lanes if (r == 1) { Cars[i].x = XLANE1; Cars[i].y = 0; // start at top Cars[i].xm = 0; Cars[i].ym = s; // travel down slower } if (r == 2) { Cars[i].x = XLANE2; Cars[i].y = 0; // start at top Cars[i].xm = 0; Cars[i].ym = s + 2; // travel down faster } if (r == 3) { Cars[i].x = XLANE3; Cars[i].y = 480; // start at bottom Cars[i].xm = 0; Cars[i].ym = -(s + 2); // travel up faster } if (r == 4) { Cars[i].x = XLANE4; Cars[i].y = 480; // start at bottom Cars[i].xm = 0; Cars[i].ym = -s; // travel up slower } if (r == 5) { Cars[i].x = XLANE5; Cars[i].y = 0; // start at top Cars[i].xm = 0; Cars[i].ym = s; // travel down slower } if (r == 6) { Cars[i].x = XLANE6; Cars[i].y = 0; // start at top Cars[i].xm = 0; Cars[i].ym = s + 2; // travel down faster } if (r == 7) { Cars[i].x = XLANE7; Cars[i].y = 480; // start at bottom Cars[i].xm = 0; Cars[i].ym = -(s + 2); // travel up faster } if (r == 8) { Cars[i].x = XLANE8; Cars[i].y = 480; // start at bottom Cars[i].xm = 0; Cars[i].ym = -s; // travel up slower } // BUG FIX: remove any cars in same lane for (c = 0; c < MAX_CARS; c++) { if ((c != i) && Cars[c].alive) // if car exists and not same one we are checking { // if cars are in same lane -- remove new car if (Cars[c].x == Cars[i].x) Cars[c].alive = FALSE; // erase car } // end if } // end for } // end for } // END OF SetCars ////////////////////////////////////////////////////////////// // move/update all the cars once ////////////////////////////////////////////////////////////// void MoveCars() { int i, t, c; // loop, car type. car bmp bool d; // whether to draw car for (i = 0; i < MAX_CARS; i++) { if (Cars[i].alive) { d = TRUE; // draw car Cars[i].x += Cars[i].xm; Cars[i].y += Cars[i].ym; if (Cars[i].y < 0) // disappear top of screen { Cars[i].alive = FALSE; d = FALSE; } if (Cars[i].y > 480) // disappear bottom of screen { Cars[i].alive = FALSE; d = FALSE; } if (d) // if car still exists, draw car BMP to back buffer { t = Cars[i].type; // save car type if (t == 1) c = 0; // car 1 if (t == 2) c = 2; // car 2 if (t == 3) c = 4; // car 3 if (t == 4) c = 6; // police car if (t == 5) c = 8; // fire car if (Cars[i].ym < 0) c++; // if car travels up, use up car bmp, otherwise down car SelectObject(bmp_dc, hcarbmp[c]); TransparentBlt(back_dc, Cars[i].x, Cars[i].y, 80, 130, bmp_dc, 0, 0, 80, 130, RGB(255,255,255)); } // end if draw } // end if car alive } // end for InsertCar(); // check whether to insert new car } // END OF MoveCars ///////////////////////////////////////////////////////////////// // Insert a new car based on level # ///////////////////////////////////////////////////////////////// void InsertCar() { int i, r, c, t, s; // loop, chance to insert a car, car type, speed of car int newcar; // save inserted car index to check r = (11 - game_level) * 100; if (r < 1) r = 100; c = (rand()%r); if (c > 25) return; // small chance to insert car for (i = 0; i < MAX_CARS; i++) { if (!Cars[i].alive) // insert a car here { Cars[i].alive = TRUE; newcar = i; // save index to check later t = (rand()%3) + 1; // car type 1 to 3 if (c == 0 || c == 1 || c == 2) t = 4; // police car if (c == 7) t = 5; // fire car Cars[i].type = t; s = (rand()%5) + 2; // speed 2 to 6 for slow if (game_difficulty == DIFFICULTY_EASY) s = (rand()%3) + 1; r = (rand()%8) + 1; // one of eight lanes if (r == 1) { Cars[i].x = XLANE1; Cars[i].y = 0; // start at top Cars[i].xm = 0; Cars[i].ym = s; // travel down slower } if (r == 2) { Cars[i].x = XLANE2; Cars[i].y = 0; // start at top Cars[i].xm = 0; Cars[i].ym = s + 2; // travel down faster } if (r == 3) { Cars[i].x = XLANE3; Cars[i].y = 480; // start at bottom Cars[i].xm = 0; Cars[i].ym = -(s + 2); // travel up faster } if (r == 4) { Cars[i].x = XLANE4; Cars[i].y = 480; // start at bottom Cars[i].xm = 0; Cars[i].ym = -s; // travel up slower } if (r == 5) { Cars[i].x = XLANE5; Cars[i].y = 0; // start at top Cars[i].xm = 0; Cars[i].ym = s; // travel down slower } if (r == 6) { Cars[i].x = XLANE6; Cars[i].y = 0; // start at top Cars[i].xm = 0; Cars[i].ym = s + 2; // travel down faster } if (r == 7) { Cars[i].x = XLANE7; Cars[i].y = 480; // start at bottom Cars[i].xm = 0; Cars[i].ym = -(s + 2); // travel up faster } if (r == 8) { Cars[i].x = XLANE8; Cars[i].y = 480; // start at bottom Cars[i].xm = 0; Cars[i].ym = -s; // travel up slower } if (t == 4 || t == 5) // if police or fire truck { if (Cars[i].ym > 0) Cars[i].ym += 2; // add a little +speed else Cars[i].ym -= 2; // add a little -speed } break; // break out } // end if insert } // end for // check if cars in same lane for (i = 0; i < MAX_CARS; i++) { if (Cars[i].alive && (newcar != i)) // if car exists and not same one we are checking { // if cars are in same lane AND distance is within a car length OR speed of new car is greater if (Cars[i].x == Cars[newcar].x && (abs(Cars[i].y - Cars[newcar].y) < 140 || abs(Cars[i].ym) < abs(Cars[newcar].ym))) { Cars[newcar].alive = FALSE; // erase new car } } // end if } // end for if (Cars[newcar].alive && sound_ok && game_state == GAME_STATE_GAME_RUN) // play police or fire car sound { if (c == 1) IDirectSoundBuffer_Play(game_sound_siren1,0,0,NULL); if (c == 2) IDirectSoundBuffer_Play(game_sound_siren2,0,0,NULL); if (c == 0) IDirectSoundBuffer_Play(game_sound_siren2,0,0,NULL); if (c == 7) IDirectSoundBuffer_Play(game_sound_siren3,0,0,NULL); } // end if } // END OF InsertCar //////////////////////////////////////////////////////////////// // Insert Particles for explosion at point x,y of type t // (if t = 1 then small, 2 = larger explosion, 3 = largest, etc) //////////////////////////////////////////////////////////////// void InsertParticles(int x, int y, int t) { int i, p, a, d; float xc, yc, v; xc = (float)x; yc = (float)y; p = t * 50; // get how many particles to insert for (i = 0; i < MAX_PARTICLES; i++) { if (!Particles[i].alive) // particle space is free -- insert here { Particles[i].alive = TRUE; Particles[i].x = xc; Particles[i].y = yc; a = rand()%32; // get random angle 0 to 31 v = (float)(rand()%5 + 2); // get random velocity d = (rand()%8 + 5) * t; // get random duration Particles[i].xm = xdir[a] * v; Particles[i].ym = ydir[a] * v; Particles[i].count = d; p--; if (p == 0) return; } // end of if particle free } // end of for particles } // END OF InsertParticles ///////////////////////////////////////////////////////// // move all existing particles once ///////////////////////////////////////////////////////// void MoveParticles() { int i, xi, yi; float x, y; COLORREF c = RGB(255,0,0); for (i = 0; i < MAX_PARTICLES; i++) { if (Particles[i].alive) { x = Particles[i].x; y = Particles[i].y; // save particle x y x += Particles[i].xm; y += Particles[i].ym; // move particle if (x < 3) x = WINDOW_WIDTH - 3; else if (x > (WINDOW_WIDTH - 3)) x = 3; if (y < 3) y = WINDOW_HEIGHT - 3; else if (y > (WINDOW_HEIGHT - 3)) y = 3; Particles[i].x = x; Particles[i].y = y; xi = (int)x; yi = (int)y; SetPixel(back_dc, xi, yi, c); // plot a pixel Particles[i].count--; // check if duration over if (Particles[i].count == 0) Particles[i].alive = FALSE; } // end of if } // end of for } // END OF MoveParticles /////////////////////////////////////// // Insert a random new bug /////////////////////////////////////// void InsertBug() { int i, r, b; // loop, chance to insert a bug if (game_level < 3) return; // allow bug level 3+ r = (11 - game_level) * 1000; if (r < 1) r = 100; b = (rand()%r); if (b > 20) return; // small chance to insert bug for (i = 0; i < MAX_BUGS; i++) { if (!Bugs[i].alive) { Bugs[i].alive = TRUE; Bugs[i].count = (rand()%250) + 250; // stay on screen a short time Bugs[i].y = (rand()%510) + 10; // y from 10 to 520 r = (rand()%3)+1; if (r == 1) // insert bug on left side { Bugs[i].x = 3; } if (r == 2) // insert bug in center { Bugs[i].x = 372; } if (r == 3) // insert bug on right side { Bugs[i].x = 740; } if (sound_ok && game_state == GAME_STATE_GAME_RUN) IDirectSoundBuffer_Play(game_sound_buzz,0,0,NULL); break; } // end if insert } // end for } //////////////////////////////////////// // Move (adjust count of) all bugs //////////////////////////////////////// void MoveBugs() { int i; for (i = 0; i < MAX_BUGS; i++) { if (Bugs[i].alive) { SelectObject(bmp_dc, hbugbmp); // select and draw the bmp TransparentBlt(back_dc, Bugs[i].x, Bugs[i].y, 50, 50, bmp_dc, 0, 0, 50, 50, RGB(255,255,255)); Bugs[i].count--; // countdown if (Bugs[i].count == 0) Bugs[i].alive = FALSE; } } InsertBug(); // whether to insert a new bug } /////////////////////////////////////////////////////// // // Initialize DirectSound and individual sound buffers // /////////////////////////////////////////////////////// bool SoundInit() { if (DirectSoundCreate(NULL, &game_sound_main, NULL) != DS_OK) { MessageBox(game_window, "Sound could not be initialized -- Direct Sound Create Error","Sound Error",MB_OK); return FALSE; } // // Direct Sound object succeeded so set coop level // if (IDirectSound_SetCooperativeLevel(game_sound_main, game_window, DSSCL_PRIORITY) != DS_OK) { MessageBox(game_window, "Sound could not be initialized -- Cooperative Level Error","Sound Error",MB_OK); return FALSE; } // // Cooperative Level succeeded so set up // secondary buffers and load wave file sound resources // game_sound_theme = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_THEME)); game_sound_frog01 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG01)); game_sound_frog02 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG02)); game_sound_frog03 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG03)); game_sound_frog04 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG04)); game_sound_frog05 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG05)); game_sound_frog06 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG06)); game_sound_frog07 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG07)); game_sound_frog08 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG08)); game_sound_frog09 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG09)); game_sound_frog10 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG10)); game_sound_frog11 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG11)); game_sound_frog12 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG12)); game_sound_frog13 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG13)); game_sound_frog14 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG14)); game_sound_frog15 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG15)); game_sound_frog16 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG16)); game_sound_frog17 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG17)); game_sound_frog18 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG18)); game_sound_frog19 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG19)); game_sound_frog20 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_FROG20)); game_sound_horn1 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_HORN1)); game_sound_horn2 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_HORN2)); game_sound_horn3 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_HORN3)); game_sound_horn4 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_HORN4)); game_sound_horn5 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_HORN5)); game_sound_move1 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_MOVE1)); game_sound_move2 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_MOVE2)); game_sound_move3 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_MOVE3)); game_sound_move4 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_MOVE4)); game_sound_move5 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_MOVE5)); game_sound_siren1 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_SIREN1)); game_sound_siren2 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_SIREN2)); game_sound_siren3 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_SIREN3)); game_sound_beep1 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_BEEP1)); game_sound_beep2 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_BEEP2)); game_sound_beep3 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_BEEP3)); game_sound_beep4 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_BEEP4)); game_sound_beep5 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_BEEP5)); game_sound_buzz = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_BUZZ)); game_sound_lick1 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_LICK1)); game_sound_lick2 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_LICK2)); game_sound_lick3 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_LICK3)); game_sound_splat1 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_SPLAT1)); game_sound_splat2 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_SPLAT2)); game_sound_splat3 = DSLoadSoundBuffer(game_sound_main, MAKEINTRESOURCE(SOUND_SPLAT3)); // return TRUE since main DirectSound initialized ok return TRUE; } // END OF SoundInit ////////////////////////////////////////////////////// // // Stop all sounds and close DirectSound and buffers // ///////////////////////////////////////////////////// void SoundQuit() { // if sound was set okay, release DirectSound objects if (game_sound_main) { // FIRST RELEASE SECONDARY BUFFERS IDirectSound_Release(game_sound_theme); IDirectSound_Release(game_sound_frog01); IDirectSound_Release(game_sound_frog02); IDirectSound_Release(game_sound_frog03); IDirectSound_Release(game_sound_frog04); IDirectSound_Release(game_sound_frog05); IDirectSound_Release(game_sound_frog06); IDirectSound_Release(game_sound_frog07); IDirectSound_Release(game_sound_frog08); IDirectSound_Release(game_sound_frog09); IDirectSound_Release(game_sound_frog10); IDirectSound_Release(game_sound_frog11); IDirectSound_Release(game_sound_frog12); IDirectSound_Release(game_sound_frog13); IDirectSound_Release(game_sound_frog14); IDirectSound_Release(game_sound_frog15); IDirectSound_Release(game_sound_frog16); IDirectSound_Release(game_sound_frog17); IDirectSound_Release(game_sound_frog18); IDirectSound_Release(game_sound_frog19); IDirectSound_Release(game_sound_frog20); IDirectSound_Release(game_sound_horn1); IDirectSound_Release(game_sound_horn2); IDirectSound_Release(game_sound_horn3); IDirectSound_Release(game_sound_horn4); IDirectSound_Release(game_sound_horn5); IDirectSound_Release(game_sound_move1); IDirectSound_Release(game_sound_move2); IDirectSound_Release(game_sound_move3); IDirectSound_Release(game_sound_move4); IDirectSound_Release(game_sound_move5); IDirectSound_Release(game_sound_siren1); IDirectSound_Release(game_sound_siren2); IDirectSound_Release(game_sound_siren3); IDirectSound_Release(game_sound_beep1); IDirectSound_Release(game_sound_beep2); IDirectSound_Release(game_sound_beep3); IDirectSound_Release(game_sound_beep4); IDirectSound_Release(game_sound_beep5); IDirectSound_Release(game_sound_buzz); IDirectSound_Release(game_sound_lick1); IDirectSound_Release(game_sound_lick2); IDirectSound_Release(game_sound_lick3); IDirectSound_Release(game_sound_splat1); IDirectSound_Release(game_sound_splat2); IDirectSound_Release(game_sound_splat3); // THEN RELEASE MAIN DIRECT SOUND OBJECT IDirectSound_Release(game_sound_main); } } // END OF SoundQuit ////////////////////////////////////////////// // Check ALL potential collisions ////////////////////////////////////////////// void CheckCollisions() { int i, r; // loop and random sound int cx, cy; // center point of player for collision detection cx = Player.x + 26; if (Player.face < 17) cx = Player.x + 43; cy = Player.y + 43; if (Player.face < 17) cy = Player.y + 26; for (i = 0; i < MAX_BUGS; i++) { if (Bugs[i].alive) { if ((cx > Bugs[i].x) && (cx < (Bugs[i].x + 50)) && (cy > Bugs[i].y) && (cy < (Bugs[i].y + 50))) { // frog gets bug! Bugs[i].alive = FALSE; game_score += 100; r = (rand()%2); // beep (ting) sound if ((r == 0) && sound_ok) IDirectSoundBuffer_Play(game_sound_beep1,0,0,NULL); if ((r == 1) && sound_ok) IDirectSoundBuffer_Play(game_sound_beep2,0,0,NULL); r = (rand()%3) + 1; // lick slurp sound if ((r == 1) && sound_ok) IDirectSoundBuffer_Play(game_sound_lick1,0,0,NULL); if ((r == 2) && sound_ok) IDirectSoundBuffer_Play(game_sound_lick2,0,0,NULL); if ((r == 3) && sound_ok) IDirectSoundBuffer_Play(game_sound_lick3,0,0,NULL); InsertParticles(Bugs[i].x + 25, Bugs[i].y + 25, 1); // small explosion Player.wait = 300; // go to fast player speed for a certain wait time } // end if player get bug } // end if bug alive } // end for for (i = 0; i < MAX_CARS; i++) { if (Cars[i].alive) { if ((cx > Cars[i].x) && (cx < (Cars[i].x + 80)) && (cy > Cars[i].y) && (cy < (Cars[i].y + 130))) { // frog hits a car! frogs_left--; if (frogs_left == 0) game_state = GAME_STATE_DEMO_INIT; r = (rand()%3) + 1; if ((r == 1) && sound_ok) IDirectSoundBuffer_Play(game_sound_splat1,0,0,NULL); if ((r == 2) && sound_ok) IDirectSoundBuffer_Play(game_sound_splat2,0,0,NULL); if ((r == 3) && sound_ok) IDirectSoundBuffer_Play(game_sound_splat3,0,0,NULL); InsertParticles(cx, cy, 3); // large explosion SetPlayer(); level_countdown = LEVEL_PAUSE; // pause a little bit break; } // end if player hit car } // end if car alive } // end for } // END OF CheckCollisions ///////////////////////////////////////////////////////////////////////// // Reset (initialize/clear) all cars, particles, etc ///////////////////////////////////////////////////////////////////////// void ResetAll() { int i; for (i = 0; i < MAX_CARS; i++) Cars[i].alive = FALSE; for (i = 0; i < MAX_BUGS; i++) Bugs[i].alive = FALSE; } // END OF ResetAll //////////////////////////////////////////////////////////////////////// // JOYSTICK SUPPORT //////////////////////////////////////////////////////////////////////// bool JoyInit() { // clear joystick status joy_left = 0; joy_right = 0; joy_up = 0; joy_down = 0; joy_but1 = 0; joy_but2 = 0; joy_but3 = 0; joy_but4 = 0; // make sure joystick driver is present if ((joy_num = joyGetNumDevs()) == 0) return FALSE; // make sure the joystick is attached if (joyGetPos(JOYSTICKID1, &joy_info) != JOYERR_UNPLUGGED) joy_ID = JOYSTICKID1; else return FALSE; // calculate the trip values joyGetDevCaps(joy_ID, &joy_caps, sizeof(JOYCAPS)); joy_xcenter = ((DWORD)joy_caps.wXmin + joy_caps.wXmax) / 2; joy_ycenter = ((DWORD)joy_caps.wYmin + joy_caps.wYmax) / 2; joy_trip.left = (joy_caps.wXmin + (WORD)joy_xcenter) / 2; joy_trip.right = (joy_caps.wXmax + (WORD)joy_xcenter) / 2; joy_trip.top = (joy_caps.wYmin + (WORD)joy_ycenter) / 2; joy_trip.bottom = (joy_caps.wYmax + (WORD)joy_ycenter) / 2; // capture the joystick joySetCapture(game_window, joy_ID, NULL, TRUE); return TRUE; } void JoyQuit() { // release joystick if (joy_ok) joyReleaseCapture(joy_ID); } void JoyStatus() { if (joy_ok && joyGetPos(joy_ID, &joy_info) == JOYERR_NOERROR) { // if we have no errors check the joystick position // check horizontal movement joy_left = 0; joy_right = 0; if (joy_info.wXpos < (WORD)joy_trip.left) joy_left = 1; else if (joy_info.wXpos > (WORD)joy_trip.right) joy_right = 1; // check vertical movement joy_up = 0; joy_down = 0; if (joy_info.wYpos < (WORD)joy_trip.top) joy_up = 1; else if (joy_info.wYpos > (WORD)joy_trip.bottom) joy_down = 1; // check four buttons joy_but1 = 0; joy_but2 = 0; joy_but3 = 0; joy_but4 = 0; if (joy_info.wButtons & JOY_BUTTON1) joy_but1 = 1; if (joy_info.wButtons & JOY_BUTTON2) joy_but2 = 1; if (joy_info.wButtons & JOY_BUTTON3) joy_but3 = 1; if (joy_info.wButtons & JOY_BUTTON4) joy_but4 = 1; } // end of if joy_ok AND NOERROR } ///////////////////////////////////// // Play Random Move Sound ///////////////////////////////////// void PlayRandomMoveSound() { int r; do { r = (rand()%5); } while (r == last_frog_sound); if (sound_ok) { if (r == 0) IDirectSoundBuffer_Play(game_sound_move1,0,0,NULL); if (r == 1) IDirectSoundBuffer_Play(game_sound_move2,0,0,NULL); if (r == 2) IDirectSoundBuffer_Play(game_sound_move3,0,0,NULL); if (r == 3) IDirectSoundBuffer_Play(game_sound_move4,0,0,NULL); if (r == 4) IDirectSoundBuffer_Play(game_sound_move5,0,0,NULL); } last_frog_sound = r; } //////////////////////////////////////// // Play Random Background Sound //////////////////////////////////////// void PlayRandomBackSound() { int r; if (!sound_ok) return; r = (rand()%9999); // less chance to play longer frog sounds if (r == 1) IDirectSoundBuffer_Play(game_sound_frog01,0,0,NULL); if (r == 2) IDirectSoundBuffer_Play(game_sound_frog02,0,0,NULL); if (r == 3) IDirectSoundBuffer_Play(game_sound_frog03,0,0,NULL); if (r == 4) IDirectSoundBuffer_Play(game_sound_frog04,0,0,NULL); if (r == 5) IDirectSoundBuffer_Play(game_sound_frog05,0,0,NULL); if (r == 6) IDirectSoundBuffer_Play(game_sound_frog06,0,0,NULL); if (r == 7) IDirectSoundBuffer_Play(game_sound_frog07,0,0,NULL); if (r == 8) IDirectSoundBuffer_Play(game_sound_frog08,0,0,NULL); r = (rand()%999); // more chance to play shorter frog sounds if (r == 9) IDirectSoundBuffer_Play(game_sound_frog09,0,0,NULL); if (r == 10) IDirectSoundBuffer_Play(game_sound_frog10,0,0,NULL); if (r == 11) IDirectSoundBuffer_Play(game_sound_frog11,0,0,NULL); if (r == 12) IDirectSoundBuffer_Play(game_sound_frog12,0,0,NULL); if (r == 13) IDirectSoundBuffer_Play(game_sound_frog13,0,0,NULL); if (r == 14) IDirectSoundBuffer_Play(game_sound_frog14,0,0,NULL); if (r == 15) IDirectSoundBuffer_Play(game_sound_frog15,0,0,NULL); if (r == 16) IDirectSoundBuffer_Play(game_sound_frog16,0,0,NULL); if (r == 17) IDirectSoundBuffer_Play(game_sound_frog17,0,0,NULL); if (r == 18) IDirectSoundBuffer_Play(game_sound_frog18,0,0,NULL); if (r == 19) IDirectSoundBuffer_Play(game_sound_frog19,0,0,NULL); if (r == 20) IDirectSoundBuffer_Play(game_sound_frog20,0,0,NULL); r = (rand()%3333); // less chance to play car horn sounds if (r == 1) IDirectSoundBuffer_Play(game_sound_horn1,0,0,NULL); if (r == 2) IDirectSoundBuffer_Play(game_sound_horn2,0,0,NULL); if (r == 3) IDirectSoundBuffer_Play(game_sound_horn3,0,0,NULL); if (r == 4) IDirectSoundBuffer_Play(game_sound_horn4,0,0,NULL); if (r == 5) IDirectSoundBuffer_Play(game_sound_horn5,0,0,NULL); } // END GAME CODE ///////////////////////////////////////////////////////////////