dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Bullets fired in all directions

  1. #1
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227

    Bullets fired in all directions

    Hello, I need help with some thing. I need this so badly. Here is a sample file. Notice how the bullets fly in the direction that the person aims at, can anyone point out what does this? Or could anyone teach me how? I have inspected this game and cannot find the source of it. Please help!!??! Please PM me if you want, it makes it easier for me to find answers. Sometimes I loose the post that I posted in, thanks.
    -Brent
    Attached Files Attached Files
    Last edited by cobrasniper555; 08-28-2005 at 08:47 PM.

  2. #2
    Member
    Join Date
    Dec 2004
    Posts
    68
    the supplied code is very ugly, but it's inside one of the players (the triangles) actions:

    Code:
    		if (Key.isDown(Key.LEFT)) {
    			_rotation-=rspeed;
    		}
    		if (Key.isDown(Key.RIGHT)) {
    			_rotation+=rspeed;
    		}
    everytime you press the RIGHT or LEFT arrow key, the rotation is changed according to the rspeed variable. raised if RIGHT, lowered if LEFT.

    then, the angle is converted to radians
    Code:
    radangle=_rotation/180*Math.PI;
    and whenever you press the SHIFT key, a bullet is fired:
    Code:
    if (Key.isDown(Key.SHIFT) && timer<1) {
    			shots++;
    			_root.level++;
    			duplicateMovieClip(_root.shot,"shot"+_root.level,_root.level);
    			mc=eval("_root.shot"+_root.level);
    			mc.fired=true;
    			<B>mc.radangle=radangle;
    			mc._x=_x+(Math.sin(radangle)*_width/2);
    			mc._y=_y-(Math.cos(radangle)*_height/2);</B>
    			mc.pn=pn;
    			timer=maxtime;
    		}
    using trig, the bullet is placed with the proper orientation (the bold code above)

  3. #3
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227
    Ok, thanks so much. Now can I use this for other games or is there a simpler way of doing it?
    Excuse my horrible spelling....you can blame my English teacher for that!

  4. #4
    Member
    Join Date
    Dec 2004
    Posts
    68
    The only parts you would need for tracing the angle would be the RIGHT/LEFT button presses, the conversion from degrees to radians, and then the placement on an x,y plane according to the angle...

    Code:
    if (Key.isDown(Key.LEFT)) {
    			_rotation-=rspeed;
    		}
    		if (Key.isDown(Key.RIGHT)) {
    			_rotation+=rspeed;
    		}
    
    
    
    radangle=_rotation/180*Math.PI;
    
    
    mc.radangle=radangle;
    			mc._x=_x+(Math.sin(radangle)*_width/2);
    			mc._y=_y-(Math.cos(radangle)*_height/2);

  5. #5
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227
    And then could I have a variable with all of that as it's value, and then have the bullet shoot to this variable's coordinates?
    Excuse my horrible spelling....you can blame my English teacher for that!

  6. #6
    Member
    Join Date
    Dec 2004
    Posts
    68
    This tutorial on flashkit is pretty helpful...
    http://www.flashkit.com/tutorials/Ga...u-81/index.php

  7. #7
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227
    That code is in Flash 4 though. I have Flash MX Pro 2004. Where is a tut on that for Flash MX Pro 2004?
    Excuse my horrible spelling....you can blame my English teacher for that!

  8. #8
    Member
    Join Date
    Dec 2004
    Posts
    68
    the rotation part of this is the same as what you need...

    Code:
    _root.onEnterFrame=function(){
     if(Key.isDown(Key.SHIFT)){
    //speed of the object when shift is pressed
     speed=
     }else{
    //speed of the object when shift is not pressed
     speed=
     }
    //turns the object counter-clockwise
     if(Key.isDown(Key.LEFT)){
    ._rotation-=speed
     }
    //turns the object clockwise
     if(Key.isDown(Key.RIGHT)){
    ._rotation+=speed
     }
    //calculates the direction of the object and moves it forward
     if(Key.isDown(Key.UP)){
    ._x += speed*Math.sin(._rotation*(Math.PI/180));
    ._y -= speed*Math.cos(._rotation*(Math.PI/180))
     }
    //calculates the direction of the object and moves it forward
     if(Key.isDown(Key.DOWN)){
    ._x -= speed*Math.sin(._rotation*(Math.PI/180));
    ._y += speed*Math.cos(._rotation*(Math.PI/180))
     }
    taken from:
    http://www.flashkit.com/tutorials/Ga...-956/index.php

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center