A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Bow and arrow... Need some code help...

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    4

    Bow and arrow... Need some code help...

    Hello flash programmers!

    As most of you probably don't know, I have started making a bow-man type of game..... There's just one problem: The code

    Here is what I have so far:

    bow.onEnterFrame = function() {
    angle = (180*Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x))/Math.PI+0;
    this._rotation = angle;

    };


    _root.onMouseDown = function() {

    Arrow_Create();
    }
    //add gravity with the code below:
    //arrow.dy += 1;



    function Arrow_Create() {
    var Arrow_speed = 30;

    arrow._rotation = bow._rotation;

    radians = Math.PI*(bow._rotation/180);

    arrow._x = arrow._x - Math.cos(radians)*Arrow_speed;
    arrow._y = arrow._y - Math.sin(radians)*Arrow_speed;
    }
    The major problem is having the arrow's angle be final when I click the mouse, and to shoot out correctly at that angle, and not be still rotating based off the bow's rotation.

    So, if anyone could help me out with this, then that would be great.

    Thanks in advance.
    ~Eyer24.

  2. #2
    Junior Member
    Join Date
    Aug 2010
    Posts
    17
    HI!
    I made a file which is exactly you wanted a few days ago. If you are interested,msg me.
    Last edited by Areslee; 08-21-2010 at 11:39 AM. Reason: breaking the rules

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Areslee, please keep posts in this Forum. If you have a solution, attach it to your post.

    gparis

  4. #4
    Junior Member
    Join Date
    Aug 2010
    Posts
    17
    OK.I'm sorry for breaking the rules!
    I just don't konw how to attach file in this forum.

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    manage attachments - please, read the top sticky and this Forum guidelines.

    gparis

  6. #6
    Junior Member
    Join Date
    May 2010
    Posts
    4
    erm.... those posts dont help me at all either....

    @Areslee: Cant you just post the file here (or better yet the code xD).

  7. #7
    Junior Member
    Join Date
    Aug 2010
    Posts
    17
    this is the code in "arrow" mc:
    onClipEvent (load) {
    if (this._name != "arrows") {
    var arg = this._rotation*Math.PI/180;
    var vx = Math.cos(arg)*20;
    var vy = Math.sin(arg)*20;
    var shoot = true;
    var ground = _root.bow._y+50;
    }
    }

    onClipEvent (enterFrame) {
    if (this._name != "arrows") {
    if (shoot) {
    vy += 0.5;
    this._rotation = Math.atan2(vy, vx)*180/Math.PI;
    this._x += vx;
    this._y += vy;
    if (this._y>=ground) {
    shoot = false;
    }
    } else {
    this._alpha -= 1;
    if (this._alpha == 0) {
    removeMovieClip(this);
    }
    }
    }
    }

  8. #8
    Junior Member
    Join Date
    Aug 2010
    Posts
    17
    this is the code in "bow" mc:
    Actionscript Code:
    onClipEvent (load) {
        var dx = 0;
        var dy = 0;
        var arg = 0;
        var gapcount = 60;
        var gap = false;
    }

    onClipEvent (enterFrame) {
        dx = _root._xmouse-this._x;
        dy = _root._ymouse-this._y;
        arg = Math.atan2(dy, dx)*180/Math.PI;
        this._rotation = arg;
        if (Key.isDown(65)) {
            if (this._x>_root.lw._x+25) {
                this._x -= 5;
            }
        }
        if (Key.isDown(68)) {
            if (this._x<_root.rw._x-20) {
                this._x += 5;
            }
        }
        if (Key.isDown(83)) {
            if (this._y<Stage.height-20) {
                this._y += 5;
            }
        }
        if (Key.isDown(87)) {
            if (this._y>20) {
                this._y -= 5;
            }
        }
    }

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