I’ve been working on learning the scripting for a game with the use of arrow keys and space bar to go in circles and shoot stuff :-. I’ve gotten to the point in which I got everything to work but one thing. Whenever I hit spacebar, it does what its supposed to do, but when I hit it again, the one that was originally being shot out is warped back and shot out again. How can I have more than one out on the screen? (I have the .fla attached if you need to look at my scripting.)
hmm… the code in that fla was a little inefficient :hangover: and i couldn’t find the fire scripting so i made you a new fla it’s not commented because i got tired from all that scripting but if you want i’ll comment it later but for now try to look through it. the things that may confuse you the most are the ‘tertiary operator’ and the fact that i’m using prototype instead of functions. to read more those topics then check out these links:
if you need me to comment the code then just let me know…
-zylum
:hat: Sorry to put you through the trouble. but could you try to make it a tad simpler to understand? ^_^; I have no idea what almost all this scripting means. :x
first ill try commenting it in depth and if you still have trouble then i’ll simplify it (which will make it longer)
deal?
i commented the first function (this took more time than i expected…) do you understand it?
[AS]screenWidth = 700;
screenHeight = 480;
MovieClip.prototype.moveMe = function(topSpd, turnSpd) {//starts a prototype named moveMe with the variables topSpd(controls the ships top speed) and turnSpd(controls how fast the ship turns)
Key.isDown(Key.LEFT) ? this.turn=-turnSpd /* if left key is pressed then turn = negative turnSpd*/ : /else/ Key.isDown(Key.RIGHT) ? this.turn=turnSpd /* if Right key is pressed then turn = positive turnSpd*/ else/ this.turn *= 0.85; //turn is multiplaied by 0.85. this gradually lowers turn to zero
Key.isDown(Key.UP) ? this.speed += 0.2 /if up is pressed, then speed is increased by 0.2/: Key.isDown(Key.DOWN) ? this.speed *= 0.94/if down is pressed, then speed is multiplied by 0.94 to slow it down quickly/ : this.speed *= 0.99;//else, the speed is multiplied by 0.99 to slow it down slowly
this.speed =/*speed is equal to: */ this.speed>topSpd/if speed is greater than topSpd then speed = topSpd. this keeps the speed from going too high/ ? topSpd : this.speed;/else the speed doesn’t change/
this.ang += this.turn; /turn is added to the ships angle/
this.dx = Math.cos(this.ang)*this.speed; /some trig to determine how far to move on the x axis/
this.dy = Math.sin(this.ang)*this.speed; /some trig to determine how far to move on the y axis/
this._x += this.dx; /*dx is added to the ships x position */
this._y += this.dy; /*dy is added to the ships y position /
this._rotation = this.ang(180/Math.PI); /the ships rotation is determined. the angle(in radians) is converted to degrees/
this._x = this._x>screenWidth ? 0 /if the ships x is greater than the screen width then it’s x becomes 0/ : this._x<0 ? screenWidth /if the x is less then zero, then it becomes the screen’s width/: this._x;/if the x is neither greater than the screenwidth nor less than zero, then the x stays the same/
this._y = this._y>screenHeight ? 0 : this._y<0 ? screenHeight : this._y; //same as above but for the y axis
//the above 2 lines prevent the ship from leaving the screen by making it go to the opposite side of the screen when it goes off one side
};[/AS]
i know the commenting is not too good but do you understand it?
I’m still kindof confuesed… :-\ Instead of having the movement of the ship like this, think you could have it simpler like it is in the attachment I had? (Sorry for all the trouble :()