我刚学游戏编程时写的程序,对初学者可能有用,希望大家喜欢 :-)
执行文件下载地址:
http://bbs.gameres.com/upload/sf_2007427195529.rar
代码:
http://blog.csdn.net/BillHsu1024/archive/2008/05/10/2430273.aspx
/*
********************
紫日2037 RPG 游戏
合肥八中 许仕鹏 制作
********************
*/
#define WIN32_LEAN_AND_MEAN //定义不使用MFC库
#include <windows.h>
#include "Pub_Def.h"
#include <stdio.h>
#include<stdlib.h>
//定义人物方向
#define Role_UP 0
#define Role_DOWN 1
#define Role_LEFT 2
#define Role_RIGHT 3
//定义动作
#define Act_1 0
#define Act_2 1
#define Act_3 2
//定义图片的宽度和高度
#define Bmp_Width 32
#define Bmp_Height 64
RECT rect;
//全局变量,用来存储窗口的句柄
HWND hwnd;
//地图的Struct
struct Map_struct{
char name[10];
int NpcNo;
int Width;
int Height;
int **Data;
}Map[MAX_MAPS];
//人物的Struct
struct NPCs_struct{
int seeable;
int name;
int NPC_Status;
int Pos_y;
int Pos_x;
};
//指向一个场景中的人物
struct NPC_struct{
NPCs_struct *NPCs;
}NPC[MAX_MAPS];
HDC windowDC = NULL;//窗口DC
HDC MainRoleDC = NULL;//主角DC
HDC memDC =NULL;//记忆DC
HDC msgboxDC=NULL;//消息框DC
HDC MapDC=NULL;//装地图图片的DC
HDC TmpMapDC=NULL;//画出地图的DC
HDC TmpSceneDC=NULL;//画出场景DC
HDC FaceDC=NULL;//人物脸DC
HDC Boy1DC=NULL;//男孩1DC
HDC Boy2DC=NULL;//男孩2DC
HDC Girl1DC=NULL;//女孩1DC
HDC Girl2DC=NULL;//女孩2DC
HDC DiagDC=NULL;//DiagDC
HFONT Font;//字体物件
//以下为图片物件,和上面的DC对应
HBITMAP MainRoleBMP = NULL;
HBITMAP memBMP=NULL;
HBITMAP msgboxBMP=NULL;
HBITMAP MapBMP=NULL;
HBITMAP TmpMapBMP=NULL;
HBITMAP TmpSceneBMP=NULL;
HBITMAP FaceBMP=NULL;
HBITMAP Boy1BMP=NULL;
HBITMAP Boy2BMP=NULL;
HBITMAP Girl1BMP=NULL;
HBITMAP Girl2BMP=NULL;
HBITMAP DiagBMP=NULL;
unsigned int active;//本窗口是否为活动
UINT width;//屏幕宽
UINT height;//屏幕高
int Role_X;//人物X坐标
int Role_Y;//人物Y坐标
int Role_Act;//人物动作
int Role_Status;//人物状态(上、下、左、右)
int Map_y=0;//地图Y坐标
int Map_x=0;//地图X坐标
int Scene=0;//场景编号
int ObjTmp;
int ObjTmp_x;
int ObjTmp_y;
int hStory=0;//故事编号
//以下为判断状态的变量
bool enter_1=false;
bool enter_2=false;
bool enter_3=false;
bool enter_4=false;
bool enter_5=false;
bool enter_6=false;
bool enter_7=false;
bool enter_8=false;
bool enter_9=false;
bool enter_10=false;
bool visit_1=false;
bool visit_2=false;
bool visit_3=false;
bool visit_4=false;
bool Get_Sanshi=false;
bool Get_Sunzi=false;
bool enter_zuo=false;
bool visit_zuo=false;
bool talk_apsh=false;
bool talk_czn=false;
bool talk_xz=false;
bool Get_sun=false;
//以下为函数定义
HRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);//消息处理
void DoMain(void);//主循环
void Move(void);//移动主角
void Delay(long time);//延时
void ClearScr(void);//清屏
void Draw(void);//将记忆DC画到窗口DC
void GameTitle(void);//游戏开头字幕
void PrintText(char * chr,int x,int y);//打印文字
void TalkText(int face,char * chr,char * Obj_Name);//人物对话
void MoveNPC(int NPC_Num,int NPC_Dt);//移动人物
执行文件下载地址:
http://bbs.gameres.com/upload/sf_2007427195529.rar
代码:
http://blog.csdn.net/BillHsu1024/archive/2008/05/10/2430273.aspx
/*
********************
紫日2037 RPG 游戏
合肥八中 许仕鹏 制作
********************
*/
#define WIN32_LEAN_AND_MEAN //定义不使用MFC库
#include <windows.h>
#include "Pub_Def.h"
#include <stdio.h>
#include<stdlib.h>
//定义人物方向
#define Role_UP 0
#define Role_DOWN 1
#define Role_LEFT 2
#define Role_RIGHT 3
//定义动作
#define Act_1 0
#define Act_2 1
#define Act_3 2
//定义图片的宽度和高度
#define Bmp_Width 32
#define Bmp_Height 64
RECT rect;
//全局变量,用来存储窗口的句柄
HWND hwnd;
//地图的Struct
struct Map_struct{
char name[10];
int NpcNo;
int Width;
int Height;
int **Data;
}Map[MAX_MAPS];
//人物的Struct
struct NPCs_struct{
int seeable;
int name;
int NPC_Status;
int Pos_y;
int Pos_x;
};
//指向一个场景中的人物
struct NPC_struct{
NPCs_struct *NPCs;
}NPC[MAX_MAPS];
HDC windowDC = NULL;//窗口DC
HDC MainRoleDC = NULL;//主角DC
HDC memDC =NULL;//记忆DC
HDC msgboxDC=NULL;//消息框DC
HDC MapDC=NULL;//装地图图片的DC
HDC TmpMapDC=NULL;//画出地图的DC
HDC TmpSceneDC=NULL;//画出场景DC
HDC FaceDC=NULL;//人物脸DC
HDC Boy1DC=NULL;//男孩1DC
HDC Boy2DC=NULL;//男孩2DC
HDC Girl1DC=NULL;//女孩1DC
HDC Girl2DC=NULL;//女孩2DC
HDC DiagDC=NULL;//DiagDC
HFONT Font;//字体物件
//以下为图片物件,和上面的DC对应
HBITMAP MainRoleBMP = NULL;
HBITMAP memBMP=NULL;
HBITMAP msgboxBMP=NULL;
HBITMAP MapBMP=NULL;
HBITMAP TmpMapBMP=NULL;
HBITMAP TmpSceneBMP=NULL;
HBITMAP FaceBMP=NULL;
HBITMAP Boy1BMP=NULL;
HBITMAP Boy2BMP=NULL;
HBITMAP Girl1BMP=NULL;
HBITMAP Girl2BMP=NULL;
HBITMAP DiagBMP=NULL;
unsigned int active;//本窗口是否为活动
UINT width;//屏幕宽
UINT height;//屏幕高
int Role_X;//人物X坐标
int Role_Y;//人物Y坐标
int Role_Act;//人物动作
int Role_Status;//人物状态(上、下、左、右)
int Map_y=0;//地图Y坐标
int Map_x=0;//地图X坐标
int Scene=0;//场景编号
int ObjTmp;
int ObjTmp_x;
int ObjTmp_y;
int hStory=0;//故事编号
//以下为判断状态的变量
bool enter_1=false;
bool enter_2=false;
bool enter_3=false;
bool enter_4=false;
bool enter_5=false;
bool enter_6=false;
bool enter_7=false;
bool enter_8=false;
bool enter_9=false;
bool enter_10=false;
bool visit_1=false;
bool visit_2=false;
bool visit_3=false;
bool visit_4=false;
bool Get_Sanshi=false;
bool Get_Sunzi=false;
bool enter_zuo=false;
bool visit_zuo=false;
bool talk_apsh=false;
bool talk_czn=false;
bool talk_xz=false;
bool Get_sun=false;
//以下为函数定义
HRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);//消息处理
void DoMain(void);//主循环
void Move(void);//移动主角
void Delay(long time);//延时
void ClearScr(void);//清屏
void Draw(void);//将记忆DC画到窗口DC
void GameTitle(void);//游戏开头字幕
void PrintText(char * chr,int x,int y);//打印文字
void TalkText(int face,char * chr,char * Obj_Name);//人物对话
void MoveNPC(int NPC_Num,int NPC_Dt);//移动人物