Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-02-2009, 11:24 PM
Damix2 Damix2 is offline
RED SQUARE CLUB
Join Date: Nov 2003
Location: NY-what's better?
Posts: 3,577
Damix2 will become famous soon enough
Snake

A few things, this is very basic snake, nothing really fancy about it. I got bored so I made it. My GScript is very limited as you can see, thanks to Tig for answering a few questions along the way.

Since I am very new (this I would say, is probably the 5th thing I've ever really tried to do) I'd love for some constructive criticism.

I'm sure there a a million things wrong (but hey, at least it works!), or inefficient about what I did, and if you could point out 1, 2 or all of them I'd be very happy.

Some of my indenting got screwy when I copied and pasted, sorry.


PHP Code:
//#CLIENTSIDE
  
function onWeaponFired() {
    if (
this.on == 0) {
      
setUpBoard(); 
        
placeCandy();
        
this.on 1;
        
setTimer(0.1);            
      }
      else {        
        
this.on 0;                 
      }
    }
    function 
onTimeOut() {      
    if (
this.on == 1) {
      
freezeplayer(1);      
      if (
keydown(1)) {
       
this.dir 1;
      }
      if (
keydown(2)) {
       
this.dir 2;
      }
      if (
keydown(3)) {
       
this.dir 3;
      }
      if (
keydown(0)) {
       
this.dir 4;
      }
      switch (
this.dir) {
        case 
1: {          
          
newCoord();
          
this.x1[0] = this.x1[0] - 10;
          
this.x2[0] = this.x1[0] + 10;
          break;
        }
        case 
2: {          
          
newCoord();
          
this.y1[0] = this.y1[0] + 10;
          
this.y2[0] = this.y1[0] + 10;
          break;
        }
        case 
3: {          
          
newCoord();
          
this.x1[0] = this.x1[0] + 10;
          
this.x2[0] = this.x1[0] + 10;
          break;
        }
        case 
4: {          
          
newCoord();
          
this.y1[0] = this.y1[0] - 10;
          
this.y2[0] = this.y1[0] + 10;
          break;
        }        
      }      
      
checkCandy();
      
doMovement();
      
setTimer(.1);
    }
    else {
      
setTimer(0); 
      
hideimgs(200,1000);      
      
freezeplayer(0); 
    }
  }
  
  function 
checkCandy() {
     if ((
this.x1[0] == this.candyx) && (this.y1[0] == this.candyy)) {
       
this.score++;
       
this.chain++;       
       
showtext(299this.startx+10,this.starty-20"Arial""c"this.score);
       
changeimgvis(2995);    
       
placeCandy();
       
this.x1[this.chain] = this.x1[this.chain-1]-10;       
     }  
  }
  
  function 
placeCandy() {    
    
this.candyx rand.randint()%50 10 this.startx;
      
this.candyy rand.randint()%30 10 this.starty;      
      
showpoly(203, {this.candyx,this.candyy,this.candyx,this.candyy+10,this.candyx+10,this.candyy+10,this.candyx+10,this.candyy});
    
changeimgvis(2036);
    
changeimgcolors(203,1,0,0,.99);  
  }
  
  function 
setUpBoard() {
    
this.x1 = new[1000];
    
this.y1 = new[1000];
    
this.x2 = new[1000];
    
this.y2 = new[1000];
    
this.border 4;
    
this.score 0;
    
this.startx screenwidth/3;
    
this.starty screenheight/3;
    
showpoly(200, {this.startx-this.border,this.starty-this.border,this.startx-this.border,this.starty+300+this.border,this.startx+500+this.border,this.starty+300+this.border,this.startx+500+this.border,this.starty-this.border});
    
changeimgvis(2004);
    
changeimgcolors(200,0,0,0,.99);
    
showpoly(201, {this.startx,this.starty,this.startx,this.starty+300,this.startx+500,this.starty+300,this.startx+500,this.starty});
    
changeimgvis(2015);
    
changeimgcolors(201,1,1,1,.99);
    
showtext(299this.startx+10,this.starty-20"Arial""c"this.score);
      
changeimgvis(2995);      
    
this.x1[0] = screenwidth/250;
    
this.y1[0] = screenheight/150;
    
this.x2[0] = this.x1[0] + 10;
    
this.y2[0] =    this.y1[0] + 10;     
      
this.dir 0;
      
this.chain 1;
      
rand = new MRandomLCG();                
  }
  
  function 
doMovement() {    
    if ((
this.x1[0] >= this.startx) && (this.y1[0] >= this.starty) && (this.y2[0] <= this.starty+300) && (this.x2[0] <= this.startx+500)) {  
      for (
0this.chaini++) {        
        
showpoly(500+i, {this.x1[i],this.y1[i],this.x1[i],this.y2[i],this.x2[i],this.y2[i],this.x2[i],this.y1[i]});
        
changeimgvis(500+i6);
        
changeimgcolors(500+i,0,0,0,.99);        
      }             
    }
    else {
      
this.on 0;
    }
    for (
1this.chaini++) {
      if ((
this.x1[0] == this.x1[i]) && (this.y1[0] == this.y1[i])) {
        
this.on 0;
      }  
    }
  }
  
  function 
newCoord() {
    for (
this.chain 10i--) {
      
this.x1[i] = this.x1[i-1];
      
this.x2[i] = this.x2[i-1];
      
this.y1[i] = this.y1[i-1];
      
this.y2[i] = this.y2[i-1];
    }
  } 
__________________
Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 06:15 PM.


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