Skip to content

sarumaj/edu-space-invaders

Repository files navigation

deploy Go Report Card Maintainability Go Reference Go version


space-invaders

this is an example project to showcase the game development using the Web Assembly Framework in Go. Web Assembly allows us to develop web-frontend applications in a runtime like Go.

Gameover

Click here to play the game:

https://space-invaders.sarumaj.com

Setup

To setup similar project follow following steps:

  1. Create GitHub repository.
  2. Install git CLI and authenticate it.
  3. Clone your repository:
    git clone https://github.com/[username]/[repository name]
    cd [repository name]
    
  4. Initialize new Go module: go mod init github.com/[username]/[repository name], where github.com/[username]/[repository name] will be your module name.
  5. Start coding. Additional libraries can ben added using go get [module name]. Use go mod tidy if necessary.
  6. Define unit tests and execute: go test -v ./...
  7. Generate Assembly files and goodies for the distribution package: go generate ./...
  8. Execute: go run [program entrypoint file]
  9. Build: go build [program entrypoint file]
  10. Utilize version control:
  11. Status check: git status
  12. Pull: git pull
  13. Stage and commit:
    git add .
    git commit -m "[your commit message goes here]"
    
  14. Push: git push
  15. Advanced usage:
    1. Create a temporary branch: git checkout -b [branch name]
    2. Pull, stage, commit
    3. Push: git push --set-upstream origin [branch name]
    4. Create pull request and merge it through the web interface (github.com)

Application structure

The script build.sh is meant to compile the web assembly package (main.wasm) and create a distribution package dist. To authenticate the WASM application towards the game server, the jwt.sh can be used. The application will then be able to call protected endpoints of the game servers, like POST /scores which is used to publish a highscore record. The JWT based authentication scheme is meant to prevent the manipulation of the scoreboard from outside.

The game server serves the files from the distribution package using the web assembly. The files can be served in any other runtime than Go. Some code components are meant to be compiled only for the JS WASM architecture (e.g. js_util.go and handler_js.go).

To be able to compile the code for other targets and to run tests against it, build tags has been leveraged and some mock-ups haven been defined (e.g. js_placebo.go and handler_os.go). The heart of the web application is the JavaScript script building the bridge between the WASM package: wasm.js and our static web page: index.html.

The game engine uses the Hyperplane separation theorem to detect object collisions.

The game server exposes access to the configuration of the game engine:

You may be interested to take a look at it.

Furter reading

Questionary

Analyze this project and answer following questions:

  1. Game engine
    1. Actors
      • What actors and objects do occur in the game?
      • What are the relations among them?
      • Illustrate with an UML diagram.
    2. Rules and axioms
      • How does the collision detection work?
      • What rules make the objects move? (Enemies, Planets, Stars)
      • What transitions apply to the objects? (Spaceship, Enemies)
      • What role do probabilities play?
    3. User interface
      • What kind of user input is being processed?
      • How does the event handling work?
      • How is the UI designed? (HTML, CSS, JS, WASM)
    4. Tests
      • What is being tested and how?
      • What could be tested?
      • What is a subject to manual testing?
    5. Build
      • How does the build process of the WebAssembly module work?
  2. Web API
    1. Design
      • What is the bridge between the WASM frontend and the API backend and how does it work?
      • Which endpoints does the Web API expose?
      • What kind of web technology stack is being used?
      • How is the Postgres Database being used?
    2. Security
      • How does the authentication work?
      • How is cryptography being used?
      • How is the API protected against common attack patterns (DDoS, XSS, etc.)?
      • What are vulnerabilities of the API?