// Flappy bird: a background image, a bird image and pipes. Space or a click flaps, Escape quits. use gui, random struct Pipe { x = 0 gap = 0 } fun main() { width = 480 height = 640 window = new.window("Flappy comet", width, height) bird_y = 300.0 speed = 0.0 started = false score = 0 pipes = [Pipe(500, 260)] while (window.open()) { key = window.key() if (key == "escape") { break } if (key == "space" or window.mouse_down()) { speed = -6.5 started = true } if (started) { speed += 0.45 bird_y += speed for (pipe in pipes) { pipe.x -= 3 } if (pipes[-1].x < 260) { pipes.add(Pipe(500, random(120 to 400))) } if (pipes[0].x < -60) { pipes.pop(0) score += 1 } } window.clear() window.image("city.png", 0, 0, width, height) window.color("green") hit = bird_y < 0 or bird_y > height - 36 for (pipe in pipes) { window.rect(pipe.x, 0, 60, pipe.gap) window.rect(pipe.x, pipe.gap + 160, 60, height) if (pipe.x < 108 and pipe.x > 12 and (bird_y < pipe.gap or bird_y + 36 > pipe.gap + 160)) { hit = true } } window.image("bird.png", 60, bird_y, 48, 36) window.color("white") window.print("Score: {score}", 10, 10) if (not started) { window.print("Press space or tap to start", 120, 200) } if (hit) { window.alert("Game over! Score: {score}") break } window.sleep(0.02) } window.close() }