From 1814a4fee3ea61fe50882195d15b5d8f9a6e89e9 Mon Sep 17 00:00:00 2001 From: Lilis Iskandar Date: Mon, 25 Mar 2024 10:45:02 +0800 Subject: [PATCH] Fix typo in README.md sdl.WaitEvent() example and remove usage of running variable Signed-off-by: Lilis Iskandar --- README.md | 60 ++++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index b01d4ed2..642cfefc 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,6 @@ const ( var ( playerX, playerY = int32(WIDTH / 2), int32(HEIGHT / 2) - running = true ) func main() { @@ -236,39 +235,36 @@ func main() { // Draw initial frame draw(window, surface) - for running { - for event := sdl.WaitEvent(); event != nil; event = sdl.PollEvent() { - switch t := event.(type) { - case sdl.QuitEvent: // NOTE: Please use `*sdl.QuitEvent` for `v0.4.x` (current version). - println("Quitting..") - running = false - break - case sdl.KeyboardEvent: - if t.State == sdl.RELEASED { - if t.Keysym.Sym == sdl.K_LEFT { - playerX -= 4 - } else if t.Keysym.Sym == sdl.K_RIGHT { - playerX += 4 - } - if t.Keysym.Sym == sdl.K_UP { - playerY -= 4 - } else if t.Keysym.Sym == sdl.K_DOWN { - playerY += 4 - } - if playerX < 0 { - playerX = WIDTH - } else if playerX > WIDTH { - playerX = 0 - } - if playerY < 0 { - playerY = HEIGHT - } else if playerY > HEIGHT { - playerY = 0 - } - draw(window, surface) + for event := sdl.WaitEvent(); event != nil; event = sdl.WaitEvent() { + switch t := event.(type) { + case sdl.QuitEvent: // NOTE: Please use `*sdl.QuitEvent` for `v0.4.x` (current version). + println("Quitting..") + return + case sdl.KeyboardEvent: + if t.State == sdl.RELEASED { + if t.Keysym.Sym == sdl.K_LEFT { + playerX -= 4 + } else if t.Keysym.Sym == sdl.K_RIGHT { + playerX += 4 } - break + if t.Keysym.Sym == sdl.K_UP { + playerY -= 4 + } else if t.Keysym.Sym == sdl.K_DOWN { + playerY += 4 + } + if playerX < 0 { + playerX = WIDTH + } else if playerX > WIDTH { + playerX = 0 + } + if playerY < 0 { + playerY = HEIGHT + } else if playerY > HEIGHT { + playerY = 0 + } + draw(window, surface) } + break } } }