人类的本质应该就是摆烂。正如同不就活就不更新领英,不面试就不上传github不更新blog。躺了两个多月之后,没想到现实中诸多原因直接让我面临着做项目和做科研的双重压力。反正自己也擅长偷工减料投机取巧,脑海中+上手操作排除了几个做起来特别麻烦的idea,觉得换皮的类银河战士恶魔城还能搞,当然不排除最后搞成了马里奥。stg的话,如果要做个东方,哪怕只做一面,无数的敌人的位置,子弹,符卡,过场,想想都知道你那个class得加到爆炸,留给有时间还不急功近利的高境界人士去做吧。
至于一开始想直接换皮空洞骑士,后面想想万一吃律师函了呢,不如直接换皮silk song,反正他们估计也赚够了不想更这个dlc了。刚好解包里面有大黄蜂小姐姐,懒得一张一张拆开看了就直接拿来用。
这个项目可能会后续进行十篇文章左右的大型更新,第一期我就先从搭建环境和创建第一个窗口开始讲起吧。总体思路和教程都参考了那本C++开始游戏编程,知乎上也有个北航本庆应佬现在在某主机游戏公司就职的人写的连续教程文,只不过现在无限延期了,所以我也不排除我突然太监这个系列的可能,一问我就说向大佬致敬。具体的书名和知乎文链接我也懒得帮你们去翻来贴在这里,之后有人问我要可能我会去找,但现在码字的心情是不想碰。
还有就是我打算开发PS Vita的版本,所以直接在ubuntu上做开发了,看了下也懒得学qt,直接sdl2吧。先看看vscode和sublime能不能用,反正最后要交叉编译.vpk也得去写CmakeList.txt,不如pc端也直接拿vim搞了算球了。
至于会不会教Windows版本(msvc)和Mac(Xcode),我只能说得看心情,反正今天不会搞,明天大概率也不会,而且我明天估计连工位都不会来。

系统信息

Ubuntu 18.04

1
Linux fly-vm 4.15.0-142-generic #146~18.04.1-Ubuntu SMP Tue Apr 13 09:27:15 UTC 2021 x86_64 x86_64 GNU/Linux

Introduce to SDL2

SDL(Simple DirectMedia Layer)是一个多媒体跨平台开发库,本质上也就是个图形引擎,调用一些putimage/loadimage,initgraph,window啥的函数。
有人可能好奇为啥不用easyX,还有国外的SFML啥的,或者有些整天觉得自己将来要去搞ai的,搞什么计算机图形学CG的,口味比较叼,要求比较高的,还问为什么不用OpenGL,VULKAN之类的。用SDL是因为全平台移植性好,尤其是这个还能用在switch和psv上,这一功能直接相当于给你了一个新玩具。
此外,不用后面两个是因为沉没成本,我自己都不知道将来会在哪,花那么大功夫all in游戏业界属实把路走窄了。真要用我如果入职了游戏公司在考虑研究折腾下。

以下内容来源于官网

Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. It is used by video playback software, emulators, and popular games including Valve’s award winning catalog and many Humble Bundle games.
SDL officially supports Windows, macOS, Linux, iOS, and Android. Support for other platforms may be found in the source code.
SDL is written in C, works natively with C++, and there are bindings available for several other languages, including C# and Python.
SDL 2.0 is distributed under the zlib license. This license allows you to use SDL freely in any software.Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. It is used by video playback software, emulators, and popular games including Valve’s award winning catalog and many Humble Bundle games.
SDL officially supports Windows, macOS, Linux, iOS, and Android. Support for other platforms may be found in the source code.
SDL is written in C, works natively with C++, and there are bindings available for several other languages, including C# and Python.
SDL 2.0 is distributed under the zlib license. This license allows you to use SDL freely in any software.

下载链接

官网地址:Simple DirectMedia Layer - Homepage

Source Code: https://www.libsdl.org/release/SDL2-2.0.14.tar.gz

GitHub: https://github.com/libsdl-org/SDL 7000star的项目呵呵

Install

这里我不知道为啥cmake用不了,我在源代码目录外或者内部都试过,反正就是一直报错,让你去outside创建directory,只能说这个世界充满了惊喜和意外。

那就只能这样来了:

1
2
3
4
5
tar -zxvf SDL2-2.0.14.tar.gz
cd SDL2-2.0.14
configure --prefix=$PWD/_instal
make && make install
cd _install/

暂更,爷去做邮件发过来的code test了

—————————————-分界线——————————————-

爷回来了,这几天想了一下到底什么是工程师,什么又是工程师思维。我认为工程师相对于学术界,你的区分关键点在于能解决实际问题,能把项目落地。所以我认为没必要在这里继续折磨各位折磨自己,我们直接ubuntu 18.04 sudo apt-get到/usr/include/lib 项目开跑吧,搞那么多软硬链接 makefile啥的,没屁用。你真要去开发游戏到时候也是直接把DirectX3D用msvc自带的项目界面里配置环境变量,用不上Vim和gnu这堆有的没的。

A more easy way

基本开发包

1
2
sudo apt-get update
sudo apt-get install libsdl2-dev

图像开发包

1
sudo apt-get install libsdl2-image-dev

音频开发包

1
sudo apt-get install libsdl2-mixer-dev

文字开发包

1
sudo apt-get install libsdl2-ttf-dev

*注意编译生成可执行文件的时候我们真的需要把这几个开发包在命令行软连接上去,反正原因不明,我装的boost之类的库可以在ide里直接编译,sdl2的话include指令的确不报错,但是找不到对应函数,反正不会是路径问题,我猜测可能是依赖的锅

测试和运行

下面我们直接来生成一个窗口作为游戏开发的第一步。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <SDL2/SDL.h>

int main(int argc, char* argv[])
{
//Init SDL
if(SDL_Init(SDL_INIT_VIDEO) != =)
{
printf("SDL_Init Error.\n");
return 1;
}

//Create Renderer
SDL_Renderer* ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if(ren == NULL)
{
SDL_DestroyWindow(win);
printf("SDL_CreateRenderer Error.\n");
return 1;
}

//Load Image
SDL_Surface* bmp = SDL_LoadBMP("menu.bmp");
if(bmp == NULL)
{
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
printf("SDL_LoadBMP Error.\n");
SDL_Quit();
return 1;
}

SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, bmp);
SDL_FreeSurface(bmp);
if(tex == NULL){
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
printf("SDL_CreateTextureFromSurface Error.\n");
SDL_Quit();
return 1;
}

for(int i = 0; i < 3; ++i){
SDL_RenderClear(ren);
SDL_RenderCopy(ren, tex, NULL, NULL);
SDL_RenderPresent(ren);
SDL_Delay(1000);
}

SDL_DestroyTexture(tex);
SDL_DestroyRenderer(ren);
SDL_DestrpyWindow(win);
SDL_Quit();

return 0;
}

编译Compile

1
g++ main.cpp -o SilkSong -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer

这里使用gnu complier生成可执行文件,但是具体编译环境怎么配置,以及软连接之类的,对Linux命令行指令和C++特性和工程不熟悉的,我是不会在这里去特意解释原理啥的。

预览

menu