i am making a game, sort of like galaga or something similar. for the time being, i am substituting a keypress for getting hit by an enemy’s missile. the problem is, the shields are screwed up. i have if commands for them, to go to different frames when the value of health is at different levels, but their movement seems to be erratic. will someone please look at the fla, and tell me what i’ve done wrong?
www.barbdwyer.com/game/shipwithcontrols.fla
i’ve looked at your files and im having a really big problem finding how the space bar actually does something — but your problem probably comes from coding, if I could find it i’d be glad…
Post it here otherwise…
mlk
it’s coded in the shield symbol:
[AS]on (keyPress “<Space>”) {
_root.shiphealth = _root.shiphealth-1;
}
{[/AS]
[AS]onClipEvent (enterFrame) {
if (_root.shiphealth == 6) {
_parent.gotoAndStop(“6”);
}
}
[/AS]
then on the frame labeled “6”
[AS]onClipEvent (enterFrame) {
if (_root.shiphealth == 5) {
_parent.gotoAndStop(“5”);
}
}
[/AS]
And so on
i really have a problem understanding how everything works - bit confused by all the labels and transparent MCs…
Try adding lots of “trace” functions while debugging your code to see what goes wrong…
sry, i’m a newbie… what is a trace function?
Example of a using the trace method:
trace(“Show me”);
If you put that in a frame or a function when the frame is entered or the function is executed then the trace method will run. It displays an output box. You can put a string in quotes to show a message you want to see or you can use variables to show values.
I’ll look at your fla now,
Regards,
Viru.
I really dont want to be a meanie and say this but !!! How much planning did you do before you started? Honestly dude your code is quite repetitive. I can see what your trying to do but there are better ways to do it.
If you dont mind i’d like to make my own changes to what i think would work better, i’ll post the fla back on here in a few days when i get time to do it.
Regards,
Viru.
lol, at first, i wasn’t even planning on making a game, my friend asked me to make him some images for a game he was making in basic… but then he gave up (after i had already made the image) so, since im just learning flash, i decided it would be a good learning experience to turn it into a game… so the answer is no planning whatsoever lol
thanks for the help
Ok fair enough, at least your trying right, practice makes perfect and all that stuff :P.
Do you mind if i make changes to your fla?
V.
no, i don’t mind, but could you explain to me what you’re doing? it’ll help me learn
Hi,
Firstly i organised your library into folders. Makes it much neater and nicer, :).
I have made the lights on the spaceship into movieclips so their visibility can be set to false, i.e so they become hidden.
I added my own action script to the first frame in the shields movieclip. You might be surprised, i’ve changed that movie clip so that there are only two layers and only one frame. Still use the Space Bar to imitate a hit.
I dont think it’s too complicated, if your unclear about something just ask.
Best Regards,
Viru.
var hitCount = 7;
hitListener = new Object();
hitListener.onKeyDown = function() {
if(Key.isDown(Key.SPACE)) {
takenHit(hitCount);
}
}
Key.addListener(hitListener);
function takenHit(aNum) {
if(hitCount <= 0) {
// Do nothing
}
else {
if (hitCount == 1) {
_root.crashed.text = "Crashed and Burned!!";
}
this[aNum]._visible = false;
hitCount--;
trace(hitCount);
}
}
i know what this does… but could you explain how it works?
btw, thanks for all the help
OK i’ll put a comment next to each line.
var hitCount = 7; // Sets the hitCount variable to 7.
hitListener = new Object(); // Creates an Object.
hitListener.onKeyDown = function() { // Function that executes when ANY key is pressed.
if(Key.isDown(Key.SPACE)) { // Test to see if the SPACE BAR was pressed.
takenHit(hitCount); // If the space bar was pressed then the takenHit method is called to be executed.
}
}
Key.addListener(hitListener); // Tells our object to ‘listen’ out for key strokes.
function takenHit(aNum) { // Function name, and parameter passed as an argument is aNum.
if(hitCount <= 0) { Test to see if all the lights have gone out.
// Do nothing // If all lights are out then nothing happens.
}
else { // If they are not all out then....
if (hitCount == 1) {
_root.crashed.text = "Crashed and Burned!!";
}
this[aNum]._visible = false; //takes the number is passed in the parameters when the function is called when the space bar is pressed. And makes the light invisible. All the lights are MCs with instance names 1-6.
hitCount--; // Decrease the hitCount variable by 1.
trace(hitCount); // So you can see the count go down as the lights go out.
}
}
Regards,
V.
takenHit(hitCount); // The hitCount variable will store a number. The number it stores will be used to relate to the light instances on the ship.
1 relates to the RED light.
2 relates to the ORANGE light.
ETC ETC
6 relates to the LAST GREEN light.
Just added this incase you werent clear.
V.
ok, i think i get it now, thanks a lot!!
Ok. Try planning a bit next time.
I came up with that after about only 2 mins of thinking, plus with about 8 months of flash experience.
Keep it up!