3. Learning Outcomes
• Learn the main code needed to run a
browser-based game.
• Gain experience in rapid prototyping
a game to provide scalable challenge.
• BTEC: Unit 39: LO1.1 / 2.1 / 2.3
6. HTML Canvas (briefly)
<canvas id="gamebox" width=500
height=400></canvas>
gamebox = document.getElementById("gamebox");
ctx = gamebox.getContext("2d");
ctx.beginPath();
ctx.arc(x, y, 3, 0, 2 * Math.PI, false);
ctx.fillStyle = '#00DD00';
ctx.fill();
Get reference to do 2D drawing
Draw something
HTML element on the page
8. Call the Setup Function
// *** TODO: Perform level setup
levelSetup();
9. Starting a Main Game Loop
// *** TODO: Start game loop
intervalID = setInterval(update, 1000 / 16);
10. Starting a Main Game Loop
// *** TODO: Start game loop
intervalID = setInterval(update, 1000 / 16);
Built-in JavaScript
function
Function to act
as game loop
Interval between
game loops
Reference to the
timer
11. Stopping the Game Loop
// *** TODO: Stop the game loop
clearInterval(intervalID);