A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [Help] Sniper Game

  1. #1
    Junior Member
    Join Date
    Jan 2004
    Posts
    12

    [Help] Sniper Game

    Very simple problem, i'm trying to make the enemy stop when the player shoots it. To make it move I have this:

    code:
    onClipEvent(enterFrame) {
    speed=1
    this._x += speed
    }



    I have an invisible button over the enemy, and when you click it, it goes to the animation of the enemy dead. I've tried several things that have not worked. I put the code in the button when I tried it.

    Help is appreciated~

  2. #2
    Member
    Join Date
    Dec 2003
    Location
    Here.
    Posts
    48

    Re: [Help] Sniper Game

    Originally posted by Venoxo
    Very simple problem, i'm trying to make the enemy stop when the player shoots it. To make it move I have this:

    code:
    onClipEvent(enterFrame) {
    speed=1
    this._x += speed
    }



    I have an invisible button over the enemy, and when you click it, it goes to the animation of the enemy dead. I've tried several things that have not worked. I put the code in the button when I tried it.

    Help is appreciated~
    Now, I am a n00b and this is my first day learning actionscript so don't trust me fully on this one, but I think you are missing a semicolon after the word speed.
    Ding.

  3. #3
    Member
    Join Date
    Dec 2003
    Location
    Here.
    Posts
    48
    I would have done it like this, but I still might be wrong:

    code:
    onClipEvent(enterFrame) {
    speed = 1;
    this._x += speed;
    }



    Might have nothing to do with it though...
    Ding.

  4. #4
    Member
    Join Date
    Dec 2003
    Location
    Here.
    Posts
    48
    Ok, wait... I don't get what you are doing... ignore me -.-'

    I am so stupid, pretend I never posted o.O

    [EDIT] I just realized I could have edited all those posts, omg I am the stupidest n00b ever.

    lol, umm, still ignore those.
    Last edited by mrwackoisme; 01-17-2004 at 05:26 PM.
    Ding.

  5. #5
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666

    Re: [Help] Sniper Game

    Venoxo,
    first of all,if you have a variable which always has the same value,you don´t need to define it inside your enterframe loop (as you did with your speed variable).its just a minor thing,but you should keep in mind to only put things inside your enterframe loops which you really need to refresh each screen refresh
    (to save cpu power you need somewhere else).
    next,if you want to move the character only if hes alive,put a check in his movement code to see if hes alive,something like this:

    code:

    onClipEvent(load){
    speed=1
    alive=true
    }
    onClipEvent(enterFrame) {
    if(alive){
    this._x += speed}
    }

    //and on the button something like this:
    on(press){
    alive=false}



    mrwackoisme,no worries,everyone has started like that (or similar)
    and bout your suggestion: a semi colon is good coding behaviour but not needed to make the code work.
    (and you don´t have to quote your posts,you can just press the reply button )

  6. #6
    Yea, what the guy above said... you need a quick if statment to check if he is alive... then just have somthing that changes that so he no longer moves... =)

    Ely

  7. #7
    Junior Member
    Join Date
    Jan 2004
    Posts
    12
    Forgot to post that it worked, thanks tomsamson.

  8. #8
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    Huh!! sniper games are boring, totally rediculous.........well Iam working on one too so plz make some other game, or go and have a pizza or something or just totally forget about flash.... <Vanish> there did that work?
    -Aditya

  9. #9
    Junior Member
    Join Date
    Jan 2004
    Posts
    12
    [NEW PROBLEM]
    Part of my game is the player moves the character around and uses the mouse to aim at the enimies to shoot them. So i have a movie clip that follows the mouse movement. Code:
    code:


    onClipEvent(load){

    X = this._x;
    Y = this._y;

    }
    onClipEvent(mouseMove){

    Xm = _parent._xmouse;
    Ym = _parent._ymouse;

    Xdiff = Xm - X;
    Ydiff = Ym - Y;

    radAngle = Math.atan2(Ydiff , Xdiff);

    this._rotation = radAngle*360/(2*Math.PI);

    }



    Now, it works fine, and follows the player when I move. The player can duck, and in the keyframe I moved the movie clip down. But when I run the game and I duck, it stays in the exact same position as when standing.

    Help plx?

  10. #10
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    If the code is on the mc you moved down, then hopefully you can just change:


    onClipEvent(enterFrame){
    X = this._x;
    Y = this._y;
    }

    But if the mc you moved down is inside another mc and the code is on that parent mc, then you would need to calculate X and Y differently depending on is player standing or ducking.

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