Thread: Boomerang
View Single Post
  #1  
Old 08-09-2010, 10:33 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Boomerang

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.vecx(player.dir);
  
this.boomerang_y player.1.5 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.1.5this.boomerang_y player.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.xplayer.3| && this.boomerang_y in |player.yplayer.3|) {
      
this.active false;
    }
  }
  
// Draw boomerang
  
updateBoomerang();
  
// Hit Objects
  
temp.plyr testplayer(this.boomerang_x 0.5this.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)) {  
    
thiso.boomerang_x;
    
thiso.boomerang_y;
    
ani "classic_boomerang";
    
layer 1;
  }
}

function 
hideBoomerang() {
  
hideimg(1);
}

function 
updateBoomerang() {
  
with (findimg(1)) {  
    
thiso.boomerang_x;
    
thiso.boomerang_y;
  }

Included the gani that it uses as well, it uses the default sprites.
Attached Files
File Type: gani classic_boomerang.gani (493 Bytes, 553 views)
__________________
Quote:
Reply With Quote