# Problem with a shooting game =O

**URL:** <https://forum.kirupa.com/t/problem-with-a-shooting-game-o/22693>\
**Category:** flash\
**Created:** [June 7, 2003, 3:12am UTC](https://forum.kirupa.com/t/problem-with-a-shooting-game-o/22693 "2003-06-07T03:12:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elion](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@elion](https://forum.kirupa.com/u/elion)\
**Post date:** [June 7, 2003, 3:12am UTC](https://forum.kirupa.com/t/problem-with-a-shooting-game-o/22693/1 "2003-06-07T03:12:16Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 7, 2003, 6:42pm UTC](https://forum.kirupa.com/t/problem-with-a-shooting-game-o/22693/2 "2003-06-07T18:42:57Z")

</div>

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:

[tertiary operator](http://www.kirupa.com/developer/actionscript/tricks/tertiary.asp)  
[prototypes](http://www.kirupa.com/developer/actionscript/tricks/prototypes.asp)

if you need me to comment the code then just let me know…

-zylum

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 7, 2003, 6:51pm UTC](https://forum.kirupa.com/t/problem-with-a-shooting-game-o/22693/3 "2003-06-07T18:51:56Z")

</div>

: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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 7, 2003, 6:54pm UTC](https://forum.kirupa.com/t/problem-with-a-shooting-game-o/22693/4 "2003-06-07T18:54:43Z")

</div>

first ill try commenting it in depth and if you still have trouble then i’ll simplify it (which will make it longer)

deal?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 7, 2003, 7:25pm UTC](https://forum.kirupa.com/t/problem-with-a-shooting-game-o/22693/5 "2003-06-07T19:25:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 7, 2003, 8:01pm UTC](https://forum.kirupa.com/t/problem-with-a-shooting-game-o/22693/6 "2003-06-07T20:01:24Z")

</div>

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 :()
