Name: Homing Missile
Type: Weapon
Author: John Doe
Description: Player fires a missile that chases the first player it finds.
Notes: Haven't tested online. Required images attached.
[code]if (playertouchsme) {
toweapons Homing Missile;
hidelocal;
}
if (playerenters) {
show;
hideimg 1;
this.active = 0;
this.accel = .1;
this.maxaccel = 1;
timeout = 0;
}
if (weaponfired) {
if (playerbombs >= 1 && playerdarts >= 3 && this.active == 0) {
// playerbombs -= 1;
// playerdarts -= 3;
freezeplayer .6;
timeout = .5;
setbow hominggun.png;
playersprite = 33;
this.flyx = playerx + 1.5;
this.flyy = playery + 2;
this.mx = 0; this.my = 0;
if (playerdir == 0) { this.flyy -= 2; this.my = -this.accel; }
if (playerdir == 1) { this.flyx -= 2; this.mx = -this.accel; }
if (playerdir == 2) { this.flyy += 2; this.my = this.accel; }
if (playerdir == 3) { this.flyx += 2; this.mx = this.accel; }
this.ax = this.mx; this.ay = this.my;
this.lock = 0;
this.locktype = 0;
this.lastplayers = playerscount;
this.lastcomps = compuscount;
this.active = 1;
} else if (this.active == 1) {
this.active = 2;
}
}
if (timeout && this.active > 0) {
if (this.lastplayers != playerscount || this.lastcomps != compuscount) this.locktype = 0;
if (this.locktype == 0) {
distance = 4096;
lock = -1; locktype = 0;
for (i = 1; i < playerscount; i++) {
j = players[i].x + 1.5 - this.flyx; j = abs(j * j);
k = players[i].y + 2 - this.flyy; k = abs(k * k);
if (j + k < distance) {
lock = i; locktype = 1; distance = j + k;
}
}
for (i = 0; i < compuscount; i++) {
j = compus[i].x + 1.5 - this.flyx; j = abs(j * j);
k = compus[i].y + 1.5 - this.flyy; k = abs(k * k);
if (j + k < distance) {
lock = i; locktype = 2; distance = j + k;
}
}
this.lastplayers = playerscount;
this.lastcomps = compuscount;
this.lock = lock;
this.locktype = locktype;
}
i = this.lock;
if (this.locktype == 1) {
if (players[i].x + 2 > this.flyx) this.ax = this.accel;
else if (players[i].x + 1 < this.flyx) this.ax = -this.accel;
else this.ax = 0;
if (players[i].y + 2.5 > this.flyy) this.ay = this.accel;
else if (players[i].y + 1.5 < this.flyy) this.ay = -this.accel;
else this.ay = 0;
} else if (this.locktype == 2) {
if (compus[i].x + 2.5 > this.flyx) this.ax = this.accel;
else if (compus[i].x + 1.5 < this.flyx) this.ax = -this.accel;
else this.ax = 0;
if (compus[i].y + 2.5 > this.flyy) this.ay = this.accel;
else if (compus[i].y + 1.5 < this.flyy) this.ay = -this.accel;
else this.ay = 0;
}
if (abs(this.ax+this.mx) <= this.maxaccel) this.mx += this.ax;
if (abs(this.ay+this.my) <= this.maxaccel) this.my += this.ay;
this.flyx += this.mx; this.flyy += this.my;
hit = 0;
j = playerscount; if (j < compuscount) j = compuscount;
for (i = 0; i < j; i++) {
if (i < playerscount)
if (abs(this.flyx-players[i].x-1.5)<1.5 && abs(this.flyy-players[i].y-2)<1.5) hit = 1;
if (i < compuscount)
if (abs(this.flyx-compus[i].x-1.5)<1.5 && abs(this.flyy-compus[i].y-2)<1.5) hit = 1;
}
if (this.active == 2 || onwall(this.flyx,this.flyy)) hit = 1;
if (hit == 1) {
hideimg 1;
this.active = 0;
putexplosion 2,this.flyx-1,this.flyy-1;
} else {
putx = this.flyx - .3125;
puty = this.flyy - .3125;
left = 0; wide = 30;
top = 0; high = 30;
if (this.mx == 0) { left = 30; wide = 9; }
if (this.mx > 0) { left = 39; putx -= 1.5625; }
if (this.my == 0) { top = 30; high = 9; }
if (this.my > 0) { top = 39; puty -= 1.5625; }
showimg 1,homing.png,putx,puty;
changeimgpart 1,left,top,wide,high;
timeout = .05;
}
}
[/code]
[attachment deleted by admin]