View Single Post
  #4  
Old 07-08-2005, 10:20 PM
Velox Cruentus Velox Cruentus is offline
Registered User
Velox Cruentus's Avatar
Join Date: Dec 2004
Location: Quebec, Canada
Posts: 465
Velox Cruentus is on a distinguished road
Send a message via ICQ to Velox Cruentus Send a message via AIM to Velox Cruentus
weapon VGame1
PHP Code:
// NPC made by Velox Cruentus
//#CLIENTSIDE
if (created){
  
this.size = {20,20};
  
this.maxlen = 30;
  
this.startlen = 2;

  
setstring client.movement,;
  
enabledefmovement;
}
if (
weaponfired || playerchats && strequals(#c,/play)) {
  
this.on = (this.on + 1) % 2;
  if (
this.on == 1){
    
setstring client.movement,false;
    
disabledefmovement;

    
this.len = this.startlen;

    
this.position = int(this.size[0] * this.size[1]/20 + this.size[0]/2);
    
setarray this.tail,this.maxlen;
    for (
this.i = 0; this.i < this.maxlen; this.i++) this.tail[this.i] = -1;
    
setarray this.mon,1; this.mon[0] = -1;

    
this.key = -1;
    
this.score = -1; this.start = 0;
    
gui();
  } else
    
dead();
  
timeout = 0.05;
}
if (
timeout){
  
this.oldtail = this.tail;
  
this.oldkey = this.key;
  for (
this.i = 0; this.i < 4; this.i ++)
    
this.key = keydown(this.i) == 1 && this.oldkey != this.i ? this.i : this.key;
  if ((
this.key + 2)%4 == this.oldkey)
    
this.key = this.oldkey;

  
this.on = !keydown(4) || this.key == -1;

  if (
this.key > -1){
    for (
this.i = this.len; this.i > -1; this.i--)
      
this.tail[this.i] = this.i == 0 ? this.position : this.tail[this.i-1];

    
this.position = (int(this.position/this.size[0])*this.size[0] + vecy(this.key)*this.size[0] + (this.position + vecx(this.key))%this.size[0])%(this.size[0]*this.size[1]);

    if (
this.position in this.tail || this.position in this.mon) dead();
    if (
this.position == this.goodie) spawn();
  }

  
gui();
  if (
this.on == 1)
    
timeout = 0.05;
  else
    
dead();
}

function 
gui(){
  if (
this.start == 0){
    
this.posgui = {screenwidth/2 - (this.size[0]/2)*10,screenheight/2 - (this.size[1]/2)*10};
    
showpoly 200,{this.posgui[0] + 0,this.posgui[1] + 0, this.posgui[0] + this.size[0]*10,this.posgui[1] + 0, this.posgui[0] + this.size[0]*10,this.posgui[1] + this.size[1]*10, this.posgui[0] + 0,this.posgui[1] + this.size[1]*10};
    
changeimgvis 200,4;
    
changeimgcolors 200,0,0,.5,1;

    for (
this.i = 0; this.i < this.size[0]*this.size[1]; this.i++){
      
this.x = this.i % this.size[0];
      
this.y = int(this.i/this.size[0]);
      
showpoly 201 + this.i,{this.posgui[0] + this.x * 10 + 1,this.posgui[1] + this.y * 10 + 1, this.posgui[0] + (this.x + 1) * 10 - 1,this.posgui[1] + this.y * 10 + 1, this.posgui[0] + (this.x + 1) * 10 - 1,this.posgui[1] + (this.y + 1) * 10 - 1, this.posgui[0] + this.x * 10 + 1,this.posgui[1] + (this.y + 1) * 10 - 1};

      if (
this.position == this.i)
        
changeimgcolors 201 + this.i,0,0,0.8,1;
      else
        
changeimgcolors 201 + this.i,0,0,0.3,1;
      
changeimgvis 201 + this.i,5;
    }
    
spawn();
    
this.start = 1;
  } else {
    
setarray this.ilist,1;
    
this.ilist[0] = this.position;
    for (
this.i = 0; this.i < arraylen(this.tail); this.i++){
      if (!(
this.tail[this.i] in this.ilist) && this.tail[this.i] != -1){
        
setarray this.ilist,arraylen(this.ilist)+1;
        
this.ilist[arraylen(this.ilist)-1] = this.tail[this.i];
      }
      if (!(
this.oldtail[this.i] in this.ilist) && this.oldtail[this.i] != -1){
        
setarray this.ilist,arraylen(this.ilist)+1;
        
this.ilist[arraylen(this.ilist)-1] = this.oldtail[this.i];
      }
    }
    for (
this.i = 0; this.i < arraylen(this.ilist); this.i++){
      
this.j = this.ilist[this.i];
      if (
this.position == this.j)
        
changeimgcolors 201 + this.j,0,0,0.8,1;
      else if (
this.j == this.goodie)
        
changeimgcolors 201 + this.j,0,0.6,0,1;
      else if (
this.j in this.tail)
        
changeimgcolors 201 + this.j,0,0,0.6,1;
      else if (
this.j in this.mon)
        
changeimgcolors 201 + this.j,0.6,0,0,1;
      else
        
changeimgcolors 201 + this.j,0,0,0.3,1;
    }
  }
}

function 
spawn(){
  
this.score ++;
  
this.len = min(this.len + 1,this.maxlen);
  if (
70 < random(0,100)){
    
setarray this.mon,arraylen(this.mon)+1;
    
this.mon[arraylen(this.mon)-1] = int(random(0,this.size[0]*this.size[1]));
    
changeimgcolors 201 + this.mon[arraylen(this.mon)-1],0.6,0,0,1;
  }

  
this.goodie = int(random(0,this.size[0]*this.size[1]));
  while (
this.goodie in this.mon) this.goodie = int(random(0,this.size[0]*this.size[1]));
  
changeimgcolors 201 + this.goodie,0,0.6,0,1;

  
showtext 202 + this.size[0]*this.size[1],this.posgui[0] + 170,this.posgui[1] + this.size[1]*10 + 10,,b,#v(this.score);
  
changeimgvis 202 + this.size[0]*this.size[1],5;
  
showtext 203 + this.size[0]*this.size[1],this.posgui[0] + 170,this.posgui[1] + this.size[1]*10 + 40,,b,#s(client.highscore);
  
changeimgvis 203 + this.size[0]*this.size[1],5;
}

function 
dead(){
  
this.on = 0;
  
hideimgs 200,203+this.size[0]*this.size[1];
  
setstring client.movement,;
  
enabledefmovement;

  if (
this.score > strtofloat(#s(client.highscore)))
    
setstring client.highscore,#v(this.score);

  
timeout = 0;
} 

I hope they are useful. Good bye.
__________________
In a world of change... Who'll you believe?
Reply With Quote