home *** CD-ROM | disk | FTP | other *** search
- function initialization()
- {
- if(_global.score == undefined)
- {
- _global.score = 0;
- }
- if(_global.Life == undefined)
- {
- _global.Life = 2;
- }
- backgroundList = new Array();
- characterList0 = new Array();
- characterList1 = new Array();
- bulletList0 = new Array();
- bulletList1 = new Array();
- time = 0;
- gravity = 5;
- stageClear = false;
- gameOver = false;
- backgroundX = 0;
- backgroundVX = 0;
- textFormat = new TextFormat();
- textFormat.font = "Arial";
- hitSound = new Sound();
- hitSound.attachSound("hitSound");
- depthUsed = 0;
- _root.stop();
- drawPanel();
- _visible = false;
- initialized = true;
- }
- function drawPanel()
- {
- _parent.createEmptyMovieClip("hpScorePanel",100000);
- with(_parent.hpScorePanel)
- {
- beginFill(0);
- moveTo(0,0);
- lineTo(700,0);
- lineTo(700,80);
- lineTo(0,80);
- lineTo(0,0);
- endFill();
- textFormat.size = 20;
- textFormat.color = 16777215;
- createTextField("text1",1,70,8,50,40);
- text1.text = "HP:";
- text1.setTextFormat(textFormat);
- createTextField("text3",2,20,40,150,40);
- text3.text = "Distance:";
- text3.setTextFormat(textFormat);
- createTextField("text2",3,470,8,200,40);
- text2.text = "Score:";
- text2.setTextFormat(textFormat);
- createTextField("score",4,550,8,200,40);
- score.text = parseInt(_global.score);
- score.setTextFormat(textFormat);
- createTextField("text4",5,470,40,200,40);
- text4.text = "Life:";
- text4.setTextFormat(textFormat);
- createTextField("life",6,550,40,200,40);
- life.text = parseInt(_global.life);
- life.setTextFormat(textFormat);
- createEmptyMovieClip("hpBarBack",7);
- with(hpBarBack)
- {
- beginFill(5570560);
- moveTo(0,0);
- lineTo(300,0);
- lineTo(300,15);
- lineTo(0,15);
- lineTo(0,0);
- endFill();
- _x = 120;
- _y = 15;
- }
- createEmptyMovieClip("hpBar",8);
- with(hpBar)
- {
- beginFill(16711680);
- moveTo(0,0);
- lineTo(300,0);
- lineTo(300,15);
- lineTo(0,15);
- lineTo(0,0);
- endFill();
- _x = 120;
- _y = 15;
- }
- createEmptyMovieClip("distanceBarBack",9);
- with(distanceBarBack)
- {
- beginFill(13056);
- moveTo(0,0);
- lineTo(300,0);
- lineTo(300,15);
- lineTo(0,15);
- lineTo(0,0);
- endFill();
- _x = 120;
- _y = 47;
- }
- createEmptyMovieClip("distanceBar",10);
- with(distanceBar)
- {
- beginFill(60928);
- moveTo(0,0);
- lineTo(1,0);
- lineTo(1,15);
- lineTo(0,15);
- lineTo(0,0);
- endFill();
- _x = 120;
- _y = 47;
- }
- }
- var Bounds = _parent.hpScorePanel.getBounds(_root);
- _parent.hpScorePanel._x -= Bounds.xMin;
- _parent.hpScorePanel._y -= Bounds.yMin;
- }
- function gameIsOver()
- {
- gameOver = true;
- stageClear = false;
- with(_parent.hpScorePanel)
- {
- createEmptyMovieClip("message",11);
- with(message)
- {
- textFormat.color = 16777215;
- textFormat.size = 50;
- createTextField("t",6,210,200,500,100);
- t.text = "Game Over!";
- t.setTextFormat(textFormat);
- textFormat.size = 25;
- createTextField("clickHere",7,235,260,500,100);
- clickHere.text = "Press \'C\' to continue.";
- clickHere.setTextFormat(textFormat);
- createTextField("quit",8,235,290,500,100);
- quit.text = "Press \'Q\' to quit.";
- quit.setTextFormat(textFormat);
- }
- }
- }
- function clearThisStage()
- {
- stageClear = true;
- gameOver = false;
- with(_parent.hpScorePanel)
- {
- createEmptyMovieClip("message",11);
- with(message)
- {
- textFormat.color = 16777215;
- textFormat.size = 50;
- createTextField("stagecleartext",6,220,200,500,100);
- stagecleartext.text = "Stage Clear!";
- stagecleartext.setTextFormat(textFormat);
- textFormat.size = 25;
- createTextField("clickHere",7,235,270,500,100);
- clickHere.text = "Press \'C\' to continue.";
- clickHere.setTextFormat(textFormat);
- }
- }
- }
- function addScore(s)
- {
- _global.score += s;
- textFormat.size = 20;
- textFormat.color = 16777215;
- _parent.hpScorePanel.score.text = parseInt(_global.score);
- _parent.hpScorePanel.score.setTextFormat(textFormat);
- }
- function deductScore(s)
- {
- _global.score -= s;
- if(_global.score < 0)
- {
- _global.score = 0;
- }
- textFormat.size = 20;
- textFormat.color = 16777215;
- _parent.hpScorePanel.score.text = parseInt(_global.score);
- _parent.hpScorePanel.score.setTextFormat(textFormat);
- }
- function addLife(s)
- {
- _global.life += s;
- textFormat.size = 20;
- textFormat.color = 16777215;
- _parent.hpScorePanel.life.text = parseInt(_global.life);
- _parent.hpScorePanel.life.setTextFormat(textFormat);
- }
- function deductLife(s)
- {
- _global.life -= s;
- if(_global.life < 0)
- {
- _global.life = 0;
- }
- textFormat.size = 20;
- textFormat.color = 16777215;
- _parent.hpScorePanel.life.text = parseInt(_global.life);
- _parent.hpScorePanel.life.setTextFormat(textFormat);
- }
- function mainCharHp(hp, fullHp)
- {
- _parent.hpScorePanel.hpBar._width = 300 * hp / fullHp;
- }
- function distanceBar(a, b)
- {
- var c = 300 * a / b;
- if(c < 1)
- {
- c = 1;
- }
- _parent.hpScorePanel.distanceBar._width = c;
- }
- function addToList(listName, item)
- {
- var list = eval(listName);
- list.push(item);
- }
- function deleteFromList(listName, item)
- {
- var list = eval(listName);
- var i;
- var deleted = false;
- i = 0;
- while(i < list.length)
- {
- if(list[i].id == item.id && list[i].parent == item.parent)
- {
- list.splice(i,1);
- deleted = true;
- break;
- }
- i++;
- }
- if(deleted == false)
- {
- trace("WARNING! gameEngine:[" + _target + "] --- delete item:[" + item.id + "] from list:[" + listName + "] failed!");
- }
- }
- function moveBackgroundRequest(vx)
- {
- backgroundVX += vx;
- }
- function moveBackground()
- {
- if(backgroundX - backgroundVX < 0)
- {
- backgroundVX = backgroundX;
- }
- if(backgroundX - backgroundVX > distance)
- {
- backgroundVX = backgroundX - distance;
- }
- var i;
- var j;
- i = 0;
- while(i < backgroundList.length)
- {
- backgroundList[i].id.move(backgroundVX);
- i++;
- }
- j = 0;
- while(j < 2)
- {
- var tempList = eval("characterList" + j);
- i = 0;
- while(i < tempList.length)
- {
- tempList[i].id.move(backgroundVX);
- i++;
- }
- var tempList = eval("bulletList" + j);
- i = 0;
- while(i < tempList.length)
- {
- tempList[i].id.move(backgroundVX);
- i++;
- }
- j++;
- }
- backgroundX -= backgroundVX;
- backgroundVX = 0;
- distanceBar(backgroundX,distance);
- }
- function createBullet(bulletName, position, team, xscale)
- {
- _root.attachMovie(bulletName,"bullet" + depthUsed,depthUsed);
- var temp = eval("_root.bullet" + depthUsed);
- temp._x = position.x;
- temp._y = position.y;
- temp.team = team;
- temp._xscale = xscale;
- depthUsed++;
- }
- function createHiting(attack, body)
- {
- var Position1 = {x:attack._x,y:attack._y};
- attack._parent.localToGlobal(Position1);
- var Position2 = {x:body._x,y:body._y};
- body._parent.localToGlobal(Position2);
- _root.attachMovie("hiting","hit" + depthUsed,depthUsed);
- var temp = eval("_root.hit" + depthUsed);
- temp._x = (Position1.x + Position2.x) / 2;
- temp._y = (Position1.y + Position2.y) / 2;
- depthUsed++;
- }
- function detectBodyAttackCollision(List1, List2)
- {
- var i;
- var j;
- var k;
- PlayHitSound = false;
- k = 0;
- while(k < 2)
- {
- var tempList1 = eval(List1 + "List" + k);
- var tempList2 = eval(List2 + "List" + (1 - k));
- j = 0;
- while(j < tempList1.length)
- {
- i = 0;
- while(i < tempList2.length)
- {
- if(tempList1[j].parent.movie.attack != undefined && tempList2[i].parent.movie.body != undefined)
- {
- if(tempList1[j].parent.movie.attack.hitTest(tempList2[i].parent.movie.body))
- {
- if(!(tempList2[i].id.frozenCounter < 0 || tempList2[i].id.frozenCounter > 0 || tempList2[i].id.invincibleCounter > 0))
- {
- playHitSound = true;
- createHiting(tempList1[j].parent.movie.attack,tempList2[i].parent.movie.body);
- tempList2[i].id.attackBy(tempList1[j].id,tempList1[j].parent.movie.attack.hp);
- }
- }
- }
- i++;
- }
- j++;
- }
- k++;
- }
- if(playHitSound)
- {
- hitSound.start();
- }
- }
- function destroyAllObject()
- {
- i = 0;
- while(i < bulletList0.length)
- {
- bulletList1[i].parent.removeMovieClip();
- i++;
- }
- i = 0;
- while(i < bulletList1.length)
- {
- bulletList1[i].parent.removeMovieClip();
- i++;
- }
- _parent.hpScorePanel.removeMovieClip();
- }
- onEnterFrame = function()
- {
- if(initialized == undefined)
- {
- initialization();
- }
- if(stageClear == false && gameOver == false)
- {
- moveBackground();
- detectBodyAttackCollision("character","character");
- detectBodyAttackCollision("character","bullet");
- detectBodyAttackCollision("bullet","character");
- if(backgroundX == distance && characterList0[0].parent._x == width)
- {
- var i;
- i = 0;
- while(i < characterList1.length)
- {
- characterList1[i].id.attackBy(characterList0[0].id,-1000);
- i++;
- }
- i = 0;
- while(i < bulletList1.length)
- {
- bulletList1[i].id.attackBy(characterList0[0].id,-1000);
- i++;
- }
- clearThisStage();
- }
- }
- else if(stageClear == true)
- {
- if(Key.isDown(67))
- {
- stageClear = false;
- destroyAllObject();
- _global.nextStageLabel = String(nextStageLabel);
- tellTarget("_root")
- {
- gotoAndPlay(_global.nextStageLabel);
- }
- }
- }
- else if(gameOver == true)
- {
- if(Key.isDown(81))
- {
- gameOver = false;
- destroyAllObject();
- _global.gameOverLabel = String(gameOverLabel);
- tellTarget("_root")
- {
- gotoAndPlay(_global.gameOverLabel);
- }
- }
- if(Key.isDown(67))
- {
- _parent.hpScorePanel.message.removeMovieClip();
- gameOver = false;
- deductScore(500);
- _global.life = 3;
- }
- }
- if(characterList0[0].id != undefined)
- {
- mainCharHp(characterList0[0].id.hp,characterList0[0].id.fullHp);
- }
- };
-