- Hands-On Game Development with WebAssembly
- Rick Battagline
- 330字
- 2021-06-24 13:41:11
Compiling game_objects.html
Now that we have built all of these game objects, we no longer have everything inside a single file. We will need to include several CPP files and compile them all into a single output file we will call game_objects.html. Because we have moved from the world of C to C++, we will be using em++ to indicate that the files we are compiling are C++ files and not C files. That is not strictly necessary, because Emscripten will figure out that we are compiling with C++ when it receives files with the .cpp extension as input. We are also telling the compiler explicitly the version of C++ we are using when we pass in the -std=c++17 flag. Go ahead and compile the game_objects.html file with the following em++ command:
em++ main.cpp enemy_ship.cpp player_ship.cpp projectile.cpp projectile_pool.cpp -std=c++17 --preload-file sprites -s USE_WEBGL2=1 -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS=["png"] -o game_objects.html
Now that we have our game_objects.html file compiled use a web server to serve the files and open it in a browser, it should look like this:

You can move your spaceship around the canvas with the arrow keys, and fire a projectile with the spacebar. The enemy ship will move around the canvas shooting randomly.
- 零點(diǎn)起飛學(xué)Xilinx FPG
- 用“芯”探核:龍芯派開發(fā)實(shí)戰(zhàn)
- Effective STL中文版:50條有效使用STL的經(jīng)驗(yàn)(雙色)
- 基于ARM的嵌入式系統(tǒng)和物聯(lián)網(wǎng)開發(fā)
- Artificial Intelligence Business:How you can profit from AI
- 基于Proteus仿真的51單片機(jī)應(yīng)用
- Hands-On Artificial Intelligence for Banking
- VMware Workstation:No Experience Necessary
- 超大流量分布式系統(tǒng)架構(gòu)解決方案:人人都是架構(gòu)師2.0
- Arduino項(xiàng)目案例:游戲開發(fā)
- 計(jì)算機(jī)組裝與維護(hù)(慕課版)
- Corona SDK Mobile Game Development:Beginner's Guide
- The Deep Learning Workshop
- USB 3.0編程寶典
- 超炫的35個(gè)Arduino制作項(xiàng)目