Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
// turret.js
// Turret that fires bullets.
var ticons = new Array;
var ticon = new GIcon;
ticon.image = "images/turret_ur.png";
ticon.shadow = "images/dummy_shadow.png";
ticon.iconSize = new GSize(8, 8);
ticon.shadowSize = new GSize(1, 1);
ticon.iconAnchor = new GPoint(4, 4);
ticons.push(ticon);
var ticon2 = new GIcon(ticon);
ticon2.image = "images/turret_dl.png";
ticons.push(ticon2);
function Turret() {
this.point = new GPoint;
this.type;
this.interval;
this.speed;
this.cnt;
this.destroyedCnt;
this.exists = false;
this.markers = new Array;
this.markers.push(new GMarker(
new GPoint(mapManager.centerX, mapManager.centerY), ticons[0]));
this.markers.push(new GMarker(
new GPoint(mapManager.centerX, mapManager.centerY), ticons[1]));
this.set = function(x, y, type, interval, speed) {
this.point.x = x;
this.point.y = y;
this.type = type;
this.interval = interval;
this.speed = speed;
this.cnt = 0;
this.destroyedCnt = 0;
this.exists = true;
this.updateMakersPos(0);
for (var i = 0; i < 2; i++)
map.addOverlay(this.markers[i]);
}
this.update = function() {
if (!this.exists)
return;
if (this.point.x < mapManager.bounds.minX ||
this.point.x > mapManager.bounds.maxX ||
this.point.y < mapManager.bounds.minY ||
this.point.y > mapManager.bounds.maxY) {
this.exists = false;
for (var i = 0; i < 2; i++)
map.removeOverlay(this.markers[i]);
return;
}
if (((this.cnt - 30) % this.interval) == 0 && this.destroyedCnt <= 0) {
var b = getBulletInstance();
if (b != null) {
var d = Math.atan2(ship.marker.point.x - this.point.x,
ship.marker.point.y - this.point.y);
b.set(this.type, this.point.x, this.point.y, d, this.speed);
}
}
this.cnt++;
if (this.cnt <= 30)
this.updateMakersPos(this.cnt);
if (this.destroyedCnt > 0) {
this.updateMakersPos(30 - this.destroyedCnt * 2);
this.destroyedCnt++;
if (this.destroyedCnt >= 15) {
this.exists = false;
for (var i = 0; i < 2; i++)
map.removeOverlay(this.markers[i]);
return;
}
}
for (var i = 0; i < 2; i++)
this.markers[i].redraw(true);
}
this.updateMakersPos = function(c) {
var d = c * 0.1 + 0.9 + 3.14;
var r = (30 - c) * 0.00005 + 0.00005;
var m;
for (var i = 0; i < 2; i++) {
m = this.markers[i];
m.point.x = this.point.x + Math.sin(d) * r;
m.point.y = this.point.y + Math.cos(d) * r;
d += 3.14;
}
}
this.checkHit = function(p) {
if (Math.abs(p.x - this.point.x) < 0.0001 &&
Math.abs(p.y - this.point.y) < 0.0001)
this.destroyed();
}
this.destroyed = function() {
this.destroyedCnt = 1;
}
}