更新时间:2021-06-24 13:41:55
coverpage
Title Page
Copyright and Credits
Hands-On Game Development with WebAssembly
Dedication
About Packt
Why subscribe?
Packt.com
Contributors
About the author
About the reviewers
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Introduction to WebAssembly and Emscripten
What is WebAssembly?
Why do we need WebAssembly?
Why is WebAssembly faster than JavaScript?
Will WebAssembly replace JavaScript?
What is asm.js?
A brief introduction to LLVM
A brief introduction to WebAssembly text
Emscripten
Installing Emscripten on Windows
Installing Emscripten on Ubuntu
Using Emscripten
Additional installation resources
Summary
HTML5 and WebAssembly
The Emscripten minimal shell file
Creating a new HTML shell and C file
Defining the CSS
HTML5 and game development
Immediate mode versus retained mode
Adding a canvas to the Emscripten template
Introduction to WebGL
WebGL and canvas contexts
An introduction to WebGL shaders
WebGL and JavaScript
WebGL coordinate system versus 2D canvas
Vertex and UV data
2D canvas to WebGL
Minor tweaks to the head tag
Major JavaScript changes
WebGL global variables
The return of vertex and texture data
Buffer constants
Defining the shaders
The ModuleLoaded function
The ShipPosition function
The MoveShip function
Sprite Animations in WebAssembly with SDL
Using SDL in WebAssembly
Initializing SDL
Clearing the SDL renderer
Using the WebAssembly virtual filesystem
Rendering a texture to the HTML5 canvas
Cleaning up SDL
Compiling hello_sdl.html
Render a sprite to the canvas
Animating a sprite
Moving the sprite
Compiling sprite.html
Keyboard Input
JavaScript keyboard input
Adding SDL keyboard input to WebAssembly
Using keyboard input to move a sprite
Game Objects and the Game Loop
Understanding the game loop
Writing a basic game loop
Compiling gameloop.html
Game objects
The player's spaceship game object
Object pooling
Pooling the player's projectiles
Creating an enemy
Compiling game_objects.html
Collision Detection
Types of 2D collision detection
Circle collision detection
Rectangle collision detection
A short refresher on trigonometry
Line collision detection
Compound colliders
Implementing circle collision detection
Destroying a spaceship on collision
Pointers in memory