//在此处定义WINDOW头文件
#include <windows.h> // Windows 头文件
#include <stdio.h>
#include <stdlib.h>
//在此处引用程序要求的附加头文件:
//在此处引用本程序的头文件
#include "game_1.h" // 类头文件
#include "player.h"
#include "boss.h"
#include "malloc.h"
//在此处定义WINDOWS全局变量:
GL_Window* OGL_window;
Keys* OGL_keys;
bool start;
bool startp; //表示预处理结束
bool player_die;
bool boss_die;
bool starte;
bool mutex_msg; //消息互斥量
bool mutex_s;
Player *player=NULL;
boss *boss1=NULL;
DWORD lastTickCount=0; // 运行到上一帧的时间点,用于求帧间隔时间
DWORD tickCount=0; // 运行到当前帧的时间点,用于求帧间隔时间
int timer=0; // 这一帧的运行时间
float moveground=0.0f;
float moveground1=0.0f;
float moveground_x=0.0f;
int stone1_move=2;
int fps;
int count=3;;
GLuint texture[10];
GLuint base; // Base Display List For The Font Set
// 设置时钟
bool msg_r;
GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
{
HFONT font; // Windows Font ID
HFONT oldfont; // Used For Good House Keeping
base = glGenLists(96); // Storage For 96 Characters
font = CreateFont( -24, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_BOLD, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
ANTIALIASED_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
"Courier New"); // Font Name
oldfont = (HFONT)SelectObject(OGL_window->hDC, font); // Selects The Font We Want
wglUseFontBitmaps(OGL_window->hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
SelectObject(OGL_window->hDC, oldfont); // Selects The Font We Want
DeleteObject(font); // Delete The Font
}
GLvoid glPrint(const char *fmt) // Custom GL "Print" Routine
{ // Results Are Stored In Text
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glCallLists(strlen(fmt), GL_UNSIGNED_BYTE, fmt); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
}
void setTimer()
{
lastTickCount=tickCount;
tickCount=GetTickCount();
timer=tickCount-lastTickCount; // 得到每帧的运行时间
}
// 游戏初始化
void GameInit(void)
{
starte=true;
player_die=false;
boss_die=false;
player=new Player(0.0f,-270.0f,0.0f,4);
player->InitPlayer();
start=true;
boss1=new boss(0.0f,250.0f,3.0f,400);
boss1->InitBoss();
/*int i;
for(i=0; i<MAX_AMMUNITION; i++){ // 清除全部子弹
ammunitions[i].setLife(0); // 将全部子弹无效
ammunitions[i].setExplosible(false); // 并且不让爆炸
}
for(i=0; i<MAX_AWARD; i++){ // 清除全部物品
awards[i].setLife(0); // 将全部物品无效
}
for (i=0; i<MAX_COMPUTER; i++) // 对所有电脑飞机进行初始化设置
computers[i].compinit();
myPlane.initPlane(0,-230,100,2); // 对玩家飞机初始化设置
myPlaneNum=MAX_PLAYER; // 设置玩家飞机个数
starttime=0; // 辅助控制游戏开始片头的播放时间
startQuadOffset=0;*/ // 辅助控制游戏开始片头移动距离
}
// If Load Failed Return NUL}
BOOL BuildTexture(char *szPathName, GLuint &texid) // 载入图片并转换为纹理
{
pngInfo info;
glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2D, texid);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
if (!pngLoad(szPathName, PNG_NOMIPMAP, PNG_SOLID, &info)) {
puts("Can't load file");
exit(1);
}
///#else // Using pngLoadAndBind to set texture parameters automatically.
texid = pngBind(szPathName, PNG_NOMIPMAP, PNG_ALPHA, &info, GL_REPEAT, GL_NEAREST, GL_NEAREST);
if (texid == 0) {
puts("Can't load file");
exit(1);
}
return true;
//#endif // 返回 TRUE
}
// 载入所需纹理
void LoadTexture(void)
{
BuildTexture("Data/water.png", texture[0]);
BuildTexture("Data/bg/stone1.png", texture[1]);
BuildTexture("Data/bg/stone2.png", texture[2]);
BuildTexture("Data/bg/stone.png", texture[3]);
BuildTexture("Data/bg/tree1.png", texture[4]);
BuildTexture("Data/bg/tree2.png", texture[5]);
}
// OpenGL初始化
BOOL Initialize(GL_Window* window, Keys* keys)
{
// 设置全局变量
OGL_window = window;
OGL_keys = keys;
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // 清屏为黑色
glClearDepth(1.0f); // 设置深度缓存
glDepthFunc(GL_LEQUAL); // 选择深度测试方式
glEnable(GL_DEPTH_TEST); // 开启深度测试
glShadeModel(GL_SMOOTH); // 阴暗处理采用平滑方式
//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // 最精细的透视计算
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_ONE, GL_ZERO);
LoadTexture(); // 调用载入纹理函数 // 调用初始化声音函数
BuildFont();
return TRUE; // 初始化成功返回TRUE
}
// 游戏背景绘制
void Background(void)
{
glEnable(GL_TEXTURE_2D);
float text_yspeed=0.0078125;
if(moveground>=640.0f)
moveground=0.0f;
if(moveground1>=640.0f)
moveground1=0.0f;
// 左右两个始终存在的方框
glPopMatrix();
glPushMatrix();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glTranslatef(0.0f, 0.0f, 0.0f);
glBindTexture(GL_TEXTURE_2D,texture[3]);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glTexCoord2f(4.0f, 5.0f);glVertex3f( 256.0f, 640.0f,0.0f);
glTexCoord2f(0.0f, 5.0f);glVertex3f(-256.0f, 640.0f,0.0f);
glTexCoord2f(0.0f, 0.0f);glVertex3f(-256.0f, -640.0f,0.0f);
glTexCoord2f(4.0f, 0.0f);glVertex3f( 256.0f, -640.0f,0.0f);
glEnd();
glDisable(GL_BLEND);
glPopMatrix();
glPushMatrix();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glTranslatef(0.0f, 0.0f, 0.0f);
glBindTexture(GL_TEXTURE_2D,texture[0]);
glColor4f(1.0f,1.0f,1.0f,0.6f);
glBindTexture(GL_TEXTURE_2D,texture[0]);
glBegin(GL_QUADS);
glTexCoord2f(4.0f-text_yspeed*moveground_x, 5.0f-text_yspeed*moveground);glVertex3f( 256.0f, 640.0f,0.0f);
glTexCoord2f(0.0f-text_yspeed*moveground_x, 5.0f-text_yspeed*moveground);glVertex3f(-256.0f, 640.0f,0.0f);
glTexCoord2f(0.0f-text_yspeed*moveground_x, 0.0f-text_yspeed*moveground);glVertex3f(-256.0f, -640.0f,0.0f);
glTexCoord2f(4.0f-text_yspeed*moveground_x, 0.0f-text_yspeed*moveground);glVertex3f( 256.0f, -640.0f,0.0f);
glEnd();
glDisable(GL_BLEND);
glPopMatrix();
glPushMatrix();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glTranslatef(0.0f, 0.0f, 1.0f);
glBindTexture(GL_TEXTURE_2D,texture[0]);
glColor4f(1.0f,1.0f,1.0f,0.5f);
glBegin(GL_QUADS);
glTexCoord2f(4.0f+text_yspeed*moveground_x, 5.0f+text_yspeed*moveground1);glVertex3f( 256.0f, 640.0f,0.0f);
glTexCoord2f(0.0f+text_yspeed*moveground_x, 5.0f+text_yspeed*moveground1);glVertex3f(-256.0f, 640.0f,0.0f);
glTexCoord2f(0.0f+text_yspeed*moveground_x, -5.0f+text_yspeed*moveground1);glVertex3f(-256.0f, -640.0f,0.0f);
glTexCoord2f(4.0f+text_yspeed*moveground_x, -5.0f+text_yspeed*moveground1);glVertex3f( 256.0f, -640.0f,0.0f);
glEnd();
glDisable(GL_BLEND);
glPopMatrix();
glPushMatrix();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0);
glTranslatef(0.0f, 0.0f, 2.0f);
glBindTexture(GL_TEXTURE_2D,texture[1]);
glColor4f(1.0f,1.0f,1.0f,0.8f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f);glVertex3f( -256.0f, 128.0f-stone1_move,0.0f);
glTexCoord2f(0.0f,1.0f);glVertex3f(-256.0f, -128.0f-stone1_move,0.0f);
glTexCoord2f(1.0f,1.0f);glVerte
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
East.rar (90个子文件)
East
Bullet.cpp 2KB
game_1.cpp 11KB
Debug
BaseObject.obj 8KB
Player_Bullet.sbr 0B
vc60.pdb 84KB
boss.sbr 0B
Bullet.sbr 0B
vc60.idb 161KB
Player_Bullet.obj 20KB
BaseObject.sbr 0B
game_1.pdb 641KB
Game.sbr 0B
game_1.ilk 401KB
game_1.obj 23KB
Player.obj 27KB
Data
water.png 41KB
bullet
bullet1.png 367B
boss
boss.png 5KB
player
player7.png 2KB
player2.png 2KB
player8.png 2KB
bullet.png 859B
life.png 16KB
player9.png 2KB
player5.png 2KB
player3.png 2KB
player1.png 2KB
player0.png 2KB
player6.png 2KB
player4.png 2KB
bg
tree1.png 413KB
stone2.png 89KB
tree2.png 124KB
stone.png 476KB
Thumbs.db 84KB
stone1.png 51KB
S_bg_water.png 41KB
game_1.pch 4.49MB
Bullet.obj 20KB
game_1.bsc 2.93MB
GLPNG.H 3KB
game_1.exe 320KB
Game.obj 44KB
boss.obj 27KB
Player.sbr 0B
GLPNG.LIB 111KB
game_1.sbr 0B
game_1.dsw 537B
game_1.dsp 5KB
game_1.h 2KB
Player_Bullet.h 972B
Player.h 1KB
game_1.plg 2KB
Bullet.h 880B
glut32.dll 166KB
glu32.dll 127KB
Player_Bullet.cpp 2KB
game_1.ncb 137KB
Game.cpp 15KB
glut.dll 166KB
BaseObject.h 810B
boss.h 1KB
Data
water.png 41KB
bullet
bullet1.png 367B
boss
boss.png 5KB
player
player7.png 2KB
player2.png 2KB
player8.png 2KB
bullet.png 859B
life.png 16KB
player9.png 2KB
player5.png 2KB
player3.png 2KB
player1.png 2KB
player0.png 2KB
player6.png 2KB
player4.png 2KB
bg
tree1.png 413KB
stone2.png 89KB
tree2.png 124KB
stone.png 476KB
Thumbs.db 84KB
stone1.png 51KB
S_bg_water.png 41KB
boss.cpp 3KB
BaseObject.cpp 931B
GLPNG.H 3KB
Player.cpp 3KB
game_1.opt 52KB
GLPNG.LIB 111KB
共 90 条
- 1
失落的风
- 粉丝: 1
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页