当前位置:编程学习 > 网站相关 >>

游戏编程基础005---景物贴图

代码地址:/2012/0118/20120118075200799.rar
 
 
 
[cpp] view plaincopyprint?
/************************************************************************/ 
/* 
    在<004canvas斜角地图贴图>中加入不同的景物
*/ 
/************************************************************************// 
 
 
#include "stdafx.h" 
 
//全局变量声明 www.zzzyk.com
HINSTANCE hInst; 
HBITMAP fullmap; 
HDC     mdc; 
const int rows = 10,cols = 10; 
 
//全局函数 
void                MyPaint(HDC hdc); 
ATOM                MyRegisterClass(HINSTANCE hInstance); 
BOOL                InitInstance(HINSTANCE, int); 
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM); 
 
//****程序入口************************************** 
int APIENTRY WinMain(HINSTANCE hInstance, 
                     HINSTANCE hPrevInstance, 
                     LPSTR     lpCmdLine, 
                     int       nCmdShow) 

    MSG msg; 
 
    MyRegisterClass(hInstance); 
 
    //运行初始化函数 
    if (!InitInstance (hInstance, nCmdShow))   
    { 
        return FALSE; 
    } 
 
    //消息循环 
    while (GetMessage(&msg, NULL, 0, 0))  
    { 
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    } 
 
    return msg.wParam; 

 
//****定义及注册窗口类别函数************************* 
ATOM MyRegisterClass(HINSTANCE hInstance) 

    WNDCLASSEX wcex; 
 
    wcex.cbSize = sizeof(WNDCLASSEX);  
    wcex.style          = CS_HREDRAW | CS_VREDRAW; 
    wcex.lpfnWndProc    = (WNDPROC)WndProc; 
    wcex.cbClsExtra     = 0; 
    wcex.cbWndExtra     = 0; 
    wcex.hInstance      = hInstance; 
    wcex.hIcon          = NULL; 
    wcex.hCursor        = NULL; 
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW); 
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1); 
    wcex.lpszMenuName   = NULL; 
    wcex.lpszClassName  = "canvas";  //类别名称 
    wcex.hIconSm        = NULL; 
 
    return RegisterClassEx(&wcex); 

 
//****初始化************************************* 
// 什么地图数组,进行图块贴图,完成地图衔接 
//  
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 

    HWND hWnd; 
    HDC hdc,bufdc; 
 
    hInst = hInstance; 
 
    hWnd = CreateWindow("canvas", "绘图窗口" , WS_OVERLAPPEDWINDOW, 
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); 
 
    if (!hWnd) 
    { 
        return FALSE; 
    } 
 
    MoveWindow(hWnd,10,10,600,450,true); 
    ShowWindow(hWnd, nCmdShow); 
    UpdateWindow(hWnd); 
 
    int mapIndex[rows*cols] = { 2,2,2,2,2,0,1,0,1,0,  //第1列 
        3,3,2,2,0,0,0,1,1,0,   
        3,0,0,0,0,0,0,0,1,2,   
        2,2,0,0,0,0,0,2,2,2,   
        2,2,0,0,0,0,2,2,2,2,  
        2,2,0,0,0,2,2,0,0,2,   
        2,0,0,2,2,2,0,0,1,0,   
        0,0,2,0,0,0,1,1,1,1,   
        0,2,0,3,3,3,3,3,3,1,   
        2,0,3,3,3,3,3,3,3,3 };//第10列 
 
    //景物 
    int sceneIndex[rows*cols] = { 0,2,2,0,2,0,1,0,1,1,  //第1列 
        0,0,0,0,0,0,0,1,1,0,   
        0,0,0,0,0,0,1,0,1,0,   
        0,0,1,0,1,0,0,0,2,0,   
        2,2,0,0,1,0,0,0,0,2,   
        0,0,0,0,0,0,0,0,0,0,   
        0,0,1,0,0,0,0,0,1,0,   
        0,0,0,0,0,0,1,1,1,1,   
        1,0,0,0,0,0,0,0,0,1,   
        2,0,0,0,0,0,0,0,0,0 };//第10列 
 
    hdc = GetDC(hWnd); 
    mdc = CreateCompatibleDC(hdc); 
    bufdc = CreateCompatibleDC(hdc); 
 
    HBITMAP map[4], scene[2]; 
    char filename[20] = ""; 
    int rowNum,colNum; 
    int i,x,y; 
    int xstart,ystart; 
 
    xstart = 32 * (rows-1); 
    ystart = 0; 
 
    fullmap = (HBITMAP)LoadImage(NULL,"bg.bmp",IMAGE_BITMAP,640,480,LR_LOADFROMFILE);  
    SelectObject(mdc,fullmap); 
 
    //加载各图块位图 
    for(i=0;i<4;i++) 
    { 
        sprintf(file
补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,