PDA

View Full Version : [AS2] Game Help


ajk62089
02-28-2009, 08:05 PM
I'm not sure if the forums allow html so here's a link to my first game.

http://www.geocities.com/alexkitka/FinalGame.swf

It was a project in which i aced but im not happy with it. Im looking to make it so each time you gain a level, it adds to the the variable nrEnemies. I tried to make it like
var nrEnemies = 8 + _root.level
but i guess it doesnt work like that lol. Any help is greatly appreciated.

My e-mail is alexjk_620@hotmail.com.



stop();
var nrEnemies = 11;
var timer = 5;

xb = _x;
yb = _y;

for (i=1; i<nrEnemies; i++) {
_root.Enemy0.duplicateMovieClip("Enemy"+i,_root.getNextHighestDepth());
}

var i = 0;
var score = 0;
var lives = 5;
var level = 1;
var experience = 0;
this.onEnterFrame = function() {
timer++;

if (_root.lives<=0) {
gotoAndPlay("Scene 2", 2);
}
if (Key.isDown(Key.SPACE)) {
i++;

if (timer>=5) {
_root.attachMovie("Bullet2","Bullet2"+i,_root.getNextHighestDepth());
_root["Bullet2"+i]._x = Ship._x+3;
_root["Bullet2"+i]._y = Ship._y;
timer = 0;
}

}
};

bluemagica
03-01-2009, 04:38 AM
initialise the variable in the onload function of some other frame, like the menu.....and make it a global variable

_global.nrEnemy = 0;

on level up, just change it like _global.nrEnemy += 1;

ajk62089
03-01-2009, 07:05 PM
Making it global seemed like it was gonna work. Everything worked perfect but still didnt add to the nrEnemies variable on level up.

ajk62089
03-01-2009, 09:18 PM
Here's what i have so far if u want to check it out. Go easy on me though, i've only been playing in actionscript for about 2 weeks.

http://www.geocities.com/alexkitka/FinalGame.swf

Its decent but i still need to continue to work on it. Im trying to find a way to add a little progression just so ur not killing the same 11 enemies without the game acually getting harder. Im thinking that i may add a few big enemies that come on to screen after maybe 45 seconds of playing and give them health especially if i can't get the variavle nrEnemies to be added to on each level up.

bluemagica
03-02-2009, 01:47 AM
we are not psychics so we cant help you with the swf.....post your code!

ajk62089
03-02-2009, 02:34 AM
stop();

var nrEnemies = 11; //Number of enemies on the screen.
var timer = 30; //Timer used for bullets.

xb = _x;
yb = _y;

for (i=1; i<nrEnemies; i++) { //Duplicating Enemy0 movie clip
_root.Enemy0.duplicateMovieClip("Enemy"+i,_root.getNextHighestDepth());
}

var i = 0;
var score = 0;
var lives = 5;
var level = 1;
var experience = 0;
var gausGun = 10;
var lazerGun = 5;
var rocketGun = 1;
var bombs = 0;
this.onEnterFrame = function() {
timer++;

if (_root.lives<=0) {
gotoAndPlay("Scene 2", 2); //If i run out of lives
}

if (Key.isDown(49)) {
i++;

if (timer>=6) {
_root.attachMovie("DefaultBullet","DefaultBullet"+i,_root.getNextHighestDepth());
_root["DefaultBullet"+i]._x = Ship._x+3;
_root["DefaultBullet"+i]._y = Ship._y; //Default Weapon
timer = 0;
var shoot_sound = new Sound();
shoot_sound.attachSound("bullet");
shoot_sound.start();
}

}
if (Key.isDown(50)) {
i++;

if (timer>=8 and _root.gausGun >= 1) {
_root.attachMovie("GausBullet","GausBullet"+i,_root.getNextHighestDepth()); //Gaus Weapon
_root["GausBullet"+i]._x = Ship._x+3;
_root["GausBullet"+i]._y = Ship._y;
timer = 0;
_root.gausGun -= 1;
}

}
if (Key.isDown(51)) {
i++;

if (timer>=8 and _root.lazerGun >= 1) {
_root.attachMovie("LazerBullet","LazerBullet"+i,_root.getNextHighestDepth()); //Lazer Weapon
_root["LazerBullet"+i]._x = Ship._x+3;
_root["LazerBullet"+i]._y = Ship._y;
timer = 0;
_root.lazerGun -= 1;
}

}
if (Key.isDown(52)) {
i++;

if (timer>=8 and _root.rocketGun >= 1) {
_root.attachMovie("RocketBullet","RocketBullet"+i,_root.getNextHighestDepth());
_root["RocketBullet"+i]._x = Ship._x+3; //Rocket Weapon
_root["RocketBullet"+i]._y = Ship._y;
timer = 0;
_root.rocketGun -= 1;
}

}
if (Key.isDown(53)) {
i++;

if (timer>=8 and _root.bombs >= 1) {
_root.attachMovie("Bomb","Bomb"+i,_root.getNextHighestDepth());
_root["Bomb"+i]._x = Ship._x+3;
_root["Bomb"+i]._y = Ship._y; //Bomb Weapon
timer = 0;
_root.bombs -= 1;
}

}
};

