; [[World _vtable] methodAt: 'tickEvent put: (lambda () 0) with: 0] ; [editor fontSize: '20] ; (define CompilerOptions (import "CompilerOptions")) ; [CompilerOptions verboseSyntax: false] (define World (import "WorldView")) (load "bunnu.k") { bunnu-program } // -------------------- Bunnu Tennis Game -------------------- // // Print functions editor.replace = function(start, size, string) { #[editor replaceFrom: start size: size with: string]; }; var showChar = function(x, y, string) { var offset = #[editor getOffset: [x, y]]; var length = string.size(); editor.replace(offset, length, string); }; // Initialization var width = 20; var height = 16; var ballX = 10; var ballY = 2; var ballDX = 1; var ballDY = 1; var playerX = 10; var playerY = height - 1; var playerXNext = 10; var timer = 0; var init = function() { for (y = 0; y < height; y = y + 1) { editor.replace(0, 0, "....................\n"); } }; init(); // Main Loop var tick = function (display) { showChar(ballX, ballY, "."); showChar(playerX, playerY, "..."); if ((ballX <= 0) || (width - 1 <= ballX)) ballDX = 0 - ballDX; if (ballY <= 0) ballDY = 0 - ballDY; if (height - 1 <= ballY) ballDY = 0 - ballDY; ballX = ballX + ballDX; ballY = ballY + ballDY; playerX = playerXNext; showChar(ballX, ballY, "O"); showChar(playerX, height - 1, "==="); }; // Event Handlers editor.pointerMotionEvent = function(event) { var x = (event.localPosition().x() / 10).asInteger(); if ((0 <= x) && (x <= (width - 3))) playerXNext = x; }; World.tickEvent = function() { timer = timer + 1; if ((timer % 2) == 0) tick(); };