📄 invasion.cpp
字号:
/*
* The game Invasion was written by Christian Ofenberg 2000. (www.ablazespace.de)
* The most functions were taken out from the tutorials from NeHe. (nehe.gamedev.net)
* So a big thank to Jeff Molofee for his great homepage who helps
* people which started in OpenGL coding.
*/
#define APP_TITLE "Invasion"
#define VERSION "V1.1"
#include "Invasion.h"
#include "Levels.h"
typedef struct AS_TEXTURE
{
char byFilename[256]; // The filename of the texture
BYTE *pbyData; // The texture data
int iColorDepth; // Color depth
int iWidth, iHeight; // The size of the texture
int iID; // The ID
GLuint iOpenGLID; // The OpenGL ID
int iUsed; // How often is this texture used?
GLenum iFormat; // The texture format RGB or RGBA
int iImageBits; // The number of image bit depth
char byColorComponents; // The number of color components
BOOL bNoMipmap; // This texture should never used as mipmap (maybe there are some graphic bugs...)
} AS_TEXTURE;
#define WORLD_WIDTH 22 // Holds The Width Of Our World
#define WORLD_HALFWIDTH 11 // Holds Half The Width Of Our World
#define WORLD_HEIGHT 16 // Holds The Height Of Our World
#define WORLD_HALFHEIGHT 8 // Holds Half The Height Of Our World
#define WORLD_DEPTH -20 //
#define TEXTURES 16 // The Number Of Used Textures
#define NUM_LISTS 1 // The Number Of Display Lists
HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
HANDLE hMutex; // Whith this handle we could go sure that the program
// runs only one time at the same time
bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool bSoundPossible; // Is Sound Possible?
int iCmdShow;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
GLuint base; // Base Display List For The Font
AS_TEXTURE GameTexture[TEXTURES];
//GLuint texture[TEXTURES]; // Storage For Our Font Texture
GLuint background_list; // The Background List
GLuint loop; // Generic Loop Variable
char byTemp[256]; // Generic String Variable
GLfloat g_fBackgroundRot = 0.0f; // Background Motion Velocity
int g_iFps = 0; // Frames Per Second Variable
long g_lGameLength = 0; // Application Run Time Variable
long g_lNow = 0; // The Actual Time
long g_lLastlooptime = 0; // Time When Last Loop Was Started
long g_lDeltatime = 0; // Change In Time Since Last Iteration
long g_lFramesRendered = 0; // The Total Number Of Rendered Frames
long g_lProgramStartTime = 0; // The Program Start Time
long g_lLastChecktime = 0; // The Time Where The Last FPS Update happened
long g_lFramesRenderedSinceCheck = 0; // The Number Of Frames Rendered Since The Last FPS Update
// General Light
GLfloat LightDiffuse[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightAmbient[] = { 0.8f, 0.8f, 0.8f, 1.0f };
GLfloat LightPosition[] = { 10.0f, 10.0f, 10.0f, 1.0f };
// Path Info
char ExeName[_MAX_PATH];
char Drive[_MAX_DRIVE];
char Dir[_MAX_DIR];
char Directory[_MAX_DRIVE+_MAX_DIR];
// OpenGL Info
char *pbyOpenGLVersion, *pbyOpenGLChipInfo, *pbyOpenGLRendererInfo, *pbyOpenGLExtensionInfo;
///////////////////////////////////////////////////////////////////
SYSTEMTIME MidiStartTime;
char byMidi;
int iMaxLights; // The Maximum Number Of Lights Which Are Supported
char byWall[MAX_ALIEN_COLUMN]; // All Walls
char LEVELS; // The Number Of Levels
char byLevel, // The Current Level Number
byStartLevel; // The start level
AS_CONFIG Config; // Configurations Info
LEVEL *pLevel; // Pointer To The Current Level
LEVEL *pLevels[NORMAL_LEVELS]; // Pointer To All Levels
// Normal Levels
LEVEL *pNormalLevels[NORMAL_LEVELS] =
{&Level1, &Level2, &Level3, &Level4, &Level5, &Level6, &Level7, &Level8,
&Level9, &Level10, &Level11, &Level12, &Level13, &Level14, &Level15, &Level16};
// Easter Egg Levels
LEVEL *pEasterEggLevels[NORMAL_LEVELS] =
{&EasterEggLevel1, &EasterEggLevel2, &EasterEggLevel3, &EasterEggLevel4,
&EasterEggLevel5, &EasterEggLevel6, &EasterEggLevel7, &EasterEggLevel8,
&EasterEggLevel9, &EasterEggLevel10, &EasterEggLevel11};
// All Game Objects
AS_OBJECT *pPlanet;
AS_OBJECT *pShot1;
AS_OBJECT *pShot2;
AS_OBJECT *pShot3;
AS_OBJECT *pWormholeShot;
AS_OBJECT *pAlien1;
AS_OBJECT *pAlien2;
AS_OBJECT *pAlien3;
AS_OBJECT *pAlien4;
AS_OBJECT *pAlien5;
AS_OBJECT *pBigBoss;
AS_OBJECT *pShip;
AS_OBJECT *pWall;
AS_OBJECT *pPower;
AS_OBJECT *pObjectLive;
AS_OBJECT *pObjectWall;
AS_OBJECT *pObjectSingleLaser;
AS_OBJECT *pObjectDoubleLaser;
AS_OBJECT *pObjectPowerIncrease;
// All Sounds
SoundObject *pExplosion1Sound;
SoundObject *pExplosion2Sound;
SoundObject *pWormholeSound;
SoundObject *pInvasionSound;
SoundObject *pPlayerShotSound;
SoundObject *pAlienShotSound;
SoundObject *pAlien5ShotSound;
SoundObject *pBigBossShotSound;
SoundObject *pWormholeShotSound;
SoundObject *pAlien5DeadSound;
SoundObject *pBigBossDeadSound;
SoundObject *pAlienAttackSound;
SoundObject *pObjectLiveSound;
SoundObject *pObjectWallSound;
SoundObject *pObjectSingleLaserSound;
SoundObject *pObjectDoubleLaserSound;
SoundObject *pObjectPowerIncreaseSound;
// All Actors
ACTOR pPlayer;
ACTOR pAlien[MAX_ALIENS];
ACTOR pObject[MAX_OBJECTS];
ACTOR pShot[MAX_SHOTS];
// Game Variables
float fPlanetZScale, fPlanetZScaleVelocity; // Planet Stuff
FLOAT3 fRot; // The Game Field Rotation
float fZPos, fXRot; // The Game Field Direction
BOOL bGameOver; // Is The Game Over?
BOOL bGameWon; // Is The Game Won?
long lLastPlayerShotTime;
// The Wormhole Animation
char byWormholeAni[WORMHOLE_ANIS] = {7, 8, 9, 10, 11, 10, 9, 8, 7, 8};
char byWormholeAniStep; // The Current Wormhole Animation Step
float fWormholeHitPoints; // The Wormhole Hitpoints
char byPlayerWeapon; // The Current Player Weapon
long iScore; // The Players Score
BOOL done; // Bool Variable To Exit The Main Loop
BOOL bAnyKeyMessage; // For The Blinking Any Key Message In The Game Intro
BOOL bShowHighscore; // Should The Highscore Displayed At The Game Intro
BOOL bMoorhuhnCheat, bInvulnerableCheat, bUnlimitedPower, bAlwaysDouble;
// Highscore stuff
typedef struct
{
char byName[30];
int iLevel;
long iScore;
} HIGHSCORE;
HIGHSCORE Highscore[MAX_HIGHSCORES] =
{
{"Invasion", 1, 1000},
{"is a AblazeSpace", 0, 1},
{"project", 0, 1},
{"-------", 0, 1},
{"Programmed & Designed", 0, 1},
{"by Christian Ofenberg", 0, 1},
{"-------", 0, 1},
{"Music by", 0, 1},
{"Mike Spang", 0, 1},
{"-------", 1},
};
BOOL bPlayerEnteringHighScore;
char byPlayersHScorePlace;
char byHighScoreInitialsIndex;
const char byLegalHighScoreChars[38] = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// Other Stuff
BOOL bProgramStart;
BOOL bGameIntro;
ACTOR::ACTOR(void)
{
memset(this, 0, sizeof(ACTOR));
}
ACTOR::~ACTOR(void)
{
}
void InitActor(ACTOR *pActor)
{
short i;
float t;
pActor->iAnimationT = 0;
pActor->iStepT = 0;
pActor->iTemp = 0;
pActor->bActive = TRUE;
pActor->bAttack = FALSE;
pActor->iExplosionStep = -1;
pActor->bShield = FALSE;
pActor->fPower = pActor->fMaxPower;
t = pActor->fPos[Y];
for(i = 0; i < 3; i++)
pActor->fRotVelocity[i] = pActor->fRot[i] = pActor->fPos[i] =
pActor->fPos2[i] = pActor->fPosVelocity[i] = pActor->fPos2Velocity[i] = 0.0f;
if(pActor->iType == PLAYER)
{
pActor->fPos[X] = SPACE_WIDTH/2;
pActor->fPos[Y] = t;
pActor->bGhost = TRUE;
pActor->lStartTime = GetTickCount();
}
}
void SetWalls(void)
{
ACTOR *pActor;
short x;
// Set The Walls
for(x = 0; x < MAX_ALIEN_COLUMN; x++)
{
pActor = &pAlien[MAX_ALIEN_ROW*MAX_ALIEN_COLUMN+x];
InitActor(pActor);
pActor->fPos[X] = (float) 5+x*10;
pActor->fPos[Y] = (float) 13.0f;
pActor->iType = WALL;
pActor->byLives = 4; // This Wall Could Be 5 Times Hit
pActor->iAnimationT = 0;
}
}
BOOL ASPlayMidi(HWND hWnd, char *sFileName)
{
if(!Config.bMusic)
return FALSE;
char buf[256];
sprintf(buf, "open %s type sequencer alias MUSIC", sFileName);
if(mciSendString("close all", NULL, 0, NULL) != 0)
return FALSE;
if(mciSendString(buf, NULL, 0, NULL) != 0)
return FALSE;
if(mciSendString("play MUSIC from 0", NULL, 0, hWnd) != 0)
return FALSE;
return TRUE;
}
BOOL ASStopMidi(void)
{
if(!Config.bMusic)
return FALSE;
if(mciSendString("close all", NULL, 0, NULL) != 0)
return FALSE;
return TRUE;
}
BOOL PauseMidi()
{
if(!Config.bMusic)
return FALSE;
if (mciSendString("stop MUSIC", NULL, 0, NULL) != 0)
return(FALSE);
return TRUE;
}
BOOL ResumeMidi()
{
if(!Config.bMusic)
return FALSE;
if (mciSendString("play MUSIC notify", NULL, 0, hWnd) != 0)
return(FALSE);
return TRUE;
}
void StartNewMidi(void)
{
int t;
ASStopMidi();
switch(rand() % 3)
{
case 0:
ASPlayMidi(hWnd, "IntoLigh.mid");
byMidi = 0;
break;
case 1:
ASPlayMidi(hWnd, "TheCruiser.mid");
byMidi = 1;
break;
case 2:
ASPlayMidi(hWnd, "Ursa.mid");
byMidi = 2;
break;
default:
t= 0;
}
GetLocalTime(&MidiStartTime);
}
void CheckMidi(void)
{
SYSTEMTIME SystemTime;
WORD wSecondDifference = 0, wMinuteDifference = 0;
GetLocalTime(&SystemTime);
wSecondDifference = SystemTime.wSecond-MidiStartTime.wSecond;
if(wSecondDifference < 0)
wSecondDifference = -wSecondDifference;
wMinuteDifference = SystemTime.wMinute-MidiStartTime.wMinute;
switch(byMidi)
{
case 0:
if(wMinuteDifference >= 5 && wSecondDifference >= 8)
StartNewMidi();
break;
case 1:
if(wMinuteDifference >= 5 && wSecondDifference >= 10)
StartNewMidi();
break;
case 2:
if(wMinuteDifference >= 4 && wSecondDifference >= 56)
StartNewMidi();
break;
}
}
void ShowMouseCursor(BOOL bState)
{ // begin ShowMouseCursor()
int i;
// Disables/Enables the mouse cursor:
if(!bState)
{
for(;;)
{
i = ShowCursor(FALSE);
if(i < 0)
break;
}
}
else
{
for(;;)
{
i = ShowCursor(TRUE);
if(i >= 0)
break;
}
}
} // end ShowMouseCursor()
// Loads a jpg texture:
BOOL ASLoadJpegRGB(AS_TEXTURE *pTexture, char *pbyFilename)
{ // begin ASLoadJpegRGB()
JPEG_CORE_PROPERTIES jcProps;
memset(&jcProps, 0, sizeof(JPEG_CORE_PROPERTIES));
ijlInit(&jcProps);
jcProps.JPGFile = pbyFilename;
ijlRead(&jcProps, IJL_JFILE_READPARAMS);
pTexture->iWidth = (int) jcProps.JPGWidth;
pTexture->iHeight = (int) jcProps.JPGHeight;
// Setup texture information:
pTexture->iFormat = GL_RGB;
pTexture->iImageBits = 24;
pTexture->byColorComponents = 3;
pTexture->pbyData = (BYTE *) malloc(pTexture->iWidth*pTexture->iHeight*pTexture->byColorComponents);
jcProps.DIBWidth = jcProps.JPGWidth;
jcProps.DIBHeight = jcProps.JPGHeight;
jcProps.DIBChannels = 3;
jcProps.DIBColor = IJL_RGB;
jcProps.DIBPadBytes = 0;
jcProps.DIBBytes = (BYTE *) pTexture->pbyData;
jcProps.JPGColor = IJL_YCBCR;
if(ijlRead(&jcProps, IJL_JFILE_READWHOLEIMAGE) != IJL_OK)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -