// hsb_雷霆战机_20181005.cpp : 定义应用程序的入口点。
//
/*
作者:
时间:2018.10.03 - 2018.10.05
功能:雷霆战机
*/
#include "stdafx.h"
#include "hsb_雷霆战机_20181005.h"
#include "myPlane.h"
#include <GL/glut.h>
#include <math.h>
#include <windows.h>
#include <stdlib.h>
#include "EnemyPlane.h"
#include <vector>
#include <sstream>
#include <thread>
#include <iostream>
#include <math.h>
#include "enemyBullet.h"
#include "myBullet.h"
#include <stdio.h>
#include <mmSystem.h>
#include <graphics.h>
#include <conio.h>
#include "firePoint.h"
#pragma commet(lib, "WinMM.lib")
using namespace std;
#define PI 3.14159 //设置圆周率
#define THREAD_NUM 5
#define ENEMY_BULLET_NUM 128; //敌人子弹总数
int n = 6, R = 10; //多边形变数,外接圆半径
//创建飞机
MyPlane* myPlane = new MyPlane();
float fx = myPlane->x;
float fy = myPlane->y;
int epNum = 10; //敌方飞机数
int vepNum = 4; //敌方飞机vector数组总数
int ebNum = 128; //地方子弹数
int mbNum = 64; //我方子弹数
int fpNum = 50; //炸弹火焰数
int second = 0; //游戏进行时间秒数
//创建敌机
vector<EnemyPlane> veps;
EnemyPlane* eps = new EnemyPlane[epNum];
//创建敌人子弹
enemyBullet* ebs = new enemyBullet[ebNum];
myBullet* mbs = new myBullet[mbNum];
FirePoint* fps = new FirePoint[fpNum];
#define MAX_CHAR 128 //字符串的最大长度
CRITICAL_SECTION Critical; //定义临界区句柄
float theta = 0.0; //旋转初始角度值
void Keyboard(unsigned char key, int x, int y);
void Display(void);
void Reshape(int w, int h);
void myidle();
void drawString(const char* str); //屏幕显示字体
void selectFont(int size, int charset, const char* face);
void mykeyboard(unsigned char key, int x, int y);
bool checkSide(float x, float y);
void Move(int i);
bool checkEpSide(int n, float addx, float addy);
bool checkMyEpSide();
void ebsSide(int i);
void enemyShut(EnemyPlane ep);
void ebsMove();
bool ebsMyplaneSide(int i);
//void epThread(EnemyPlane& ep);
void epThread(int i);
static DWORD WINAPI EnemyPlaneMove(LPVOID lpParameter);
void myShut();
void mbsMove();
void mbsMyplaneSide(int i);
void mbsSide(int i);
void loadImage(wchar_t str[], int x, int y);
void boomView(int x, int y);
void drawPoint(int x, int y);
void mytime(int t);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
char *argv[] = { "hello ", " " };
int argc = 2; // must/should match the number of strings in argv
for (int i = 0; i < vepNum; i++)
{
veps.push_back(eps[i]);
}
PlaySound(L"background.wav",NULL,SND_FILENAME|SND_ASYNC);
//for (unsigned int i = 0; i < veps.size(); i++)
//{
// thread t(epThread, i);
// t.join();
//}
/*HANDLE hThread[THREAD_NUM];*/
//for (int i = 0; i < veps.size(); i++)
//{
// hThread[i] = CreateThread(NULL, 0, EnemyPlaneMove, (LPVOID)i, 0, NULL);
// CloseHandle(hThread[i]);//关闭内核对象,不会停止线程
//}
glutInit(&argc, argv); //初始化GLUT库;
glutInitWindowSize(800, 600); //设置显示窗口大小
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); //设置显示模式;(注意双缓冲)
glutCreateWindow("雷霆战机"); // 创建显示窗口
glutDisplayFunc(Display); //注册显示回调函数
glutKeyboardFunc(mykeyboard);//键盘注册回调函数
glutReshapeFunc(Reshape); //注册窗口改变回调函数
glutIdleFunc(myidle); //注册闲置回调函数
glutTimerFunc(1000, mytime, 10); //注册闲时函数
glutDisplayFunc(&Display);//在程序运行时是自动调用的,即程序会自动调用display函数重绘窗口
glutMainLoop(); //进入事件处理循环
return 0;
}
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
/*thread* task = new thread[THREAD_NUM];*/
if (myPlane->live == true)
{
//画自己飞机
planeHead(*myPlane);
planeBody(*myPlane);
planeTail(*myPlane);
planeWing(*myPlane);
myPlane->planeMove(fx, fy);