@@ -4,7 +4,7 @@ var MEDIA_PATH = staticurl + '/media/';
4
4
var snippeteditor ;
5
5
var gamecontainer ;
6
6
var firstColorError = true ;
7
- var Vectoroids ;
7
+ var SpaceGame ;
8
8
9
9
$ ( document ) . ready ( function ( ) {
10
10
@@ -14,11 +14,11 @@ $(document).ready( function() {
14
14
// Toggle game when editing
15
15
16
16
snippeteditor . on ( 'focus' , function ( ) {
17
- if ( Vectoroids ) Vectoroids . stop ( ) ;
17
+ if ( SpaceGame ) SpaceGame . stop ( ) ;
18
18
} ) ;
19
19
20
20
snippeteditor . on ( 'blur' , function ( ) {
21
- if ( Vectoroids ) Vectoroids . start ( ) ;
21
+ if ( SpaceGame ) SpaceGame . start ( ) ;
22
22
} ) ;
23
23
24
24
$ ( "#closepanel" ) . click ( function ( ) {
@@ -40,10 +40,10 @@ $(document).ready( function() {
40
40
41
41
// Initialize game
42
42
GameCode . container = gamecontainer . get ( 0 ) ;
43
- Vectoroids = Game2D . create ( GameCode ) ;
43
+ SpaceGame = Game2D . create ( GameCode ) ;
44
44
45
45
configureEditor ( {
46
- target : 'Vectoroids ' ,
46
+ target : 'SpaceGame ' ,
47
47
comment : 'Try changing the variables below and see how they affect the game' ,
48
48
props : [
49
49
'projectileColor' ,
@@ -55,13 +55,13 @@ $(document).ready( function() {
55
55
'fillShapes'
56
56
]
57
57
} , {
58
- target : 'Vectoroids .ship' ,
58
+ target : 'SpaceGame .ship' ,
59
59
comment : 'The 3 letter name for your ship and high scores' ,
60
60
props : [
61
61
'name'
62
62
]
63
63
} , {
64
- target : 'Vectoroids .ship' ,
64
+ target : 'SpaceGame .ship' ,
65
65
comment : 'Ship properties' ,
66
66
props : [
67
67
'speed' ,
@@ -85,7 +85,7 @@ var closeTools = function() {
85
85
86
86
// Ensure the game knows about dimension changes
87
87
setTimeout ( function ( ) {
88
- Vectoroids . __resize ( ) ;
88
+ SpaceGame . __resize ( ) ;
89
89
} , 500 ) ;
90
90
} ;
91
91
@@ -96,7 +96,7 @@ var openTools = function() {
96
96
97
97
// Ensure the game knows about dimension changes
98
98
setTimeout ( function ( ) {
99
- Vectoroids . __resize ( ) ;
99
+ SpaceGame . __resize ( ) ;
100
100
} , 500 ) ;
101
101
} ;
102
102
@@ -152,16 +152,16 @@ var configureEditor = function() {
152
152
} ;
153
153
154
154
/*
155
- Coder.loadData( 'vectoroids :data', function( result ) {
155
+ Coder.loadData( 'spacegame :data', function( result ) {
156
156
157
157
if ( result && result.data ) {
158
158
159
159
console.log( 'LOAD DATA', result );
160
160
161
- Vectoroids .data = JSON.parse( result.data );
161
+ SpaceGame .data = JSON.parse( result.data );
162
162
163
- if ( Vectoroids .data.code && Vectoroids .data.code !== snippeteditor.getValue() ) {
164
- snippeteditor.setValue( Vectoroids .data.code );
163
+ if ( SpaceGame .data.code && SpaceGame .data.code !== snippeteditor.getValue() ) {
164
+ snippeteditor.setValue( SpaceGame .data.code );
165
165
snippeteditor.gotoLine(1);
166
166
}
167
167
}
@@ -172,12 +172,12 @@ var configureEditor = function() {
172
172
173
173
var saveCode = function ( ) {
174
174
175
- Vectoroids . data . code = snippeteditor . getValue ( ) ;
176
- var data = JSON . stringify ( Vectoroids . data ) ;
175
+ SpaceGame . data . code = snippeteditor . getValue ( ) ;
176
+ var data = JSON . stringify ( SpaceGame . data ) ;
177
177
178
178
/*
179
- Coder.saveData( 'vectoroids :data', data, function() {
180
- console.log( 'SAVE DATA', 'vectoroids :data', +new Date, data );
179
+ Coder.saveData( 'spacegame :data', data, function() {
180
+ console.log( 'SAVE DATA', 'spacegame :data', +new Date, data );
181
181
});
182
182
*/
183
183
} ;
@@ -187,8 +187,8 @@ var configureEditor = function() {
187
187
try {
188
188
189
189
eval ( snippeteditor . getValue ( ) ) ;
190
- Vectoroids . clear ( ) ;
191
- Vectoroids . draw ( ) ;
190
+ SpaceGame . clear ( ) ;
191
+ SpaceGame . draw ( ) ;
192
192
193
193
clearTimeout ( saveTimeout ) ;
194
194
saveTimeout = setTimeout ( saveCode , 1500 ) ;
@@ -257,7 +257,7 @@ var Entity = Polygon.extend({
257
257
}
258
258
} ) ;
259
259
260
- var Vectoroid = Entity . extend ( {
260
+ var Asteroid = Entity . extend ( {
261
261
262
262
init : function ( generation ) {
263
263
@@ -292,8 +292,8 @@ var Vectoroid = Entity.extend({
292
292
293
293
split : function ( ) {
294
294
295
- var child1 = new Vectoroid ( this . generation + 1 ) ;
296
- var child2 = new Vectoroid ( this . generation + 1 ) ;
295
+ var child1 = new Asteroid ( this . generation + 1 ) ;
296
+ var child2 = new Asteroid ( this . generation + 1 ) ;
297
297
298
298
child1 . translate ( this . center ) ;
299
299
child2 . translate ( this . center ) ;
@@ -501,9 +501,9 @@ var STATES = {
501
501
} ;
502
502
503
503
var SOUNDS = {
504
- DESTROY_VECTOROID : new Sound ( MEDIA_PATH + 'die_vectoroid .mp3' ) ,
504
+ DESTROY_VECTOROID : new Sound ( MEDIA_PATH + 'die_asteroid .mp3' ) ,
505
505
DESTROY_SHIP : new Sound ( MEDIA_PATH + 'die_ship.mp3' ) ,
506
- SHOOT : new Sound ( MEDIA_PATH + 'vectoroids_shoot .mp3' ) ,
506
+ SHOOT : new Sound ( MEDIA_PATH + 'asteroids_shoot .mp3' ) ,
507
507
THRUST : new Loop ( MEDIA_PATH + 'thrust.mp3' ) ,
508
508
509
509
stop : function ( ) {
@@ -536,11 +536,11 @@ var GameCode = {
536
536
fillShapes : true ,
537
537
lineThickness : 2 ,
538
538
539
- minVectoroids : 10 ,
539
+ minAsteroids : 10 ,
540
540
projectileSpeed : 400 ,
541
541
maxProjectiles : 10 ,
542
542
projectiles : [ ] ,
543
- vectoroids : [ ] ,
543
+ asteroids : [ ] ,
544
544
canFire : true ,
545
545
state : '' ,
546
546
score : 0 ,
@@ -560,7 +560,7 @@ var GameCode = {
560
560
561
561
this . lives = 3 ;
562
562
this . score = 0 ;
563
- this . vectoroids = [ ] ;
563
+ this . asteroids = [ ] ;
564
564
this . projectiles = [ ] ;
565
565
566
566
this . resetShip ( ) ;
@@ -592,7 +592,7 @@ var GameCode = {
592
592
593
593
case STATES . INTRO :
594
594
595
- $ ( '.title' ) . text ( 'Vectoroids ' ) ;
595
+ $ ( '.title' ) . text ( 'Space Game! ' ) ;
596
596
$ ( '.start' ) . text ( 'Start Game' ) ;
597
597
this . getScores ( ) ;
598
598
@@ -636,7 +636,7 @@ var GameCode = {
636
636
me . showScores ( ) ;
637
637
638
638
/*
639
- Coder.loadData( 'vectoroids :data', function( result ) {
639
+ Coder.loadData( 'spacegame :data', function( result ) {
640
640
641
641
if ( typeof result.data !== 'undefined' && result.data != null && result.data != "" ) {
642
642
me.data = JSON.parse(result.data);
@@ -662,8 +662,8 @@ var GameCode = {
662
662
663
663
var data = JSON . stringify ( this . data ) ;
664
664
/*
665
- Coder.saveData( 'vectoroids :data', data, function() {
666
- console.log( 'saved data', 'vectoroids :data', +new Date, data );
665
+ Coder.saveData( 'spacegame :data', data, function() {
666
+ console.log( 'saved data', 'spacegame :data', +new Date, data );
667
667
});
668
668
*/
669
669
} ,
@@ -699,52 +699,52 @@ var GameCode = {
699
699
} , 1500 ) ;
700
700
} ,
701
701
702
- createVectoroid : function ( ) {
702
+ createAsteroid : function ( ) {
703
703
704
- var vectoroid = new Vectoroid ( ) ;
704
+ var asteroid = new Asteroid ( ) ;
705
705
706
706
var x = random ( this . width * 0.25 ) ;
707
707
var y = random ( this . height * 0.25 ) ;
708
708
709
709
if ( chance ( ) ) x = this . width - x ;
710
710
if ( chance ( ) ) y = this . height - y ;
711
711
712
- vectoroid . translate ( new Vector ( x , y ) ) ;
713
- this . vectoroids . push ( vectoroid ) ;
712
+ asteroid . translate ( new Vector ( x , y ) ) ;
713
+ this . asteroids . push ( asteroid ) ;
714
714
} ,
715
715
716
- destroyVectoroid : function ( vectoroid ) {
716
+ destroyAsteroid : function ( asteroid ) {
717
717
718
718
SOUNDS . DESTROY_VECTOROID . play ( ) ;
719
719
720
- var index = this . vectoroids . indexOf ( vectoroid ) ;
720
+ var index = this . asteroids . indexOf ( asteroid ) ;
721
721
722
722
if ( index > - 1 ) {
723
723
724
- this . vectoroids . splice ( index , 1 ) ;
724
+ this . asteroids . splice ( index , 1 ) ;
725
725
726
- if ( vectoroid . generation < 3 ) {
727
- this . vectoroids = this . vectoroids . concat ( vectoroid . split ( ) ) ;
726
+ if ( asteroid . generation < 3 ) {
727
+ this . asteroids = this . asteroids . concat ( asteroid . split ( ) ) ;
728
728
}
729
729
}
730
730
} ,
731
731
732
732
update : function ( ) {
733
733
734
734
var dtSeconds = this . dt / 1000 ;
735
- var i , j , n , m , vectoroid , projectile ;
735
+ var i , j , n , m , asteroid , projectile ;
736
736
737
- // Update vectoroids
737
+ // Update asteroids
738
738
739
- while ( this . vectoroids . length < this . minVectoroids ) {
740
- this . createVectoroid ( ) ;
739
+ while ( this . asteroids . length < this . minAsteroids ) {
740
+ this . createAsteroid ( ) ;
741
741
}
742
742
743
- for ( i = 0 , n = this . vectoroids . length ; i < n ; i ++ ) {
743
+ for ( i = 0 , n = this . asteroids . length ; i < n ; i ++ ) {
744
744
745
- vectoroid = this . vectoroids [ i ] ;
746
- vectoroid . wrap ( 0 , 0 , this . width , this . height ) ;
747
- vectoroid . update ( dtSeconds ) ;
745
+ asteroid = this . asteroids [ i ] ;
746
+ asteroid . wrap ( 0 , 0 , this . width , this . height ) ;
747
+ asteroid . update ( dtSeconds ) ;
748
748
}
749
749
750
750
// Update projectiles
@@ -815,50 +815,50 @@ var GameCode = {
815
815
draw : function ( ) {
816
816
817
817
var shipColor = this . shipColor ;
818
- var i , j , n , m , color , vectoroid , projectile , child1 , child2 ;
818
+ var i , j , n , m , color , asteroid , projectile , child1 , child2 ;
819
819
820
820
this . container . style . backgroundColor = this . backgroundColor ;
821
821
this . container . style . color = this . textColor ;
822
822
823
- // Draw vectoroids
823
+ // Draw asteroids
824
824
825
825
this . graphics . lineWidth = min ( 10 , max ( 0 , abs ( this . lineThickness ) ) ) ;
826
826
this . graphics . globalCompositeOperation = 'lighter' ;
827
827
828
- for ( i = 0 , n = this . vectoroids . length ; i < n ; i ++ ) {
828
+ for ( i = 0 , n = this . asteroids . length ; i < n ; i ++ ) {
829
829
830
- vectoroid = this . vectoroids [ i ] ;
830
+ asteroid = this . asteroids [ i ] ;
831
831
832
- color = this . enemyColors [ vectoroid . seed * this . enemyColors . length | 0 ] ;
832
+ color = this . enemyColors [ asteroid . seed * this . enemyColors . length | 0 ] ;
833
833
834
834
this . graphics . strokeStyle = color ;
835
835
this . graphics . fillStyle = color ;
836
836
837
- // Check for vectoroid -projectile collision
837
+ // Check for asteroid -projectile collision
838
838
839
839
for ( j = 0 , m = this . projectiles . length ; j < m ; j ++ ) {
840
840
841
841
projectile = this . projectiles [ j ] ;
842
842
843
- // If projectile is hitting vectoroid
843
+ // If projectile is hitting asteroid
844
844
845
- if ( vectoroid . contains ( projectile . vertices [ 0 ] ) ) {
845
+ if ( asteroid . contains ( projectile . vertices [ 0 ] ) ) {
846
846
847
847
this . score += 20 ;
848
848
849
849
this . projectiles . splice ( j , 1 ) ;
850
- this . destroyVectoroid ( vectoroid ) ;
850
+ this . destroyAsteroid ( asteroid ) ;
851
851
852
- n = this . vectoroids . length ;
852
+ n = this . asteroids . length ;
853
853
m = this . projectiles . length ;
854
854
855
855
break ;
856
856
}
857
857
}
858
858
859
- // Check for vectoroid -ship collision
859
+ // Check for asteroid -ship collision
860
860
861
- if ( ! this . ship . invincible && this . ship . intersects ( vectoroid ) ) {
861
+ if ( ! this . ship . invincible && this . ship . intersects ( asteroid ) ) {
862
862
863
863
if ( this . lives <= 1 ) {
864
864
@@ -868,15 +868,15 @@ var GameCode = {
868
868
869
869
SOUNDS . DESTROY_SHIP . play ( ) ;
870
870
871
- this . destroyVectoroid ( vectoroid ) ;
872
- n = this . vectoroids . length ;
871
+ this . destroyAsteroid ( asteroid ) ;
872
+ n = this . asteroids . length ;
873
873
874
874
this . resetShip ( ) ;
875
875
this . lives -- ;
876
876
}
877
877
}
878
878
879
- vectoroid . draw ( this . graphics ) ;
879
+ asteroid . draw ( this . graphics ) ;
880
880
881
881
if ( this . fillShapes ) {
882
882
this . graphics . globalAlpha = 0.5 ;
@@ -890,7 +890,7 @@ var GameCode = {
890
890
891
891
if ( this . drawBounds ) {
892
892
893
- vectoroid . drawBounds ( this . graphics ) ;
893
+ asteroid . drawBounds ( this . graphics ) ;
894
894
this . graphics . globalAlpha = 0.5 ;
895
895
this . graphics . stroke ( ) ;
896
896
}
0 commit comments