Last active
January 6, 2021 13:59
-
-
Save olso/c9bf8c4d51ef62dc2510c6c17d3fc098 to your computer and use it in GitHub Desktop.
https://github.com/olso/go-wasm-cat-game-on-canvas-with-docker 🧶 https://olso.space 🧶 https://twitter.com/olso_uznebolo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func updatePlayer(event js.Value) { | |
mouseX := event.Get("clientX").Float() | |
mouseY := event.Get("clientY").Float() | |
// basically threads/async/parallelism | |
// TODO difference with Web Workers | |
// TODO difference with Service Workers | |
// https://gobyexample.com/goroutines | |
go log("mouseEvent", "x", mouseX, "y", mouseY) | |
// next gist | |
if isLaserCaught(mouseX, mouseY, gs.laserX, gs.laserY) { | |
go playSound() | |
} | |
} | |
// no this isn't some magic; it's straight from HTML5 | |
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement#Basic_usage | |
func playSound() { | |
beep.Call("play") | |
window.Get("navigator").Call("vibrate", 300) | |
} | |
// basically a rest+spread from javascript | |
// ...interface{} is more or less `any` from Typescript | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters#Description | |
func log(args ...interface{}) { | |
window.Get("console").Call("log", args...) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment