# MyWorld2 **Repository Path**: guifeng/my-world2 ## Basic Information - **Project Name**: MyWorld2 - **Description**: 面向C语言编程初学者,从零开始创造一个虚拟的新世界,英文名”My World“,中文”迷界“。 - **Primary Language**: C - **License**: MIT - **Default Branch**: master - **Homepage**: https://zhuanlan.zhihu.com/p/667835455 - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-10-25 - **Last Updated**: 2023-11-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # My World C语言实现游戏场景(地图)查看,使用SDL2图形库。 ## 图形库 * SDL2教程:[Beginning Game Programming v2.0](https://lazyfoo.net/tutorials/SDL/index.php) ## 运行依赖 * 字体文件msyh.ttf,以显示文本 * 动态链接库SDL2.dll,SDL2_ttf.dll ## 编译环境 以下编译环境都可以,需要将include、lib分别拷贝到编译器能找到的目录里;或者加上编译参数,使能找到头文件与库文件。 * Visual Studio 2019 + SDL2 VC版 * Dev C++ 5.11 + SDL2 mingw版 ## 场景设计 场景数据结构及API定义在[场景设计.xlsx](/doc/场景设计.xlsx),需要实现以下定义或函数。 ```c /* pixel size of tile */ #define TILE_SIZE 20 /* total number of tiles, with NONE as the first, LAST the last type */ #define NUM_TILES (LAST + 1) /* windows size, unit of tiles */ #define WINDOW_WIDTH 40 #define WINDOW_HEIGHT 30 /* world size, unit of tiles */ #define WORLD_WIDTH 80 #define WORLD_HEIGHT 60 /* initialize the scene */ void world_init(); /* calculate which tile on window position (tx, ty) */ void * window_tile(int tx, int ty); /* render tile on (tx, ty), unit of tile, origin point is the top-left of the window */ _Bool window_render(int tx, int ty); /* move window with unit of offset (dx, dy) */ void window_move(int dx, int dy); /* move the window to the world position (wx, wy) */ void window_moveto(int wx, int wy); ``` 需要在[mario.c](/mario.c)里实现以上函数。 键盘ASDW,上下左右方向键,可在场景中浏览,该功能已在[world.c](/world.c)里实现。