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

>_<: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;
RECT rect;//窗口矩形
int x[] , y[];//位置
int vx[] , vy[];//速度
int ax[] , ay[];//加速度
int t= , num=;//时间 // 此代码模块中包含的函数的前向声明:
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[]=;ax[]=;ay[]=; 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); BitBlt(hdc,,,,,mdc,,,SRCCOPY); for(int i=;i<;i++){
//计算x轴方向坐标及速度
vx[i]+=ax[i];
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轴方向坐标及速度
vy[i]+=ay[i];
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]-;
}
}
}

[游戏模版21] Win32 物理引擎 能量守恒的更多相关文章

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

    >_<:Learning the physical engine >_<:resource >_<:code #include <windows.h> ...

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

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

  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. libgdx学习记录21——Box2d物理引擎之碰撞Contact、冲量Impulse、关节Joint

    Box2d中,物体可以接受力(Force).冲量(Impulse)和扭矩(Torque).这些物理元素都能改变物体的运动形式,并且默认都会唤醒物体,当然只是针对动态物体. 力是一个持久的效果,通过Bo ...

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

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

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

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

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

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

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

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

随机推荐

  1. jQuery 屏幕遮罩

    1.先做一个可以覆盖整个屏幕的div,颜色为黑色,然后再设置透明度,作为遮罩#zhezhao { position: absolute; top: 0px; left: 0px; width: 100 ...

  2. EXTJS 4 动态grid

    var grid=Ext.getCmp("GridPanel1"); var store = grid.getStore(); Ext.Ajax.request({ url:&qu ...

  3. AndroidStudio调试APP

    AndroidStudio调试APP 电脑用数据线连上手机 开启手机的开发者模式 注:通常连续狂点手机的版本号即可显示出开发者选项,然后进入菜单,勾选开发者选项.USB调试. 给程序加断点 单击调试按 ...

  4. addClass() 和 toggleClass()

    addClass()是在原有的类基础上增加类属性,仍然保留原有的类的样式.语法格式为:addClass(class0 class1 ...) ,例如: $("p").addClas ...

  5. System.IO.Directory类

    1.参考的博客:System.IO.Directory类和System.DirectoryInfo类(http://blog.sina.com.cn/s/blog_614f473101017du4.h ...

  6. 开源PLM软件Aras详解三 服务端简易开发

    废话少说,直接进入主题, 以CAD为例: 先找到CAD对象类:具体操作见下图 双击打开,找到服务端事件:见下图 点击新建对象,点击添加,新建Method 编写Method,语言分为前端和后端,前端支持 ...

  7. AppcompatActivity闪退问题解决方案

    apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0. ...

  8. -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable

    在 myEclipse 中 需要配置 解决方法: window --> preferences --> java --> installed JREs 设置 Default VM A ...

  9. 将asp.net页面弄成伪静态

    在Web.config中写: <RewriterConfig>     <Rules> <RewriterRule>         <LookFor> ...

  10. 基本数据类型范围大小&&字节大小

    char -128 ~ +127 short -32767 ~ + 32768 unsigned short 0 ~ 65536 int -2147483648 ~ +2147483647 unsig ...