Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/space-invaders/assets/javascript/state/Play.js
1520 views
1
/**
2
* Created by stryker on 2014.03.22..
3
*/
4
define(['module/Background','module/Player','module/Aliens','module/Bullets','module/Explosions','module/HUD'],function(Background,Player,Aliens,Bullets,Explosions,HUD){
5
var _game = null,
6
_nextState = null;
7
8
var aliens = null;
9
10
//Playing State
11
var _Play = {
12
create: function(){
13
14
Background.create();
15
16
HUD.createStat(0,100,3);
17
18
//Setting up Player
19
var playerConfiguration = {
20
health: 100,
21
lives: 3,
22
score: 0,
23
firingTime: 300,
24
bulletSpeed: 500
25
};
26
27
Player.create(playerConfiguration);
28
Player.setBulletGroup(Bullets.create(10,'bullet',100));
29
Player.setExplosionGroup(Explosions.create(1,'kaboom'));
30
31
//Setting up Aliens
32
var alienConfiguration = {
33
rows:4,
34
cols:10,
35
scoreValue:10,
36
firingTime:200,
37
bulletSpeed:200,
38
health: 100,
39
easing: Phaser.Easing.Linear.None
40
};
41
42
aliens = Aliens.create(alienConfiguration);
43
aliens.setBulletGroup(Bullets.create(30,'enemyBullet',10));
44
aliens.setExplosionGroup(Explosions.create(5,'kaboom'));
45
Aliens.setPlayerShip(Player.getPlayerShip());
46
47
Player.setAliensAndAlienGroup(aliens);
48
49
//They start shoting, shooting is triggered by a time loop
50
Player.startShooting();
51
aliens.startShooting();
52
},
53
update: function(){
54
Background.update();
55
Player.update();
56
57
//Setting up the collision handling
58
aliens.createOverLap(Player.getBulletGroup());
59
Player.createOverLap(aliens.getBulletGroup());
60
}
61
}
62
63
return{
64
init: function(game,nextState){
65
_game = game;
66
_nextState = nextState;
67
},
68
getPlayState: function(){
69
return(_Play);
70
}
71
}
72
})
73