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
// main.js
// Handling a map, actors and an interval timer.
var map;
var mapManager;
var ship;
var CLEFTS_NUM = 20;
var clefts;
var cleftsIdx = 0;
var BULLETS_NUM = 40;
var bullets;
var bulletsIdx = 0;
var TURRETS_NUM = 10;
var turrets;
var turretsIdx = 0;
var turretAppCnt;
var timerID;
// Initialize.
window.onload = function() {
map = new GMap(document.getElementById("map"));
mapManager = new MapManager(map);
ship = new Ship;
clefts = new Array();
for (var i = 0; i < CLEFTS_NUM; i++)
clefts.push(new Cleft);
bullets = new Array();
for (var i = 0; i < BULLETS_NUM; i++)
bullets.push(new Bullet);
turrets = new Array();
for (var i = 0; i < TURRETS_NUM; i++)
turrets.push(new Turret);
turretAppCnt = 0;
timerID = setInterval("update()", 66);
}
// Clear an interval timer.
window.onunload = function() {
clearInterval(timerID);
}
// Update the state to the next frame.
update = function() {
mapManager.update();
ship.update();
for (var i = 0; i < CLEFTS_NUM; i++)
clefts[i].update();
for (var i = 0; i < BULLETS_NUM; i++)
bullets[i].update();
for (var i = 0; i < TURRETS_NUM; i++)
turrets[i].update();
turretAppCnt--;
if (turretAppCnt <= 0) {
addTurret();
turretAppCnt = Math.random() * 50 + 10;
}
}
getCleftInstance = function() {
for (var i = 0; i < CLEFTS_NUM; i++) {
cleftsIdx++;
if (cleftsIdx >= CLEFTS_NUM)
cleftsIdx = 0;
if (!clefts[cleftsIdx].exists) {
return clefts[cleftsIdx];
}
}
return null;
}
getBulletInstance = function() {
for (var i = 0; i < BULLETS_NUM; i++) {
bulletsIdx++;
if (bulletsIdx >= BULLETS_NUM)
bulletsIdx = 0;
if (!bullets[bulletsIdx].exists) {
return bullets[bulletsIdx];
}
}
return null;
}
getTurretInstance = function() {
for (var i = 0; i < TURRETS_NUM; i++) {
turretsIdx++;
if (turretsIdx >= TURRETS_NUM)
turretsIdx = 0;
if (!turrets[turretsIdx].exists) {
return turrets[turretsIdx];
}
}
return null;
}
checkTurretsHit = function(p) {
var t;
for (var i = 0; i < TURRETS_NUM; i++) {
t = turrets[i];
if (t.exists)
t.checkHit(p);
}
}
addTurret = function() {
var t = getTurretInstance();
if (t == null)
return;
var type;
var interval;
var speed;
switch (Math.floor(Math.random() * 10)) {
case 0:
case 1:
case 2:
case 3:
case 4:
type = BULLET_TYPE_AIM;
interval = 20 + Math.random() * 20;
break;
case 5:
case 6:
type = BULLET_TYPE_SHOTGUN;
interval = 40 + Math.random() * 20;
break;
case 7:
case 8:
type = BULLET_TYPE_3WAY;
interval = 40 + Math.random() * 20;
break;
case 9:
type = BULLET_TYPE_5WAY;
interval = 50 + Math.random() * 10;
break;
}
speed = 0.00003 + Math.random() * 0.00002;
t.set(Math.random() * (mapManager.bounds.maxX - mapManager.bounds.minX) + mapManager.bounds.minX,
mapManager.bounds.maxY - Math.random() * (mapManager.bounds.maxY - mapManager.bounds.minY) * 0.2,
type, interval, speed);
}