tetris/glfw: fix warnings

pull/2562/head
Alexander Medvednikov 2019-10-27 10:13:40 +03:00
parent 59378dce46
commit efdadc3758
2 changed files with 26 additions and 20 deletions

View File

@ -382,25 +382,28 @@ fn key_down(wnd voidptr, key, code, action, mods int) {
// Fetch the game object stored in the user pointer // Fetch the game object stored in the user pointer
mut game := &Game(glfw.get_window_user_pointer(wnd)) mut game := &Game(glfw.get_window_user_pointer(wnd))
// global keys // global keys
switch key { match key {
case glfw.KEY_ESCAPE: glfw.KEY_ESCAPE {
glfw.set_should_close(wnd, true) glfw.set_should_close(wnd, true)
case glfw.key_space: }
if game.state == .running { glfw.key_space {
game.state = .paused if game.state == .running {
} else if game.state == .paused { game.state = .paused
game.state = .running } else if game.state == .paused {
} else if game.state == .gameover { game.state = .running
game.init_game() } else if game.state == .gameover {
game.state = .running game.init_game()
game.state = .running
}
} }
} }
if game.state != .running { if game.state != .running {
return return
} }
// keys while game is running // keys while game is running
switch key { match key {
case glfw.KeyUp: glfw.KeyUp {
// Rotate the tetro // Rotate the tetro
old_rotation_idx := game.rotation_idx old_rotation_idx := game.rotation_idx
game.rotation_idx++ game.rotation_idx++
@ -412,15 +415,18 @@ fn key_down(wnd voidptr, key, code, action, mods int) {
game.rotation_idx = old_rotation_idx game.rotation_idx = old_rotation_idx
game.get_tetro() game.get_tetro()
} }
if game.pos_x < 0 { if game.pos_x < 0 {
game.pos_x = 1 game.pos_x = 1
} }
case glfw.KeyLeft: }
glfw.KeyLeft {
game.move_right(-1) game.move_right(-1)
case glfw.KeyRight: }
glfw.KeyRight {
game.move_right(1) game.move_right(1)
case glfw.KeyDown: }
glfw.KeyDown {
game.move_tetro() // drop faster when the player presses <down> game.move_tetro() // drop faster when the player presses <down>
} }
}
} }

View File

@ -27,18 +27,18 @@ import gl
// #flag darwin -framework Cocoa // #flag darwin -framework Cocoa
// #flag darwin -framework CoreVideo // #flag darwin -framework CoreVideo
// #flag darwin -framework IOKit // #flag darwin -framework IOKit
const ( pub const (
RESIZABLE = 1 RESIZABLE = 1
DECORATED = 2 DECORATED = 2
) )
const ( pub const (
KEY_ESCAPE = 256 KEY_ESCAPE = 256
key_space = 32 key_space = 32
KEY_LEFT_SUPER = 343 KEY_LEFT_SUPER = 343
) )
const ( pub const (
KeyUp = 265 KeyUp = 265
KeyLeft = 263 KeyLeft = 263
KeyRight = 262 KeyRight = 262