Winmain.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:76k
- //*******************************************************
- //* INVASION - By Maur韈io Teichmann RItter 1998 *
- //* Please, respect the copyright *
- //*******************************************************
- #include <windows.h>
- #include <windowsx.h>
- #include <stdio.h>
- #include <math.h>
- #include <ddraw.h>
- #include "ddutil.h"
- #include "dsutil.hpp"
- #include "ufo.hpp"
- #include "resource.h"
- // Define Weapon kinds
- #define WP_1_LASER 0
- #define WP_2_LASER 1
- #define WP_3_LASER 2
- #define WP_1_PHOTON 3
- #define WP_2_PHOTON 4
- #define WP_3_PHOTON 5
- // Define Ship States
- #define SHIP_OK 0
- #define SHIP_EXPLODING 1
- #define SHIP_DESTROYED 3
- // Define the application states
- #define APP_MAINMENU 0
- #define APP_GAMESCREEN 1
- #define APP_CREDITS 2
- #define APP_HELPSCREEN 3
- int iAppState = APP_MAINMENU;
- LPDIRECTDRAW7 lpDD;
- LPDIRECTDRAWSURFACE7 lpFrontBuffer;
- LPDIRECTDRAWSURFACE7 lpBackBuffer;
- LPDIRECTDRAWSURFACE7 lpUfo;
- LPDIRECTDRAWSURFACE7 lpBkGround;
- LPDIRECTDRAWSURFACE7 lpShip;
- LPDIRECTDRAWSURFACE7 lpShoot;
- LPDIRECTDRAWSURFACE7 lpShoot2;
- LPDIRECTDRAWSURFACE7 lpUfoShoot;
- LPDIRECTDRAWSURFACE7 lpBoom;
- LPDIRECTDRAWSURFACE7 lpShipBoom;
- LPDIRECTDRAWSURFACE7 lpAlpha;
- LPDIRECTDRAWSURFACE7 lpSelect;
- LPDIRECTDRAWSURFACE7 lpStatusBar;
- LPDIRECTDRAWSURFACE7 lpExtra;
- LPDIRECTDRAWPALETTE lpArtPalette;
- //** INITIAL POINTERS
- Ovni* pUFO = NULL;
- Bullet* pBullet = NULL;
- Extra* pExtra = NULL;
- unsigned int score;
- unsigned int Lastscore;
- DWORD dwShipExplode;
- int iOption;
- LPDIRECTSOUND lpDS;
- HSNDOBJ hsoEnter = NULL;
- HSNDOBJ hsoShoot = NULL;
- HSNDOBJ hsoStop = NULL;
- HSNDOBJ hsoBoom = NULL;
- HSNDOBJ hsoUfoShoot = NULL;
- HSNDOBJ hsoSelect = NULL;
- HSNDOBJ hsoGetExtra = NULL;
- HSNDOBJ hsoGameOver = NULL;
- BOOL bSoundEnabled = FALSE;
- BOOL bShipStop = FALSE;
- BOOL bShootEnable = TRUE;
- BOOL bShoot = FALSE;
- BOOL iRepaint = -1;
- HWND hWndMain;
- HINSTANCE hInst;
- BOOL bIsActive;
- DWORD dwTransType;
- DWORD lastTickCount = 0;
- DWORD dwFillColor;
- //** SHIP VARIABLES
- int iShipMov;
- int iShipState = 0;
- int iShipPos = 285;
- int iWeapon = 0;
- int iLastWeapon = -1;
- int iPhotonAmmo = 0;
- int iLaserAmmo = 100;
- int iLastAmmo = -1;
- int iMaxWeapon = 0;
- int iShield = 0;
- int iLastShield = -1;
- //** LEVEL VARIABLES
- int iLevel;
- int SHOOTCHANCE = 1000;
- // Defini玢o das fun珲es
- int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow );
- BOOL RestoreSurfaces( void );
- void DestroyGame(void);
- BOOL RestoreSurfaces( void );
- void bltText(char* buffer, int x, int y);
- void ShowGameOver();
- void DrawBackGround(LPDIRECTDRAWSURFACE7 lpDest, int x, int y, int wx, int wy);
- BOOL LoadUfoSurface(int iFlags);
- BOOL CleanupAndExit( char *err);
- void InitLevel(BOOL bStart)
- {
- Ovni* pFirst;
- Bullet* auxpBullet;
- Extra* pAuxExtra;
- int i = 0;
- int valInc = 1;
- int rem;
- int iLastExtra = 0;
- DWORD tick;
- HRESULT hRet;
- DDBLTFX ddbltfx;
- char buffer[10];
- while(pExtra !=NULL)
- {
- pAuxExtra = pExtra->GetNext();
- delete(pExtra);
- pExtra = pAuxExtra;
- }
- while(pBullet !=NULL)
- {
- auxpBullet = pBullet->GetNext();
- delete(pBullet);
- pBullet = auxpBullet;
- }
- iLevel++;
- if (LoadUfoSurface(iLevel) != TRUE)
- CleanupAndExit("General Failed loading Ufo... Restart Game !");
- switch(iLevel % 6)
- {
- case 0:
- int i;
- i = iLevel / 6;
- pUFO = new Ovni;
- pFirst = pUFO;
- pUFO->SetXY(20,20);
- iLastExtra = pUFO->CreateExtra(0);
- pUFO->SetInc(i);
- pUFO->SetMov(0);
- pUFO->iType = 2;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(110,90);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(i);
- pUFO->SetMov(0);
- pUFO->iType = 2;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(20,160);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(i);
- pUFO->SetMov(0);
- pUFO->iType = 2;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(540,20);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(i);
- pUFO->SetMov(1);
- pUFO->iType = 2;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(470,90);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(i);
- pUFO->SetMov(1);
- pUFO->iType = 2;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(540,160);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(i);
- pUFO->SetMov(1);
- pUFO->iType = 2;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- break;
- case 1:
-
- for (i=0; i<3; i++)
- {
- if (i==0)
- {
- pUFO = new Ovni;
- pFirst = pUFO;
-
- }
- else
- {
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- }
-
- pUFO->SetXY(15 + (i*30),(i * 65)+10);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(1);
- pUFO->SetMov(0);
- pUFO->SetNext(NULL);
- pUFO->SetQtdeDown(1);
- pUFO->SetStr((int)(iLevel /7)+1);
- }
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(45,195);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(1);
- pUFO->SetMov(0);
- pUFO->SetNext(NULL);
- pUFO->SetQtdeDown(1);
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(15,260);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(1);
- pUFO->SetMov(0);
- pUFO->SetNext(NULL);
- pUFO->SetQtdeDown(1);
- pUFO->SetStr((int)(iLevel /7)+1);
- for (i=0; i<3; i++)
- {
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(560 - (i*30),(i * 65)+10);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(-1);
- pUFO->SetMov(0);
- pUFO->SetNext(NULL);
- pUFO->SetQtdeDown(1);
- pUFO->SetStr((int)(iLevel /7)+1);
- }
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(530,195);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(-1);
- pUFO->SetMov(0);
- pUFO->SetNext(NULL);
- pUFO->SetQtdeDown(1);
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(560,260);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(-1);
- pUFO->SetMov(0);
- pUFO->SetNext(NULL);
- pUFO->SetQtdeDown(1);
- pUFO->SetStr((int)(iLevel /7)+1);
- break;
- case 2:
- for (i=0; i<5; i++)
- {
- if (i==0)
- {
- pUFO = new Ovni;
- pFirst = pUFO;
- }
- else
- {
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- }
- pUFO->SetXY(15 + (i*30),(i * 65)+10);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(1);
- pUFO->SetMov(0);
- pUFO->SetNext(NULL);
- pUFO->SetQtdeDown(1);
- pUFO->SetStr((int)(iLevel /7)+1);
- }
- for (i=0; i<5; i++)
- {
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(560 - (i*30),(i * 65)+10);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(-1);
- pUFO->SetMov(0);
- pUFO->SetNext(NULL);
- pUFO->SetQtdeDown(1);
- pUFO->SetStr((int)(iLevel /7)+1);
- }
- break;
- case 4:
- pUFO = new Ovni;
- pFirst = pUFO;
- pUFO->SetXY(20,20);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(2);
- pUFO->SetMov(2);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(180,180);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(2);
- pUFO->SetMov(2);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(530,110);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(2);
- pUFO->SetMov(3);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(100,100);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(2);
- pUFO->SetMov(1);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(450,190);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(2);
- pUFO->SetMov(0);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- break;
- case 5:
- pUFO = new Ovni;
- pFirst = pUFO;
- pUFO->SetXY(20,20);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(3);
- pUFO->SetMov(2);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(90,90);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(3);
- pUFO->SetMov(2);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(20,160);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(3);
- pUFO->SetMov(3);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(540,20);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(3);
- pUFO->SetMov(3);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(470,90);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(3);
- pUFO->SetMov(3);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- pUFO->SetXY(540,160);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(3);
- pUFO->SetMov(2);
- pUFO->iType = 1;
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- break;
- case 3:
- for (int j=0;j<3;j++)
- {
- for (i=0;i<8;i++)
- {
- if (j==0 && i==0)
- {
- pUFO = new Ovni;
- pFirst = pUFO;
- }
- else
- {
- pUFO->SetNext(new Ovni);
- pUFO = pUFO->GetNext();
- }
- pUFO->SetXY((i * 77)+15,j*80);
- iLastExtra = pUFO->CreateExtra(iLastExtra);
- pUFO->SetInc(valInc);
- pUFO->SetMov(0);
- pUFO->SetStr((int)(iLevel /7)+1);
- pUFO->SetNext(NULL);
- }
- //pUFO->SetMov(1);
- //pUFO->SetInc (abs(pUFO->GetInc()) * -1);
- valInc = valInc * -1;
- }
- break;
- }
- pUFO = pFirst;
- ddbltfx.dwSize = sizeof( ddbltfx );
- ddbltfx.dwFillColor = dwFillColor;
- while (1)
- {
- hRet = lpFrontBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- strcpy(buffer,"LEVEL");
- buffer[5] = ' ';
- buffer[6] = iLevel/100 + '0';
- rem = iLevel % 100;
- buffer[7] = rem/10 + '0';
- rem = iLevel % 10;
- buffer[8] = rem + '0';
- buffer[9] = ' ';
- bltText(buffer,250,200);
- tick = GetTickCount();
-
- while(GetTickCount() - tick < 3000);
- iShipState = 0;
- iShipMov = 0;
- iShipPos = 285;
- iLastWeapon = -1;
- iLastAmmo = -1;
- iLastShield = -1;
- Lastscore = -1;
- SHOOTCHANCE = 180 - (40 * (int)(iLevel /7));
- if (SHOOTCHANCE < 50)
- SHOOTCHANCE = 50;
- }
- void ShowGameOver()
- {
- DWORD tick;
- HRESULT hRet;
- DDBLTFX ddbltfx;
- char buffer[10];
- ddbltfx.dwSize = sizeof( ddbltfx );
- ddbltfx.dwFillColor = dwFillColor;
- while (1)
- {
- hRet = lpFrontBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- strcpy(buffer,"GAME OVER");
- buffer[9] = ' ';
- bltText(buffer,250,200);
- tick = GetTickCount();
- SndObjPlay(hsoGameOver, NULL);
- while(GetTickCount() - tick < 3500);
- }
- void ShowCredits()
- {
- DWORD tick;
- HRESULT hRet;
- DDBLTFX ddbltfx;
- char buffer[24];
- ddbltfx.dwSize = sizeof( ddbltfx );
- ddbltfx.dwFillColor = dwFillColor;
- while (1)
- {
- hRet = lpFrontBuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- strcpy(buffer,"THIS GAME IS FREEWARE ");
- bltText(buffer,145,60);
- strcpy(buffer,"IF YOU WANT TO MAIL ME ");
- bltText(buffer,130,130);
- strcpy(buffer,"OR YOU ARE FROM A GAME ");
- bltText(buffer,120,200);
- strcpy(buffer,"COMPANY AND WANT TO ");
- bltText(buffer,140,270);
- strcpy(buffer,"HIRE ME, MY MAIL IS ");
- bltText(buffer,150,340);
- strcpy(buffer,"MAURICIORITTER@HOTMAIL.COM ");
- bltText(buffer,120,410);
- tick = GetTickCount();
- // SndObjPlay(hsoGameOver, NULL);
- while(GetTickCount() - tick < 6000);
- }
- void InitializeSound( void )
- {
- bSoundEnabled = FALSE;
- if (SUCCEEDED(DirectSoundCreate(NULL, &lpDS, NULL)))
- {
- if (SUCCEEDED(lpDS->SetCooperativeLevel(hWndMain,
- DSSCL_NORMAL)))
- {
- hsoStop = SndObjCreate(lpDS, "Stop", 1);
- hsoShoot = SndObjCreate(lpDS, "Shoot",1);
- hsoBoom = SndObjCreate(lpDS, "Boom", 8);
- hsoUfoShoot = SndObjCreate(lpDS, "UfoShoot", 8);
- hsoEnter = SndObjCreate(lpDS, "Enter", 1);
- hsoSelect = SndObjCreate(lpDS, "Select", 1);
- hsoGetExtra = SndObjCreate(lpDS, "GetExtra", 1);
- hsoGameOver = SndObjCreate(lpDS, "GameOver", 1);
- bSoundEnabled = TRUE;
- }
- else
- {
- lpDS->Release();
- lpDS = NULL;
- }
- }
- }
- void DestroySound( void )
- {
- // if(!bWantSound)
- // return; //No work to be done
- bSoundEnabled = FALSE;
- if (lpDS != NULL)
- {
- SndObjDestroy(hsoEnter);
- hsoEnter = NULL;
- SndObjDestroy(hsoStop);
- hsoStop = NULL;
- SndObjDestroy(hsoShoot);
- hsoShoot = NULL;
- SndObjDestroy(hsoUfoShoot);
- hsoUfoShoot = NULL;
- SndObjDestroy(hsoBoom);
- hsoBoom = NULL;
- SndObjDestroy(hsoSelect);
- hsoSelect = NULL;
- SndObjDestroy(hsoGetExtra);
- hsoGetExtra = NULL;
- SndObjDestroy(hsoGameOver);
- hsoGameOver = NULL;
- lpDS->Release();
- lpDS = NULL;
- }
- }
- long FAR PASCAL MainWndproc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
- {
- Bullet* pNewBullet, *pFirstBullet;
- switch( message )
- {
- case WM_TIMER:
- switch(wParam)
- {
- case 1:
- bShootEnable = TRUE;
- KillTimer(hWnd,1);
- break;
- }
- break;
- case WM_ACTIVATEAPP:
- iAppState = APP_MAINMENU;
- bIsActive = (BOOL) wParam;
- break;
- case WM_KEYDOWN:
- // If We are at the help screen an hit any key, go back to MainMenu
- if (iAppState == APP_HELPSCREEN)
- {
- lastTickCount = 0;
- iAppState = APP_MAINMENU;
- return 0L;
- }
- switch (wParam)
- {
- case VK_RETURN:
- if (iAppState == APP_MAINMENU)
- {
- // if the user hit <enter> at the menu
- // change the app setting depending on the user selection
- switch(iOption)
- {
- case 0:
- lastTickCount = 0;
- SndObjPlay(hsoEnter, FALSE);
- // Set the app state to start the game
- iAppState = APP_GAMESCREEN;
-
- lastTickCount = 0;
-
- // Reset the score counter, level, ship state and ammo
- score = 0;
- iLevel = 0;
- iShipState = 0;
- iWeapon = 0;
- iLaserAmmo = 100;
- iPhotonAmmo = 0;
- iShield = 50;
- iMaxWeapon = 0;
- Lastscore = 99;
- // Initialize Level
- InitLevel(TRUE);
- break;
- case 1:
- // User selected the second option, credits
- iAppState = APP_CREDITS;
- break;
- case 2:
- // User selected the help screen
- iAppState = APP_HELPSCREEN;
- lastTickCount = 0;
- break;
- case 3:
- // User want磗 to quit
- // Cleanup up everything
- DestroyGame();
- PostQuitMessage(0);
- break;
- }
- }
- else
- {
- // If we are at the game screen, enter can be used to stop the
- // ship
-
- // If the ship is not ok, doen磘 need to stop it,
- if (iShipState != SHIP_OK)
- break;
- // If the ship is already stopped, get out
- if (iShipMov == 0)
- break;
- // Stop the ship
- bShipStop = TRUE;
- iShipMov = 0;
- }
- break;
- case VK_CONTROL:
- // Control key is used to change the weapon
- // If not in game screen, get out
- if (iAppState != APP_GAMESCREEN)
- break;
- // Increment weapon type
- iWeapon++;
- // If we reached the Maximum weapon avaible for the ship
- // reset to the first weapon
- if (iWeapon > iMaxWeapon)
- iWeapon = 0;
- break;
- case VK_LEFT:
- // If not in game screen, get out
- if (iAppState != APP_GAMESCREEN)
- break;
-
- // If the ship is not ok, can磘 be moved
- if (iShipState != SHIP_OK)
- break;
- // Set the movement rate to -4 pixel
- iShipMov = -4;
- break;
- case VK_UP:
-
- // Up key is just used in the main menu screen
- // If not in main menu, get out
- if (iAppState != APP_MAINMENU)
- break;
-
- // User hit up key, raise up 1 menu option
- iOption--;
- // Play the select option sound
- SndObjStop(hsoSelect);
- SndObjPlay(hsoSelect,NULL);
- // If we reach the first option, go the last one
- if (iOption < 0)
- iOption = 3;
- break;
- case VK_RIGHT:
-
- // Right key is just used during the game
- // If we aren磘 in the game screen, get out
- if (iAppState != APP_GAMESCREEN)
- break;
- // If the ship is not ok, can磘 be moved
- if (iShipState != SHIP_OK)
- break;
- // Set the movement rate to +4 pixels
- iShipMov = 4;
- break;
- case VK_DOWN:
-
- // Down key can be used in the main screen or at the
- // the game screen to stp the ship
- switch (iAppState)
- {
- case APP_MAINMENU:
- // Select the down key at main menu
- // increment option counter
- iOption++;
- SndObjStop(hsoSelect);
- SndObjPlay(hsoSelect,NULL);
- if (iOption > 3)
- iOption = 0;
- break;
- case APP_GAMESCREEN:
- // Select down key at the game screen, stop the
- // ship if it磗 ok and not destroyed
- // If the ship is not ok, doen磘 need to stop it,
- if (iShipState != SHIP_OK)
- break;
- // If the ship is already stopped, get out
- if (iShipMov == 0)
- break;
- bShipStop = TRUE;
- iShipMov = 0;
- break;
- }
- break;
- case VK_SPACE:
- // SPACE BAR is used to shoot during the game screen
- // Not at the game screen
- if (iAppState != APP_GAMESCREEN)
- break;
- // If ship is not ok, get out
- if (iShipState != SHIP_OK)
- break;
- // Check if we can shoot or we are waiting for our weapon
- // recharge
- if (bShootEnable == FALSE)
- break;
- // Start shooting flag
- bShoot = TRUE;
-
- // Check the weapon we are using
- switch (iWeapon)
- {
- case WP_1_LASER:
- // using single laser
- // if we are out of ammo, get energy from the shields
- if (iLaserAmmo == 0)
- iShield -= 1;
- else
- iLaserAmmo--;
- // Create a new bullet object and add it to bullet list
- pNewBullet = new Bullet;
- if (pBullet == NULL)
- {
- pBullet = pNewBullet;
- pNewBullet->SetXY(iShipPos+24, 380);
- pBullet->SetType(2);
- }
- else
- {
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+24, 380);
- pNewBullet->SetType(2);
- pBullet = pFirstBullet;
- }
- break;
- case WP_2_LASER:
- // If we are out of ammo, not shoot
- if (iLaserAmmo < 2)
- return 0L;
- iLaserAmmo-=2;
- // Create a new bullet object and add it to bullet list
- pNewBullet = new Bullet;
- if (pBullet == NULL)
- {
- pBullet = pNewBullet;
- pNewBullet->SetXY(iShipPos+11, 380);
- pNewBullet->SetType(2);
- pFirstBullet = pBullet;
- }
- else
- {
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+11, 385);
- pNewBullet->SetType(2);
- pBullet = pFirstBullet;
- }
- pNewBullet = new Bullet;
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+34, 385);
- pNewBullet->SetType(2);
- pBullet = pFirstBullet;
- break;
- case WP_3_LASER:
-
- // If we are out of ammo, not shoot
- if (iLaserAmmo < 3)
- return 0L;
-
- iLaserAmmo-=3;
-
- pNewBullet = new Bullet;
-
- if (pBullet == NULL)
- {
- pBullet = pNewBullet;
- pNewBullet->SetXY(iShipPos+11, 380);
- pNewBullet->SetType(2);
- pFirstBullet = pBullet;
- }
- else
- {
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+11, 385);
- pNewBullet->SetType(2);
- pBullet = pFirstBullet;
- }
- pNewBullet = new Bullet;
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+35, 385);
- pNewBullet->SetType(2);
- pBullet = pFirstBullet;
- pNewBullet = new Bullet;
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+23, 380);
- pNewBullet->SetType(2);
- pBullet = pFirstBullet;
- break;
-
- case WP_1_PHOTON:
- if (iPhotonAmmo == 0)
- return 0L;
- iPhotonAmmo--;
- pNewBullet = new Bullet;
- if (pBullet == NULL)
- {
- pBullet = pNewBullet;
- pNewBullet->SetXY(iShipPos+24, 380);
- }
- else
- {
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+24, 380);
- pBullet = pFirstBullet;
- }
- break;
- case WP_2_PHOTON:
- if (iPhotonAmmo < 2)
- return 0L;
- iPhotonAmmo-=2;
- pNewBullet = new Bullet;
- if (pBullet == NULL)
- {
- pBullet = pNewBullet;
- pNewBullet->SetXY(iShipPos+11, 380);
- pFirstBullet = pBullet;
- }
- else
- {
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+11, 385);
- pBullet = pFirstBullet;
- }
- pNewBullet = new Bullet;
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+34, 385);
- pBullet = pFirstBullet;
- break;
- case WP_3_PHOTON:
- if (iPhotonAmmo < 3)
- return 0L;
- iPhotonAmmo-=3;
- pNewBullet = new Bullet;
- if (pBullet == NULL)
- {
- pBullet = pNewBullet;
- pNewBullet->SetXY(iShipPos+11, 380);
- pFirstBullet = pBullet;
- }
- else
- {
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+11, 385);
- pBullet = pFirstBullet;
- }
- pNewBullet = new Bullet;
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+35, 385);
- pBullet = pFirstBullet;
- pNewBullet = new Bullet;
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(iShipPos+23, 380);
- pBullet = pFirstBullet;
- break;
- }
-
- SndObjStop(hsoShoot);
- SndObjPlay(hsoShoot,0);
- bShootEnable = FALSE;
- if (iWeapon == 0)
- SetTimer(hWnd,1,400,NULL);
- else
- SetTimer(hWnd,1,680,NULL);
- break;
- case VK_F12:
- case VK_ESCAPE:
-
- // ESCAPE KEY AND F12 IS THE SAME AS QUIT
- // Quit if main menu, gameover if gamescreen
- if (iAppState == APP_MAINMENU)
- {
- DestroyGame();
- PostQuitMessage(0);
- break;
- }
- else
- {
- Ovni* auxpUFO;
- Bullet* auxpBullet;
- Extra* auxpExtra;
-
- while(pExtra !=NULL)
- {
- auxpExtra = pExtra->GetNext();
- delete(pExtra);
- pExtra = auxpExtra;
- }
- while(pUFO !=NULL)
- {
- auxpUFO = pUFO->GetNext();
- delete(pUFO);
- pUFO = auxpUFO;
- }
- while(pBullet !=NULL)
- {
- auxpBullet = pBullet->GetNext();
- delete(pBullet);
- pBullet = auxpBullet;
- }
- lastTickCount = 0;
- iAppState = 0;
- }
- break;
- }
- break;
- case WM_CREATE:
- break;
- case WM_DESTROY:
- DestroyGame();
- PostQuitMessage(0);
- break;
- default:
- break;
- }
- return DefWindowProc(hWnd, message, wParam, lParam);
- } /* MainWndproc */
- void DrawBackGround(LPDIRECTDRAWSURFACE7 lpDest, int x, int y, int wx, int wy)
- {
- // Blit the background to the destination surface
- RECT rcRect;
- HRESULT hRet;
- rcRect.left = x;
- rcRect.top = y;
- rcRect.right = wx;
- rcRect.bottom = wy;
- while (1)
- {
- hRet = lpDest->BltFast(x, y, lpBkGround, &rcRect, FALSE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- }
- void DestroyBullet(Bullet* pDeadBullet)
- {
- HRESULT hRet;
- RECT rcRect;
- // Destroy a bullet in the screen
- rcRect.left = pDeadBullet->GetX();
- rcRect.top = pDeadBullet->GetY()-6;
- rcRect.right = pDeadBullet->GetX()+20;
- rcRect.bottom = pDeadBullet->GetY()+32;
-
- if (rcRect.bottom > 640)
- rcRect.bottom = 640;
- DrawBackGround(lpBackBuffer, pDeadBullet->GetX(),pDeadBullet->GetY(),pDeadBullet->GetX()+20,pDeadBullet->GetY()+20);
- while (1)
- {
- hRet = lpFrontBuffer->BltFast(pDeadBullet->GetX(), pDeadBullet->GetY()-6, lpBkGround, &rcRect, FALSE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- }
- void DrawInvalidBackGround()
- {
-
- // Redraw background
- RECT rcRect;
- HRESULT hRet;
- static y = 0;
- const int iFim = 455;
- if (lastTickCount = 0)
- {
- y =0;
- }
- y += 1;
- if (y>iFim)
- y = 0;
- rcRect.left = 0;
- rcRect.top = 0;
- rcRect.right = 640;
- rcRect.bottom = iFim-y;
-
- while (1)
- {
- hRet = lpBackBuffer->BltFast(0, y, lpBkGround, &rcRect, DDBLTFAST_NOCOLORKEY);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- rcRect.left = 0;
- rcRect.top = iFim-y;
- rcRect.right = 640;
- rcRect.bottom = iFim;
- while (1)
- {
- hRet = lpBackBuffer->BltFast(0, 0, lpBkGround, &rcRect, DDBLTFAST_NOCOLORKEY);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- //DrawBackGround(lpBackBuffer,0,y,640,460);
- /* Bullet* pFirstBullet;
- Extra* pFirstExtra;
- Ovni* pFirstUFO;
- int left;
- int right;
-
- if (iRepaint == -1)
- {
- pFirstExtra = pExtra;
- while (pExtra != NULL)
- {
-
- pExtra->Repaint(lpBackBuffer,lpBkGround,NULL);
- pExtra = pExtra->GetNext();
- }
- pExtra = pFirstExtra;
- pFirstUFO = pUFO;
- while (pUFO != NULL)
- {
-
- pUFO->Repaint(lpBackBuffer, lpBkGround, NULL);
- pUFO = pUFO->GetNext();
- }
- pUFO = pFirstUFO;
- pFirstBullet = pBullet;
- while (pBullet != NULL)
- {
- pBullet->Repaint(lpBackBuffer,lpBkGround,NULL);
- //DrawBackGround(iTempX,iTempY-12, iTempX+20, iTempY+34);
- pBullet = pBullet->GetNext();
- }
- pBullet = pFirstBullet;
- left = iShipPos-25;
- if (left < 0)
- left=0;
- right = iShipPos+95;
- if (right > 640)
- right=640;
- DrawBackGround(lpBackBuffer,left,380,right,456);
- }
- else
- {
- DrawBackGround(lpBackBuffer,0,0,640,480);
- iRepaint--;
- iLastWeapon = -1;
- iLastAmmo = -1;
- Lastscore = -1;
- iLastShield = -1;
- }*/
- }
- void DrawExtra()
- {
- // Draw extra objects in the screen (ammo, bonus, etc)
- Extra* pFirstExtra;
- Extra* pNextExtra = NULL;
- Extra* pLastExtra = NULL;
- Extra* pPrevExtra = NULL;
- pFirstExtra = pExtra;
- //因为当前屏幕中可能有多个奖子,所以这里使用while语句就是要将所有的奖子都绘制出来,
- //当前屏幕中的奖子都被保存在同一个奖子链表中,所以绘制所有奖子时要求遍历整个奖子队列
- while (pExtra != NULL)
- {
- //传入的是-3,即每次掉落3个象素点
- pExtra->Move(-3);
- //绘制当前节点奖子
- pExtra->Draw(lpBackBuffer,lpExtra);
- //如果当前的奖子已经掉落到屏幕以外,则调整奖子列表,删除当前奖子节点
- if (pExtra->GetY() > 455)
- {
- //调整奖子链表节点和相关指针
- if (pPrevExtra != NULL)
- pPrevExtra->SetNext( pExtra->GetNext() );
- pNextExtra = pExtra->GetNext();
- if (pNextExtra != NULL)
- pNextExtra->SetPrev(pPrevExtra);
- //如果当前奖子节点位于链表中的第一位置,则还需要再调整链表
- if (pExtra == pFirstExtra)
- pFirstExtra=pExtra->GetNext();
- //删除当前奖子节点
- delete(pExtra);
- //重置当前奖子节点
- pExtra = pNextExtra;
- }
- else
- {
- //遍历奖子链表:当前奖子节点指向链表中下一个节点
- pPrevExtra = pExtra;
- pExtra = pExtra->GetNext();
- }
- }
- pExtra = pFirstExtra;
- }
- void DrawBullet()
- {
- // Draw bullets in the screen
- Bullet* pFirstBullet;
- Bullet* pNextBullet = NULL;
- Bullet* pLastBullet = NULL;
- Bullet* pPrevBullet = NULL;
- pFirstBullet = pBullet;
- while (pBullet != NULL)
- {
- switch(pBullet->GetType())
- {
- case 0:
- pBullet->Move(6);
- pBullet->Draw(lpBackBuffer,lpShoot);
- break;
- case 1:
- pBullet->Move(-6);
- pBullet->Draw(lpBackBuffer,lpUfoShoot);
- break;
- case 2:
- pBullet->Move(10);
- pBullet->Draw(lpBackBuffer,lpShoot2);
- break;
- }
- if ((pBullet->GetY() <= -26) ||
- (pBullet->GetY() > 455))
- {
- if (pPrevBullet != NULL)
- pPrevBullet->SetNext( pBullet->GetNext() );
- pNextBullet = pBullet->GetNext();
- if (pNextBullet != NULL)
- pNextBullet->SetPrev(pPrevBullet);
- if (pBullet == pFirstBullet)
- pFirstBullet=pBullet->GetNext();
- //pBullet->Repaint(lpFrontBuffer,lpBkGround, NULL);
- //pBullet->Repaint(lpBackBuffer,lpBkGround, 1);
- delete(pBullet);
- pBullet = pNextBullet;
- }
- else
- {
- pPrevBullet = pBullet;
- pBullet = pBullet->GetNext();
- }
- }
- pBullet = pFirstBullet;
- }
- int CheckHitExtra(void)
- {
- Extra *pFirstExtra, *pPrevExtra, *pNextExtra;
- int iReturn = 0;
- // Check if the ship get an extra
- pPrevExtra = NULL;
- pNextExtra = NULL;
- pFirstExtra = pExtra;
- while (pExtra != NULL)
- {
- if ((pExtra->GetX() >= iShipPos &&
- pExtra->GetX() < iShipPos+54 &&
- pExtra->GetY() > 385 &&
- pExtra->GetY() < 425) &&
- (pExtra->GetType() != 0))
- {
- if (pPrevExtra != NULL)
- pPrevExtra->SetNext( pExtra->GetNext() );
- pNextExtra = pExtra->GetNext();
- if (pNextExtra != NULL)
- pNextExtra->SetPrev(pPrevExtra);
- if (pExtra == pFirstExtra)
- pFirstExtra=pExtra->GetNext();
- iReturn = pExtra->GetType();
- //pExtra->Repaint(lpFrontBuffer,lpBkGround,0);
- //pExtra->Repaint(lpBackBuffer,lpBkGround,1);
- delete(pExtra);
- pExtra = pFirstExtra;
- return iReturn;
- }
- pPrevExtra = pExtra;
- pExtra = pExtra->GetNext();
- }
- pExtra = pFirstExtra;
- return iReturn;
- }
- BOOL CheckHitShip(void)
- {
- Bullet *pFirstBullet, *pPrevBullet, *pNextBullet;;
- // chekc if the ship was hitted
- if (iShipState == 1)
- return FALSE;
- pPrevBullet = NULL;
- pNextBullet = NULL;
- pFirstBullet = pBullet;
- while (pBullet != NULL)
- {
- if ((pBullet->GetX() >= iShipPos &&
- pBullet->GetX() < iShipPos+54 &&
- pBullet->GetY() > 385 &&
- pBullet->GetY() < 425) &&
- (pBullet->GetType() != 0))
- {
- if (pPrevBullet != NULL)
- pPrevBullet->SetNext( pBullet->GetNext() );
- pNextBullet = pBullet->GetNext();
- if (pNextBullet != NULL)
- pNextBullet->SetPrev(pPrevBullet);
- if (pBullet == pFirstBullet)
- pFirstBullet=pBullet->GetNext();
- DestroyBullet(pBullet);
- delete(pBullet);
- pBullet = pFirstBullet;
- return TRUE;
- }
- pPrevBullet = pBullet;
- pBullet = pBullet->GetNext();
- }
- pBullet = pFirstBullet;
- return FALSE;
- }
- void DrawShip()
- {
- static int ArgPosY = 0;
- static int ArgPosX = 0;
- static int inc = 70;
-
- // draw the ship
- RECT rcRect;
- HRESULT hRet;
- // DrawUFO();
- rcRect.left = ArgPosX;
- rcRect.top = ArgPosY;
- rcRect.right = ArgPosX + 70;
- rcRect.bottom = ArgPosY + 70;
- if (bShipStop)
- {
- SndObjPlay(hsoStop,0);
- bShipStop = FALSE;
- }
- iShipPos += iShipMov;
- if (iShipPos <= 1)
- {
- iShipMov = 0;
- iShipPos = 1;
- }
- if (iShipPos >= 569)
- {
- iShipMov = 0;
- iShipPos = 569;
- }
- if (iShipState == 0 && CheckHitShip() == TRUE)
- {
- iShield = iShield - 20;
- }
- if (iShield <= 0 && iShipState == 0)
- {
- iShield = 0;
- iShipState = 1;
- iShipMov = 0;
- ArgPosX = 0;
- ArgPosY = 0;
- rcRect.left = ArgPosX;
- rcRect.top = ArgPosY;
- rcRect.right = ArgPosX + 70;
- rcRect.bottom = ArgPosY + 70;
- inc = 70;
- }
- if (iShipState == SHIP_OK &&
- pExtra != NULL)
- {
- int iType;
- // check if we hit an extra
- // if so, select the kinf of extra
- iType = CheckHitExtra();
- switch (iType)
- {
- case 1:
- iPhotonAmmo += 25;
- if (iPhotonAmmo > 999)
- iPhotonAmmo = 999;
- SndObjStop(hsoGetExtra);
- SndObjPlay(hsoGetExtra, NULL);
- break;
- case 2:
- iMaxWeapon++;
- if (iMaxWeapon > 5)
- iMaxWeapon = 5;
- else
- iWeapon = iMaxWeapon;
- SndObjStop(hsoGetExtra);
- SndObjPlay(hsoGetExtra, NULL);
- break;
- case 3:
- score += 100;
- SndObjStop(hsoGetExtra);
- SndObjPlay(hsoGetExtra, NULL);
- break;
- case 4:
- iLaserAmmo += 40;
- if (iLaserAmmo > 999)
- iLaserAmmo = 999;
- SndObjStop(hsoGetExtra);
- SndObjPlay(hsoGetExtra, NULL);
- break;
- case 5:
- iShield += 10;
- if (iShield > 50)
- iShield = 50;
- SndObjStop(hsoGetExtra);
- SndObjPlay(hsoGetExtra, NULL);
- break;
- }
- }
- // Draw the ship sprite
- while (1)
- {
- if (iShipState == 0)
- hRet = lpBackBuffer->BltFast(iShipPos,380, lpShip, &rcRect, TRUE);
- else
- hRet = lpBackBuffer->BltFast(iShipPos,380, lpShipBoom, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- switch (iShipState)
- {
- case SHIP_OK:
- ArgPosX += inc;
- if (ArgPosX == 350 && inc > 0)
- {
- ArgPosX = 0;
- ArgPosY += inc;
- if (ArgPosY == 350)
- {
- ArgPosX=280;
- ArgPosY=280;
- inc = -70;
- return;
- }
- }
- if (ArgPosX == -70 && inc < 0)
- {
- ArgPosX = 280;
- ArgPosY += inc;
- if (ArgPosY == -70)
- {
- inc = 70;
- ArgPosX = 0;
- ArgPosY = 0;
- }
- }
- break;
- case SHIP_EXPLODING:
- ArgPosX += inc;
- if (ArgPosX == 490 && inc > 0)
- {
- ArgPosX = 0;
- ArgPosY += inc;
- if (ArgPosY == 210)
- {
- dwShipExplode = GetTickCount();
- iShipState = SHIP_DESTROYED;
- return;
- }
- }
- break;
- }
-
- }
- BOOL CheckHit(Ovni* pCheckUfo)
- {
- Bullet *pFirstBullet, *pPrevBullet, *pNextBullet;;
- // Check if we have hitted and UFO
- if (pCheckUfo->isExploding() == TRUE)
- return FALSE;
- pPrevBullet = NULL;
- pNextBullet = NULL;
- pFirstBullet = pBullet;
- while (pBullet != NULL)
- {
- if ((pBullet->GetX() > pCheckUfo->GetX() &&
- pBullet->GetX() < pCheckUfo->GetX()+64 &&
- pBullet->GetY() > pCheckUfo->GetY() &&
- pBullet->GetY() < pCheckUfo->GetY()+56) &&
- (pBullet->GetType() != 1))
- {
- pCheckUfo->LowStr(pBullet->GetPower());
- if (pPrevBullet != NULL)
- pPrevBullet->SetNext( pBullet->GetNext() );
- pNextBullet = pBullet->GetNext();
- if (pNextBullet != NULL)
- pNextBullet->SetPrev(pPrevBullet);
- if (pBullet == pFirstBullet)
- pFirstBullet=pBullet->GetNext();
- DestroyBullet(pBullet);
- delete(pBullet);
- pBullet = pFirstBullet;
-
- if (pCheckUfo->GetStr() <= 0)
- {
- return TRUE;
- }
- else
- {
- score += 1;
- SndObjStop(hsoSelect);
- SndObjPlay(hsoSelect,NULL);
- return FALSE;
- }
- }
- pPrevBullet = pBullet;
- pBullet = pBullet->GetNext();
- }
- pBullet = pFirstBullet;
- return FALSE;
- }
-
- BOOL CheckCrash(Ovni* pCheck)
- {
- // Check if we have creashed in an UFO
- Ovni *pFirst;
- pFirst = pUFO;
- while(pUFO != NULL)
- {
- if (pUFO->isExploding() == FALSE &&
- pUFO->GetY() == pCheck->GetY() &&
- pUFO != pCheck)
- {
- if (pCheck->GetX() < pUFO->GetX())
- {
- if (pUFO->GetX() - pCheck->GetX() <= 70 &&
- (
- (pCheck->GetInc() > 0 && pCheck->iType==0) ||
- (pCheck->GetMov() == 0 && pCheck->iType==2) )
- )
- return TRUE;
- }
- else
- {
- if (pCheck->GetX() - pUFO->GetX() <= 70 &&
- ((pCheck->GetInc() < 0 &&
- pCheck->iType == 0) ||
- (pCheck->GetMov()==1 &&
- pCheck->iType==2))
- )
- return TRUE;
- }
- }
- pUFO = pUFO->GetNext();
- }
- pUFO = pFirst;
- return FALSE;
- }
- void DrawUfo()
- {
- static int ArgPosY = 0;
- static int ArgPosX = 0;
- DWORD delayshoot;
- Ovni* pFirst, *pNext, *pPrev, *pAux;
- Bullet* pNewBullet, *pFirstBullet;
- Extra* pNewExtra, *pFirstExtra;
-
- pFirst = pUFO;
-
- // draw all the ufos
- pUFO = pFirst;
- pPrev = NULL;
- while(pUFO != NULL)
- {
-
- switch (pUFO->isExploding() )
- {
- case FALSE:
- switch (pUFO->iType)
- {
- case 0:
- delayshoot = 100;
- break;
- case 1:
- delayshoot = 10;
- break;
- case 2:
- delayshoot = 70;
- break;
- }
- if (bShoot == TRUE)
- {
-
- pUFO->Move(iShipPos);
- }
- else
- pUFO->Move(NULL);
- pUFO->Draw(lpBackBuffer,lpUfo,NULL);
- if (CheckHit(pUFO) == TRUE)
- {
- pUFO->SetState(1);
- score += 10;
- //SndObjStop(hsoBoom);
- SndObjPlay(hsoBoom,0);
- }
-
- if ( (GetTickCount() - pUFO->dwLastShoot) > delayshoot)
- {
- if (rand()%SHOOTCHANCE == 0)
- {
- pUFO->dwLastShoot = GetTickCount();
- pNewBullet = new Bullet;
- if (pBullet == NULL)
- {
- pBullet = pNewBullet;
- pNewBullet->SetType(1);
- pNewBullet->SetXY(pUFO->GetX()+24, pUFO->GetY()+50);
- }
- else
- {
- pFirstBullet = pBullet;
- while (pBullet->GetNext() != NULL)
- pBullet = pBullet->GetNext();
- pBullet->SetNext(pNewBullet);
- pNewBullet->SetPrev(pBullet);
- pNewBullet->SetXY(pUFO->GetX()+24, pUFO->GetY()+50);
- pNewBullet->SetType(1);
- pBullet = pFirstBullet;
- }
- //SndObjStop(hsoUfoShoot);
- SndObjPlay(hsoUfoShoot,0);
-
- }
- }
- break;
- case TRUE:
- if (pUFO->DestroyMe() == TRUE)
- {
- if (pPrev != NULL)
- pPrev->SetNext(pUFO->GetNext());
- pNext = pUFO->GetNext();
- if (pUFO == pFirst)
- pFirst=pUFO->GetNext();
-
- //iRepaint = 1;
- //pUFO->Repaint(lpBackBuffer, lpBkGround, 1);
-
- delete(pUFO);
- if (pPrev != NULL)
- pUFO = pPrev;
- else
- pUFO = pFirst;
- break;
- }
- else
- {
- pUFO->Draw(lpBackBuffer,lpBoom,0);
- if (pUFO->DropExtra() == TRUE)
- {
- pNewExtra = new Extra;
- if (pExtra == NULL)
- {
- pExtra = pNewExtra;
- pNewExtra->SetXY(pUFO->GetX()+22, pUFO->GetY()+20);
- pNewExtra->SetType(pUFO->GetExtra());
- }
- else
- {
- pFirstExtra = pExtra;
- while (pExtra->GetNext() != NULL)
- pExtra = pExtra->GetNext();
- pExtra->SetNext(pNewExtra);
- pNewExtra->SetPrev(pExtra);
- pNewExtra->SetXY(pUFO->GetX()+22, pUFO->GetY()+20);
- pNewExtra->SetType(pUFO->GetExtra());
- pExtra = pFirstExtra;
- }
- }
- }
- break;
- }
- pPrev = pUFO;
- if (pUFO != NULL)
- pUFO = pUFO->GetNext();
- } //** While UFO-NEXT;
-
- pUFO = pFirst;
- pAux = pUFO;
- while(pAux != NULL)
- {
- if (CheckCrash(pAux) == TRUE)
- pAux->Crash();
- pAux = pAux->GetNext();
- };
- pUFO = pFirst;
- }
- void bltText(char* buffer, int x, int y)
- {
-
- // Draw text to the screen
- int pos;
- int nextx;
- RECT rcRect;
- HRESULT hRet;
- nextx = x;
- while (*buffer != ' ')
- {
- if (*buffer != ' ')
- {
- if (*buffer >= 48 &&
- *buffer <= 57)
- pos = (int) *buffer - 48;
- else
- pos = (int) *buffer - 55;
- if (*buffer == '@')
- pos = 36;
- if (*buffer == '-')
- pos = 37;
- if (*buffer == ',')
- pos = 38;
- if (*buffer == '.')
- pos = 39;
- rcRect.left = AA[pos].start;
- rcRect.right = AA[pos].end;
- rcRect.top = 0;
- rcRect.bottom = 15;
- while (1)
- {
- hRet = lpBackBuffer->BltFast(nextx, y, lpAlpha, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- while (1)
- {
- hRet = lpFrontBuffer->BltFast(nextx, y, lpAlpha, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- nextx += (AA[pos].end - AA[pos].start) + 1;
- }
- else
- nextx += 15;
- buffer++;
- }
- }
-
- void DrawScore(int x, int y)
- {
- char scorebuf[9];
- unsigned int rem;
- // blt everything in reverse order if we are doing destination transparency
- // calculate score string
- scorebuf[0] = score/10000000 + '0';
- rem = score % 10000000;
- scorebuf[1] = rem/1000000 + '0';
- rem = score % 1000000;
- scorebuf[2] = rem/100000 + '0';
- rem = score % 100000;
- scorebuf[3] = rem/10000 + '0';
- rem = score % 10000;
- scorebuf[4] = rem/1000 + '0';
- rem = score % 1000;
- scorebuf[5] = rem/100 + '0';
- rem = score % 100;
- scorebuf[6] = rem/10 + '0';
- rem = score % 10;
- scorebuf[7] = rem + '0';
- scorebuf[8] = ' ';
- bltText(scorebuf, x, y);
- }
- void DrawShield()
- {
- // Draw the shield status
- HRESULT hRet;
- DDBLTFX ddbltfx;
- RECT rcRect;
- static int iRed = 0;
- static int inc = 1;
- static DWORD lastBlitRed = 0;
-
- ddbltfx.dwSize = sizeof( ddbltfx );
- ddbltfx.dwFillColor = RGB(0,0,0);
- rcRect.top = 459;
- rcRect.left = 370;
- rcRect.bottom = 477;
- rcRect.right = 422;
-
- if (iLastShield == iShield &&
- iShield > 30)
-
- return;
- while (1)
- {
- hRet = lpBackBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- if (iLastShield != iShield &&
- iShield > 30)
- while (1)
- {
- hRet = lpFrontBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- if (iShield <= 50 &&
- iShield > 30)
- {
- iRed = -2;
- lastBlitRed = 0;
- ddbltfx.dwFillColor = RGB(0,15,0);
- }
- if (iShield <= 30 &&
- iShield > 20)
- ddbltfx.dwFillColor = RGB(0,255,255);
- if (iShield <= 20 &&
- iShield >= 0)
- {
-
- if (GetTickCount() - lastBlitRed > 30)
- {
- iRed += inc;
- if (iRed < 32)
- {
- iRed = 32;
- inc = 4;
- }
- if (iRed > 116)
- {
- iRed = 116;
- inc = -4;
- }
- lastBlitRed = GetTickCount();
- }
- ddbltfx.dwFillColor = RGB(0,iRed,0);
- }
- rcRect.top = 460;
- rcRect.left = 371;
- rcRect.bottom = 477;
- rcRect.right = 371 + iShield;
- while (1)
- {
- hRet = lpBackBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- if (iLastShield != iShield &&
- iShield > 30)
- while (1)
- {
- hRet = lpFrontBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- iLastShield = iShield;
- }
- void DrawAmmo()
- {
- char ammobuf[4];
- unsigned int rem;
- int iAmmo;
- // blt everything in reverse order if we are doing destination transparency
- // calculate score string
- if (iWeapon < 3)
- iAmmo = iLaserAmmo;
- else
- iAmmo = iPhotonAmmo;
- ammobuf[0] = iAmmo/100 + '0';
- rem = iAmmo % 100;
- ammobuf[1] = rem/10 + '0';
- rem = iAmmo % 10;
- ammobuf[2] = rem + '0';
- ammobuf[3] = ' ';
- OutputDebugString("Blit Ammo Buffn");
- bltText(ammobuf, 241, 460);
- }
- void DrawWeapon()
- {
- RECT rcRect;
- HRESULT hRet;
- // Draw the weapon we are using
- rcRect.left = iWeapon * 87;
- rcRect.right = (iWeapon * 87) + 87;
- rcRect.top = 0;
- rcRect.bottom = 20;
- while (1)
- {
- hRet = lpBackBuffer->BltFast(84, 458, lpStatusBar, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- while (1)
- {
- hRet = lpFrontBuffer->BltFast(84, 458, lpStatusBar, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- }
- void UpdateFrame( void )
- {
- int ddrval;
- DWORD thisTickCount;
- RECT rcRect;
- DWORD delay = 18;
- static int frame = 0;
- HBITMAP hbm;
- DDBLTFX ddbltfx;
- HRESULT hRet;
-
- thisTickCount = GetTickCount();
- // Main update function
- if (thisTickCount - dwShipExplode > 2000 &&
- iShipState == 3)
- {
- Ovni* auxpUFO;
- Bullet* auxpBullet;
-
- while(pUFO !=NULL)
- {
- auxpUFO = pUFO->GetNext();
- delete(pUFO);
- pUFO = auxpUFO;
- }
- while(pBullet !=NULL)
- {
- auxpBullet = pBullet->GetNext();
- delete(pBullet);
- pBullet = auxpBullet;
- }
- ShowGameOver();
- lastTickCount = 0;
- iAppState = 0;
- iShipState = 0;
- }
- switch (iAppState)
- {
- case APP_MAINMENU:
- if ((thisTickCount - lastTickCount) <= delay)
- return;
- if (lastTickCount == 0)
- {
-
- iOption = 0;
- frame = 0;
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_INVASION), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return;
- ddrval = DDCopyBitmap(lpFrontBuffer, hbm, 0, 0, 640, 480 );
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return;
- }
- ddrval = DDCopyBitmap(lpBackBuffer, hbm, 0, 0, 640, 480 );
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return;
- }
- bltText("START GAME ",190,280);
- bltText("CREDITS ",190,320);
- bltText("HELP ",190,360);
- bltText("QUIT ",190,400);
- }
- ddbltfx.dwSize = sizeof( ddbltfx );
- ddbltfx.dwFillColor = dwFillColor;
- rcRect.left = 130;
- rcRect.top = 270;
- rcRect.right = 190;
- rcRect.bottom = 460;
-
- while (1)
- {
- hRet = lpBackBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
-
- rcRect.left = frame * 32;
- rcRect.right = (frame * 32) + 32;
- rcRect.top = 0;
- rcRect.bottom = 20;
-
-
- while (1)
- {
- hRet = lpBackBuffer->BltFast(150 , 275+ (40 * iOption), lpSelect, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- frame++;
- if (frame > 19)
- frame = 0;
- while( 1 )
- {
- ddrval = lpFrontBuffer->Flip(NULL, 0 );
- if( ddrval == DD_OK )
- {
- break;
- }
- if( ddrval == DDERR_SURFACELOST )
- {
- if( !RestoreSurfaces() )
- {
- return;
- }
- }
- if( ddrval != DDERR_WASSTILLDRAWING )
- {
- break;
- }
- }
- lastTickCount = thisTickCount;
-
- return;
- case APP_GAMESCREEN:
- int iAmmo;
-
- if (lastTickCount == 0)
- {
- bShoot = FALSE;
- rcRect.left = 0;
- rcRect.top = 0;
- rcRect.right = 640;
- rcRect.bottom = 480;
- DrawBackGround(lpBackBuffer,0,455,640,480);
- DrawBackGround(lpFrontBuffer,0,455,640,480);
-
- }
-
- DrawShield();
- if (Lastscore != score)
- {
- DrawBackGround(lpBackBuffer,510,460,640,477);
- DrawBackGround(lpFrontBuffer,510,460,640,477);
- DrawScore(510,460);
- Lastscore = score;
- }
- if (iLastWeapon != iWeapon)
- {
- DrawBackGround(lpBackBuffer, 84,458, 172,477);
- DrawBackGround(lpFrontBuffer,84,458, 172,477);
- DrawWeapon();
- iLastWeapon = iWeapon;
- iLastAmmo = -1;
- }
- if (iWeapon < 3)
- iAmmo = iLaserAmmo;
- else
- iAmmo = iPhotonAmmo;
- if (iLastAmmo != iAmmo)
- {
-
- DrawBackGround(lpBackBuffer,241,459,300,477);
- DrawBackGround(lpFrontBuffer,241,459,300,477);
- DrawAmmo();
- iLastAmmo = iAmmo;
- }
- if ((thisTickCount - lastTickCount) <= delay)
- return;
-
- if (pUFO == NULL &&
- pExtra == NULL)
- {
- SndObjPlay(hsoEnter, NULL);
- InitLevel(TRUE);
- DrawBackGround(lpBackBuffer,0,0,640,480);
- DrawBackGround(lpFrontBuffer,0,0,640,480);
- DrawScore(510,459);
- lastTickCount = 0;
- return;
- }
- DrawInvalidBackGround();
- DrawExtra();
- DrawUfo();
- DrawBullet();
- DrawShip();
- bShoot = FALSE;
- while( 1 )
- {
- ddrval = lpFrontBuffer->Flip(NULL, 0 );
- if( ddrval == DD_OK )
- {
- break;
- }
- if( ddrval == DDERR_SURFACELOST )
- {
- if( !RestoreSurfaces() )
- {
- return;
- }
- }
- if( ddrval != DDERR_WASSTILLDRAWING )
- {
- break;
- }
- }
-
- lastTickCount = GetTickCount();
- break;
- case APP_CREDITS:
- ShowCredits();
- iAppState = 0;
- lastTickCount = 0;
- break;
- case APP_HELPSCREEN:
- static BOOL bBlink;
- static DWORD dwTime;
-
- if ((thisTickCount - lastTickCount) <= delay+20)
- return;
- if (lastTickCount == 0)
- {
- ddbltfx.dwSize = sizeof( ddbltfx );
- ddbltfx.dwFillColor = RGB(0,0,0);
- rcRect.left = 0;
- rcRect.top = 0;
- rcRect.right = 640;
- rcRect.bottom = 480;
-
- while (1)
- {
- hRet = lpFrontBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- while (1)
- {
- hRet = lpBackBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- bltText("PHOTON AMMO ",90,45);
- bltText("WEAPON ADVANCE ",90,95);
- bltText("100 POINTS BONUS ",90,145);
- bltText("LASER AMMO ",90,195);
- bltText("SHIELD CHARGE ",90,245);
- bltText("LEFT, RIGHT - MOVE SHIP ",50,290);
- bltText("DOWN OR ENTER - STOP SHIP ",50,325);
- bltText("CTRL - CHANGE WEAPON ",50,360);
- bltText("PRESS ANY KEY TO CONTINUE ",140,450);
- bBlink = FALSE;
- dwTime = 0;
- }
- ddbltfx.dwSize = sizeof( ddbltfx );
- ddbltfx.dwFillColor = dwFillColor;
- rcRect.left = 50;
- rcRect.top = 40;
- rcRect.right = 75;
- rcRect.bottom = 270;
-
- while (1)
- {
- hRet = lpBackBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
-
- if (bBlink == TRUE)
- {
- ddbltfx.dwSize = sizeof( ddbltfx );
- ddbltfx.dwFillColor = dwFillColor;
- rcRect.left = 0;
- rcRect.top = 450;
- rcRect.right = 640;
- rcRect.bottom = 475;
-
- while (1)
- {
- hRet = lpBackBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- dwTime = dwTime + 1;
- if (dwTime == 20)
- {
- bltText("PRESS ANY KEY TO CONTINUE ",140,450);
- bBlink = FALSE;
- dwTime = 0;
- }
- }
- else
- {
- dwTime = dwTime + 1;
- if (dwTime == 20)
- {
- //bltText("PRESS ANY KEY TO CONTINUE ",140,450);
- bBlink = TRUE;
- dwTime = 0;
- }
- }
-
- rcRect.left = frame * 25;
- rcRect.right = (frame * 25) + 25;
- rcRect.top = 0;
- rcRect.bottom = 25;
-
- while (1)
- {
- hRet = lpBackBuffer->BltFast(50, 40, lpExtra, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- rcRect.top = 25;
- rcRect.bottom = 50;
- while (1)
- {
- hRet = lpBackBuffer->BltFast(50, 90, lpExtra, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- rcRect.top = 50;
- rcRect.bottom = 75;
- while (1)
- {
- hRet = lpBackBuffer->BltFast(50, 140, lpExtra, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
-
- rcRect.top = 75;
- rcRect.bottom = 100;
- while (1)
- {
- hRet = lpBackBuffer->BltFast(50, 190, lpExtra, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
- rcRect.top = 100;
- rcRect.bottom = 125;
- while (1)
- {
- hRet = lpBackBuffer->BltFast(50, 240, lpExtra, &rcRect, TRUE);
- if (hRet == DD_OK)
- {
- break;
- }
- if (hRet == DDERR_SURFACELOST)
- {
- hRet = RestoreSurfaces();
- if (hRet != DD_OK)
- break;
- }
- if (hRet != DDERR_WASSTILLDRAWING)
- break;
- }
-
- frame++;
- if (frame == 19)
- frame = 0;
- while( 1 )
- {
- ddrval = lpFrontBuffer->Flip(NULL, 0 );
- if( ddrval == DD_OK )
- {
- break;
- }
- if( ddrval == DDERR_SURFACELOST )
- {
- if( !RestoreSurfaces() )
- {
- return;
- }
- }
- if( ddrval != DDERR_WASSTILLDRAWING )
- {
- break;
- }
- }
- lastTickCount = thisTickCount;
-
- return;
- }
- return;
- }
- void DestroyGame()
- {
- // Destroy game objects
- Ovni* auxpUFO;
- Bullet* auxpBullet;
- Extra* pAuxExtra;
-
- while(pExtra !=NULL)
- {
- pAuxExtra = pExtra->GetNext();
- delete(pExtra);
- pExtra = pAuxExtra;
- }
- while(pUFO !=NULL)
- {
- auxpUFO = pUFO->GetNext();
- delete(pUFO);
- pUFO = auxpUFO;
- }
- while(pBullet !=NULL)
- {
- auxpBullet = pBullet->GetNext();
- delete(pBullet);
- pBullet = auxpBullet;
- }
- if( lpBkGround != NULL )
- lpBkGround->Release();
- if( lpBackBuffer != NULL )
- lpBackBuffer->Release();
- if( lpFrontBuffer != NULL )
- lpFrontBuffer->Release();
- if( lpUfo != NULL )
- lpUfo->Release();
- if( lpShoot != NULL )
- lpShoot->Release();
- if( lpShoot2 != NULL )
- lpShoot2->Release();
- if( lpShip != NULL )
- lpShip->Release();
- if( lpBoom != NULL )
- lpBoom->Release();
- if( lpUfoShoot != NULL )
- lpUfoShoot->Release();
- if( lpAlpha != NULL )
- lpAlpha->Release();
- if( lpShipBoom != NULL )
- lpShipBoom->Release();
- if( lpArtPalette != NULL )
- lpArtPalette->Release();
- if( lpDD != NULL )
- lpDD->Release();
- DestroySound();
- return;
- }
- BOOL CleanupAndExit( char *err)
- {
- #ifdef DEBUG
- wsprintf(DebugBuf, "___CleanupAndExit err = %sn", err );
- OutputDebugString( DebugBuf );
- #endif
- // make the cursor visible
- SetCursor(LoadCursor( NULL, IDC_ARROW ));
-
- DestroyGame();
- MessageBox( hWndMain, err, "ERROR", MB_OK );
- return FALSE;
- }
- // Surface loading functions
- BOOL LoadUfoSurface(int iFlags)
- {
- HRESULT ddrval;
- HBITMAP hbm;
- ddrval = lpUfo->Restore();
- if( ddrval != DD_OK )
- return FALSE;
- ddrval = lpBoom->Restore();
- if( ddrval != DD_OK )
- return FALSE;
- switch(iLevel % 6)
- {
- case 0:
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_UFO3), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- break;
- case 4:
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_UFO2), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- break;
- case 5:
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_UFO2), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- break;
- default:
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_UFO), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- break;
- };
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpUfo, hbm, 0, 0, 350, 700 );
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- switch(iLevel % 6)
- {
- case 0:
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BOOM3), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- break;
- case 4:
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BOOM2), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- break;
- case 5:
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BOOM2), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- break;
- default:
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BOOM), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- break;
- };
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpBoom, hbm, 0, 0, 350, 280);
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- return TRUE;
- }
- BOOL RestoreSurfaces( void )
- {
- HRESULT ddrval;
- HBITMAP hbm;
- ddrval = lpShip->Restore();
- if( ddrval != DD_OK )
- return FALSE;
- ddrval = lpShipBoom->Restore();
- if( ddrval != DD_OK )
- return FALSE;
- ddrval = lpShoot->Restore();
- if( ddrval != DD_OK )
- return FALSE;
- ddrval = lpUfoShoot->Restore();
- if( ddrval != DD_OK )
- return FALSE;
- ddrval = lpBackBuffer->Restore();
- if( ddrval != DD_OK )
- return FALSE;
- ddrval = lpBkGround->Restore();
- if( ddrval != DD_OK )
- return FALSE;
- ddrval = lpFrontBuffer->Restore();
- if( ddrval != DD_OK )
- return FALSE;
- // Create and set the palette for the art bitmap
- lpArtPalette = DDLoadPalette( lpDD, MAKEINTRESOURCE(IDB_BOOM));
- if( NULL == lpArtPalette )
- return CleanupAndExit("DDLoadPalette UFO");
- // set the palette before loading the art
- lpFrontBuffer->SetPalette(lpArtPalette );
-
- if (LoadUfoSurface(iLevel) == FALSE)
- return FALSE;
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_FUNDO), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpBkGround, hbm, 0, 0, 640, 480 );
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_SHIP), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpShip, hbm, 0, 0, 350, 350 );
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_SHOOT), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpShoot, hbm, 0, 0, 220, 20);
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_SHOOT2), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpShoot2, hbm, 0, 0, 20, 20);
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_UFOSHOOT), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpUfoShoot, hbm, 0, 0, 400, 20);
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_SHIPEXPLODE), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpShipBoom, hbm, 0, 0, 490, 210);
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_ALPHA), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpAlpha, hbm, 0, 0, 623, 15);
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_SELECT), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpSelect, hbm, 0, 0, 640, 20);
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_STATUSBAR), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpStatusBar, hbm, 0, 0, 522, 20);
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_EXTRA), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
- if( NULL == hbm )
- return FALSE;
- ddrval = DDCopyBitmap(lpExtra, hbm, 0, 0, 500, 125);
- if( ddrval != DD_OK )
- {
- DeleteObject( hbm );
- return FALSE;
- }
- // set colorfill colors and color keys according to bitmap contents
- //dwFillColor = DDColorMatch( lpUfo, RGB(0,0,0) );
- dwFillColor = DDColorMatch( lpBackBuffer, RGB(0,0,0) );
-
- //Get Color Key
- HDC hDC;
- COLORREF rgbColor;
- lpShip->GetDC(&hDC);
- rgbColor = GetPixel(hDC,0,0);
- lpShip->ReleaseDC(hDC);
-
- DDSetColorKey(lpUfo, RGB(0,0,0));
- DDSetColorKey(lpShip, rgbColor);
- DDSetColorKey(lpShoot, RGB(0,0,0));
- DDSetColorKey(lpShoot2, RGB(0,0,0));
- DDSetColorKey(lpBoom, RGB(0,0,0));
- DDSetColorKey(lpUfoShoot, RGB(0,0,0));
- DDSetColorKey(lpShipBoom, RGB(19,19,19));
- DDSetColorKey(lpAlpha, RGB(0,0,0));
- DDSetColorKey(lpSelect, RGB(0,0,0));
- DDSetColorKey(lpStatusBar, RGB(0,0,0));
- DDSetColorKey(lpExtra, RGB(0,0,0));
- return TRUE;
- }
- BOOL initApplication( HINSTANCE hInstance, int nCmdShow )
- {
- WNDCLASS wc;
- BOOL rc;
- wc.style = CS_DBLCLKS;
- wc.lpfnWndProc = MainWndproc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_UFO));
- wc.hCursor = LoadCursor( NULL, IDC_ARROW );
- wc.hbrBackground = CreateSolidBrush(RGB(0,0,0));
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "InvasionClass";
- rc = RegisterClass( &wc );
- if( !rc )
- {
- return FALSE;
- }
- hWndMain = CreateWindowEx(0, // WS_EX_TOPMOST,
- "InvasionClass",
- "Invasion",
- WS_VISIBLE | // so we don't have to call ShowWindow
- WS_POPUP, // | // non-app window
- //WS_SYSMENU//so we get an icon in the tray
- 0,
- 0,
- GetSystemMetrics(SM_CXSCREEN),
- GetSystemMetrics(SM_CYSCREEN),
- NULL,
- NULL,
- hInstance,
- NULL );
- if( !hWndMain )
- {
- return FALSE;
- }
- UpdateWindow( hWndMain );
- return TRUE;
- } /* initApplication */
- BOOL InitializeGame( void )
- {
- DDCAPS ddcaps;
- HRESULT ddrval;
- DDSURFACEDESC2 ddsd;
- DDSCAPS2 ddscaps;
- LPDIRECTDRAW pDD;
- LPVOID lpSurface = NULL;
-
- ShowCursor(FALSE);
- srand( GetTickCount() );
- ddrval = DirectDrawCreate( NULL, &pDD, NULL );
- if( ddrval != DD_OK )
- return CleanupAndExit("DirectDrawCreate Failed!");
- // Fetch DirectDraw7 interface
- ddrval = pDD->QueryInterface(IID_IDirectDraw7, (LPVOID*)&lpDD);
- if (ddrval != DD_OK)
- return CleanupAndExit("QueryInterface Failed!");
- pDD->Release();
-
- ddrval = lpDD->SetCooperativeLevel(hWndMain, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
- if( ddrval != DD_OK )
- return CleanupAndExit("SetCooperativeLevel Failed");
- // set the mode
- ddrval = lpDD->SetDisplayMode(640, 480, 16, 0, 0 );
- if( ddrval != DD_OK )
- return CleanupAndExit("SetDisplayMode Failed!");
- // check the color key hardware capabilities
- dwTransType = DDBLTFAST_SRCCOLORKEY;
- ddcaps.dwSize = sizeof( ddcaps );
- // Create surfaces
- memset( &ddsd, 0, sizeof( ddsd ) );
- ddsd.dwSize = sizeof( ddsd );
- ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
-
- ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
- DDSCAPS_FLIP |
- DDSCAPS_COMPLEX;
-
- ddsd.dwBackBufferCount = 1;
- ddrval = lpDD->CreateSurface(&ddsd, &lpFrontBuffer, NULL );
- if( ddrval != DD_OK )
- return CleanupAndExit("CreateSurface FrontBuffer Failed!");
- // get a pointer to the back buffer
-
- ZeroMemory(&ddscaps, sizeof(ddscaps));
- ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
- ddrval = lpFrontBuffer->GetAttachedSurface(
- &ddscaps,
- &lpBackBuffer);
- if( ddrval != DD_OK )
- {
- return CleanupAndExit("GetAttachedSurfaceError");
- }
-
- // Create a surface for each one of the objects we are going to use in the game
- // Then 碽lit this surfaces to the main surface
- ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_VIDEOMEMORY;
- ddsd.dwWidth = 350;
- ddsd.dwHeight = 700;
- ddrval = lpDD->CreateSurface(&ddsd, &lpUfo, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpUfo, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface lpUfo Failed!");
- }
- else
- return CleanupAndExit("CreateSurface lpUfo Failed!");
- }
-
- dwTransType = DDBLTFAST_NOCOLORKEY;
- ddsd.dwWidth = 640;
- ddsd.dwHeight = 480;
- ddrval = lpDD->CreateSurface(&ddsd, &lpBkGround, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpBkGround, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface lpUfo Failed!");
- }
- else
- return CleanupAndExit("CreateSurface Background Failed!");
- }
- dwTransType = DDBLTFAST_SRCCOLORKEY;
- ddsd.dwWidth = 350;
- ddsd.dwHeight = 350;
- ddrval = lpDD->CreateSurface(&ddsd, &lpShip, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpShip, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface Background Failed!");
- }
- else
- return CleanupAndExit("CreateSurface Background Failed!");
- }
- ddsd.dwWidth = 220;
- ddsd.dwHeight = 20;
- ddrval = lpDD->CreateSurface(&ddsd, &lpShoot, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpShoot, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface Shoot Failed!");
- }
- else
- return CleanupAndExit("CreateSurface Shoot Failed!");
- }
- ddsd.dwWidth = 20;
- ddsd.dwHeight = 20;
- ddrval = lpDD->CreateSurface(&ddsd, &lpShoot2, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpShoot2, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface Shoot 2 Failed!");
- }
- else
- return CleanupAndExit("CreateSurface Shoot 2 Failed!");
- }
-
- ddsd.dwWidth = 350;
- ddsd.dwHeight = 280;
- ddrval = lpDD->CreateSurface(&ddsd, &lpBoom, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpBoom, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface Boom Failed!");
- }
- else
- return CleanupAndExit("CreateSurface Boom Failed!");
- }
- ddsd.dwWidth = 400;
- ddsd.dwHeight = 20;
- ddrval = lpDD->CreateSurface(&ddsd, &lpUfoShoot, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpUfoShoot, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface UfoShoot Failed!");
- }
- else
- return CleanupAndExit("CreateSurface UfoShoot Failed!");
- }
- ddsd.dwWidth = 490;
- ddsd.dwHeight = 210;
- ddrval = lpDD->CreateSurface(&ddsd, &lpShipBoom, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpShipBoom, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface ShipExplode Failed!");
- }
- else
- return CleanupAndExit("CreateSurface ShipExplode Failed!");
- }
- ddsd.dwWidth = 623;
- ddsd.dwHeight = 15;
- ddrval = lpDD->CreateSurface(&ddsd, &lpAlpha, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpAlpha, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface Alphabet Failed!");
- }
- else
- return CleanupAndExit("CreateSurface Alphabet Failed!");
- }
- ddsd.dwWidth = 640;
- ddsd.dwHeight = 20;
- ddrval = lpDD->CreateSurface(&ddsd, &lpSelect, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpSelect, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface Selection Failed!");
- }
- else
- return CleanupAndExit("CreateSurface Selection Failed!");
- }
- ddsd.dwWidth = 522;
- ddsd.dwHeight = 20;
- ddrval = lpDD->CreateSurface(&ddsd, &lpStatusBar, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpStatusBar, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface StatusBar Failed!");
- }
- else
- return CleanupAndExit("CreateSurface StatusBar Failed!");
- }
- ddsd.dwWidth = 500;
- ddsd.dwHeight = 125;
- ddrval = lpDD->CreateSurface(&ddsd, &lpExtra, NULL );
- if( ddrval != DD_OK )
- {
- if(ddrval == DDERR_OUTOFMEMORY)
- {
- ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
- DDSCAPS_SYSTEMMEMORY;
- ddrval = lpDD->CreateSurface(&ddsd, &lpExtra, NULL );
- if(ddrval != DD_OK)
- return CleanupAndExit("CreateSurface Extras Failed!");
- }
- else
- return CleanupAndExit("CreateSurface Extras Failed!");
- }
- if( !RestoreSurfaces() )
- return CleanupAndExit("RestoreSurfaces Failed!");
- return 1;
- }
- int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
- int nCmdShow )
- {
- MSG msg;
- // save off application instance
- hInst = hInstance;
- if( !initApplication(hInstance, nCmdShow) )
- {
- return FALSE;
- }
- // Call the initialization procedure
- if( !InitializeGame() )
- {
- OutputDebugString("ERROR STARTING THE GAMEn");
- DestroyWindow( hWndMain );
- return FALSE;
- }
- // Initialize Sound Buffer
- InitializeSound();
- // Go throught the message look
- // When Idle update the screen
- while( 1 )
- {
-
- if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
- {
- if( !GetMessage( &msg, NULL, 0, 0 ) )
- {
- return msg.wParam;
- }
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- else if ( bIsActive )
- {
-
- UpdateFrame();
- }
- else
- {
- WaitMessage();
- }
- }
- }