Frame 1
var dx = 0;
var dy = 0;
var ggX = 0;
var ggY = 0;
var ggV = 5;
var ggHealth = 10;
var piu = null;
var piuCount = 0;
var gad = null;
var gadCount = 0;
var killCount = 0;
var hueKing = 0;
Stage.scaleMode = "exactFit";
_root.attachMovie("GG", "gg1", 2);
_root.attachMovie("MAP", "map1", 1);
piu = Array();
gad = Array();
var i = 0;
while (i < 10) {
gad["gad" + gadCount] = _root.attachMovie("GAD", "gad" + gadCount, _root.getNextHighestDepth());
i++;
}
Key.addListener(_root);
_root.onKeyDown = function () {
if (Key.getCode() == 40) {
dy = ggV;
dx = 0;
}
if (Key.getCode() == 38) {
dy = -ggV;
dx = 0;
}
if (Key.getCode() == 39) {
dx = ggV;
dy = 0;
}
if (Key.getCode() == 37) {
dx = -ggV;
dy = 0;
}
};
_root.onKeyUp = function () {
if (Key.getCode() == 40) {
dy = 0;
}
if (Key.getCode() == 38) {
dy = 0;
}
if (Key.getCode() == 39) {
dx = 0;
}
if (Key.getCode() == 37) {
dx = 0;
}
};
map1.onMouseDown = function () {
var _local2 = _root.attachMovie("PIU", "piu" + piuCount, _root.getNextHighestDepth());
_local2.px = ggX + (gg1._width * 0.3);
_local2.py = ggY - (gg1._height * 0.6);
_local2.setTarget(map1._xmouse - (map1._width * 0.5), map1._ymouse - (map1._height * 0.5));
_local2.sender = 1;
piu[_local2._name] = _local2;
};
_root.onEnterFrame = function () {
if ((ggHealth > 0) & (hueKing != 2)) {
ggX = ggX + dx;
ggY = ggY + dy;
if ((((ggX >= (_root.map1._width * 0.5)) || (ggX <= ((-_root.map1._width) * 0.5))) || (ggY >= (_root.map1._height * 0.5))) || (ggY <= (-((-_root.gg1._height) + (_root.map1._height * 0.5))))) {
ggX = ggX - dx;
ggY = ggY - dy;
}
if (ggX >= ((_root.map1._width * 0.5) - 275)) {
_root.gg1._x = ((ggX - (_root.map1._width * 0.5)) + 550) - (_root.gg1._width * 0.5);
_root.map1._x = 550 - _root.map1._width;
} else if (ggX <= (((-_root.map1._width) * 0.5) + 275)) {
_root.gg1._x = (ggX + (_root.map1._width * 0.5)) - (_root.gg1._width * 0.5);
_root.map1._x = 0;
} else {
_root.gg1._x = 275 - (_root.gg1._width * 0.5);
_root.map1._x = (275 - (_root.map1._width * 0.5)) - ggX;
}
if (ggY >= ((_root.map1._height * 0.5) - 200)) {
_root.gg1._y = ((ggY - (_root.map1._height * 0.5)) + 400) - _root.gg1._height;
_root.map1._y = 400 - _root.map1._height;
} else if (ggY <= (((-_root.map1._height) * 0.5) + 200)) {
_root.gg1._y = (ggY + (_root.map1._height * 0.5)) - _root.gg1._height;
_root.map1._y = 0;
} else {
_root.gg1._y = 200 - _root.gg1._height;
_root.map1._y = (200 - (_root.map1._height * 0.5)) - ggY;
}
for (var _local5 in piu) {
if (piu[_local5].step() != 0) {
piu[_local5].removeMovieClip();
delete piu[_local5];
}
if (piu[_local5].sender == 1) {
for (var _local4 in gad) {
if (piu[_local5].hitTest(gad[_local4])) {
piu[_local5].removeMovieClip();
delete piu[_local5];
gad[_local4].health = gad[_local4].health - 1;
if (gad[_local4].health <= 0) {
if (gad[_local4].v == 10) {
hueKing = 2;
}
gad[_local4].removeMovieClip();
delete gad[_local4];
killCount++;
}
}
}
}
}
for (var _local4 in gad) {
gad[_local4].step();
if (Math.random() < gad[_local4].fireRate) {
var _local2 = _root.attachMovie("PIU", "piu" + piuCount, _root.getNextHighestDepth());
_local2.px = gad[_local4].px;
_local2.py = gad[_local4].py;
_local2.v = 10;
_local2.setTarget(ggX, ggY);
_local2.sender = 0;
piu[_local2._name] = _local2;
}
}
if (Math.random() < 0.02) {
gad["gad" + gadCount] = _root.attachMovie("GAD", "gad" + gadCount, _root.getNextHighestDepth());
}
if ((killCount > 10) & (hueKing == 0)) {
hueKing = 1;
var _local3 = _root.attachMovie("GAD", "gad" + gadCount, _root.getNextHighestDepth());
_local3.clear();
_local3.attachMovie("hueking", "hueking", _root.getNextHighestDepth());
_local3.v = 10;
_local3.fireRate = 0.08;
_local3.health = 50;
gad[_local3._name] = _local3;
}
} else if (hueKing == 2) {
_root.attachMovie("win", "win", _root.getNextHighestDepth());
} else {
_root.attachMovie("fail", "fail", _root.getNextHighestDepth());
}
};
Symbol 8 MovieClip [PIU] Frame 1
#initclip 4
Object.registerClass("PIU", PIU);
#endinitclip
Symbol 11 MovieClip [GAD] Frame 1
#initclip 3
Object.registerClass("GAD", GAD);
#endinitclip
Symbol 20 MovieClip [__Packages.GAD] Frame 0
class GAD extends MovieClip
{
var _x, _y;
function GAD () {
super();
py = (Math.random() - 0.5) * (_root.map1._height - 50);
px = (Math.random() - 0.5) * (_root.map1._width - 50);
setTarget((Math.random() - 0.5) * (_root.map1._width - 50), (Math.random() - 0.5) * (_root.map1._height - 50));
_root.gadCount++;
}
function setTarget(tx, ty) {
var _local2 = Math.sqrt(Math.pow(px - tx, 2) + Math.pow(py - ty, 2));
if (_local2 == 0) {
_local2 = 1;
}
dx = v * ((tx - px) / _local2);
dy = v * ((ty - py) / _local2);
}
function step() {
px = px + dx;
py = py + dy;
_x = (px + _root.map1._x) + (_root.map1._width * 0.5);
_y = (py + _root.map1._y) + (_root.map1._height * 0.5);
var _local3 = 0;
if (Math.random() < 0.02) {
setTarget((Math.random() - 0.5) * (_root.map1._height - 50), (Math.random() - 0.5) * (_root.map1._width - 50));
}
return(_local3);
}
var px = 0;
var py = 0;
var dx = 0;
var dy = 0;
var v = 5;
var health = 5;
var fireRate = 0.02;
}
Symbol 21 MovieClip [__Packages.PIU] Frame 0
class PIU extends MovieClip
{
var _x, _y;
function PIU () {
super();
_root.piuCount++;
}
function setTarget(tx, ty) {
var _local2 = Math.sqrt(Math.pow(px - tx, 2) + Math.pow(py - ty, 2));
if (_local2 == 0) {
_local2 = 1;
}
dx = v * ((tx - px) / _local2);
dy = v * ((ty - py) / _local2);
}
function step() {
px = px + dx;
py = py + dy;
_x = (px + _root.map1._x) + (_root.map1._width * 0.5);
_y = (py + _root.map1._y) + (_root.map1._height * 0.5);
var _local3 = 0;
if ((((px >= (_root.map1._width * 0.5)) || (px <= ((-_root.map1._width) * 0.5))) || (py >= (_root.map1._height * 0.5))) || (py <= ((-_root.map1._height) * 0.5))) {
_local3 = 2;
}
if (_root.gg1.hitTest(this) & (sender != 1)) {
_local3 = 1;
_root.ggHealth = _root.ggHealth - 1;
}
return(_local3);
}
var px = 0;
var py = 0;
var dx = 0;
var dy = 0;
var v = 20;
var dangerTime = 10;
var sender = 0;
}