大家好,我是业余写来玩玩的,写不好的地方不要取笑哦!
自定义头文件WinMain.h源码
#include <Windows.h>
#include<list>
#include<time.h>
#include<ctime>
#include "resource.h"
#include "resource1.h"
#include <gdiplus.h>
#include <mmsystem.h>
#pragma comment(lib,"gdiplus.lib")
#pragma comment(lib,"Msimg32.lib")
#pragma comment(lib,"Winmm.lib")
using namespace Gdiplus;
using namespace std;
#define CLIENTWIDTH 400
#define CLIENTHEIGHT 600
#define TIMERID_1 10
#define TIMERID_2 20
#define GAMEFRAME 180
#define VE_NPCONE 1
#define VE_NPCTWO 1
#define VE_NPCTRE 1
#define MENU_ITEM_WIDTH 120
#define MENU_ITEM_HEIGHT 40
#define RATIO 0.1
enum GAMESCENE
{
SCENE_START,
SCENE_PLAY,
SCENE_OVER
};
enum ENEMYTYPE
{
NPCONE,
NPCTWO,
NPCTRE,
SUPNPCONE
};
enum BULLETTYPE
{
BULLETONE,
BULLETTWO
};
enum MENUTYPE
{
SETFOCUS,
KILLFOCUS
};
enum AWARD
{
AWARDONE,
AWARDTWO
};
HBITMAP hBitmap_start, hBitmap_play, hBitmap_over;
HBITMAP hBitmap_npc1, hBitmap_npc2, hBitmap_npc3, hBitmap_player, hBitmap_bullet1, hBitmap_bullet2, hBitmap_supnpc1, hBitmap_award1, hBitmap_award2, hBitmap_bomb;
GAMESCENE curScene;
Point point;
Rect PlayerCollisionRect;
int player_xPos, player_yPos;
int collision_maxY, collision_minY, collision_maxX, collision_minX;
int index;
bool death;
bool isdeath;
int flag, flag_bullet;
bool upgrade;
int upgrade_num;
bool Bomb;
int Bomb_num;
clock_t tmp;
void GameInit();
void LoadImg();
void GamePaint(HDC hdc);
void ReleaseRes();
void DelImage();
void MouseClick(int x,int y,HWND hwnd);
void DrawStartOver(HDC hdc, HBITMAP hBmp);
void DrawPlay(HDC hdc);
void GameLogic();
void DrawMenu(HDC hdc, RectF rect, MENUTYPE type, PTCHAR text);
void CreateNpc(HBITMAP hbmp);
void CreateBullet(HBITMAP hbmp);
void IsHit();
void IsFocus(int x, int y);
void CreateAward(HBITMAP hbmp);
bool isCollsionWithRect(Rect rect1, Rect rect2);
void CreateBomb(HBITMAP hbmp);
void BigBang();
void LoadSound();
void CloseSound();
void Update(HDC hdc, HDC hdcMem, HDC hdcMemTemp, BLENDFUNCTION dc_bf);
class EnemyPlane
{
private:
public:
double PosX;
double PosY;
int Blood;
int collision_maxY, collision_minY, collision_maxX, collision_minX;
int index;
bool isdeath;
bool death;
Rect ColRect;
HBITMAP Type;
ENEMYTYPE enemyType;
EnemyPlane(HBITMAP h)
{
Type = h;
if (h == hBitmap_npc1)
{
enemyType = NPCONE;
Blood = 2;
index = 0;
isdeath = death = false;
}
if (h == hBitmap_npc2)
{
enemyType = NPCTWO;
Blood = 6;
index = 0;
isdeath = death = false;
}
if (h == hBitmap_npc3)
{
enemyType = NPCTRE;
PosY = -245;
Blood = 20;
index = 0;
isdeath = death = false;
}
if (h == hBitmap_supnpc1)
{
enemyType = SUPNPCONE;
Blood = 3;
index = 0;
isdeath = death = false;
}
}
void CollsionRect(HBITMAP Type, Rect &ColRect)
{
BITMAP bmp;
GetObject(Type, sizeof(BITMAP), &bmp);
ColRect.X = PosX + bmp.bmWidth/4*RATIO;
ColRect.Y = PosY + bmp.bmHeight*RATIO;
ColRect.Width = bmp.bmWidth/4 - bmp.bmWidth/4*RATIO*2;
ColRect.Height = bmp.bmHeight - bmp.bmHeight*RATIO*2;
}
double Vel()
{
switch (enemyType)
{
case NPCONE:
return 4;
break;
case NPCTWO:
return 1;
break;
case NPCTRE:
return 0.5;
break;
case SUPNPCONE:
return 2;
break;
default:
break;
}
}
};
list <EnemyPlane> npcList;
list <EnemyPlane>::iterator iter_npc;
class Bullet
{
private:
public:
int PosX;
int PosY;
int velocity = 20;
int tmp;
Rect ColRect;
HBITMAP Type;
BULLETTYPE bulletType;
Bullet(HBITMAP h)
{
Type = h;
if (h == hBitmap_bullet1)
{
bulletType = BULLETONE;
}
if (h == hBitmap_bullet2)
{
bulletType = BULLETTWO;
}
}
void CollsionRect(HBITMAP Type, Rect &ColRect)
{
BITMAP bmp;
GetObject(Type, sizeof(BITMAP), &bmp);
ColRect.X = PosX + bmp.bmWidth*RATIO;
ColRect.Y = PosY + bmp.bmHeight*RATIO;
ColRect.Width = bmp.bmWidth - bmp.bmWidth*RATIO*2;
ColRect.Height = bmp.bmHeight - bmp.bmHeight*RATIO*2;
}
};
list <Bullet> bulletList;
list <Bullet>::iterator iter_bullet;
class Menu
{
public:
RectF rect;
MENUTYPE menuType = KILLFOCUS;
PTCHAR menuText;
Menu(int x, int y, PTCHAR text)
{
rect.X = x;
rect.Y = y;
rect.Width = MENU_ITEM_WIDTH;
rect.Height = MENU_ITEM_HEIGHT;
menuText = text;
};
private:
};
list <Menu> menuList_Start;
list <Menu> menuList_End;
list <Menu>::iterator iter_menu;
class Award
{
public:
double PosX;
double PosY;
double velocity = 0.8;
Rect ColRect;
HBITMAP Type;
AWARD awardType;
Award(HBITMAP h)
{
Type = h;
if (h == hBitmap_award1)
{
awardType = AWARDONE;
}
if (h == hBitmap_award2)
{
awardType = AWARDTWO;
}
}
void CollsionRect(HBITMAP Type, Rect &ColRect)
{
BITMAP bmp;
GetObject(Type, sizeof(BITMAP), &bmp);
ColRect.X = PosX + bmp.bmWidth*RATIO;
ColRect.Y = PosY + bmp.bmHeight*RATIO;
ColRect.Width = bmp.bmWidth - bmp.bmWidth*RATIO*2;
ColRect.Height = bmp.bmHeight - bmp.bmHeight*RATIO*2;
}
private:
};
list <Award> awardList;
list <Award>::iterator iter_award;
class Bomb_
{
public:
int PosX;
int PosY;
HBITMAP Type;
Bomb_(HBITMAP h)
{
PosX = 0;
PosY = CLIENTHEIGHT - 36;
Type = h;
}
private:
};
list <Bomb_> bombList;
list <Bomb_>::iterator iter_bomb;
主程序源文件WinMain.cpp源码
#include"WinMain.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szWndClassName[] = TEXT("hellowin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wndclass.hCursor = LoadCursor(NULL