Razor Disc

Name: Razor Disc
Type: Weapon
Author: John Doe
Description: Player throws a disc that ricochets off the walls several times before returning to the user.

[code]if (playertouchsme) {
toweapons Razor Disc;
}

if (weaponfired) {
if (this.state==0) {
if (playermp>=4) {
playermp-=4;

setbow no-bow.gif;
playersprite=33;
sleep 0.25;
playersprite=0;

this.numrepeats=5;
this.speed=0.5;
this.state=1;
this.hitsleft=5;
this.x=int(playerx+1.5);
this.y=int(playery+1.5);
this.dx=0;
this.dy=0;

if (keydown(0)||playerdir==0) {this.dy=-1;}
if (keydown(1)||playerdir==1) {this.dx=-1;}
if (keydown(2)||playerdir==2) {this.dy=1;}
if (keydown(3)||playerdir==3) {this.dx=1;}

timeout=0.05;
}
} else if (this.state==1) {
this.state=2;
}
}

if (timeout) {
for (this.repeat=0;this.repeat<this.numrepeats&&this.state>0;this.repeat++) {
if (onwater(this.x,this.y)) {putleaps 5,this.x-1,this.y-1.5;}

if (this.state==1) {
//Move & reflect when a wall is hit

this.tries=0;
while (onwall(this.x+this.dxthis.speed,this.y+this.dythis.speed)&&this.tries<10) {
this.dx=int(random(-1,1.99));
this.dy=int(random(-1,1.99));
while (this.dx==0&&this.dx==0) {
this.dx=int(random(-1,1.99));
this.dy=int(random(-1,1.99));
}
this.tries++;
}

if (this.tries>=10) {this.state=2;}

if (this.tries>0) {
playermp-=2;
this.hitsleft–;
if (this.hitsleft<=0||playermp<2) {
this.state=2;
}
}

this.x+=this.dxthis.speed;
this.y+=this.dy
this.speed;
} else if (this.state==2) {
//Move towards the player

this.tox=playerx+2;
this.toy=playery+2;

this.distx=abs(this.tox-this.x);
this.disty=abs(this.toy-this.y);
if (this.disty==0){
if (this.tox<this.x){
this.addx=-1this.speed;
}
if (this.tox>this.x){
this.addx=this.speed;
}
}else if (this.distx==0){
if (this.toy<this.y){
this.addy=-1
this.speed;
}
if (this.toy>this.y){
this.addy=this.speed;
}
}else if (this.disty>this.distx){
this.ratio=this.distx/this.disty;
if (this.toy<this.y){
this.addy=-1this.speed;
}
if (this.toy>this.y){
this.addy=this.speed;
}
if (this.tox<this.x){
this.addx=-1
this.speedthis.ratio;
}
if (this.tox>this.x){
this.addx=this.speed
this.ratio;
}
}else if (this.disty<this.distx){
this.ratio=this.disty/this.distx;
if (this.toy<this.y){
this.addy=-1this.speedthis.ratio;
}
if (this.toy>this.y){
this.addy=this.speedthis.ratio;
}
if (this.tox<this.x){
this.addx=-1
this.speed;
}
if (this.tox>this.x){
this.addx=this.speed;
}
}
this.x+=this.addx;
this.y+=this.addy;

if (this.distx<1&&this.disty<1) {this.state=0;}
}

//Hit players & baddies
for (i=1;i<playerscount;i++){
if (abs(players[i].x-this.x)<=1 && abs(players[i].y-this.y)<=1){
hitplayer i,1,this.x,this.y;
this.state=2;
}
}
for (i=0;i<compuscount;i++){
if (abs(compus[i].x-this.x)<=1&&
abs(compus[i].y-this.y)<=1&&
compus[i].mode!=3&&
compus[i].mode!=5){
hitcompu i,2,this.x,this.y;
}
}
}

showimg 0,razordisc.gif,this.x-0.5,this.y-0.5;

if (this.state>0) {
timeout=0.05;
} else {
hideimg 0;
}
}
[/code]

[attachment deleted by admin]