Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-07-2010, 09:50 PM   #1
Mcasey
Registered User
 
Join Date: Mar 2010
Posts: 1
Default [AS2] Pause/ Play Button in Flash CS4

I really need help constructing a Play/ Pause button. I am making a tower defense game and need 2 things. A play/pause button that totally freezes everything, like in other tower defenses, and a code line that when a "creep" hits one of my towers, it stays there. Lets just say the tower's instant name is "stuck" Any help would be EXTREMELY appreciated!!

Here is my code now.
stop();

(some is missing for space purposes)

_root.hasGameStarted = false;
_root.hasGameFinished = false;

_root.towerCount = 0;
_root.selectedTower = "";

_root.currentNumberOfCreeps = 0;
_root.creepCount = 0;
_root.creepArray = [];
_root.creepLeaks = 0;

_root.explosionCount = 0;
_root.particleCount = 0;

_root.kills = 0;

_root.gold = 50;

_root.count = 1;
_root.maxCount = 40;
_root.updateDuration = 2;

_root.health = 20;

_root.score = 0;

function executeCallback() {

if (_root.hasGameStarted) {
if(_root.count >= _root.maxCount) {
_root.newLevel();
_root.count = 1;
}

if ((_root.wave - 1) < (_root.waves.length - 1))
{
_root.count++;
}
else
{
if (_root.currentNumberOfCreeps <= 0)
{
_root.hasGameStarted = false;
_root.inGameMessage("<font color=\'#0000FF\'>Great Job! You did, you saved us all!</font>");
}
}
}
else
{
for (var i = 1; i <= _root.towerCount; i++)
{
b = _root["t" + i];
if ("" + b != "undefined")
{
Explosion("projectile_fire", b._x, b._y);
b.removeMovieClip();
} // end if
} // end of for
}
}

function towerInfo(tower)
{
_root.selectedTower = tower;
_root.ranger._x = tower._x;
_root.ranger._y = tower._y;
_root.ranger._width = tower.range * 2;
_root.ranger._height = tower.range * 2;

_root.UpgradeTowerInfo._visible = true;
if (tower.upgrades.length >= tower.level)
{
_root.UpgradeTowerInfo.UpgradeInfoText.text = tower.upgrades[tower.level - 1][0];
_root.UpgradeTowerInfo.TowerInfoText.text = "Damage: " + tower.damage +
"\rRange: " + tower.range +
"\rSplash: " + (tower.splash?"Yes":"No") +
"\rSlow: " + (tower.slow?"Yes":"No") +
"\rPoison: " + (tower.poison?"Yes":"No");

_root.UpgradeTowerInfo.UpgradeButton.UpgradeButton Text.text =
"Upgrade [$" + tower.upgrades[tower.level - 1][1] + "]";
_root.UpgradeTowerInfo.UpgradeButton._visible = true;
}
else
{
_root.UpgradeTowerInfo.f.text = "";
_root.UpgradeTowerInfo.UpgradeButton._visible = false;
_root.UpgradeTowerInfo.h.text = "";
} // end else if
}


function newLevel()
{
_root.wave++;

updateInfoBar();

//_root.creepCount = 0;
//_root.creepArray = [];

if ((_root.wave - 1) < (_root.waves.length - 1))
{
_root.inGameMessage("<b>Start Wave: " + _root.wave + " - Enemy Health: " + _root.waves[_root.wave - 1][1] + " </b>");
_root["spawnInterval" + _root.wave] = setInterval(_root, "spawn", _root.waves[_root.wave - 1][3],
_root.wave,
"creep1",
_root.waves[_root.wave - 1][2],
_root.waves[_root.wave - 1][1],
_root.waves[_root.wave - 1][4]);

_root["creepEventInterval" + _root.wave] = setInterval(_root, "creepEvent", 500);

_root["spawned" + _root.wave] = _root.waves[_root.wave - 1][0];
}

updateScore();
}


function creepEvent () {
for (i = 0; i <= _root.creepArray.length; i++)
{
if ("" + _root.creepArray[i] != "")
{
if (_root.creepArray[i].poison > 0) {
_root.creepArray[i].health = _root.creepArray[i].health -
((_root.creepArray[i].poison * _root.creepArray[i].health) / 100);
_root.creepArray[i].poison--;
}
}
}
}

function spawn(level, creep, speed, health, gold)
{
if (_root["spawned" + level] == 0)
{
clearInterval(_root["spawnInterval" + level]);
}
else
{
--_root["spawned" + level];
++_root.creepCount;
++_root.currentNumberOfCreeps

_root[creep].duplicateMovieClip("c" + _root.creepCount, 1000 + _root.creepCount);
c = _root["c" + _root.creepCount];
_root.creepArray[_root.creepArray.length] = c;
c.creep.gotoAndStop(level);
c._x = wp1._x;
c._y = wp1._y;
c.speed = speed;
c.maxspeed = speed;
c.targ = 2;
c.rnd = random(10);
c.health = health;
c.maxHealth = health;
c.isDead = 0;
c.gold = gold;

c.onEnterFrame = function ()
{
if (this.health <= 0)
{
_root.kill(this);
}

if (this.speed < this.maxspeed)
{
this.speed = this.speed + 1.000000E-001;
}

this.targX = _root["wp" + this.targ]._x - 5 + this.rnd;
this.targY = _root["wp" + this.targ]._y - 5 + this.rnd;
this.dir = Math.atan2(this.targY - this._y, this.targX - this._x) * 180 / 3.141593E+000;

// This is all new as it relates to rotation
this.r = this.dir + Math.sin((getTimer() + this.rnd * 100) / 100) * 7;

if (this.creep._rotation + 10 < this.r)
{
this.creep._rotation = this.creep._rotation + 10;
}
else if (this.creep._rotation - 10 > this.r)
{
this.creep._rotation = this.creep._rotation - 10;
}
else
{
this.creep._rotation = r;
} // end else if


this.rads = this.dir * 3.141593E+000 / 180;
this._x = this._x + Math.cos(this.rads) * this.speed;
this._y = this._y + Math.sin(this.rads) * this.speed;
d = Math.sqrt(Math.pow(this._x - this.targX, 2) + Math.pow(this._y - this.targY, 2));
if (d < 5)
{
++this.targ;
if (this.targ > 8)
{
_root.leak(this);
_root.updateInfoBar();
}
}

this.health_bar.health._width = 30 / this.maxHealth * this.health;

//Lets make the health bar for the creep visible
this.health_bar._visible = true;
};
} // end else if
} // End of the function
Mcasey is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:43 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.