-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
149 lines (121 loc) · 2.88 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
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
var TOP_ROW = 0; // reminder to self: top row coordinate is 0
var BG_COLOR = 0x000000; // background color
var ROCKET_COLOR = 0xF70000; // rocket color
var FireX = new Array();
var FireY = new Array();
PS.Init = function ( options )
{
"use strict";
var y;
// 30 x 30 grid
PS.GridSize( 30, 30 );
//The drag effect behind the rocket bead up to the grid's height of 30
for ( y = 0; y < 30; y += 1 )
{
// turning the flash true to create trail effect
PS.BeadFlash( PS.ALL, y, true );
PS.BeadFlashColor(PS.ALL, y, ROCKET_COLOR);
}
PS.GridBGColor( BG_COLOR );
PS.BeadBorderWidth( PS.ALL, PS.ALL, 0 );
// load audio files
PS.AudioLoad( "fx_gun" );
PS.AudioLoad( "fx_bomb1" );
// Set color and text of title
PS.StatusColor( 0xFFFF66 );
PS.StatusText( "Rocketeer!" );
PS.Clock(6);
};
PS.Click = function ( x, y, data, options )
{
"use strict";
// Adding x & y position of rocket drag to the animation list
FireX.push( x );
FireY.push( y );
// Beginning trail of rocket
if ( y > TOP_ROW )
{
PS.BeadColor( x, y, ROCKET_COLOR ); // set the color for rocket
PS.AudioPlay( "fx_gun" ); // play for the fire shooting off sound
}
// Rocket explodes/ends
else
{
PS.BeadColor( x, y, BG_COLOR );
PS.AudioPlay( "fx_bomb1" ); // BOOM!
}
};
PS.Tick = function ( options )
{
"use strict";
var length;
var i = 0;
var x;
var y;
// The length of the FireX array is the current number of rockets to fire
length = FireX.length;
// loop through each active rocket
while ( i < length )
{
// get current position of the rocket
x = FireX[i];
y = FireY[i];
// if bead is below top row, erase it and re-draw one bead lower
if ( y > TOP_ROW )
{
// erase the existing rocket
PS.BeadColor( x, y, BG_COLOR );
// subtract 1 from y position
y--;
// update the y position in the array
FireY[i] = y;
// This helps define if the rocket has reached the top row yet
if ( y > TOP_ROW )
{
// Repaint the rocket one bead lower
PS.BeadColor( x, y, ROCKET_COLOR );
}
// Reaching the top to explode
else
{
PS.BeadColor( x, y, BG_COLOR );
PS.AudioPlay( "fx_bomb1" ); //BOOM!
}
// point index to next fire
i++;
}
// Bead is on last row
else
{
// Remove this rocket from x/y arrays
FireX.splice( i, 1 );
FireY.splice( i, 1 );
// Updating array length variable
length--;
}
}
};
PS.Release = function (x, y, data, options)
{
"use strict";
};
PS.Enter = function (x, y, data, options)
{
"use strict";
};
PS.Leave = function (x, y, data, options)
{
"use strict";
};
PS.KeyDown = function (key, shift, ctrl, options)
{
"use strict";
};
PS.KeyUp = function (key, shift, ctrl, options)
{
"use strict";
};
PS.Wheel = function (delta, options)
{
"use strict";
};