Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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, 570 views)
__________________
Quote:
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.