A Flash Developer Resource Site

Results 1 to 20 of 49

Thread: health AS2

Threaded View

  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

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