ajk62089
03-02-2009, 02:35 AM
onClipEvent (enterFrame) {
this._xscale = _root.experience;
if (this._xscale>=200) {
_root.experience = 0;
_root.level += 1;
_root.nrEnemies += 1;
_root.score *= 2;
_root.gausGun += 5;
_root.lazerGun += 3;
_root.rocketGun += 1;
}

}

bluemagica
03-02-2009, 02:59 AM
use code tags while posting code.... [code] your code [ / code] //remove the spaces

and you are not using global variables...use it and it will work!

ajk62089
03-02-2009, 03:05 AM
I tried making it global, it still would not add to that specific variable on level up so i changed it back. I will add notes to all of my code right now on this thread then make all my variables global anyways.

bluemagica
03-02-2009, 03:21 AM
if it dosent work with global, then post your edited code and your fla!

ajk62089
03-02-2009, 04:04 AM
Ok. here's the fla. I only changed the nrEnemies variable to global and everything connected to it. The default is the only bullet that cant hit it for now until i change them all(assuming the _global works and i did something wrong).

Experience Bar Code
onClipEvent (enterFrame) {
this._xscale = _root.experience;
if (this._xscale>=200) {
_root.experience = 0;
_root.level += 1;
_global.nrEnemies += 1;
_root.score *= 2;
_root.gausGun += 5;
_root.lazerGun += 3;
_root.rocketGun += 1;
}
}



Action Layer Code

stop();

_global.nrEnemies = 1;
var timer = 30;

xb = _x;
yb = _y;

for (i=1; i<nrEnemies; i++) {
_root.Enemy0.duplicateMovieClip("Enemy"+i,_root.getNextHighestDepth());//Duplicates enemy into nrEnemies
}

var i = 0;
var score = 0;
var lives = 5;
var level = 1;
var experience = 190;
var gausGun = 10;
var lazerGun = 5;
var rocketGun = 1;
var bombs = 0;
this.onEnterFrame = function() {
timer++;

if (_root.lives<=0) {
Ship.removeMovieClip();
for (k=0; k<_global.nrEnemies; k++) {
_root["Enemy"+k].removeMovieClip();

}
gotoAndPlay("Scene 2", 2);

}

if (Key.isDown(49)) {
i++;

if (timer>=6) {
_root.attachMovie("DefaultBullet","DefaultBullet"+i,_root.getNextHighestDepth());
_root["DefaultBullet"+i]._x = Ship._x+3;
_root["DefaultBullet"+i]._y = Ship._y;
timer = 0;
var shoot_sound = new Sound();
shoot_sound.attachSound("bullet");
shoot_sound.start();
}

}
if (Key.isDown(50)) {
i++;

if (timer>=8 and _root.gausGun>=1) {
_root.attachMovie("GausBullet","GausBullet"+i,_root.getNextHighestDepth());
_root["GausBullet"+i]._x = Ship._x+3;
_root["GausBullet"+i]._y = Ship._y;
timer = 0;
_root.gausGun -= 1;
}

}
if (Key.isDown(51)) {
i++;

if (timer>=8 and _root.lazerGun>=1) {
_root.attachMovie("LazerBullet","LazerBullet"+i,_root.getNextHighestDepth());
_root["LazerBullet"+i]._x = Ship._x+3;
_root["LazerBullet"+i]._y = Ship._y;
timer = 0;
_root.lazerGun -= 1;
}

}
if (Key.isDown(52)) {
i++;

if (timer>=8 and _root.rocketGun>=1) {
_root.attachMovie("RocketBullet","RocketBullet"+i,_root.getNextHighestDepth());
_root["RocketBullet"+i]._x = Ship._x+3;
_root["RocketBullet"+i]._y = Ship._y;
timer = 0;
_root.rocketGun -= 1;
}

}
if (Key.isDown(53)) {
i++;

if (timer>=8 and _root.bombs>=1) {
_root.attachMovie("Bomb","Bomb"+i,_root.getNextHighestDepth());
_root["Bomb"+i]._x = Ship._x+3;
_root["Bomb"+i]._y = Ship._y;
timer = 0;
_root.bombs -= 1;
}

}
};

bluemagica
03-02-2009, 05:06 AM
as far as i see it is adding to the variable.....how can you say it is not?

if you mean it just creates only 1 enemy, that is because the for loop is executed only the first time, you aren't calling it anywhere else!

ajk62089
03-02-2009, 04:37 PM
It didnt add to the variable. I made a text box and linked it to the variable and it never changed from 1.
i tried calling the for loop before but im still a newb. Can i get maybe an example of where and how it would look? i tried it about 3 different ways but chances are, i missed something small and gave up too early.