home *** CD-ROM | disk | FTP | other *** search
- function degToRad(deg)
- {
- return deg * 3.141592653589793 / 180;
- }
- function radToDeg(rad)
- {
- return rad * 180 / 3.141592653589793;
- }
- function rotate(obj, deg)
- {
- rad = degToRad(deg);
- cos = Math.cos(rad);
- sin = Math.sin(rad) * aspect;
- matrix = new flash.geom.Matrix(cos * obj._xscale / 100,sin,0,obj._yscale / 100,obj._x,obj._y);
- obj.transform.matrix = matrix;
- }
- function easeTo(pos, trg, amnt)
- {
- return (trg + pos * (amnt - 1)) / amnt;
- }
- function closeGame()
- {
- Key.removeListener(charListener);
- }
- function moveChar(charMC)
- {
- charMC.xspeed *= 0.6;
- charMC.yspeed *= 0.6;
- charMC.x += charMC.xspeed;
- charMC.y += charMC.yspeed;
- if(charMC.x < (- mapwide) / 2)
- {
- charMC.x = (- mapwide) / 2;
- }
- if(charMC.x > mapwide / 2)
- {
- charMC.x = mapwide / 2;
- }
- if(charMC.y < (- maphigh) / 2)
- {
- if(charMC.y < -440)
- {
- charMC.y += 20;
- if(charMC.x > 80)
- {
- charMC.x = 80;
- }
- if(charMC.x < -80)
- {
- charMC.x = -80;
- }
- }
- else
- {
- charMC.y = (- maphigh) / 2;
- }
- walkin = true;
- }
- if(charMC.y > maphigh / 2)
- {
- charMC.y -= 20;
- walkin = true;
- }
- }
- function attachWallPanel(x, y, rot, type)
- {
- d = game.getNextHighestDepth();
- panel = game.attachMovie(type,"wallpanel" + itemRoller++,d);
- wallpanels.push(panel);
- panel.x = x;
- panel.y = y;
- panel.z = 0;
- panel.rot = rot;
- panel.hardcodeDepth = hardcodeDepth;
- return panel;
- }
- function attachTopPanel(x, y, rot, hardcodeDepth)
- {
- d = hardcodeDepth === undefined ? game.getNextHighestDepth() : hardcodeDepth + 100000;
- panelHolder = game.createEmptyMovieClip("topTileHolder" + itemRoller++,d);
- panel = panelHolder.attachMovie("blockTopTile","panel",1);
- panelHolder._yscale = 100 * aspect;
- toppanels.push(panel);
- panel.x = x;
- panel.y = y;
- panelHolder.y = y - 200;
- panelHolder.z = wallHeight;
- panelHolder.hardcodeDepth = hardcodeDepth;
- panel.rot = rot;
- return panelHolder;
- }
- function addCharacter(name, x, y, jumpPower, walkSpeed, att, def, team, charnum, boss)
- {
- s = game.attachMovie(name,"char" + itemRoller++,game.getNextHighestDepth());
- s.points = startPoints;
- s.charnum = charnum;
- s.x = x;
- s.y = y;
- s.z = 0;
- s.att = att;
- s.def = def;
- s.team = team;
- s.boss = boss;
- s.jumpPower = jumpPower;
- s.walkSpeed = walkSpeed;
- s.xspeed = 0;
- s.yspeed = 0;
- s.zspeed = 0;
- s.health = 100;
- s.shadow = game.attachMovie("shadow","shadow" + itemRoller++,game.getNextHighestDepth());
- s.shadow._yscale = 100 * aspect;
- activeChars.push(s);
- return s;
- }
- function sortDepths(ar)
- {
- newar = [];
- for(a in ar)
- {
- obj = ar[a];
- newar.push({obj:obj,y:obj.y});
- }
- newar.sortOn("y",Array.NUMERIC);
- a = 0;
- while(a < newar.length)
- {
- v = newar.shift();
- newar.push(v.obj);
- a++;
- }
- return newar;
- }
- changeBGMusic("battlemusic");
- var so = SharedObject.getLocal("unlockable");
- if(!battlesound)
- {
- battlesound = new Sound();
- }
- battlesound.setVolume(curvol);
- stop();
- aspect = 0.5;
- test_aspect._y = 50;
- test_aspect.onPress = function()
- {
- this.active = true;
- };
- test_aspect.onRelease = test_aspect.onReleaseOutside = function()
- {
- this.active = false;
- };
- test_aspect.onEnterFrame = function()
- {
- if(this.active)
- {
- this._y = _root._ymouse;
- depthaspect = this._y;
- }
- };
- depthaspect = 200;
- arenaRotation = 0;
- wallHeight = 80;
- groundHolder = game.createEmptyMovieClip("groundholder",-1000000);
- ground = groundHolder.attachMovie("groundtile","ground",-1000);
- groundHolder._yscale = 100 * aspect;
- activeChars = [];
- wallpanels = [];
- toppanels = [];
- itemRoller = 0;
- mapwide = 800;
- maphigh = 800;
- pts1 = pts2 = pts3 = pts4 = pts5 = pts6 = startPoints;
- playerStats = {agi:40,def:0,att:0};
- itms = new Array();
- itms.push(possibleWeapons[playerActiveWeapon]);
- itms.push(possibleShields[playerActiveShield]);
- itms.push(possibleHelmets[playerActiveHelmet]);
- itms.push(possibleArmours[playerActiveArmour]);
- itms.push(possibleArms[playerActiveArms]);
- itms.push(possibleBoots[playerActiveBoots]);
- for(i in itms)
- {
- item = itms[i];
- if(item.attr.agi !== undefined)
- {
- playerStats.agi += item.attr.agi;
- }
- if(item.attr.att !== undefined)
- {
- playerStats.att += item.attr.att;
- }
- if(item.attr.def !== undefined)
- {
- playerStats.def += item.attr.def;
- }
- }
- if(so.data.doubledamage)
- {
- playerStats.att *= 2;
- }
- playerCharacter = addCharacter("dwarf",0,1000,playerStats.agi,playerStats.agi / 4,playerStats.att,playerStats.def,1,1);
- addCharacter("dwarf",0,900,40,10,0,0,1,2);
- pts3mc._visible = pts4mc._visible = pts5mc._visible = pts6mc._visible = false;
- _root.pts3_txt = _root.pts4_txt = _root.pts5_txt = _root.pts6_txt = "";
- for(e in battleEnemies)
- {
- en = battleEnemies[e];
- n = 3 + Number(e);
- _root["pts" + n + "mc"]._visible = true;
- _root["pts" + n + "_txt"] = en.mc;
- addCharacter(en.mc,0,-800,en.jump,en.walk,en.att,en.def,2,n,en.boss);
- }
- l = attachWallPanel(100,100,270,"wallpanel");
- r = attachWallPanel(300,100,270,"wallpanel");
- f = attachWallPanel(300,300,0,"wallpanel");
- t = attachTopPanel(100,300,0);
- boxFront = [l,r,f,t];
- l = attachWallPanel(-300,-300,270,"wallpanel");
- r = attachWallPanel(-100,-300,270,"wallpanel");
- f = attachWallPanel(-100,-100,0,"wallpanel");
- t = attachTopPanel(-300,-100,0);
- boxRear = [l,r,f,t];
- backWall = attachWallPanel(400,-400,0,"backWall");
- wallObjects = new Array();
- wallObjects.push(new flash.geom.Rectangle(100,100,200,200));
- wallObjects.push(new flash.geom.Rectangle(-300,-300,200,200));
- var charListener = new Object();
- charListener.char = char;
- charListener.onKeyUp = function()
- {
- if(Key.getCode() == 37)
- {
- lastLeftUp = getTimer();
- }
- if(Key.getCode() == 39)
- {
- lastRightUp = getTimer();
- }
- };
- charListener.onKeyDown = function()
- {
- if(Key.getCode() == 37)
- {
- if(getTimer() - lastLeftUp < 100)
- {
- if(!playerCharacter.waitForAnimation)
- {
- playerCharacter.gotoAndPlay("dash");
- }
- }
- }
- if(Key.getCode() == 39)
- {
- if(getTimer() - lastRightUp < 100)
- {
- if(!playerCharacter.waitForAnimation)
- {
- playerCharacter.gotoAndPlay("dash");
- }
- }
- }
- if(Key.getCode() == 88)
- {
- if(!playerCharacter.waitForAnimation)
- {
- if(playerCharacter.airborne)
- {
- playerCharacter.gotoAndPlay("airattack");
- }
- else
- {
- switch(possibleWeapons[playerActiveWeapon].type)
- {
- case "sword":
- playerCharacter.gotoAndPlay("attack1");
- break;
- case "spear":
- playerCharacter.gotoAndPlay("attackspear");
- break;
- case "axe":
- playerCharacter.gotoAndPlay("attackaxe");
- }
- }
- playerCharacter.comboLvl = 1;
- }
- else
- {
- playerCharacter.comboLvl = playerCharacter.comboLvl + 1;
- if(playerCharacter.currentAction == "dash")
- {
- }
- }
- }
- if(Key.getCode() == 90)
- {
- if(!playerCharacter.airborne and !playerCharacter.waitForAnimation)
- {
- playerCharacter.zspeed += playerCharacter.jumpPower;
- playerCharacter.airborne = true;
- }
- }
- if(Key.getCode() == 67)
- {
- if(!playerCharacter.airborne and !playerCharacter.waitForAnimation)
- {
- playerCharacter.gotoAndPlay("block");
- }
- }
- };
- Key.addListener(charListener);
- game.onEnterFrame = function()
- {
- if(playerCharacter)
- {
- arenaRotation = (- playerCharacter.x) / 15;
- }
- r = degToRad(arenaRotation);
- c = Math.cos(r);
- s = Math.sin(r);
- ground._rotation = arenaRotation;
- for(ch in activeChars)
- {
- char = activeChars[ch];
- spd = 18;
- if(!char.waitForAnimation)
- {
- oldpos = {x:char.x,y:char.y};
- if(char == playerCharacter)
- {
- walkin = false;
- if(Key.isDown(38))
- {
- char.yspeed -= char.walkSpeed;
- walkin = true;
- }
- else if(Key.isDown(40))
- {
- char.yspeed += char.walkSpeed;
- walkin = true;
- }
- if(Key.isDown(37))
- {
- char.xspeed -= char.walkSpeed;
- char._xscale = 100;
- walkin = true;
- }
- else if(Key.isDown(39))
- {
- char.xspeed += char.walkSpeed;
- char._xscale = -100;
- walkin = true;
- }
- moveChar(char);
- }
- else
- {
- if(typeof char.fighting == "number")
- {
- char.fighting--;
- if(char.fighting < 0)
- {
- char.fighting = undefined;
- }
- }
- else if(char.fighting == undefined or char.fighting.currentAction == "die" or !random(20))
- {
- closestDist = Infinity;
- closest = undefined;
- chars = [];
- for(ch2 in activeChars)
- {
- char2 = activeChars[ch2];
- if(char2 !== char and char2.currentAction !== "die" and char2.team !== char.team)
- {
- dist = Math.abs(char2.x - char.x) + Math.abs(char2.y - char.y);
- chars.push(char2);
- if(dist < closestDist)
- {
- closestDist = dist;
- closest = char2;
- }
- }
- }
- if(closestDist > 200 and !random(4))
- {
- char.fighting = random(40);
- }
- else
- {
- char.fighting = chars[random(chars.length)];
- }
- }
- phase = (Math.cos(getTimer() / 2000) + 1) * 40;
- if(char.health < phase and (char.fighting.currentAction == "attack1" or !char.fighting.waitForAnimation and (char.x >= char.fighting.x ? char.fighting._xscale < 0 : char.fighting._xscale > 0)))
- {
- char.standoff = true;
- xbuffer = 150;
- ybuffer = 20;
- }
- else
- {
- char.standoff = false;
- xbuffer = 60;
- ybuffer = 10;
- }
- walkin = false;
- if(char.x < char.fighting.x - xbuffer)
- {
- char._xscale = -100;
- char.xspeed += char.walkSpeed;
- walkin = true;
- }
- else if(char.x > char.fighting.x + xbuffer)
- {
- char._xscale = 100;
- char.xspeed -= char.walkSpeed;
- walkin = true;
- }
- else
- {
- diff = Math.abs(char.x - char.fighting.x);
- if(diff < xbuffer / 2)
- {
- walkin = true;
- if(char.x > char.fighting.x)
- {
- char.xspeed += char.walkSpeed / 2;
- char._xscale = -100;
- }
- else
- {
- char.xspeed -= char.walkSpeed / 2;
- char._xscale = 100;
- }
- }
- else if(char.x > char.fighting.x)
- {
- char._xscale = 100;
- }
- else
- {
- char._xscale = -100;
- }
- }
- if(char.y < char.fighting.y - ybuffer)
- {
- char.yspeed += char.walkSpeed;
- walkin = true;
- }
- else if(char.y > char.fighting.y + ybuffer)
- {
- char.yspeed -= char.walkSpeed;
- walkin = true;
- }
- moveChar(char);
- if(!walkin and char.fighting !== undefined and !char.standoff and typeof char.fighting == "movieclip")
- {
- if(!random(5))
- {
- if(char.airborne)
- {
- if(char.z > char.fighting.z || char.z < char.fighting.z - 60)
- {
- char.gotoAndPlay("airattack");
- }
- }
- else
- {
- char.gotoAndPlay("attack1");
- }
- char.waitForAnimation = true;
- char.comboLvl = 1;
- char.xspeed = char.yspeed = 0;
- }
- }
- }
- overBlock = false;
- for(ob in wallObjects)
- {
- obj = wallObjects[ob];
- if(obj.contains(char.x,char.y))
- {
- if(char.z < wallHeight)
- {
- if(obj.contains(oldpos.x,char.y))
- {
- char.y = oldpos.y;
- }
- if(obj.contains(char.x,oldpos.y))
- {
- char.x = oldpos.x;
- }
- if(char !== playerCharacter)
- {
- if(!char.airborne)
- {
- char.zspeed += char.jumpPower;
- char.airborne = true;
- }
- }
- }
- else
- {
- overBlock = true;
- }
- }
- }
- groundheight = !overBlock ? 0 : wallHeight;
- if(!char.waitForAnimation)
- {
- if(char.z > groundheight)
- {
- char.gotoAndStop("jump");
- }
- else if(walkin)
- {
- if(char.currentAction !== "run")
- {
- char.gotoAndPlay("run");
- }
- }
- else
- {
- char.gotoAndStop("stand");
- }
- }
- }
- else
- {
- oldpos = {x:char.x,y:char.y};
- moveChar(char);
- overBlock = false;
- for(ob in wallObjects)
- {
- obj = wallObjects[ob];
- if(obj.contains(char.x,char.y))
- {
- if(char.z < wallHeight)
- {
- if(obj.contains(oldpos.x,char.y))
- {
- char.y = oldpos.y;
- char.yspeed *= -1;
- }
- if(obj.contains(char.x,oldpos.y))
- {
- char.x = oldpos.x;
- char.xspeed *= -1;
- }
- }
- else
- {
- overBlock = true;
- }
- }
- }
- if(char.attack)
- {
- char.attack = false;
- for(ch2 in activeChars)
- {
- char2 = activeChars[ch2];
- if(char2 !== char and char2.team !== char.team and char2.currentAction !== "die")
- {
- if(Math.abs(char2.z - char.z) < 60)
- {
- pt = new flash.geom.Point(char2._x,char2._y);
- game.localToGlobal(pt);
- if(char.hit.hitTest(pt.x,pt.y,false))
- {
- if(char !== playerCharacter)
- {
- char.comboLvl = char.comboLvl + 1;
- }
- if(char2.boss == true and char2.currentAction == "attack1")
- {
- char.gotoAndPlay("recoil");
- char.zspeed = 15;
- }
- else if(char2.currentAction == "block")
- {
- char.gotoAndPlay("recoil");
- char.zspeed = 15;
- }
- else if(!random(!char2.standoff ? 12 : 2) and (char.x >= char.fighting.x ? char.fighting._xscale < 0 : char.fighting._xscale > 0))
- {
- char2.gotoAndPlay("block");
- char.gotoAndPlay("recoil");
- char.zspeed = 15;
- }
- else
- {
- char2.fighting = char;
- battlesound.attachSound("swordsound" + random(3));
- battlesound.start();
- char2.health -= char.str * (1 + char.att / 100) * (1 - char2.def / 200);
- if(so.data.godmode)
- {
- playerCharacter.health = 100;
- }
- if(char == playerCharacter)
- {
- playerMoney += Math.floor(char.str * (1 + char2.def / 30));
- }
- if(char2.health > 0)
- {
- char2.healthbar._xscale = char2.health;
- char2.gotoAndPlay("recoil");
- }
- else
- {
- switch(battleMode)
- {
- case "elimination":
- char.points--;
- _root["pts" + char.charnum] = char.points;
- if(char.points == 0)
- {
- winningteam = char.team;
- if(winningteam == playerCharacter.team)
- {
- battleProgress++;
- playerMoney += 100 * battleProgress;
- closeGame();
- win.play();
- }
- else
- {
- lose.play();
- }
- delete game.onEnterFrame;
- blackscreen._alpha = -100;
- blackscreen._visible = true;
- blackscreen.onEnterFrame = function()
- {
- blackscreen._alpha += 3;
- if(blackscreen._alpha >= 100)
- {
- _root.gotoAndStop("prebattle");
- }
- };
- }
- break;
- case "survival":
- char2.points--;
- _root["pts" + char2.charnum] = char2.points;
- enpts = 0;
- for(ch3 in activeChars)
- {
- if(activeChars[ch3].team !== char.team)
- {
- enpts += activeChars[ch3].points;
- }
- }
- if(!enpts)
- {
- winningteam = char.team;
- if(winningteam == playerCharacter.team)
- {
- battleProgress++;
- if(so.data.furthest == undefined)
- {
- so.data.furthest = 0;
- }
- so.data.furthest = battleProgress <= so.data.furthest ? so.data.furthest : battleProgress;
- if(battleProgress == battles.length)
- {
- gotoAndStop("outro");
- if(so.data.timesFinished)
- {
- so.data.timesFinished = so.data.timesFinished + 1;
- }
- else
- {
- so.data.timesFinished = 1;
- }
- }
- so.data.flush();
- playerMoney += 100 * battleProgress;
- closeGame();
- win.play();
- }
- else
- {
- lose.play();
- }
- blackscreen._alpha = -100;
- blackscreen._visible = true;
- blackscreen.onEnterFrame = function()
- {
- blackscreen._alpha += 3;
- if(blackscreen._alpha >= 100)
- {
- _root.gotoAndStop("prebattle");
- }
- };
- }
- }
- char2.healthbar._xscale = 0;
- char2.gotoAndPlay("die");
- char2.currentAction = "die";
- char.fighting = undefined;
- }
- char2.waitForAnimation = true;
- if(char.knockback)
- {
- char.fighting = undefined;
- char2.zspeed = 30;
- if(char2.x < char.x)
- {
- char2._xscale = -100;
- char2.xspeed = -60;
- }
- else
- {
- char2._xscale = 100;
- char2.xspeed = 60;
- }
- }
- else
- {
- char2.zspeed = 15;
- if(char2.x < char.x)
- {
- char2._xscale = -100;
- }
- else
- {
- char2._xscale = 100;
- }
- }
- }
- }
- }
- }
- }
- char.knockback = false;
- }
- }
- aspect = 0.5 - playerCharacter.z / 1000;
- dist = Math.sqrt(Math.pow(char.x,2) + Math.pow(char.y,2));
- myrad = r + Math.atan2(char.y,char.x);
- myc = Math.cos(myrad);
- mys = Math.sin(myrad);
- groundheight = !overBlock ? 0 : wallHeight;
- if(char.zspeed !== 0 or char.z !== groundheight)
- {
- char.zspeed -= 6;
- char.z += char.zspeed;
- if(char.z <= groundheight)
- {
- char.z = groundheight;
- char.zspeed = 0;
- if(!char.waitForAnimation)
- {
- char.gotoAndPlay("land");
- }
- char.airborne = false;
- }
- }
- char._x = myc * dist;
- char._y = mys * dist * aspect - char.z;
- char.shadow._x = char._x;
- char.shadow._y = char._y + char.z;
- char.shadow._xscale = 100 - char.z / 2;
- if(char.shadow._xscale < 30)
- {
- char.shadow._xscale = 30;
- }
- char.shadow._yscale = char.shadow._xscale * aspect;
- char.shadow.swapDepths(char.getDepth() - 1);
- if(overBlock)
- {
- char.shadow._y -= wallHeight;
- }
- char.overBlock = overBlock;
- }
- for(wp in wallpanels)
- {
- panel = wallpanels[wp];
- dist = Math.sqrt(Math.pow(panel.x,2) + Math.pow(panel.y,2));
- myrad = r + Math.atan2(panel.y,panel.x);
- panel._x = Math.cos(myrad) * dist;
- panel._y = Math.sin(myrad) * dist * aspect;
- rotate(panel,arenaRotation + panel.rot);
- }
- for(tp in toppanels)
- {
- panel = toppanels[tp];
- dist = Math.sqrt(Math.pow(panel.x,2) + Math.pow(panel.y,2));
- myrad = r + Math.atan2(panel.y,panel.x);
- panel._parent._x = Math.cos(myrad) * dist;
- panel._parent._y = Math.sin(myrad) * dist * aspect - wallHeight;
- panel._rotation = arenaRotation;
- panel._parent._yscale = 100 * aspect;
- }
- topRow = [];
- frontRow = [];
- middleRow = [];
- backRow = [];
- offstageRow = [];
- for(ch in activeChars)
- {
- char = activeChars[ch];
- if(char.overBlock)
- {
- topRow.push(char);
- }
- else if(Math.abs(char.x) <= char.y and char.y > 1)
- {
- frontRow.push(char);
- }
- else if(Math.abs(char.x) <= char.y + mapwide / 2 and char.y > (- mapwide) / 2)
- {
- middleRow.push(char);
- }
- else if(char.y >= (- mapwide) / 2)
- {
- backRow.push(char);
- }
- else
- {
- offstageRow.push(char);
- }
- }
- topRow = sortDepths(topRow);
- frontRow = sortDepths(frontRow);
- middleRow = sortDepths(middleRow);
- backRow = sortDepths(backRow);
- offstageRow = sortDepths(offstageRow);
- depthAr = offstageRow.concat([backWall],backRow,boxRear,middleRow,boxFront,frontRow,topRow);
- depthcount = 1;
- d = 0;
- while(d < depthAr.length)
- {
- obj = depthAr[d];
- obj.swapDepths((d + 1) * 2);
- d++;
- }
- for(ch in activeChars)
- {
- char = activeChars[ch];
- char.shadow.swapDepths(char.getDepth() - 1);
- }
- game._x = (Stage.width / 2 - playerCharacter._x + game._x * 5) / 6;
- game._y = (Stage.height / 2 - playerCharacter._y + game._y * 5) / 6;
- groundHolder._yscale = 100 * aspect;
- };
-