1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tetris/glfw: fix warnings

This commit is contained in:
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
mut game := &Game(glfw.get_window_user_pointer(wnd))
// global keys
switch key {
case glfw.KEY_ESCAPE:
glfw.set_should_close(wnd, true)
case glfw.key_space:
if game.state == .running {
game.state = .paused
} else if game.state == .paused {
game.state = .running
} else if game.state == .gameover {
game.init_game()
game.state = .running
match key {
glfw.KEY_ESCAPE {
glfw.set_should_close(wnd, true)
}
glfw.key_space {
if game.state == .running {
game.state = .paused
} else if game.state == .paused {
game.state = .running
} else if game.state == .gameover {
game.init_game()
game.state = .running
}
}
}
if game.state != .running {
return
}
// keys while game is running
switch key {
case glfw.KeyUp:
match key {
glfw.KeyUp {
// Rotate the tetro
old_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.get_tetro()
}
if game.pos_x < 0 {
game.pos_x = 1
}
case glfw.KeyLeft:
}
glfw.KeyLeft {
game.move_right(-1)
case glfw.KeyRight:
}
glfw.KeyRight {
game.move_right(1)
case glfw.KeyDown:
}
glfw.KeyDown {
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 CoreVideo
// #flag darwin -framework IOKit
const (
pub const (
RESIZABLE = 1
DECORATED = 2
)
const (
pub const (
KEY_ESCAPE = 256
key_space = 32
KEY_LEFT_SUPER = 343
)
const (
pub const (
KeyUp = 265
KeyLeft = 263
KeyRight = 262