>_<:AI introduction.

>_<:According the plane position (nowX,nowY) relative to birds' position (p[i].x,p[i].y)  automaticly change birds' position.

 //贴上小鸟
SelectObject(bufdc,bird);
for(i=;i<;i++){
if(rand()%!=){
if(p[i].y>nowY-)
p[i].y-=;
else
p[i].y+=; if(p[i].x>nowX-)
p[i].x-=;
else
p[i].x+=;
}
if(p[i].x>nowX-){ //判断小鸟移动方向
BitBlt(mdc,p[i].x,p[i].y,,,bufdc,,,SRCAND);
BitBlt(mdc,p[i].x,p[i].y,,,bufdc,,,SRCPAINT);
}else{
BitBlt(mdc,p[i].x,p[i].y,,,bufdc,,,SRCAND);
BitBlt(mdc,p[i].x,p[i].y,,,bufdc,,,SRCPAINT);
}
}

>_<:resource

 #include <windows.h>
// C 运行时头文件
#include <stdlib.h>
#include <cstdio>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <string> //定义结构,飞机子弹
struct BULLET{
int x,y;
bool exist;
}; // 全局变量:
HINSTANCE hInst; // 当前实例 HBITMAP bg,ship,bullet,bird;//背景图,飞机图,子弹图,鸟
HDC hdc,mdc,bufdc;
HWND hWnd;
int x,y,nowX,nowY;//鼠标坐标,飞机坐标(贴图坐标)
int w=,bcount;//滚动背景所要剪切的宽度,子弹数目
BULLET b[];//存储飞机发出的子弹
POINT p[];//鸟的位置 // 此代码模块中包含的函数的前向声明:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void MyPaint(HDC hdc); int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow){ MSG msg;
MyRegisterClass(hInstance);
// 执行应用程序初始化:
if (!InitInstance (hInstance, nCmdShow)){
return FALSE;
}
// 主消息循环:
while (GetMessage(&msg, NULL, , )){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
} // 函数: MyRegisterClass()
//
// 目的: 注册窗口类。
ATOM MyRegisterClass(HINSTANCE hInstance){
WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = ;
wcex.cbWndExtra = ;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+);
wcex.lpszMenuName = "Beautifulzzzz";
wcex.lpszClassName = "Beautifulzzzz";
wcex.hIconSm = NULL; return RegisterClassEx(&wcex);
} // 函数: InitInstance(HINSTANCE, int)
//
// 目的: 保存实例句柄并创建主窗口
//
// 注释:
//
// 在此函数中,我们在全局变量中保存实例句柄并
// 创建和显示主程序窗口。
// 1.设定飞机的初始位置
// 2.设定鼠标位置及隐藏
// 3.设定鼠标光标移动区域
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){ HBITMAP bmp;
POINT pt,lt,rb;
RECT rect; hInst = hInstance; // 将实例句柄存储在全局变量中 hWnd = CreateWindow("Beautifulzzzz","Beautifulzzzz", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, , CW_USEDEFAULT, , NULL, NULL, hInstance, NULL); if (!hWnd)
{
return FALSE;
} MoveWindow(hWnd,,,,,true);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd); hdc=GetDC(hWnd);
mdc=CreateCompatibleDC(hdc);
bufdc=CreateCompatibleDC(hdc); bmp=CreateCompatibleBitmap(hdc,,);
SelectObject(mdc,bmp); bg=(HBITMAP)LoadImageA(NULL,"bg.bmp",IMAGE_BITMAP,,,LR_LOADFROMFILE);
ship=(HBITMAP)LoadImageA(NULL,"ship.bmp",IMAGE_BITMAP,,,LR_LOADFROMFILE);
bullet=(HBITMAP)LoadImageA(NULL,"bullet.bmp",IMAGE_BITMAP,,,LR_LOADFROMFILE);
bird=(HBITMAP)LoadImageA(NULL,"bird.bmp",IMAGE_BITMAP,,,LR_LOADFROMFILE); x=;
y=;
nowX=;
nowY=; //设定鼠标光标位置
pt.x=;
pt.y=;
ClientToScreen(hWnd,&pt);
SetCursorPos(pt.x,pt.y); ShowCursor(false);//隐藏鼠标光标 //限制鼠标光标移动区域
GetClientRect(hWnd,&rect);
lt.x=rect.left;
lt.y=rect.top;
rb.x=rect.right;
rb.y=rect.bottom;
ClientToScreen(hWnd,&lt);
ClientToScreen(hWnd,&rb);
rect.left=lt.x;
rect.top=lt.y;
rect.right=rb.x;
rect.bottom=rb.y;
ClipCursor(&rect); SetTimer(hWnd,,,NULL);
MyPaint(hdc); return TRUE;
} //
// 函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// 目的: 处理主窗口的消息。
//
// WM_COMMAND - 处理应用程序菜单
// WM_PAINT - 绘制主窗口
// WM_DESTROY - 发送退出消息并返回
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
int i;
int wmId, wmEvent;
PAINTSTRUCT ps; switch (message)
{
case WM_KEYDOWN: //按下消息
if(wParam==VK_ESCAPE) //按下[esc]
PostQuitMessage();
break;
case WM_LBUTTONDOWN: //单击鼠标左键消息
for(i=;i<;i++)
{
if(!b[i].exist)
{
b[i].x=nowX;
b[i].y=nowY+;
b[i].exist=true;
bcount++;
break;
}
}
case WM_MOUSEMOVE:
x=LOWORD(lParam); //取得鼠标x坐标
if(x>)
x=;
else if(x<)
x=; y=HIWORD(lParam);
if(y>)
y=;
else if(y<)
y=; break;
case WM_TIMER:
A:MyPaint(hdc);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
ClipCursor(NULL);//回复鼠标移动区域 DeleteDC(mdc);
DeleteDC(bufdc);
DeleteObject(bg);
DeleteObject(bullet);
DeleteObject(ship);
ReleaseDC(hWnd,hdc); PostQuitMessage();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return ;
} //1.设定飞机坐标并进行贴图
//2.设定所有子弹坐标并进行贴图
//3.显示真正的鼠标坐标所在的坐标
void MyPaint(HDC hdc){
char str[]="";
int i; //贴上背景图
SelectObject(bufdc,bg);
BitBlt(mdc,,,w,,bufdc,-w,,SRCCOPY);
BitBlt(mdc,w,,-w,,bufdc,,,SRCCOPY); //飞机坐标向鼠标坐标位置靠近
if(nowX<x){
nowX+=;
if(nowX>x)
nowX=x;
}else{
nowX-=;
if(nowX<x)
nowX=x;
} if(nowY<y){
nowY-=;
if(nowY<y)
nowY=y;
}else{
nowY+=;
if(nowY>y)
nowY=y;
} //贴上飞机图
SelectObject(bufdc,ship);
BitBlt(mdc,nowX,nowY,,,bufdc,,,SRCAND);
BitBlt(mdc,nowX,nowY,,,bufdc,,,SRCPAINT); SelectObject(bufdc,bullet);
if(bcount!=){
for(i=;i<;i++){
if(b[i].exist){
//贴上子弹图
BitBlt(mdc,b[i].x,b[i].y,,,bufdc,,,SRCAND);
BitBlt(mdc,b[i].x,b[i].y,,,bufdc,,,SRCPAINT); b[i].x-=;
if(b[i].x<){
bcount--;
b[i].exist=false;
}
}
}
} //贴上小鸟
SelectObject(bufdc,bird);
for(i=;i<;i++){
if(rand()%!=){
if(p[i].y>nowY-)
p[i].y-=;
else
p[i].y+=; if(p[i].x>nowX-)
p[i].x-=;
else
p[i].x+=;
}
if(p[i].x>nowX-){ //判断小鸟移动方向
BitBlt(mdc,p[i].x,p[i].y,,,bufdc,,,SRCAND);
BitBlt(mdc,p[i].x,p[i].y,,,bufdc,,,SRCPAINT);
}else{
BitBlt(mdc,p[i].x,p[i].y,,,bufdc,,,SRCAND);
BitBlt(mdc,p[i].x,p[i].y,,,bufdc,,,SRCPAINT);
}
} //显示鼠标坐标
sprintf(str,"x坐标: %d ",x);
TextOutA(mdc,,,str,strlen(str));
sprintf(str,"y坐标: %d ",y);
TextOutA(mdc,,,str,strlen(str)); BitBlt(hdc,,,,,mdc,,,SRCCOPY); w+=;
if(w==)
w=;
}

