forked from benspector3/pong-asd
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
54 lines (37 loc) · 1.72 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* global $, sessionStorage */
$(document).ready(runProgram); // wait for the HTML / CSS elements of the page to fully load, then execute runProgram()
function runProgram(){
////////////////////////////////////////////////////////////////////////////////
//////////////////////////// SETUP /////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constant Variables
const FRAME_RATE = 60;
const FRAMES_PER_SECOND_INTERVAL = 1000 / FRAME_RATE;
// Game Item Objects
// one-time setup
let interval = setInterval(newFrame, FRAMES_PER_SECOND_INTERVAL); // execute newFrame every 0.0166 seconds (60 Frames per second)
$(document).on('eventType', handleEvent); // change 'eventType' to the type of event you want to handle
////////////////////////////////////////////////////////////////////////////////
///////////////////////// CORE LOGIC ///////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
On each "tick" of the timer, a new frame is dynamically drawn using JavaScript
by calling this function and executing the code inside.
*/
function newFrame() {
}
/*
Called in response to events.
*/
function handleEvent(event) {
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////// HELPER FUNCTIONS ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
function endGame() {
// stop the interval timer
clearInterval(interval);
// turn off event handlers
$(document).off();
}
}