This is the boomerang script, I made for Classic iPhone a month or two ago. Basic collision detection for hitting players is in the script, but will require modification for things like throwing it diagonally initially.
PHP Code:
//#CLIENTSIDE
function onWeaponFired() {
// Check if boomerang is out
if (this.active) return;
// Player animation
setani("grab", "");
freezeplayer(0.1);
// Throw boomerang
beginBoomerang();
}
function beginBoomerang() {
// Initialize Boomerang
this.boomerang_x = player.x + 1 + 2 * vecx(player.dir);
this.boomerang_y = player.y + 1.5 + 2 * vecy(player.dir);
this.boomerang_dir = player.dir;
this.boomerang_ang = 0;
// Activate
this.active = true;
// Draw boomerang
drawBoomerang();
// Loop
setTimer(0.05);
}
function onTimeout() {
// Check if deactivating
if (!this.active) {
hideBoomerang();
return;
}
// Move boomerang
if (this.boomerang_ang < (pi / 2)) {
this.boomerang_x += vecx(this.boomerang_dir) * cos(this.boomerang_ang) * 2;
this.boomerang_y += vecy(this.boomerang_dir) * cos(this.boomerang_ang) * 2;
this.boomerang_ang += (pi / 16);
} else {
temp.newangle = getangle(this.boomerang_x - player.x - 1.5, this.boomerang_y - player.y - 1.5);
this.boomerang_x += cos(temp.newangle) * cos(this.boomerang_ang) * 1.5;
this.boomerang_y -= sin(temp.newangle) * cos(this.boomerang_ang) * 1.5;
if (this.boomerang_ang < pi) {
this.boomerang_ang += (pi / 16);
}
if (this.boomerang_x in |player.x, player.x + 3| && this.boomerang_y in |player.y, player.y + 3|) {
this.active = false;
}
}
// Draw boomerang
updateBoomerang();
// Hit Objects
temp.plyr = testplayer(this.boomerang_x + 0.5, this.boomerang_y + 0.5);
if (temp.plyr > 0) {
if (this.lasthit == 0) {
this.lasthit = 5;
// Hit Player
temp.obj = players[temp.plyr];
} else {
this.lasthit--;
}
}
// Loop
setTimer(0.05);
}
function drawBoomerang() {
with (findimg(1)) {
x = thiso.boomerang_x;
y = thiso.boomerang_y;
ani = "classic_boomerang";
layer = 1;
}
}
function hideBoomerang() {
hideimg(1);
}
function updateBoomerang() {
with (findimg(1)) {
x = thiso.boomerang_x;
y = thiso.boomerang_y;
}
}
Included the gani that it uses as well, it uses the default sprites.