-
Notifications
You must be signed in to change notification settings - Fork 3
/
Obstacle.js
75 lines (50 loc) · 1.39 KB
/
Obstacle.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
dojo.provide("Obstacle");
dojo.declare("Obstacle", [Container],{
canvasHeight : 480,
canvasWidth : 640,
lane:1,
hitRadius:0,
speedIncrement:1,
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.outerBox = new Shape();
this.innerBox = new Shape();
this.addChild(this.outerBox);
this.addChild(this.innerBox);
// 5% of the width, divided by the default 40x10
this.makeShape();
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 body
var g = this.outerBox.graphics;
g.clear();
g.setStrokeStyle(1,"round").beginStroke("#FFFFFF");
g.beginFill("#F66");
g.moveTo(20, 20); //nose
g.lineTo(20, -20); //rfin
g.lineTo(-20, -20); //notch
g.lineTo(-20, 20); //lfin
g.closePath();
//draw inner box
var o = this.innerBox;
g = o.graphics;
g.clear();
g.setStrokeStyle(1,"round").beginStroke("#F60");
g.beginFill("#F00");
g.moveTo(17, 17); //nose
g.lineTo(17, -17); //rfin
g.lineTo(-17, -17); //notch
g.lineTo(-17, 17); //lfin
g.closePath();
},
tick : function() {
this.rotation = (this.rotation + 2)%360;
}
});