A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 49

Thread: health AS2

  1. #1
    AS2 User CS4
    Join Date
    Jul 2010
    Posts
    34

    Arrow health AS2

    I am working on a platform engine for the first thing I have ever done in flash, literally. I reposted thisbecause there was some problem with the last one I spent a long time to type so I will get right to the chase. I have a _root.health.text; as the health. And I have player and enemy. What should I put where and stuff? Heres the player:
    Actionscript Code:
    onClipEvent (load) {
    var ground:MovieClip = _root.ground;
    var grav:Number = 0;
    var gravity:Number = 2;
    var speed:Number = 5;
    var maxJump:Number = -18;
    var scale:Number = _xscale;
    var touchingGround:Boolean = false;
    var dead=false;
    this.gotoAndStop(3);
    mySound = new Sound(this);
    mySound.attachSound("player_jump.wav",isStreaming);
    }
    onClipEvent (enterFrame) {
    _y += grav;
    grav += gravity;
    while (ground.hitTest(_x, _y - 1.8, true)) {
    _y -= gravity;
    grav = 0;
    }
    if (ground.hitTest(_x, _y + 5, true)) {
    touchingGround = true;
    } else {
    touchingGround = false;
    }
    if (Key.isDown(Key.RIGHT)) {
    _x += speed;
    _xscale = scale;
    isLeft=false;
    isRight=true;
    if (ground.hitTest(_x, _y + 2, true)) {
    this.gotoAndStop(2);
    } else {
    this.gotoAndStop(3);
    }
    } else if (Key.isDown(Key.LEFT)) {
    _x -= speed;
    _xscale = -scale;
    isLeft=true;
    isRight=false;
    if (ground.hitTest(_x, _y + 2, true)) {
    this.gotoAndStop(2);
    } else {
    this.gotoAndStop(3);
    }
    } else {
    if (_root.ground.hitTest(_x, _y + 2, true)) {
    this.gotoAndStop(1);
    }
    }
    if (Key.isDown(Key.UP) && touchingGround) {
    grav = maxJump;
    mySound.start();
    this.gotoAndStop(3);
    }
    if (ground.hitTest(_x + (_width / 2.5), _y - (_height / 2), true)) {
    _x -= speed;
    }
    if (ground.hitTest(_x - (_width / 2.5), _y - (_height / 2), true)) {
    _x += speed;
    }
    if (ground.hitTest(_x, _y - (_height), true)) {
    grav = 3;
    }
    }
    onClipEvent(enterFrame){
    if (_root.next_frame.hitTest(_x+1, _y, true)) {
    _parent.nextFrame()
    }
    }
    onClipEvent (enterFrame) {
    if (_root.health.text<=0) {
    health.text -= 5;
    _root._x = 0;
    maxJump=0;
    _root.player.speed = 0;
    this.gotoAndStop(4);
    delete mySound
    }
    }

    and here is the enemy:
    Actionscript Code:
    onClipEvent (load) {
    var speed:Number = 4;
    var ground:MovieClip = _root.ground;
    var grav:Number = 0;
    var gravity:Number = 2;
    var moveDir:String = "right";
    var player_attack:MovieClip = _root.player.attack_point;
    mySound = new Sound(this);
    mySound.attachSound("killed_sound.wav",isStreaming);
    }
    onClipEvent (enterFrame) {
    _y += grav;
    grav += gravity;
    while (ground.hitTest(_x, _y - 1.8, true) && !killed) {
    _y -= gravity;
    grav = 0;
    }
    //Movement
    if (moveDir == "left") {
    this._x -= speed;
    } else {
    this._x += speed;
    }

    //Check if your hitting "ground" but coming from the left
    if (_root.ground.hitTest(_x - (_width / 2), _y - (_height / 2), true) || _root.ground.hitTest(_x - (_width / 2), _y - ((_height / 6) * 4), true)) {
    if (moveDir == "left") {
    moveDir = "right";
    } else {
    moveDir = "left";
    }
    }
    //Check if your hitting "ground" but coming from the right        
    if (_root.ground.hitTest(_x + (_width / 2), _y - (_height / 2), true) || _root.ground.hitTest(_x + (_width / 2), _y - ((_height / 6) * 4), true)) {
    if (moveDir == "left") {
    moveDir = "right";
    } else {
    moveDir = "left";
    }
    }
    if (_root.player.hitTest(_x + (_width / 2), _y - (_height / 2), true) || _root.player.hitTest(_x + (_width / 2), _y - ((_height / 6) * 4), true)) {
    trace("player should of died");
    }
    if (_root.player.hitTest(_x - (_width / 2), _y - (_height / 2), true) || _root.player.hitTest(_x - (_width / 2), _y - ((_height / 6) * 4), true)) {
    trace("player should of died");
    }
    if (this._parent.player.attack_point.hitTest(this) && !killed) {
    _root.player.grav = _root.player.maxJump;
    trace(_root.player.grav);
    this.gotoAndStop(7);
    speed = 0;
    mySound.start();
    _root.score.text++;
    killed = true;
    }
    }

    thanks!

    *Addition* youve played metroid right? thats how id like the health to work, you run into the enemy, you get knocked back (but in this case, if the enemy is hit from the top, they get destroyed but I mean an all-in-general because I will add a variety of enemies) and lose a little health.
    Last edited by fettucini; 07-17-2010 at 03:49 PM. Reason: to make things more clear

  2. #2
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    well on the hittest put the little code that will minus health from the player or enemy whichever one you need it to be taken from, _root.health.text--;
    to minus 1 every time the code appears or
    _root.health.text -= 10;
    to minus 10 from the health everytime the code appears, i think you want someone to put that every where where they think it should go, i dont think anyone would do that for you as a 2 year old could do it, if thats not the case then explain your actual question a little more, then maybe you will be answered

  3. #3
    AS2 User CS4
    Join Date
    Jul 2010
    Posts
    34
    I try those things but it doesnt work how I want it to. Youve played metroid right? Thats how I want the health system to work. So could one of you please change the code(s) for me? Thanks.

  4. #4
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    yes if you give me a kiss :P only messin 8) yes ill have a quick look

  5. #5
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    what games metroid ? haha do you shoot things from your spacecraft thing ? or do you actually fly into the top of the enemy ? if you fly onto the top of the enemy do a hittest for the top of the enemy then do a if statement
    so
    if(hittest && playerdir == "down") {
    ENEMIES HEALTH DECREASES OR DIES whatever
    }


    playerdir is the direction of the player is moving in
    its best to put in the play movement like

    if (Key.isDown(Key.DOWN)) {
    playerdir = "down";
    }


    pretty obvious, that help ? as i dont exactly know what your saying haha

  6. #6
    AS2 User CS4
    Join Date
    Jul 2010
    Posts
    34
    http://www.youtube.com/watch?v=owkrM0XM8OA
    early on youll see samus hit by an enemy

  7. #7
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    ahh :P i see, basically like sonic haha, yeh do what i sed but obviously sometimes you wont press the down key to move downwards you will float down if you get me ? so youl to work out the player direction by a previous and current _y coordinate
    so set the previous coordinate and if that is more than the current y coordinate then the playerdir is down haha its hard to explain :P youll get it

  8. #8
    AS2 User CS4
    Join Date
    Jul 2010
    Posts
    34
    I am really confused, could you make me an .fla please? all you need is an instance ground, _root.health.text; player and enemy1. player is 4 frames, and enemy is three frames technically but the dead frame is 7 on my engine. thanks.

  9. #9
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    ah fecks sake man, i will make you one for tomorrow as im already busy with other things, i will attatch tomorrow, im not promising anything though

  10. #10
    AS2 User CS4
    Join Date
    Jul 2010
    Posts
    34
    ok. at least try and make it tonight though. I live mountian time I think.

  11. #11
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    it wud take me 10mins to make but i got other things to do mate, i will do wen i do

  12. #12
    AS2 User CS4
    Join Date
    Jul 2010
    Posts
    34
    ok. I just cant be on sundays.

  13. #13
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    well you can continue monday then, i am busy helping other people on this forum and others so if you wudnt mind then please let me get on with that because i cant just help you if ive already said i would help someone else

  14. #14
    AS2 User CS4
    Join Date
    Jul 2010
    Posts
    34
    ok...ok....

  15. #15
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    i just started it for you now

  16. #16
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    movements are not realistic but you will get the idea i hope it helps

  17. #17
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    done, just gotta find usb now so i can put it on computer with internet

  18. #18
    AS2 User CS4
    Join Date
    Jul 2010
    Posts
    34
    I know they arent realistic im just making an easy mario-like thing with metroid like damage

  19. #19
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    its easy to make it realistic like, its nothing hard it just takes a lil bit getting the physics for it 100% like hhaa i cant find usb il attatch when i found it though mate

  20. #20
    AS2 User CS4
    Join Date
    Jul 2010
    Posts
    34
    what do you mean you cant find usb? im guessing thats how things are hosted on this site?

Tags for this Thread

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