-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.js
114 lines (113 loc) · 9.31 KB
/
constants.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
export const DISTANCE_BETWEEN_PELLETS = 5;
export const PIXEL_SIZE = 3;
export const WIDTH = 28;
export const HEIGHT = 31;
export const SIZE_OF_PELLET = 6;
export const GRID_SQUARE_SIZE = DISTANCE_BETWEEN_PELLETS * SIZE_OF_PELLET;
export const LEFT = 37; //keyboard codes
export const UP = 38;
export const RIGHT = 39;
export const DOWN = 40;
export const REF_SPEED = 0.10;
export const FRUIT_POS = [13, 16.5];
export const numbers = [function(xPixels, yPixels, letterPixel, leftHandJust, ctx) {
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel, 3*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, 5*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 4*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, 5*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 6*letterPixel, 3*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 4*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 2*letterPixel, yPixels*letterPixel + 3*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 3*letterPixel, yPixels*letterPixel + 2*letterPixel, letterPixel, letterPixel);
},
function(xPixels, yPixels, letterPixel, leftHandJust, ctx) {
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 2*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 2*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 3*letterPixel, yPixels*letterPixel, letterPixel, 7*letterPixel);
},
function(xPixels, yPixels, letterPixel, leftHandJust, ctx) {
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel, 3*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 4*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, 2*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 3*letterPixel, yPixels*letterPixel + 3*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 2*letterPixel, yPixels*letterPixel + 4*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 5*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + 6*letterPixel, 5*letterPixel, letterPixel);
},
function(xPixels, yPixels, letterPixel, leftHandJust, ctx) {
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel, 3*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel , yPixels*letterPixel + letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 4*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, 2*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 2*letterPixel, yPixels*letterPixel + 3*letterPixel, 2*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 4*letterPixel, yPixels*letterPixel + 4*letterPixel, letterPixel, 2*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 6*letterPixel, 3*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel , yPixels*letterPixel + 5*letterPixel, letterPixel, letterPixel);
},
function(xPixels, yPixels, letterPixel, leftHandJust, ctx) {
ctx.fillRect(leftHandJust + xPixels*letterPixel + 3*letterPixel, yPixels*letterPixel, letterPixel, 7*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 2*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 2*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + 3*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + 4*letterPixel, 5*letterPixel, letterPixel);
},
function(xPixels, yPixels, letterPixel, leftHandJust, ctx) {
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel, 5*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + 2*letterPixel, 4*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 4*letterPixel, yPixels*letterPixel + 3*letterPixel, letterPixel, 3*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + 5*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 6*letterPixel, 3*letterPixel, letterPixel);
},
function(xPixels, yPixels, letterPixel, leftHandJust, ctx) {
ctx.fillRect(leftHandJust + xPixels*letterPixel + 2*letterPixel, yPixels*letterPixel, 2*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + 2*letterPixel, 4*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + 3*letterPixel, letterPixel, 3*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 4*letterPixel, yPixels*letterPixel + 3*letterPixel, letterPixel, 3*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 6*letterPixel, 3*letterPixel, letterPixel);
},
function(xPixels, yPixels, letterPixel, leftHandJust, ctx) {
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel, 5*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 4*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, 2*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 3*letterPixel, yPixels*letterPixel + 3*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 2*letterPixel, yPixels*letterPixel + 4*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 5*letterPixel, letterPixel, 2*letterPixel);
},
function(xPixels, yPixels, letterPixel, leftHandJust, ctx) {
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel, 3*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, 2*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 3*letterPixel, 3*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 4*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, 2*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 6*letterPixel, 3*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + 4*letterPixel, letterPixel, 2*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 4*letterPixel, yPixels*letterPixel + 4*letterPixel, letterPixel, 2*letterPixel);
},
function(xPixels, yPixels, letterPixel, leftHandJust, ctx) {
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel, 3*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, 3*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 4*letterPixel, 4*letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 4*letterPixel, yPixels*letterPixel + letterPixel, letterPixel, 3*letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + 3*letterPixel, yPixels*letterPixel + 5*letterPixel, letterPixel, letterPixel);
ctx.fillRect(leftHandJust + xPixels*letterPixel + letterPixel, yPixels*letterPixel + 6*letterPixel, 2*letterPixel, letterPixel);
}]
export function drawBasedOnPixels(arr, left, top, colour) {
let canvas = document.getElementById("main");
let ctx = canvas.getContext("2d");
ctx.fillStyle = colour;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (arr[i][j] === 1) {
ctx.fillRect(left + j*PIXEL_SIZE, top + i*PIXEL_SIZE, PIXEL_SIZE, PIXEL_SIZE);
}
}
}
}
//change path in function of path
export const beginningMusic = new Audio("./assets/pacman_beginning.wav");
export const chompMusic1 = new Audio("./assets/pacman_chomp1.mp3");
export const chompMusic2 = new Audio("./assets/pacman_chomp2.mp3");
export const deathMusic = new Audio("./assets/pacman_death.wav");
export const fruitMusic = new Audio("./assets/pacman_eatfruit.wav");
export const eatGhostMusic = new Audio("./assets/pacman_eatghost.wav");
export const extraLifeMusic = new Audio("./assets/pacman_extrapac.wav");
export const powerPellet = new Audio("./assets/pacman_powerpellet.mp3");
export const scaredGhost = new Audio("./assets/pacman_scaredghost.mp3");