This commit is contained in:
parent
35c01939a0
commit
97a4855bea
@ -44,6 +44,11 @@
|
||||
|
||||
<body>
|
||||
|
||||
<select name="game" id="game-select">
|
||||
<option value="pong" selected>Pong</option>
|
||||
<option value="spaceinv">Space Invaders</option>
|
||||
<option value="tetris">Tetris</option>
|
||||
</select>
|
||||
|
||||
</body>
|
||||
|
||||
|
@ -45,9 +45,15 @@ var keyMap = map[int]int{
|
||||
86: 15, // v
|
||||
}
|
||||
|
||||
var gameMap = map[string]func() []byte {
|
||||
"pong": getPong,
|
||||
"spaceinv": getSpaceInvaders,
|
||||
"tetris": getTetris,
|
||||
}
|
||||
|
||||
func keyEventHandle(event js.Value) {
|
||||
println(event.Get("type").String())
|
||||
println(event.Get("keyCode").Int())
|
||||
//println(event.Get("type").String())
|
||||
//println(event.Get("keyCode").Int())
|
||||
elem, ok := keyMap[event.Get("keyCode").Int()]
|
||||
if ok {
|
||||
keysLock.Lock()
|
||||
@ -102,6 +108,23 @@ func runGame(game []byte) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func changeGame(event js.Value) {
|
||||
//println(event.Get("target").Get("value").String())
|
||||
println(event.Get("target").Get("value").String())
|
||||
elem, ok := gameMap[event.Get("target").Get("value").String()]
|
||||
if ok {
|
||||
println("change event!!!!")
|
||||
gameRunning = false
|
||||
time.Sleep(1 * time.Second)
|
||||
//println("changing games!!")
|
||||
gameRunning = true
|
||||
go runGame(elem())
|
||||
} else {
|
||||
panic("value not found!")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
println("CHIP8 IS HERE!")
|
||||
window = js.Global()
|
||||
@ -116,6 +139,11 @@ func main() {
|
||||
return nil
|
||||
}))
|
||||
|
||||
window.Call("addEventListener", "change", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
||||
changeGame(args[0])
|
||||
return nil
|
||||
}))
|
||||
|
||||
cvs, _ = canvas.NewCanvas2d(false)
|
||||
cvs.Create(int(width)*sizeMultiplier, int(height)*sizeMultiplier)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user