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

examples: avoid using go game.run() in Tetris

This commit is contained in:
Delyan Angelov 2021-12-21 16:54:26 +02:00
parent ade14491d4
commit 88435eb769
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -143,6 +143,9 @@ fn (mut game Game) showfps() {
}
fn frame(mut game Game) {
if game.gg.frame & 15 == 0 {
game.update_game_state()
}
ws := gg.window_size()
bs := remap(block_size, 0, win_height, 0, ws.height)
m := (f32(ws.width) - bs * field_width) * 0.5
@ -175,7 +178,6 @@ fn main() {
font_path: fpath // wait_events: true
)
game.init_game()
go game.run() // Run the game loop in a new thread
game.gg.run() // Run the render loop in the main thread
}
@ -210,15 +212,11 @@ fn (mut g Game) parse_tetros() {
}
}
fn (mut g Game) run() {
for {
fn (mut g Game) update_game_state() {
if g.state == .running {
g.move_tetro()
g.delete_completed_lines()
}
// glfw.post_empty_event() // force window redraw
time.sleep(timer_period * time.millisecond)
}
}
fn (g &Game) draw_ghost() {