-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
86 lines (69 loc) · 2.35 KB
/
game.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//This is a pong game that scales (it need the other files from the github repo to work)
//Notation for the atom extension custom-folds to allow collapsing code.
//<editor-fold> Head (init the canvas, import functions and, setup functions)
//<editor-fold> Imports
//Import settings from settings.js
imported = document.createElement('script');
imported.src = './settings.js';
document.head.appendChild(imported);
delete imported;
//Import functions from pertersJSGameFunctionLibrary.js
imported = document.createElement('script');
imported.src = './petersJSGameFunctionLibrary.js';
document.head.appendChild(imported);
delete imported;
//Import functions from gameSpecificFunctions.js
imported = document.createElement('script');
imported.src = './gameSpecificFunctions.js';
document.head.appendChild(imported);
delete imported;
//Import aliases from aliases.js
imported = document.createElement('script');
imported.src = './aliases.js';
document.head.appendChild(imported);
delete imported;
//</editor-fold> Imports
//Definitions
const canvas = document.getElementById('gameCanvas');
const canvasContext = canvas.getContext('2d');
//Scaler
//Listen For Resize Event
window.addEventListener('resize', resizeCanvas, false);
//What to do on resize
function resizeCanvas() {
//Resize canvas to meet screen
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
//Call once to set canvas size on first load (does not loop)
resizeCanvas();
//</editor-fold> Head (init the canvas, import functions and, setup functions)
//<editor-fold> Init Vars
//<editor-fold> Ball
//Position
var ballX;
var ballY;
//Speed
var ballSpeed;
//</editor-fold> Ball
//<editor-fold> Paddles
//Paddles Sizes
var paddleHeight;
var paddleWidth
//Offset from edge
var paddleEdgeOffset
//Player (Paddle) positions
//Player one
var p1;
//Player two
var p2;
//</editor-fold> Paddles
//</editor-fold> Init Vars
//<editor-fold> Set starting variales
ballSpeed = 35;
//</editor-fold> Set starting variales
//Start Game
window.onload = function() {
resetGame();
setInterval(drawGameCanvas, 1000/*miliseconds*//framesPerSecond);
}