# SuperMario **Repository Path**: yuesg/Game ## Basic Information - **Project Name**: SuperMario - **Description**: 超级玛丽游戏,基于SDL2.0.9。 - **Primary Language**: C++ - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2020-03-07 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SuperMario #### 介绍 超级玛丽游戏。原游戏是用SDL1.0写的,作者叫Jens Wellmann,2005年发布的,原作者的网站现在不能访问了。我把代码迁移到了SDL2.0.9,仿照UE4写了伤害系统,修改了类之间的交互。 #### 软件架构 软件架构说明 用消息总线管理类之间的通信 用到了boost库的any库,只需要包含头文件即可,不用引入boost库。 sudo ln -s /home/workspace/boost_1_69_0/lib/include/boost /usr/local/include/boost #### 安装教程 需要SDL 2.0,lpng1636,jpeg-6b,freetype-2.10.0,SDL2_image-2.0.4,SDL2_mixer-2.0.4,SDL2_ttf-2.0.15,zlib-1.2.11这几个库。 Deepin上需要SDL 2.0,lpng1636,jjpegsrc.v9c.tar.gz或者jpegsrc.v8d1.tar.gz,freetype-2.10.0,SDL2_image-2.0.4,SDL2_mixer-2.0.4,SDL2_ttf-2.0.15,zlib-1.2.11这几个库。需要自己编译安装cmake,编译SDL时要用到。 在deepin上编译SDL需要libx11-dev xorg-dev xscreensaver 安装方法: sudo apt-get install libx11-dev sudo apt-get install xorg-dev sudo apt-get install build-dep xscreensaver sudo apt-get install xscreensaver sudo apt-get install xscreensaver-gl xscreensaver-data-extra xscreensaver-gl-extra sudo apt-get install libx11-dev 另外SDL的test编译需要自己把X11_LIBRARIES X11XCB_LIBRARIES 库导入,把test目录下的cmake 53行UNIX这里按下面所示改好 if(APPLE) add_executable(testnative testnative.c testnativecocoa.m testnativex11.c) elseif(WINDOWS) add_executable(testnative testnative.c testnativew32.c) elseif(UNIX) find_library(X11_LIBRARIES X11) list(APPEND EXTRA_LIBS ${X11_LIBRARIES}) find_library(X11XCB_LIBRARIES X11-xcb) list(APPEND EXTRA_LIBS ${X11XCB_LIBRARIES}) add_executable(testnative testnative.c testnativex11.c) target_link_libraries(testnative ${X11XCB_LIBRARIES} ${X11_LIBRARIES}) endif() 执行可执行文件或脚本文件出现类似这样的错误提示的,是因为在windows里面打开过. ./configure: /bin/sh^M: 解释器错误: 没有那个文件或目录 sed -i 's/\r$//' configure 或者执行sh这样的可执行脚本文件出现类似这样的错误提示 $'\r': 未找到命令 install-sh:行58: 未预期的符号 `$'in\r'' 附近有语法错误 'nstall-sh:行58: ` case $1 in sed -i 's/\r$//' 脚本文件名 如果出现这个错误 configure: error: cannot run /bin/sh ./config.sub [root@192 lpng1636]# cp /usr/share/libtool/config/config.guess /usr/share/libtool/config/config.sub . cp:是否覆盖"./config.guess"? y cp:是否覆盖"./config.sub"? y 各个库编译配置安装完毕后注意把库文件路径加入/etc/ld.so.conf,If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must have your system administrator add LIBDIR to '/etc/ld.so.conf' vi /etc/ld.so.conf 然后ldconfig一下 我的ld.so.conf文件内容如下 include ld.so.conf.d/*.conf /usr/local/lib /usr/local/lib64 /opt/libpng/lib /opt/sdl2_image/lib /opt/sdl2_mixer/lib /opt/sdl2_ttf/lib SDL2-2.0.9 cmake前先检查一下configure能不能正常执行 ./configure bash: ./configure: 权限不够 [root@localhost SDL2]# chmod +x configure [root@localhost SDL2]# ./configure bash: ./configure: /bin/sh^M: 解释器错误: 没有那个文件或目录 [root@localhost SDL2]# sed -i 's/\r$//' configure [root@localhost SDL2]# ./configure configure: error: cannot run /bin/sh build-scripts/config.sub 出现这个错误提示,那就安装libtool,然后把/usr/share/libtool/config/目录下的config.guess和config.sub两个文件拷贝到SDL2-2.0.9目录下面 [root@localhost SDL2]# yum install libtool [root@192 SDL2]# yum install libtool-ltdl 已加载插件:langpacks 软件包 libtool-ltdl-2.4.2-32.fc21.loongson.1.mips64el 已安装并且是最新版本 无须任何处理 [root@192 SDL2]# yum install libtool-ltdl-devel [root@192 SDL2]# cp /usr/share/libtool/config/config.guess /usr/share/libtool/config/config.sub . 然后在SDL2-2.0.9 目录先mkdir build目录,然后 cmake ../. make或者make -j2 make install 编译配置SDL2_image-2.0.4 [root@192 SDL2_image-2.0.4]# sh autogen.sh checking for jpeglib.h... no checking for jpeg_CreateDecompress in -ljpeg... no configure: WARNING: *** Unable to find JPEG library (http://www.ijg.org/) configure: WARNING: JPG image loading disabled configure: WARNING: *** Unable to find PNG library (http://www.libpng.org/pub/png/libpng.html) configure: WARNING: PNG image loading disabled 错误提示要配置jpeg库以及png库,ijg.org sdl2_image 执行configure后 输出 Unable to find JPEG library (http://www.ijg.org/)ijg网站上推荐了jpegsrc for linux and windows 下载jpegsrc.v9c.tar.gz或jpegsrc.v8d1.tar.gz 这个两个都可以,安装就是.configure && make && make install 推荐编译安装配置jpegsrc.v9c.tar.gz和jpegsrc.v8d1.tar.gz这两个库 在jpeg目录下 ./configure && make && make install 然后vi /etc/ld.so.conf 把库的路径加进去 然后ldconfig一下 png选libpng-1.6.37.tar.gz lpng1617也可以 tar -zxvf libpng-1.6.37.tar.gz cd libpng-1.6.37ls ./autogen.sh ./configure ./configure --prefix=/opt/libpng make -j2 make install 然后把/opt/libpng/lib路径加入/etc/ld.so.conf 然后编译SDL2_image-2.0.4 ./configure --prefix=/opt/sdl2_image CFLAGS="-I/usr/local/include" SDL_LIBS="-L/usr/local/lib/libSDL2.so -lSDL" LIBPNG_CFLAGS="-I/opt/libpng/include/libpng16" LIBPNG_LIBS="-L/opt/libpng/lib/libpng.a -lpng" --enable-static --enable-bmp --enable-gif --enable-jpg --enable-png --enable-tif checking for zlibVersion in -lz... no checking for z_zlibVersion in -lz... no configure: error: zlib not installed zlib [root@192 workspace]# cd zlib-1.2.11 [root@192 zlib-1.2.11]# ./configure [root@192 zlib-1.2.11]# mkdir build [root@192 zlib-1.2.11]# cd build/ [root@192 build]# cmake ../. make && make install 编译配置SDL2_ttf-2.0.15 [root@localhost SDL2_ttf-2.0.15]./configure configure: error: *** Unable to find FreeType2 library (http://www.freetype.org/) 直接yum安装,源码编译也可以,有点麻烦 yum install freetype freetype-devel 然后 ./configure --prefix=/opt/sdl2_ttf CFLAGS="-I/usr/local/include" SDL_LIBS="-L/usr/local/lib/libSDL2.so -lSDL" 编译配置sdl2_mixer SDL2_mixer-2.0.4 ./configure --prefix=/opt/sdl2_mixer CFLAGS="-I/usr/local/include" SDL_LIBS="-L/usr/local/lib/libSDL2.so -lSDL" #### 使用说明 游戏暂时只支持键盘,修改版会支持游戏手柄。 1.游戏按键说明 H or F1 = Help Arrow Keys = Movement Space = Jump Left Ctrl = Run faster / shoot P = 暂停 F12 = Screenshot ESC 退出 2.选择框 用 arrow key上下选择,回车键选中。 3.游戏中除了食人花以及带刺的爬行怪不能headbang,其余的蘑菇,乌龟,子弹都可以heandbang,碰到怪以后玛丽会死,游戏重新开始。