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(299, this.startx+10,this.starty-20, "Arial", "c", this.score);
changeimgvis(299, 5);
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(203, 6);
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(200, 4);
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(201, 5);
changeimgcolors(201,1,1,1,.99);
showtext(299, this.startx+10,this.starty-20, "Arial", "c", this.score);
changeimgvis(299, 5);
this.x1[0] = screenwidth/3 + 250;
this.y1[0] = screenheight/3 + 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 (i = 0; i < this.chain; i++) {
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+i, 6);
changeimgcolors(500+i,0,0,0,.99);
}
}
else {
this.on = 0;
}
for (i = 1; i < this.chain; i++) {
if ((this.x1[0] == this.x1[i]) && (this.y1[0] == this.y1[i])) {
this.on = 0;
}
}
}
function newCoord() {
for (i = this.chain - 1; i > 0; i--) {
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];
}
}