Skip to content

Instantly share code, notes, and snippets.

@olso
Last active January 6, 2021 13:59
Show Gist options
  • Save olso/c9bf8c4d51ef62dc2510c6c17d3fc098 to your computer and use it in GitHub Desktop.
Save olso/c9bf8c4d51ef62dc2510c6c17d3fc098 to your computer and use it in GitHub Desktop.
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