-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathShip.js
executable file
·139 lines (104 loc) · 2.93 KB
/
Ship.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
dojo.provide("Ship");
dojo.declare("Ship", [Container],{
TOGGLE: 6,
canvasHeight : 480,
canvasWidth : 640,
currentLane:1,
numberOfLanes:3,
speed:0,
engineVolume: .1,
hitRadius:0,
constructor:function(args) {
//Container Object to hold Ship and it's flame.
//dojo.safeMixin(this,new Container());
//Take arguments and mix them in.
dojo.safeMixin(this, args);
this.shipFlame = new Shape();
this.shipBody = new Shape();
this.addChild(this.shipFlame);
this.addChild(this.shipBody);
// 5% of the width, divided by the default 40x10
this.makeShape();
this.timeout = 0;
this.thrust = 0;
this.vX = 0;
this.vY = 0;
this.scaleX = (this.canvasWidth*0.1)/40;
this.scaleY = (this.canvasHeight*0.1)/30;
this.bigScalar = Math.max(this.scaleX,this.scaleY)
this.bounds = 20*this.bigScalar;
},
makeShape:function() {
//draw ship body
var g = this.shipBody.graphics;
g.clear();
g.setStrokeStyle(1,"round").beginStroke("#FFFFFF");
g.beginFill("#00F");
g.moveTo(0, 20); //nose
g.lineTo(10, -12); //rfin
g.lineTo(0, -4); //notch
g.lineTo(-10, -12); //lfin
g.closePath(); //nose
//draw ship flame
var o = this.shipFlame;
o.y = -7;
g = o.graphics;
g.clear();
g.setStrokeStyle(1,"round").beginStroke("#F60");
g.beginFill("#F00");
g.moveTo(0, 1); //ship
g.lineTo(2, -1.5); //rpoint
g.lineTo(1, -1); //rnotch
g.lineTo(0, -2.5); //tip
g.lineTo(-1, -1); //lnotch
g.lineTo(-2, -1.5); //lpoint
g.closePath(); //ship
this.rotation = 180;
},
tick : function() {
this.timeout++;
this.shipFlame.alpha = 1;
if (this.timeout > this.TOGGLE) {
this.timeout = 0;
if (this.shipFlame.scaleX == this.scaleX) {
this.shipFlame.scaleX = this.scaleX*0.5;
this.shipFlame.scaleY = this.scaleY*0.5;
}
else {
this.shipFlame.scaleX = this.scaleX;
this.shipFlame.scaleY = this.scaleY;
}
}
},
moveLeft: function(){
if(this.currentLane > 0){
this.x = (this.canvasWidth / this.numberOfLanes)*(this.currentLane-1) + (this.canvasWidth / (this.numberOfLanes*2));
this.y = (this.canvasHeight - this.bounds - 10);
this.currentLane--;
}
},
moveRight: function(){
if (this.currentLane < this.numberOfLanes - 1) {
this.x = (this.canvasWidth / this.numberOfLanes) * (this.currentLane + 1) + (this.canvasWidth / (this.numberOfLanes * 2));
this.y = (this.canvasHeight - this.bounds - 10);
this.currentLane++;
}
},
reset:function(){
this.x = (this.canvasWidth / this.numberOfLanes) * (Math.floor(this.numberOfLanes/2)) + (this.canvasWidth / (this.numberOfLanes * 2));
this.y = (this.canvasHeight - this.bounds - 10);
this.speed = 0;
},
accelerate : function() {
if (this.speed < 6) {
this.speed += 1;
this.engineVolume = .05+.2*(this.speed/10);
}
},
deccelerate : function() {
if (this.speed > 0) {
this.speed -= 1;
this.engineVolume = .05 + .2 * (this.speed / 10);
}
}
});