Frame 2
function makeSnake(Void) {
snake.push(attachMovie("head", "head", 50000));
head._x = 275;
head._y = 190;
snake.push(attachMovie("seg" + Math.floor((Math.random() * 3) + 1), "seg" + segments, segments));
snake[1]._x = snake[0]._x + 11.3;
snake[1]._y = snake[0]._y;
segments++;
snake.push(snakeMC.attachMovie("tail", "tail", 1));
snake[2]._x = snake[1]._x + 11.3;
snake[2]._y = snake[1]._y;
}
function moveCycle(Void) {
if (!pauseMove) {
var _local3 = snake.length - 1;
while (_local3 >= 1) {
var _local7 = snake[_local3];
var _local4 = snake[_local3 - 1];
_local7._rotation = _local4._rotation;
_local7._x = _local4._x;
_local7._y = _local4._y;
_local3--;
}
} else {
pauseMove = false;
var _local5 = snake[2];
var _local7 = snakeMC.attachMovie(_local5.type, _local5._name, segments);
_local7._rotation = _local5._rotation;
_local7._x = _local5._x;
_local7._y = _local5._y;
_local5.removeMovieClip();
snake.splice(2, 1, _local7);
}
if (classic) {
head._rotation = direction;
} else {
var _local8 = angle(head._x, head._y, _root._xmouse, _root._ymouse) - 180;
_local8 = angleDiff(head._rotation, _local8);
head._rotation = head._rotation + Math.max(-30, Math.min(_local8, 30));
}
head._x = head._x - (Math.cos(head._rotation * dtr) * 15);
head._y = head._y - (Math.sin(head._rotation * dtr) * 15);
addSegs();
if (headHit() || (!playBox.hitTest(head._x, head._y, false))) {
pause = true;
if (score > high) {
high = score + 1;
nextFrame();
this.onEnterFrame = function () {
snake.pop().removeMovieClip();
this.wait++;
if ((snake.length == 0) && (wait > 100)) {
gotoAndStop (3);
delete this.onEnterFrame;
}
};
} else {
this.onEnterFrame = function () {
snake.pop().removeMovieClip();
if (snake.length == 0) {
gotoAndStop (3);
delete this.onEnterFrame;
}
};
}
}
if (target.hitTest(head._x, head._y, true)) {
var _local6 = target._currentframe;
while (target._currentframe == _local6) {
target.gotoAndStop(Math.floor(Math.random() * 5) + 1);
}
targetPlace();
segsToAdd = segsToAdd + growth;
score = score + 100;
}
}
function headHit(Void) {
var _local3 = head._x;
var _local2 = head._y;
var _local6 = new Object({x:-20, y:0});
head.localToGlobal(_local6);
var _local5 = (_local6.x - _local3) / 10;
var _local4 = (_local6.y - _local2) / 10;
_local3 = _local3 - (_local5 * 10);
_local2 = _local2 - (_local4 * 10);
var _local1 = 0;
while (_local1 <= 14) {
if (snakeMC.hitTest(_local3, _local2, true)) {
return(true);
}
_local3 = _local3 + _local5;
_local2 = _local2 + _local4;
_local1++;
}
return(false);
}
function addSegs(Void) {
if (segsToAdd > 0) {
segments++;
snake.splice(1, 0, attachMovie("seg" + Math.floor((Math.random() * 3) + 1), "seg" + segments, segments));
snake[1]._x = head._x;
snake[1]._y = head._y;
snake[1]._rotation = head._rotation;
segsToAdd--;
pauseMove = true;
}
}
function targetPlace(Void) {
var _local1 = 50;
do {
target._x = 40 + Math.round(Math.random() * 420);
target._y = 25 + Math.round(Math.random() * 275);
_local1--;
} while (targetCheck() && (_local1 > 0));
if (_local1 <= 0) {
trace("Safety time out.");
}
}
function targetCheck(Void) {
if (target.hitTest(head._x, head._y, true)) {
return(true);
}
var _local4 = Math.ceil(target._width / 4);
var _local3 = Math.ceil(target._height / 4);
var _local2 = 0;
while (_local2 <= _local4) {
var _local1 = 0;
while (_local1 <= _local3) {
if (snakeMC.hitTest(target._x + (_local2 * 4), target._y + (_local1 * 4), true)) {
return(true);
}
_local1++;
}
_local2++;
}
return(false);
}
function angle(x1, y1, x2, y2) {
var _local3 = x2 - x1;
var _local2 = y2 - y1;
var _local1 = Math.atan(_local2 / _local3) * rtd;
if (_local3 < 0) {
if (_local2 < 0) {
_local1 = _local1 - 180;
} else {
_local1 = _local1 + 180;
}
}
return(_local1);
}
function angleDiff(angle1, angle2) {
var _local1 = angle2 - angle1;
while (_local1 > 180) {
_local1 = _local1 - 360;
}
while (_local1 < -180) {
_local1 = _local1 + 360;
}
return(_local1);
}
_global.dtr = (Math.PI/180);
_global.rtd = 1 / dtr;
new FPSTracker(2);
var speed = 5;
var growth = 5;
var classic = true;
var snakeMC = createEmptyMovieClip("snakeMC", 0);
var snake = new Array();
var segments = 2;
var segsToAdd = 0;
var pauseMove = false;
var pause;
var wait;
var direction = 0;
score = 0;
high = 0;
var dirTurn = new Object();
dirTurn.onKeyDown = function () {
if (Key.isDown(37) && (head._rotation != 180)) {
direction = 0;
} else if (Key.isDown(39) && (head._rotation != 0)) {
direction = 180;
} else if (Key.isDown(38) && (head._rotation != -90)) {
direction = 90;
} else if (Key.isDown(40) && (head._rotation != 90)) {
direction = -90;
}
};
var music = new Sound(_root);
music.attachSound("music");
music.start(1, 5000);
music.onKeyDown = function () {
if (Key.getCode() == 90) {
if (this.getVolume() == 100) {
this.setVolume(0);
_root.musicDisp.gotoAndPlay(161);
} else {
_root.musicDisp.gotoAndPlay(1);
this.setVolume(100);
}
}
};
Key.addListener(music);
var contextMenu = new ContextMenu();
contextMenu.hideBuiltInItems();
_root.menu = contextMenu;
Frame 3
stop();
score = 0;
direction = 0;
Frame 4
makeSnake();
targetPlace();
pause = false;
wait = 50;
this.onEnterFrame = function () {
if (!pause) {
if (wait < 1) {
moveCycle();
wait = speed;
} else {
wait--;
}
score++;
}
};
Key.addListener(dirTurn);
Frame 5
stop();
Symbol 5 MovieClip [seg2] Frame 1
var type = "seg2";
Symbol 7 MovieClip [seg3] Frame 1
var type = "seg3";
Symbol 9 MovieClip [seg1] Frame 1
var type = "seg1";
Symbol 22 MovieClip [target] Frame 1
stop();
Symbol 32 Button
on (release) {
getURL ("http://www.newgrounds.com", "blank");
}
Symbol 37 Button
on (release) {
_root.play();
}
Symbol 38 MovieClip Frame 1
_root.stop();
PercentLoaded = (_root.getBytesLoaded() / _root.getBytesTotal()) * 100;
if (PercentLoaded != 100) {
bar._xscale = PercentLoaded;
} else {
gotoAndStop ("loaded");
}
Symbol 38 MovieClip Frame 2
gotoAndPlay (1);
Symbol 96 MovieClip [__Packages.FPSTracker] Frame 0
class FPSTracker
{
var fps1, fps2, fps3, fps4, fps5, format, trackerClip;
function FPSTracker (placement, font, size, color) {
if (placement == undefined) {
placement = 3;
}
if (font == undefined) {
font = "Sydnie";
}
if (size == undefined) {
size = 20;
}
if (color == undefined) {
color = 0;
}
frames = 0;
fps1 = (fps2 = (fps3 = (fps4 = (fps5 = 0))));
format = new TextFormat();
format.size = size;
format.font = font;
format.color = color;
trackerClip = _root.createEmptyMovieClip("FPSTracker", 1000000);
trackerClip.dad = this;
switch (placement) {
case 1 :
trackerClip.createTextField("display", 1, 0, 0, 200, size * 1.5);
trackerClip._x = 0;
trackerClip._y = 0;
format.align = "left";
break;
case 2 :
trackerClip.createTextField("display", 1, -200, 0, 200, size * 1.5);
trackerClip._x = Stage.width;
trackerClip._y = 0;
format.align = "right";
break;
case 3 :
trackerClip.createTextField("display", 1, -200, (-size) * 1.5, 200, size * 1.5);
trackerClip._x = Stage.width;
trackerClip._y = Stage.height;
format.align = "right";
break;
case 4 :
trackerClip.createTextField("display", 1, 0, (-size) * 1.5, 200, size * 1.5);
trackerClip._x = 0;
trackerClip._y = Stage.height;
format.align = "left";
break;
default :
trace("Invalid placement parameter");
}
trackerClip.display.selectable = false;
trackerClip.onEnterFrame = function () {
this.dad.frames++;
};
setInterval(measure, 200, this);
}
function measure(tracker) {
with (tracker) {
fps5 = fps4;
fps4 = fps3;
fps3 = fps2;
fps2 = fps1;
fps1 = frames;
frames = 0;
trackerClip.display.text = (((fps1 + fps2) + fps3) + fps4) + fps5;
trackerClip.display.setTextFormat(format);
}
}
var frames = 0;
}
Symbol 43 MovieClip Frame 1
this.onEnterFrame = function () {
_x = (_x + 2);
if (_x > 560) {
this._y = Math.random() * 530;
this.gotoAndStop(Math.floor(Math.random() * 4) + 2);
this._x = -this._width;
}
};
gotoAndStop(Math.floor(Math.random() * 4) + 2);
Symbol 66 MovieClip Frame 160
gotoAndPlay (1);
Symbol 66 MovieClip Frame 320
gotoAndPlay (161);
Symbol 74 Button
on (release) {
_root.nextFrame();
}
Symbol 79 Button
on (release) {
speed = Math.min(10, speed + 1);
_root.speed = 10 - speed;
}
Symbol 80 Button
on (release) {
growth = Math.min(10, growth + 1);
_root.growth = growth;
}
Symbol 81 Button
on (release) {
if (_root.classic) {
mode = "Mouse Follow";
_root.classic = false;
} else {
mode = "Classic Arrows";
_root.classic = true;
}
}
Symbol 82 Button
on (release) {
speed = Math.max(1, speed - 1);
_root.speed = 10 - speed;
}
Symbol 83 Button
on (release) {
growth = Math.max(1, growth - 1);
_root.growth = growth;
}
Symbol 90 MovieClip Frame 1
speed = 10 - _root.speed;
growth = _root.growth;
if (_root.classic) {
mode = "Classic Arrows";
} else {
mode = "Mouse Follow";
}
Symbol 95 MovieClip Frame 1
hscoredisp = _root.score;