This commit is contained in:
parent
35c01939a0
commit
97a4855bea
@ -44,6 +44,11 @@
|
|||||||
|
|
||||||
<body>
|
<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>
|
</body>
|
||||||
|
|
||||||
|
@ -45,9 +45,15 @@ var keyMap = map[int]int{
|
|||||||
86: 15, // v
|
86: 15, // v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var gameMap = map[string]func() []byte {
|
||||||
|
"pong": getPong,
|
||||||
|
"spaceinv": getSpaceInvaders,
|
||||||
|
"tetris": getTetris,
|
||||||
|
}
|
||||||
|
|
||||||
func keyEventHandle(event js.Value) {
|
func keyEventHandle(event js.Value) {
|
||||||
println(event.Get("type").String())
|
//println(event.Get("type").String())
|
||||||
println(event.Get("keyCode").Int())
|
//println(event.Get("keyCode").Int())
|
||||||
elem, ok := keyMap[event.Get("keyCode").Int()]
|
elem, ok := keyMap[event.Get("keyCode").Int()]
|
||||||
if ok {
|
if ok {
|
||||||
keysLock.Lock()
|
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() {
|
func main() {
|
||||||
println("CHIP8 IS HERE!")
|
println("CHIP8 IS HERE!")
|
||||||
window = js.Global()
|
window = js.Global()
|
||||||
@ -116,6 +139,11 @@ func main() {
|
|||||||
return nil
|
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, _ = canvas.NewCanvas2d(false)
|
||||||
cvs.Create(int(width)*sizeMultiplier, int(height)*sizeMultiplier)
|
cvs.Create(int(width)*sizeMultiplier, int(height)*sizeMultiplier)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user