File size: 3,529 Bytes
4b876a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
function AlienPlatform(id,x,y, center,orientation) {
	this.orientation = orientation;
	var halfWidth, halfHeight;
	if (orientation=="horizontal") {
		halfWidth = 1.0;
		halfHeight = 0.32;
	}
	else if (orientation=="vertical") {
		halfWidth = 0.32;
		halfHeight = 1.0;
	}
	RectangleEntity.call(this, id,x,y, center, "green",halfWidth, halfHeight, false);
	this.generalColor = "#E81F78";
	this.upColor = "#1FE82A";

	this.frames = new Array();
	this.frames[0]="#1FDDE8";
	this.frames[1] ="#1FE82A";
	this.frames[2] = "#E81F78";
	this.currentFrame = 0;
	this.interval = 30;
	this.currentInterval = 0;
	this.type = 'alienPlatform';

}

AlienPlatform.prototype = new RectangleEntity();
AlienPlatform.prototype.constructor = AlienPlatform;

AlienPlatform.prototype.draw = function(ctx) {
	ctx.translate(this.x * SCALE, this.y * SCALE);
	ctx.rotate(this.angle);
	ctx.translate(-(this.x) * SCALE, -(this.y) * SCALE);

	ctx.fillStyle = this.generalColor;
	ctx.fillRect((this.x-this.halfWidth) * SCALE,
				(this.y-this.halfHeight) * SCALE,
				(this.halfWidth*2) * SCALE,
				(this.halfHeight*2) * SCALE);

	ctx.strokeStyle = this.upColor;
	ctx.lineWidth = 5;

	ctx.strokeRect( (this.x-this.halfWidth) * SCALE+2.5,
		(this.y-this.halfHeight) * SCALE+2.5,
		(this.halfWidth*2) * SCALE-2.5,
		(this.halfHeight*2) * SCALE-2.5);
	if (!theGame.mobile) {
		this.drawDecoration(ctx);
	}
}

AlienPlatform.prototype.drawDecoration = function(ctx) {
	if (this.currentInterval == this.interval) {
		this.currentInterval = 0;
		this.currentFrame++;
	}

	this.currentInterval++;

	//if at the end of the frame cycle then go back to 0
	if (this.currentFrame == this.frames.length) {
		this.currentFrame = 0;
	}

	ctx.fillStyle = this.frames[this.currentFrame];
	var x,y;
	x = y = 0;
	if (this.orientation == "vertical") {
		for(var i=0; i< 4; i++) {
			x += i*2;
			ctx.translate(-i*2, 0);
			ctx.beginPath();
			ctx.moveTo( (this.x-this.halfWidth)*SCALE-8, this.y*SCALE);
			ctx.lineTo( (this.x- this.halfWidth)*SCALE - 14, this.y*SCALE-10);
			ctx.lineTo((this.x-this.halfWidth)*SCALE-9, this.y*SCALE);
			ctx.lineTo( (this.x-this.halfWidth)*SCALE -14, this.y*SCALE+10);
			ctx.closePath();
			ctx.fill();
		}
		ctx.translate(x,y);
		x = y =0;
		for(var i=0; i< 4; i++) {
			x -= i*2;
			ctx.translate(i*2, 0);
			ctx.beginPath();
			ctx.moveTo( (this.x+this.halfWidth)*SCALE+8, this.y*SCALE);
			ctx.lineTo( (this.x+this.halfWidth)*SCALE + 14, this.y*SCALE-10);
			ctx.lineTo((this.x+this.halfWidth)*SCALE+9, this.y*SCALE);
			ctx.lineTo( (this.x+this.halfWidth)*SCALE +14, this.y*SCALE+10);
			ctx.closePath();
			ctx.fill();
		}
		ctx.translate(x,y);
	}
	else if (this.orientation == "horizontal") {
		for(var i=0; i< 4; i++) {
			y -= i*2;
			ctx.translate(0, i*2);
			ctx.beginPath();
			ctx.moveTo( this.x*SCALE, (this.y+this.halfHeight)*SCALE+8);
			ctx.lineTo( this.x*SCALE+10, (this.y+this.halfHeight)*SCALE+14);
			ctx.lineTo( this.x*SCALE, (this.y+this.halfHeight)*SCALE+9);
			ctx.lineTo( this.x*SCALE-10, (this.y+this.halfHeight)*SCALE+14);
			ctx.closePath();
			ctx.fill();
		}
		ctx.translate(x,y);
		x = y = 0;
		for(var i=0; i< 4; i++) {
			y += i*2;
			ctx.translate(0, -i*2);
			ctx.beginPath();
			ctx.moveTo( this.x*SCALE, (this.y-this.halfHeight)*SCALE-8);
			ctx.lineTo( this.x*SCALE+10, (this.y-this.halfHeight)*SCALE-14);
			ctx.lineTo( this.x*SCALE, (this.y-this.halfHeight)*SCALE-9);
			ctx.lineTo( this.x*SCALE-10, (this.y-this.halfHeight)*SCALE-14);
			ctx.closePath();
			ctx.fill();
		}
		ctx.translate(x,y);
	}

}