[游戏模版16] Win32 飞机射击 敌人追踪的更多相关文章

  1. [游戏模版15] Win32 飞机射击

    >_<:Only give you the code,try to understand it! >_<:picture resource #include <windo ...

  2. [游戏模版2] Win32最小框架

    >_<:Just the minimum Win32  frame don't have any other special function. //{{NO_DEPENDENCIES}} ...

  3. [游戏模版17] Win32 推箱子 迷宫

    >_<:Here introduce a simple game: >_<:resource >_<:only can push a box and finally ...

  4. [游戏模版18] Win32 五子棋

    >_<:Learning its AI logic. >_<:resource >_<:code: #include <windows.h> // C ...

  5. [游戏模版3] Win32 画笔 画刷 图形

    >_<:introduce the functions of define\create\use pen and brush to draw all kinds of line and s ...

  6. [游戏模版4] Win32 显示鼠标位置

    >_<:use MOUSE_MOVE message refresh the position information. >_<:use LOWORD(lParam) get ...

  7. [游戏模版5] Win32 折线 弧线

    >_<:first build some points put in poly1[],poly2[] and poly3[] in the function of InitInstance ...

  8. [游戏模版6] Win32 graph

    >_<:there in the MyPaint(...) function respectively use Ellipse(...) draw ellipse, use RoundRe ...

  9. [游戏模版7] Win32 最简单贴图

    >_<:this is the first using mapping. >_<:There will be introducing how to do: First load ...

