A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Shooter Game Help In Flash 8

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    7

    Unhappy Shooter Game Help In Flash 8

    How do you make a movie clip follow your cursor and shoot bullets when you click spacebar? I use flash 8, as2.

  2. #2
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    well, the following your cursor is easy. Just use [whatever the movieclip is].startDrag(true);

    Also, Mouse.hide() will make the mouse pointer go away, too.


    The shooting bullets is more difficult, because it really depends entirely on how you are setting up the game. However, to make it do SOMETHING when you press the spacebar, you would use this:

    Code:
    var keylistener=new Object();
    keylistener.onKeyDown=function(){
        if(Key.getCode()==Key.SPACE){
            //...your code here...
        }
    }
    Key.addListener(keylistener);
    Hope that helps!
    -Zippy Dee
    Ted Newman

  3. #3
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    legodude... you're asking us to write you your whole code, man! XD
    Actionscript Code:
    var Bdepth:Number;
    if(Bdepth > 100 || Bdepth == undefined){
    Bdepth = 20;
    }

    player_mc.onEnterFrame = function(){
    player_mc._x = _xmouse;
    player_mc._y = _ymouse;

    if(Key.isDown(Key.SPACE)){
    shoot();
    }
    }

    function shoot():Void{
    Bdepth ++;
    duplicateMovieClip(bullet_mc, "BT" + Bdepth + "_mc", Bdepth);
    var BULLET:MovieClip = _root["BT" + Bdepth + "_mc"];
    BULLET._x = _xmouse;
    BULLET._y = _ymouse;

    BULLET.onEnterFrame = function(){
    this._x += 8;
    }
    }
    }

  4. #4
    Junior Member
    Join Date
    Jul 2010
    Posts
    7
    Quote Originally Posted by koenahn View Post
    legodude... you're asking us to write you your whole code, man! XD
    Actionscript Code:
    var Bdepth:Number;
    if(Bdepth > 100 || Bdepth == undefined){
    Bdepth = 20;
    }

    player_mc.onEnterFrame = function(){
    player_mc._x = _xmouse;
    player_mc._y = _ymouse;

    if(Key.isDown(Key.SPACE)){
    shoot();
    }
    }

    function shoot():Void{
    Bdepth ++;
    duplicateMovieClip(bullet_mc, "BT" + Bdepth + "_mc", Bdepth);
    var BULLET:MovieClip = _root["BT" + Bdepth + "_mc"];
    BULLET._x = _xmouse;
    BULLET._y = _ymouse;

    BULLET.onEnterFrame = function(){
    this._x += 8;
    }
    }
    }
    Thx, but how do you make the bullets shoot the opposite way?
    Last edited by Legodude2000; 07-25-2010 at 07:52 PM.

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Location
    Montral
    Posts
    14,141
    Thx, but how do you make the bullets shoot the opposite way?
    You reverse the movement part. Do you know where it is in the code?
    Also read point #2 of this Forum's guidelines.


    gparis

  6. #6
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    Quote Originally Posted by koenahn View Post
    legodude... you're asking us to write you your whole code, man! XD
    Actionscript Code:
    var Bdepth:Number;
    if(Bdepth > 100 || Bdepth == undefined){
    Bdepth = 20;
    }

    player_mc.onEnterFrame = function(){
    player_mc._x = _xmouse;
    player_mc._y = _ymouse;

    if(Key.isDown(Key.SPACE)){
    shoot();
    }
    }

    function shoot():Void{
    Bdepth ++;
    duplicateMovieClip(bullet_mc, "BT" + Bdepth + "_mc", Bdepth);
    var BULLET:MovieClip = _root["BT" + Bdepth + "_mc"];
    BULLET._x = _xmouse;
    [B]BULLET._y = _ymouse;[/B]

    BULLET.onEnterFrame = function(){
    [B]this._x += 8;[/B]
    }
    }
    }
    BULLET._y = _ymouse; means the y-coordinate of the bullet is equal to the y-coordinate of the mouse (the 'height' on the stage, the position between top and bottom)
    if you want the bullet to be a bit lower, just change it to BULLET._y = _ymouse + 30; (you can make the 30 any number of course)


    BULLET.onEnterFrame = function(){
    this._x += 8;
    }
    this means that every frame, the bullet will change its x-coordinate (adding 8 to it [you can change this 8 to another number if you want the bullet to move faster or slower])
    if you want the bullet to go in the other direction, you must not ADD 8 to the x-coordinate every frame, but SUBSTRACT 8. this means the code should be:


    BULLET.onEnterFrame = function(){
    this._x += 8 * DIR;
    }


    you have to add a varible (a number) called DIR which is equal to -1 if your character is moving left, and 1 if your character is moving right, or whaterver should influence the direction of your shots.

    hope you understand the code.

    cheers!

  7. #7
    Junior Member
    Join Date
    Jul 2010
    Posts
    7

    Smile

    Quote Originally Posted by koenahn View Post
    BULLET._y = _ymouse; means the y-coordinate of the bullet is equal to the y-coordinate of the mouse (the 'height' on the stage, the position between top and bottom)
    if you want the bullet to be a bit lower, just change it to BULLET._y = _ymouse + 30; (you can make the 30 any number of course)


    BULLET.onEnterFrame = function(){
    this._x += 8;
    }
    this means that every frame, the bullet will change its x-coordinate (adding 8 to it [you can change this 8 to another number if you want the bullet to move faster or slower])
    if you want the bullet to go in the other direction, you must not ADD 8 to the x-coordinate every frame, but SUBSTRACT 8. this means the code should be:


    BULLET.onEnterFrame = function(){
    this._x += 8 * DIR;
    }


    you have to add a varible (a number) called DIR which is equal to -1 if your character is moving left, and 1 if your character is moving right, or whaterver should influence the direction of your shots.

    hope you understand the code.

    cheers!
    Thanks a lot, dude!!!

  8. #8
    Senior Member
    Join Date
    Mar 2010
    Posts
    157
    no problem

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