-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_data.js
executable file
Β·149 lines (143 loc) Β· 3.6 KB
/
1_data.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Any data that you need to access/manipulate throughout the program
* must be declared outside of a function
*
* Data which is not meant to change is "constant"
* aka const
* conventionally constant names are UPPERCASE
*/
const CANVAS_WIDTH = 630
const CANVAS_HEIGHT = 630
const BALL_SPEED = 4 // pixels per frame
const BALL_SPEED_INCREMENT = 0.8 // every time the ball hits a paddle, it speeds up
const BALL_SPEED_DECREMENT = 0.2 // every time the ball hits a wall, it slows down
const PADDLE_SIZE = 5 // how many squares is a paddle
const PADDLE_MOVEMENT = 7 // how many pixels per frame do paddles move
const SWING_FACTOR = 0.4 // the ball will bounce off paddles at an angle, the further from the paddle centre the bigger the angle
// emojis from https://github.com/iamcal/emoji-data
// emoji "coordinates" at https://unicodey.com/emoji-data/table.htm
const SPRITE_SHEET = 'assets/sheet_twitter_20_indexed_256.png'
const EMOJI_SIZE = 20
const EMOJI_FRAMES =
[
{
name: 'newspaper',
frame:
{
x: 18*EMOJI_SIZE,
y: 48*EMOJI_SIZE,
width: EMOJI_SIZE,
height: EMOJI_SIZE
}
},
{
name: 'rose',
frame:
{
x: 5*EMOJI_SIZE,
y: 39*EMOJI_SIZE,
width: EMOJI_SIZE,
height: EMOJI_SIZE
}
},
{
name: 'oak',
frame:
{
x: 5*EMOJI_SIZE,
y: 33*EMOJI_SIZE,
width: EMOJI_SIZE,
height: EMOJI_SIZE
}
},
{
name: 'globe',
frame:
{
x: 4*EMOJI_SIZE,
y: 46*EMOJI_SIZE,
width: EMOJI_SIZE,
height: EMOJI_SIZE
}
},
{
name: 'dove',
frame:
{
x: 20*EMOJI_SIZE,
y: 28*EMOJI_SIZE,
width: EMOJI_SIZE,
height: EMOJI_SIZE
}
},
{
name: 'toxic',
frame:
{
x: 1*EMOJI_SIZE,
y: 10*EMOJI_SIZE,
width: EMOJI_SIZE,
height: EMOJI_SIZE
}
}
]
/**
* Data that changes while the program runs is "variable"
* aka var
*/
var canvas = null // the canvas for the whole game
var swing = 0 // the angle at which the ball will take when bouncing off paddles
var spritesheets = {} // an object to collect all the spritesheets (images)
var sprites = // an object to collect all the sprites (ie the game pieces)
{
ball: {},
paddles: {}, // there will be 4 paddles
walls: {} // there will be 4 walls
}
var players = // an object with data for each player
{
left:
{
nickname: 'Labour',
isPlaying: false,
score: 13,
controlUp: 'a',
controlDown: 'x',
emoji: 'rose',
direction: 'vertical',
color: 'rgba(255, 0, 0, 0.7)',
},
right:
{
nickname: 'Tory',
score: 16,
isPlaying: false,
controlUp: 38, // UP_ARROW
controlDown: 40, // DOWN_ARROW
emoji: 'oak',
direction: 'vertical',
color: 'rgba(0, 0, 255, 0.7)'
},
top:
{
nickname: 'Green',
score: 1,
isPlaying: false,
controlLeft: '9',
controlRight: '0',
emoji: 'globe',
direction: 'horizontal',
color: 'rgba(0, 255, 0, 0.7)'
},
bottom:
{
nickname: 'Lib-Dem',
score: 2,
isPlaying: false,
controlLeft: 'b',
controlRight: 'm',
emoji: 'dove',
direction: 'horizontal',
color: 'rgba(255, 255, 0, 0.7)'
}
}