>_<:Learning the physical engine

>_<:resource

>_<:code

 #include <windows.h>
// C 运行时头文件
#include <stdlib.h>
#include <cstdio>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <time.h>
#include <string>
#include <cmath> // 全局变量:
HINSTANCE hInst; // 当前实例
HBITMAP bg , ball[];
HDC hdc,mdc,bufdc;
HWND hWnd;
DWORD tPre,tNow,tCheck;
RECT rect;//窗口矩形
int x[];
int y[];
int vx[];
int vy[]; // 此代码模块中包含的函数的前向声明:
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)
//
// 目的: 保存实例句柄并创建主窗口
//
// 注释:
//
// 在此函数中,我们在全局变量中保存实例句柄并
// 创建和显示主程序窗口。
// 棋盘拼接以及调用InitGame()开始棋局
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){
HBITMAP bmp;
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);
ball[]=(HBITMAP)LoadImageA(NULL,"ball0.bmp",IMAGE_BITMAP,,,LR_LOADFROMFILE);
ball[]=(HBITMAP)LoadImageA(NULL,"ball1.bmp",IMAGE_BITMAP,,,LR_LOADFROMFILE); GetClientRect(hWnd,&rect);//取得内部窗口区域的大小; x[]=;y[]=;vx[]=;vy[]=;
x[]=;y[]=;vx[]=-;vy[]=-; 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 wmId, wmEvent;
PAINTSTRUCT ps; switch (message){
case WM_TIMER:
A:MyPaint(hdc);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
goto A;// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
DeleteDC(mdc);
DeleteDC(bufdc);
DeleteObject(bg);
DeleteObject(ball[]);
DeleteObject(ball[]); KillTimer(hWnd,);
ReleaseDC(hWnd,hdc); PostQuitMessage();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return ;
} //MyPaint()
//1、窗口贴图
//2、计算小球贴图坐标并判断小球是否碰撞窗口边缘
void MyPaint(HDC hdc){
SelectObject(bufdc,bg);
BitBlt(mdc,,,,,bufdc,,,SRCCOPY); SelectObject(bufdc,ball[]);
BitBlt(mdc,x[],y[],,,bufdc,,,SRCAND);
BitBlt(mdc,x[],y[],,,bufdc,,,SRCPAINT); SelectObject(bufdc,ball[]);
BitBlt(mdc,x[],y[],,,bufdc,,,SRCAND);
BitBlt(mdc,x[],y[],,,bufdc,,,SRCPAINT); BitBlt(hdc,,,,,mdc,,,SRCCOPY); for(int i=;i<;i++){
//计算x轴方向贴图坐标与速度
x[i]+=vx[i];
if(x[i]<=){
x[i]=;
vx[i]=-vx[i];
}else if(x[i]>=rect.right-){
x[i]=rect.right-;
vx[i]=-vx[i];
} //计算y轴方向坐标及速度
y[i]+=vy[i];
if(y[i]<=){
y[i]=;
vy[i]=-vy[i];
}else if(y[i]>=rect.bottom-){
y[i]=rect.bottom-;
vy[i]=-vy[i];
}
} if((x[]-x[])*(x[]-x[])+(y[]-y[])*(y[]-y[])<=){
vx[]=-vx[];vy[]=-vy[];
vx[]=-vx[];vy[]=-vy[];
}
}

[游戏模版19] Win32 物理引擎 匀速运动的更多相关文章

  1. [游戏模版20] Win32 物理引擎 加速运动

    >_<:Compared with previous talk,there will be taking about how to create an accelerated speed. ...

  2. [游戏模版21] Win32 物理引擎 能量守恒

    >_<:Only a little change in the function of MyPaint(...),besides the initial value have some c ...

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

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

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

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

  5. 【Unity3D】射箭打靶游戏(简单工厂+物理引擎编程)

    打靶游戏:     1.靶对象为 5 环,按环计分:    2.箭对象,射中后要插在靶上:    3.游戏仅一轮,无限 trials: 增强要求:  添加一个风向和强度标志,提高难度 游戏成品图: U ...

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

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

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

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

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

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

  9. [游戏模版6] Win32 graph

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

随机推荐

  1. ado.net access oracle dataset via store procedure

    使用存储过程返回结果集,并绑定到ado.net对象中在sql server里面是非常直观的. 1: create procedure GetAllRecords 2: as 3: select * f ...

  2. 循序渐进Python3(四) -- 装饰器、迭代器和生成器

    初识装饰器(decorator ) Python的 decorator 本质上就是一个高阶函数,它接收一个函数作为参数,然后,返回一个新函数. 使用 decorator 用Python提供的 @ 语法 ...

  3. iOS 发送Email

    第一步:在程序中添加MessageUi.framework框架 第二步:引入#import <MessageUI/MessageUI.h>头文件 第三步:代码实现 3.1判断是否可以发送邮 ...

  4. Xml文件操作的其中一个使用方法:

    XmlNodeList students = doc.DocumentElement.ChildNodes;//Student节点集合 foreach (XmlNode stu in students ...

  5. 编辑器sublime text3 破解码

    第一段亲测有效 —– BEGIN LICENSE —–Ryan ClarkSingle User LicenseEA7E-8124792158A7DE B690A7A3 8EC04710 006A5E ...

  6. Oracle中Lpad函数和Rpad函数的用法

     http://blog.csdn.net/woshixuye/article/details/17262307 一.Lpad函数 lpad函数将左边的字符串填充一些特定的字符其语法格式如下:lpad ...

  7. 用nodej和glub-watcher写的监听go 项目自动编译,很鸡肋

    glub 一般都是很轻量的编译. go太重了,改一小个部分,就编译的话,多数是编译失败. 而且很消耗性能,还没想到完美的优化办法. 暂时用个定时器 监听2秒,停止1秒,如此循环,会减少些 “无效”的编 ...

  8. mysql 字符串处理优化

    周五下午,同事突然说有个存储过程要帮忙优化,就拿来看看,大概看了下: 数据库端需求:数据库中要存储一个AppID字段,对应一个Account可以自行设置自己的AppID(我就不从业务上多说了), 以前 ...

  9. Log4j基本用法----日志级别

    基本使用方法: Log4j由三个重要的组件构成:日志信息的优先级,日志信息的输出目的地,日志信息的输出格式.日志信息的优先级从高到低有ERROR.WARN.INFO.DEBUG,分别用来指定这条日志信 ...

  10. CGRectXXX笔记

    CoreGraphics中有关CGRect相关函数笔记 1.CGRectInset //该结构体的应用是以原rect为中心,再参考dx,dy,进行缩放或者放大. CGRect rect = CGRec ...