随机推荐

  1. windbg学习!vad

    在ring0 !address不能提供详细的信息了 可以尝试用下!vad !vad扩展显示一个或多个虚拟地址详细的虚拟地址描述符(virtual address descriptor (VAD)). ...

  2. redis3.0.5集群部署安装详细步骤

    Redis集群部署文档(centos6系统) (要让集群正常工作至少需要3个主节点,在这里我们要创建6个redis节点,其中三个为主节点,三个为从节点,对应的redis节点的ip和端口对应关系如下) ...

  3. Android_helloworld

    看见 HelloWorld 相信你就明白我要干什么了.这是每个程序的第一步,让 HelloWorld 带我们走入 Android 的学习之旅吧. 前面我们下载了海马模拟器,所以接下来我们是在模拟器上进 ...

  4. 基于bootstrap分页

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. screen 命令

    # screen [-AmRvx -ls -wipe][-d <作业名称>][-h <行数>][-r <作业名称>][-s ][-S <作业名称>] 参 ...

  6. PHP各种缓存

    缓存类型PHP缓存包括PHP变异缓存和PHP数据缓存两种:PHP编译缓存:        PHP数据缓存:    对数据库数据进行缓存    对PHP模板数据缓存 js数据缓存

  7. frame和bounds的区别与联系

    首先先看一下下面两个属性的代码实现: -(CGRect)frame{ return CGRectMake(self.frame.origin.x,self.frame.origin.y,self.fr ...

  8. Nodejs编码转化问题

    目前Node.js仅支持hex.utf8.ascii.binary.base64.ucs2几种编码的转换.对于GBK,GB2312等编码,Nodejs自带的toString()方法不支持,因此中文转化 ...

  9. Windows server 2003 WINS的配置和使用详解

    NetBios名称概述 网络中的一台计算机可以使用NETBIOS和DNS两种命名方式为其命名,在NETBIOS标准中,使用长度不超 过16个字符的名称来惟一标识每个网络资源,用于标识资源或服务类型.在 ...

  10. boa移植

    1.交叉编译 2.复制文件 配置文件boa.conf 移动到/etc/boa/ 目录下 可执行文件boa移动到/usr/sbin/目录下 3.修改配置文件 4.将Linux系统上/etc/mime.t ...