ActionScript 3 - Player enemy collide, decrease of health bar

Declaring variables

var maxHP:int = 100;

var currentHP:int = maxHP;

var percentHP:Number = currentHP / maxHP.

Here's the code when enemy player collide

If (enemyList.length > 0) {}

for (var m:int = 0; m < enemyList.length; m ++) {}

If {(player.hitTestObject (enemyList [m]))

trace ("player collided with the enemy");

currentHP = 50; decrease in bar //health

If (currentHP < = 0)

{

currentHP = 0;

trace ("You died!");

}

updateHealthBar();

}

}

}

update function

function updateHealthBar (): void

{

percentHP = currentHP / maxHP.

healthBar.barColor.scaleX = percentHP;

}

The output of this code, the player has only two health bar, 100/50.

The problem is when the player hits an enemy, the reduction of fast health bar, due to repeated as a player through the enemy visits (the size of the enemy is as big as a player).

What I want is when the player hits the enemy, the health bar lower only once, even the player through the enemy. And when the health bar 0 bar, game over and the player must restart again this level.

So, how do I get it?

You can use the setTimeout() with Boolean object method:

Create the object in the main timeline

var onTouch:Boolean = false;

If (player.hitTestObject (enemyList [m]) & onTouch == false) {}

onTouch = true;

trace ("player collided with the enemy");

currentHP = 50; decrease in bar //health

If (currentHP<=>

{

currentHP = 0;

trace ("You died!");

}

on the other

{

setTimeout (function () {onTouch = false;}, 1000); Turn it off after 1 second, if the player still alive.

}

updateHealthBar();

}

Tags: Adobe Animate

Similar Questions

  • Make the health bar down (AS2)

    Well, after some work and a lot of mistakes, so I made a health bar for my game. (It is the Actionscript 2)

    Basically, the code is the file .as my main character, there is
    var maxHealth: number = 100;
    health of the var: number = 100;

    and further down the line...
    _root.healthBar._width = (health/maxHealth) * 200;

    ~~~~~~~~

    So, when I change the number of health lower var, the health bar drops lower. Sweet! It works!

    Now, just wondering if any of you guys could help me code so an enemy can inflict damage on the main character.
    I have tried several codes, but they all failed.

    If (this.hitTest (_root. Monster))
    {

    }

    That would put the parentheses?

    Thank you

    :

    If (this.hitTest (_root. Monster))
    {
    This.Health-= 10;  for 10 damage

    and always make sure that health does not go below 0 and when it reaches 0, you take action
    }

  • Try to make the health bar

    I'm doing a health bar. I'm trying to make sure when your health goes down, the bar moves.


    Health = 100;

    HealthBar.TheBar._xscale = the health;

    function updateHealthBar() {}
    HealthBar.TheBar._xscale = the health;
    }

    So far, this is what he does. I made a button, and when you press it it takes your health 5.

    How can I do one side move to the left instead of them, both moving to the Middle?

    Position the wicker and its alignment is along its left edge.

  • Decreases in health battery optimized performance

    I have this problem where when I choose this option, the game performance decreases significantly. I have a y510p with a geforce sli dual 755 m. The second graphics card goes off when it is not plugged in, I'm guessing that the case is at the moment. I rebooted my computer with restart of the entire application and it was not fixed. What I have to reduce my battery less than 60%, then plug it in then get back to normal performance or what.

    Understand the problem. You must connect the charger and decrease the battery below the battery to optimize it. Then you plug it in and it is fine. 60% it says plugged in and not charging and the GPU works both

  • How can I get media player to go was the task bar so I don't have to keep opening upward on the main screen please?

    I just had to recover my pc but now I downloaded the media player 11, but it is more on my taskbar as before. How to do this please.

    Hello

    I suggest you follow the step and check if it helps.

    a. right-click of the mouse on a zone empty of the taskbar.
    b. in the menu that appears, click Toolbars and then click Windows Media Player.
    c. then the Windows Media Player and then reduce it.
    d. the main control buttons appear on the taskbar. You can start playing, go to the next or previous song, pause and so on.
    e. the software in large format, click on the little logo of Windows Media Player.

    See also:

  • "Actionscript file cannot have several external visible definitions:

    Armageddon_ReHash\StateMachine.as, line 15006: an ActionScript file cannot have several definitions visible from the outside: StateMachine, detectHitLevel2

    Hey thanks for checking this, I'm having an odd error that maybe just started, can you give me some comments about why this happens, here's my class and the error I get is above. Please get to me as soon as I need to know tonight.

    Thanks again!

    CODE:

    package {}

    import flash.display.MovieClip;

    import flash.events. *;

    import flash.utils.Timer;

    import flash.display.Stage;

    import flash.sampler.NewObjectSample;

    SerializableAttribute public class StateMachine extends MovieClip {}

    public static var player: Player;

    private var scoreHUD:HUD;

    public var enemyGhostTimer:Timer;

    public var enemyGhost2Timer:Timer;

    public var enemyGhost3Timer:Timer;

    public var levelTimer:Timer;

    health public var = 3;

    public var score = 0;

    public var timeleft = 80;

    Main menu

    public void StateMachine()

    {

    START menu

    var controls: Boolean = false;

    var credits: Boolean = false;

    var advice: Boolean = false;

    Event listeners

    btn_start.addEventListener (MouseEvent.MOUSE_DOWN, start_mouseDownHandler);

    btn_controls.addEventListener (MouseEvent.MOUSE_DOWN, controls_mouseDownHandler);

    btn_credits.addEventListener (MouseEvent.MOUSE_DOWN, credits_mouseDownHandler);

    btn_highscores.addEventListener (MouseEvent.MOUSE_DOWN, highscores_mouseDownHandler);

    Stop();

    Menu system

    function start_mouseDownHandler(event:MouseEvent):void

    {

    sym_pointer.y = 315;

    Stop (1, "Level 1");

    Level1();

    }

    function controls_mouseDownHandler(event:MouseEvent):void

    {

    orders = true;

    gotoAndStop ("controls");

    sym_pointer.y = 368;

    }

    function credits_mouseDownHandler(event:MouseEvent):void

    {

    credits = true;

    gotoAndStop ("credits");

    sym_pointer.y = 421;

    }

    function highscores_mouseDownHandler(event:MouseEvent):void

    {

    Tips = true;

    gotoAndStop ("hints");

    sym_pointer.y = 474;

    }

    }

    End of the game

    public void Gameover()

    {

    Stop();

    btn_restart.addEventListener (MouseEvent.MOUSE_DOWN, restart_mouseDownHandler);

    function restart_mouseDownHandler(event:MouseEvent):void

    {

    Stop (1, "Level 1");

    Level1();

    }

    }

    Timers

    function sendEnemy(e:Event)

    {

    enemy of the var = new Ghost();

    stage.addChild (enemy);

    }

    function sendEnemy2(e:Event)

    {

    var enemy2 = new Ghost2();

    stage.addChild (enemy2);

    }

    function sendEnemy3(e:Event)

    {

    var enemy3 = new Ghost3();

    stage.addChild (enemy3);

    }

    function countDown(e:Event)

    {

    If (timeleft > 0)

    {

    timeLeft-;

    }

    ElseIf (timeleft = 0)

    {

    Disable()

    GameOver();

    }

    }

    //////////////////////////////////////LEVELS////////////////////////////////////////////// ////////

    function Level1 (): void

    {

    reader = new player (internship, 400, 550);

    health = 3;

    stage.addChild (player);

    scoreHUD = new HUD (internship);

    stage.addChild (scoreHUD);

    enemyGhostTimer = new Timer (500);

    enemyGhostTimer.addEventListener ("timerEnemy", sendEnemy);

    enemyGhostTimer.start ();

    levelTimer = new Timer (1000);

    levelTimer.addEventListener ("timerLevel", count);

    levelTimer.start ();

    stage.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler, false, 0, true);

    stage.addEventListener (MouseEvent.MOUSE_UP, mouseUpHandler, false, 0, true);

    stage.addEventListener (Event.ENTER_FRAME, detectHitLevel1);

    }

    function Level2 (): void

    {

    reader = new player (internship, 400, 550);

    stage.addChild (player);

    enemyGhost2Timer = new Timer (2000);

    enemyGhost2Timer.addEventListener ("timerEnemy2", sendEnemy2);

    enemyGhost2Timer.start ();

    stage.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler, false, 0, true);

    stage.addEventListener (MouseEvent.MOUSE_UP, mouseUpHandler, false, 0, true);

    stage.addEventListener (Event.ENTER_FRAME, detectHitLevel2);

    }

    function Level3 (): void

    {

    reader = new player (stage, 25, 550);

    stage.addChild (player);

    enemyGhost3Timer = new Timer (5000);

    enemyGhost3Timer.addEventListener ("timerEnemy3", sendEnemy3);

    enemyGhost3Timer.start ();

    stage.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler, false, 0, true);

    stage.addEventListener (MouseEvent.MOUSE_UP, mouseUpHandler, false, 0, true);

    stage.addEventListener (Event.ENTER_FRAME, detectHitLevel3);

    }

    function detectHitLevel1(e:Event):void

    {

    Limits

    If (Player.hitTestObject (boundsright))

    {

    trace ("Bounds");

    Player.x = player.x-10;

    }

    If (Player.hitTestObject (boundsleft))

    {

    trace ("Bounds");

    Player.x = player.x + 10;

    }

    If (Player.hitTestObject (boundstop))

    {

    trace ("Bounds");

    Player.y = player.y + 10;

    }

    If (Player.hitTestObject (boundsbottom))

    {

    trace ("Bounds");

    Player.y = player.y-10;

    }

    Traps

    If (Player.hitTestObject (Lava1) | player.hitTestObject (Lava2) | player.hitTestObject (Lava3) | player.hitTestObject (Lava4) | player.hitTestObject (Lava5): player.hitTestObject (Lava6): player.hitTestObject (Lava7))

    {

    trace ("Lava");

    If (health < 0)

    {

    stage.removeEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);

    stage.removeEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);

    stage.removeEventListener (Event.ENTER_FRAME, detectHitLevel1);

    stage.removeChild (player);

    for (var i in Ghost.list)

    {

    Ghost.list [i]. Kill();

    }

    Stop (1, "GameOver");

    Gameover();

    }

    -health;

    scoreHUD.updateLives(-1);

    Player.x = 400;

    Player.y = 550;

    }

    Output

    If (Player.hitTestObject (lvl1exit))

    {

    lvl1exit.x = - 10;

    trace ("Exitlvl1");

    score += 10;

    health ++;

    scoreHUD.updateLives (1);

    stage.removeEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);

    stage.removeEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);

    stage.removeEventListener (Event.ENTER_FRAME, detectHitLevel1);

    stage.removeChild (player);

    for (var i in Ghost.list)

    {

    Ghost.list [i]. Kill();

    }

    }

    Stop (1, "Level 2");

    Level2();

    }

    Points

    If (player.hitTestObject (civa))

    {

    CIVA.x = - 10;

    trace ("bonus!");

    score + 5;

    scoreHUD.updateScore (5);

    }

    If (player.hitTestObject (civb))

    {

    CIVB.x = - 10;

    trace ("bonus!");

    score + 5;

    scoreHUD.updateScore (5);

    }

    If (player.hitTestObject (vicc))

    {

    CIVC.x = - 10;

    trace ("bonus!");

    score + 5;

    scoreHUD.updateScore (5);

    }

    }

    function detectHitLevel2(e:Event):void

    {

    Limits

    If (Player.hitTestObject (boundsright))

    {

    trace ("Bounds");

    Player.x = player.x-10;

    }

    If (Player.hitTestObject (boundsleft))

    {

    trace ("Bounds");

    Player.x = player.x + 10;

    }

    If (Player.hitTestObject (boundstop))

    {

    trace ("Bounds");

    Player.y = player.y + 10;

    }

    If (Player.hitTestObject (boundsbottom))

    {

    trace ("Bounds");

    Player.y = player.y-10;

    }

    Traps

    If (Player.hitTestObject (Lava1) | player.hitTestObject (Lava2) | player.hitTestObject (Lava3) | player.hitTestObject (Lava4) | player.hitTestObject (Lava5): player.hitTestObject (Lava6): player.hitTestObject (Lava7))

    {

    trace ("Lava");

    If (health > 0)

    {

    stage.removeEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);

    stage.removeEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);

    stage.removeEventListener (Event.ENTER_FRAME, detectHitLevel2);

    stage.removeChild (player);

    Stop (1, "GameOver");

    Gameover();

    }

    -health;

    scoreHUD.updateLives(-1);

    Player.x = 400;

    Player.y = 550;

    }

    Output

    If (Player.hitTestObject (lvl2exit))

    {

    lvl2exit.x = - 10;

    trace ("Exitlvl2");

    score += 10;

    health ++;

    scoreHUD.updateLives (1);

    stage.removeEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);

    stage.removeEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);

    stage.removeEventListener (Event.ENTER_FRAME, detectHitLevel2);

    stage.removeChild (player);

    Stop (1, "Niveau3");

    Level3();

    }

    Points

    If (player.hitTestObject (civa))

    {

    CIVA.x = - 10;

    trace ("bonus!");

    score + 5;

    scoreHUD.updateScore (5);

    }

    If (player.hitTestObject (civb))

    {

    CIVB.x = - 10;

    trace ("bonus!");

    score + 5;

    scoreHUD.updateScore (5);

    }

    If (player.hitTestObject (vicc))

    {

    CIVC.x = - 10;

    trace ("bonus!");

    score + 5;

    scoreHUD.updateScore (5);

    }

    }

    function detectHitLevel3(e:Event):void

    {

    Limits

    If (Player.hitTestObject (boundsright))

    {

    trace ("Bounds");

    Player.x = player.x-10;

    }

    If (Player.hitTestObject (boundsleft))

    {

    trace ("Bounds");

    Player.x = player.x + 10;

    }

    If (Player.hitTestObject (boundstop))

    {

    trace ("Bounds");

    Player.y = player.y + 10;

    }

    If (Player.hitTestObject (boundsbottom))

    {

    trace ("Bounds");

    Player.y = player.y-10;

    }

    Traps

    If (Player.hitTestObject (Lava1) | player.hitTestObject (Lava2) | player.hitTestObject (Lava3) | player.hitTestObject (Lava4) | player.hitTestObject (Lava5): player.hitTestObject (Lava6): player.hitTestObject (Lava7))

    {

    trace ("Lava");

    If (health > 0)

    {

    stage.removeEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);

    stage.removeEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);

    stage.removeEventListener (Event.ENTER_FRAME, detectHitLevel3);

    stage.removeEventListener (Event.ENTER_FRAME, loop);

    stage.removeChild (player);

    Stop (1, "GameOver");

    Gameover();

    }

    -health;

    scoreHUD.updateLives(-1);

    Player.x = 400;

    Player.y = 550;

    }

    Output

    If (Player.hitTestObject (lvl3exit))

    {

    lvl2exit.x = - 10;

    trace ("Exitlvl3");

    score += 10;

    health ++;

    scoreHUD.updateLives (1);

    stage.removeEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);

    stage.removeEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);

    stage.removeEventListener (Event.ENTER_FRAME, detectHitLevel2);

    stage.removeEventListener (Event.ENTER_FRAME, loop);

    stage.removeChild (player);

    Stop (1, "GameOver");

    Gameover();

    }

    Points

    If (player.hitTestObject (civa))

    {

    CIVA.x = - 10;

    trace ("bonus!");

    score + 5;

    scoreHUD.updateScore (5);

    }

    If (player.hitTestObject (civb))

    {

    CIVB.x = - 10;

    trace ("bonus!");

    score + 5;

    scoreHUD.updateScore (5);

    }

    If (player.hitTestObject (vicc))

    {

    CIVC.x = - 10;

    trace ("bonus!");

    score + 5;

    scoreHUD.updateScore (5);

    }

    }

    }

    I believe that the error is indicating that your class file structure is not formatted properly as it seems to be trying to define several classes in one file.  I suspect it's going to be because of incorrect provision of braces.  Unfortunately, the pileup of the code is a bit much to go through you.

    I noticed that you have many nested named functions (functions within other functions) which causes problems as well.  All functions should stand on their own.

    Maybe you need to really do is to find a way to break this class file into separate files based on the feature class.

  • Patty Burger Game health?

    Hey guys,.

    IM completely new to AS3.0 and flash also, I literally started today because its against completing me a mission design for United.

    so I started to do this prototype with a few basic features but im stuck now as snippets of sample code, our Professor of tutorial given we can't work to me.

    Registry of the mouse event functions
    bun.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);
    bun.addEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);

    tomato.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);
    tomato.addEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);

    Set a mouse down Manager (the user is dragging)
    function mouseDownHandler(evt:MouseEvent):void {}
    var object = evt.target;
    object.startDrag ();
    }
    Set a mouse Manager (stops user dragging)
    function mouseUpHandler(evt:MouseEvent):void {}
    var object = evt.target;
    object.dropTarget will give us the reference to the form of
    the object on which we have abandoned the circle.
    var target = object.dropTarget;
    object.stopDrag ();
    If the object exists AND that it is the blue button, then we change
    the text in the TextBox control.
    Given that obj.dropTarget is a form, we need its parent.
    If (target! = null & & target.parent == bun) {}
    textField.text = "Healthier".
    } else {}
    textField.text = 'UN healthy. "
    }
    }

    I'm basically dragging ingredients on the bun and when the text box is just saying that its healthy or not healthy, I want to be able to slide the bun of healthy ingredients, but have a "health bar" decrease or increase depending on what you drag on the bun.

    Thus, for example, the player moves a slice of tomato on bread, the health bar starts to say 20% she makes more "safety" and if the player drags the bacon on the bun the health bar loses 'safety. "

    IM really out of my depth now, I know what needs to be done (pseudo code ish lol) but I don't have the experience to do so.

    If someone could help me that would be GREAT FREAKING!

    see you soon

    Just do what I said and use the code that I have offered in place of what you had.  With your event listeners to add in...

    bacon.myPoints = - 20;

    tomato.myPoints = 20;

    And you should not having to have a stop() command in this function.  Stop() is an order of chronology, nothing more than that.  So unless you move along the timeline by dragging and want to stop in any framework you happen to be in when you drop an object, it is not necessary.

  • What about Flash Player 'Next '?

    I saw the Flash Player Flash player 13 12 jump and I thout it's time 'next '.

    But I've not seen anything like that.

    When Flash play "Next" beta is ariving?

    As others have said, Adobe has chosen to continue to improve the current Flash runtime architecture. Flash ActionScript and player "Next" "Next", as they were known, is more expected.

    To learn more about the most recent plans, I recommend you take a look at the roadmap for Adobe for the Flash execution environments. It includes an explanation of the decision to Adobe about 'Next', and it's a little information on releases planned until early 2014. I assumed that this document will soon be updated to include information on the further development planned for later in the year, so stayed tuned.

  • Windows Media Player 11 - Seek Bar not synchronized

    Recently, when I play the audio files in Windows Media Player 11 on Vista, the tab bar of the applicant appears and begins to move. However, if I shift it to another part of the song, little matter where I put it, it remains at the beginning of the song. Not necessarily at the beginning, but just not where it should be. The bar maxes and time keeps ticking. I can't move to any part of the song and the timer might hit easily 12 minutes for a 5 minute song as it plays. Any help to solve this? I recently installed Myst V on my computer, but am unsure if this problem started before or after.

    Do you see the correct length of MP3 files affected in the WMP library?

    I suggest that you try to repair these files with MP3 validator (after saving the files).

  • BBC I player loading problems

    It seems impossible to me more to access the BBC I player via the icon in my bar of tasks and do it through the internet. When I'm out there on the internet he asks me if I want to improve further when I try, it says I can that the application is already running (I think it might have something to do with Adobe Reader) do anything no matter which may suggest will appreciate it. Thank you

    Hello

    1. don't you make changes to the computer until the problem occurred?

    I suggest you try the steps mentioned below and check if it helps.

    Uninstall and reinstall BBC iPlayer and check if they help to resolve the issue.

    http://Windows.Microsoft.com/en-us/Windows7/uninstall-or-change-a-program

    http://iplayerhelp.external.BBC.co.UK/help/using_bbc_iplayer/desktopWindows

    If the problem persists, I suggest you to contact BBC iPlayer:

    http://www.BBC.co.uk/feedback/

    Hope this information is useful.

  • I downloaded the latest version of flash player, does not?

    I just got my computer back to be fixed and I'm redownloading everything I need.

    I have a Mac OS X Version 10.7.5 and I downloaded the latest version of flash player for it. It seems to be installed because there is a window opens saying "Thank you, enjoy flash player." or something like that after I downloaded the flash player.

    I tried several times and I STILL can't watch videos or doing things that require flash player.

    I went to my preferences system, clicked on Flash Player and went to the progress bar, and he says "plug-in version 11.9.900.117 is installed."

    However, when I go to this page: http://helpx.Adobe.com/Flash-Player.html

    And I click the "check now" button to see if flash player has been installed on my computer, it says:

    "Sorry, Flash Player is either not installed or not enabled.

    Please proceed to step 2. »

    And so I did and downloaded AGAIN. I saw the same thing once I reloaded the page and try again.

    I don't have an anti-virus program, so it can't be that.

    The flash player is enabled?

    How can I check if it has activated activate / it?

    It is usually in the Tools section of your browser.

  • How to make a bar of "health"?

    Hi, I need a tutorial on how to create a bar of 'health' - I don't have a better word for it, but my idea is to have a bar (showing the happiness of a pet) and whenever you press a button - the pet gains happiness - and the bar 'health' develops. What it is called and is at - it a guide I can read telling me how to create such a code?

    Create a rectangular movieclip for the bar and adjust its width or height property.  Example, were bar is the name of the instance of the health bar abd btn is the instance name of the button

    bar. Width = 0;

    var growValue:Number = 10;

    btn.addEventListener (MouseEvent.CLICK, growBar);

    function growBar(evt:MouseEvent):void {}

    bar. Width += growValue;

    }

  • audio cd playback on blu - ray player

    I have a Sony BDP Blu ray player BX320 and looking to play audio CDs.  The Blu - ray player is connected to a sound bar Vizio via HDMI connections at each end and all works well, both dvd and cd audio.

    The problem is that I'm also enjoying my Bose sound with speakers system in several rooms.  It is connected via a receiver of Techniques very old with only the rca inputs.

    So finally, I would like to read my DVDs through the current installation and audio CDs through the receiver of Techniques to the Bose speakers.  The problem is that the receiver Techniques accepts only the rca inputs.

    I tried to connect the Blu - ray player to the receiver via the digital coaxial Techniques using a digital audio coaxial cable to a double (female RCA to RCA male) separator to the receiver - with the TV/soundbar in the wide receiver.  But it does not work.

    Is it possible to make these connections?

    Technical salute!

    It will work not only with the help of a separator, because you're dealing with analog and digital signals. In this case, you will need an analog converter instead of just a digital splitter. However, Sony does not guarantee complete compatibility/functionality of the use of converters/dispatchers of part 3.

    If you have a TV with HDMI input and output audio RCA, you can also connect your Sony Blu - ray player to your TV via HDMI and audio system via the audio output RCA on the TV without needing the converter/splitter. Then put the audio from your TV on external speakers.

    If my post answered your question, please mark it as "accept as a Solution.

    Thank you

    -Anthony

  • Error #1126

    Hello guys, I am needing help with this bug in adobe flash professional cs6

    Scene 1, 'actions', Quadro 1, Linha 100 Camada1126: a language nao tem um corpo.

    This is the code:

    var maxHP:int = 100;

    var currentHP:int = maxHP;

    var percentHP:Number = currentHP / maxHP.

    function updateHealthBar (): void

    {

    percentHP = currentHP / maxHP.

    healthBar.barColor.scaleX = percentHP;

    }

    function restartGame (): void {}

    currentHP = maxHP;

    updateHealthBar();

    }

    var leftPressed:Boolean = false;

    var rightPressed:Boolean = false;

    var upPressed:Boolean = false;

    var downPressed:Boolean = false;

    var leftBumping:Boolean = false;

    var rightBumping:Boolean = false;

    var upBumping:Boolean = false;

    var downBumping:Boolean = false;

    var leftBumpPoint:Point = new Point (-30, -55);

    var rightBumpPoint:Point = new Point (30, -55);

    var upBumpPoint:Point = new Point (0, -120);

    var downBumpPoint:Point = new Point (0, 0);

    var scrollX:Number = 0;

    var scrollY: number = 500;

    var xSpeed:Number = 0;

    var ySpeed:Number = 0;

    var speedConstant:Number = 4;

    var frictionConstant:Number = 0.9;

    var gravityConstant:Number = 1.8;

    var jumpConstant:Number = - 35;

    var maxSpeedConstant:Number = 18;

    var doubleJumpReady:Boolean = false;

    var upReleasedInAir:Boolean = false;

    var keyCollected:Boolean = false;

    var doorOpen:Boolean = false;

    var currentLevel:int = 1;

    var animationState:String = "rest."

    var bulletList:Array = new Array();

    var enemyList:Array = new Array();

    var bumperList:Array = new Array();

    stage.addEventListener (KeyboardEvent.KEY_DOWN, keyDownHandler);

    stage.addEventListener (KeyboardEvent.KEY_UP, keyUpHandler);

    stage.addEventListener (Event.ENTER_FRAME, loop);

    addEnemiesToLevel1();

    addBumpersToLevel1();

    function addEnemiesToLevel1 (): void

    {

    addEnemy (620,-115);

    addEnemy (900,-490);

    addEnemy (2005-115);

    addEnemy (1225,-875);

    }

    function addBumpersToLevel1 (): void

    {

    addBumper (500,-115);

    addBumper (740,-115);

    }

    function loop(event:Event):void -code says the error is here, I'm a newbie with flash, I don't know if there is an error, if anyone can help, thanks!

    If (back.collisions.hitTestPoint (leftBumpPoint.x, player.y, player.x + leftBumpPoint.y, true)) {}

    trace ("leftBumping");

    leftBumping = true;

    } else {}

    leftBumping = false;

    }

    If (back.collisions.hitTestPoint (rightBumpPoint.x, player.y, player.x + rightBumpPoint.y, true)) {}

    trace ("rightBumping");

    rightBumping = true;

    } else {}

    rightBumping = false;

    }

    If (back.collisions.hitTestPoint (upBumpPoint.x, player.y, player.x + upBumpPoint.y, true)) {}

    trace ("upBumping");

    upBumping = true;

    } else {}

    upBumping = false;

    }

    If (back.collisions.hitTestPoint (downBumpPoint.x, player.y, player.x + downBumpPoint.y, true)) {}

    trace ("downBumping");

    downBumping = true;

    } else {}

    downBumping = false;

    }

    {if (leftPressed)}

    xSpeed = speedConstant;

    player.scaleX = - 1;

    } else {if (rightPressed)

    xSpeed += speedConstant;

    player.scaleX = 1;

    }

    / * if (upPressed) {}

    ySpeed = speedConstant;

    } else {if (downPressed)

    ySpeed += speedConstant;

    }*/

    {if (leftBumping)}

    If (xSpeed < 0) {}

    xSpeed * = - 0.5;

    }

    }

    {if (rightBumping)}

    If (xSpeed > 0) {}

    xSpeed * = - 0.5;

    }

    }

    {if (upBumping)}

    If (ySpeed < 0) {}

    ySpeed * = - 0.5;

    }

    }

    If (downBumping) {//if we touch the ground

    If (ySpeed > 0) {}

    ySpeed = 0; set the speed of y to zero

    }

    If (upPressed) {//and so you press the arrow pointing upwards

    ySpeed = jumpConstant; set the speed of y to the constant jump

    }

    DOUBLE JUMP

    if(upReleasedInAir == true) {}

    upReleasedInAir = false;

    }

    if(doubleJumpReady == false) {}

    doubleJumpReady = true;

    }

    } else {//if we don't touch the floor

    ySpeed += gravityConstant; speed down

    DOUBLE JUMP

    If (upPressed == false & & upReleasedInAir == false) {}

    upReleasedInAir = true;

    trace ("upReleasedInAir");

    }

    If (doubleJumpReady & & upReleasedInAir) {}

    If (upPressed) {//and so you press the arrow pointing upwards

    trace ("after!");

    doubleJumpReady = false;

    ySpeed = jumpConstant; set the speed of y to the constant jump

    }

    }

    }

    if(keyCollected == false) {}

    {if (Player.hitTestObject (back.other.doorKey))}

    back.other.doorKey.visible = false;

    keyCollected = true;

    trace ("collected key");

    }

    }

    if(doorOpen == false) {}

    if(keyCollected == true) {}

    {if (Player.hitTestObject (back.other.lockedDoor))}

    back.other.lockedDoor.gotoAndStop (2);

    D'Enhaut = true;

    trace ("door open");

    }

    }

    }

    if(xSpeed > maxSpeedConstant) {//moving right

    xSpeed = maxSpeedConstant;

    } ElseIf (xSpeed < (maxSpeedConstant *-1)) {//moving left

    xSpeed = (maxSpeedConstant *-1);

    }

    xSpeed * = frictionConstant;

    ySpeed * = frictionConstant;

    {if (Math.ABS (xSpeed) < 0.5)

    xSpeed = 0;

    }

    scrollX = xSpeed;

    scrollY = ySpeed;

    Back.x = scrollX;

    Back.y = scrollY;

    Sky.x = scrollX * 0.2;

    Sky.y = scrollY * 0.2;

    If ((leftPressed || rightPressed || xSpeed > speedConstant || xSpeed < speedConstant *-1) & & downBumping) {}

    animationState = "running";

    } else {if (downBumping)

    animationState = "rest."

    } else {}

    animationState = "jump";

    }

    If (player.currentLabel! = animationState) {}

    player.gotoAndStop (animationState);

    }

    If (enemyList.length > 0) / / if there are enemies on the left in the enemyList

    {

    for (var i: int = 0; i < enemyList.length; i ++) / / for every enemy in the enemyList

    {

    If (bulletList.length > 0) / / if there is live fleas

    {

    for (var j: int = 0; j < bulletList.length; j ++) / / for each chip in the bulletList

    {

    If (enemyList [i] .hitTestObject ([j] bulletList))

    {

    trace ("Bullet and enemy are in collision");

    enemyList [i] .removeSelf ();

    bulletList [j] .removeSelf ();

    }

    enemyList [i] will give you the current enemy

    bulletList [j] will give you the current ball

    This will check all combinations of bullets and enemies

    and see if everything is in collision

    }

    }

    }

    }

    neutralize the bad guys with bumper

    If (enemyList.length > 0) {//enemies left in the enemyList?

    for (var k: int = 0; k < enemyList.length; k ++) {/ / for every enemy in the enemyList}

    If (bumperList.length > 0) {}

    for (var h:int = 0; h < bumperList.length; h ++) {/ / for each buffer in the list}

    If {(enemyList [k] .hitTestObject (bumperList [h]))

    enemyList [k] .changeDirection ();

    }

    }

    }

    }

    }

    Player and enemy of collisions

    If (enemyList.length > 0) {//enemies left?

    for (var m:int = 0; m < enemyList.length; m ++) {/ / for every enemy in the enemyList}

    If {(enemyList [m] .hitTestObject (player))

    trace ("player collided with the enemy");

    Insert here the code for the reader to damage, may be integrated with a health bar?

    enemyList [m] .removeSelf ();

    }

    }

    }

    function nextLevel (): void {}

    currentLevel ++;

    trace ("next level:" + currentLevel);

    if(currentLevel == 2) {}

    gotoLevel2();

    }

    can be extended...

    another if (currentLevel == 3) {gotoLevel3() ;} / / etc., etc.}

    }

    function gotoLevel2 (): void {}

    back.other.gotoAndStop (2);

    back.visuals.gotoAndStop (2);

    back.collisions.gotoAndStop (2);

    scrollX = 0;

    scrollY = 500;

    keyCollected = false;

    back.other.doorKey.visible = true;

    D'Enhaut = false;

    back.other.lockedDoor.gotoAndStop (1);

    }

    function keyDownHandler(e:KeyboardEvent):void {}

    if(e.keycode == Keyboard.A) {}

    leftPressed = true;

    } else if(e.keyCode == Keyboard.D) {}

    rightPressed = true;

    } else if(e.keyCode == Keyboard.W) {}

    upPressed = true;

    } else if(e.keyCode == Keyboard.S) {}

    downPressed = true;

    If (d'Enhaut & & player.hitTestObject (back.other.lockedDoor)) {}

    Go to the next level if the player touches an open door

    nextLevel();

    }

    }

    }

    function keyUpHandler(e:KeyboardEvent):void {}

    if(e.keycode == Keyboard.A) {}

    leftPressed = false;

    } else if(e.keyCode == Keyboard.D) {}

    rightPressed = false;

    } else if(e.keyCode == Keyboard.W) {}

    upPressed = false;

    } else if(e.keyCode == Keyboard.S) {}

    downPressed = false;

    }

    if(e.keycode == Keyboard.Space) {}

    fireBullet();

    }

    }

    function fireBullet (): void

    {

    var playerDirection:String;

    If (player.scaleX < 1) {}

    playerDirection = 'left ';

    } else if (player.scaleX >-1) {}

    playerDirection = 'right ';

    }

    ball: ball of var = new Bullet (player.x - scrollX, player.y - scrollY, playerDirection, xSpeed);

    back.addChild (bullet);

    bullet.addEventListener (Event.REMOVED, bulletRemoved);

    bulletList.push (bullet);

    }

    function bulletRemoved(e:Event):void

    {

    e.currentTarget.removeEventListener (Event.REMOVED, bulletRemoved); This command simply deletes the eventListener if we do not get an error

    bulletList.splice (bulletList.indexOf (e.currentTarget), 1); This command removes the bulletList, to index something caused this function activate 1 item

    }

    function addEnemy(xLocation:int,_yLocation:int):void

    {

    var enemy: enemy = new enemy (xLocation, yLocation);

    back.addChild (enemy);

    enemy.addEventListener (Event.REMOVED, enemyRemoved);

    enemyList.push (enemy);

    }

    function addBumper(xLocation:int,_yLocation:int):void

    {

    var bumper: bumper = new bumper (xLocation, yLocation);

    back.addChild (bumper);

    Bumper.Visible = false;

    bumperList.push (bumper);

    }

    function enemyRemoved(e:Event):void

    {

    e.currentTarget.removeEventListener (Event.REMOVED, enemyRemoved); This command simply deletes the eventListener if we do not get an error

    enemyList.splice (enemyList.indexOf (e.currentTarget), 1); This command deletes the enemyList, to index something caused this function activate 1 item

    }

    then you have a mismatched after line 100 support.

  • Collision problem

    Now, I do a game as the player I need dodge the falling stone (I animate it in the timeline) sky... and when to get company, the health bar will decrease. However, when I duplicate the stone in the 3 gems, when hit the player only will decrease life bar with a stone only health. May I know why this is happening? why two other stones does not? That's what my code looks like:


    package
    {
              import flash.display.MovieClip;
              import flash.events.KeyboardEvent;
              import flash.ui.Keyboard;
              import flash.events.Event;
              import flash.events.MouseEvent;
              import flash.ui.Mouse;
              import flash.utils.Timer;
              import flash.events.TimerEvent;
      
      
              public class Assignment extends MovieClip
              {
                        var vx:int;
                        var vy:int;
                        var collisionHasOccurred:Boolean;
                        var score:uint;
      
                        public function Assignment()
                        {
                                  init();
      
                        }
                        function init():void
                        {
                                  //Initialize variable
                                  vx=0;
                                  vy=0;
                                  collisionHasOccurred=false;
                                  stone.stop();
                                  score=0;
                                  optionPage.visible=false;
      
                        //Add event listeners
                        stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
                        stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
                        addEventListener(Event.ENTER_FRAME, onEnterFrame);
      
                        }
      
                        function onKeyDown(event:KeyboardEvent):void
                        {
                                  if(event.keyCode==Keyboard.LEFT)
                                  {
                                            vx=-5;
                                  }
                                  else if (event.keyCode==Keyboard.RIGHT)
                                  {
                                            vx=5;
                                  }
                                  else if (event.keyCode==Keyboard.UP)
                                  {
                                            vy=-5;
      
                                  }
                                  else if (event.keyCode==Keyboard.DOWN)
                                  {
                                            vy=5;
                                  }
      
                        }
                        function onKeyUp(event:KeyboardEvent):void
                        {
                                  if (event.keyCode==Keyboard.LEFT || event.keyCode==Keyboard.RIGHT)
                                  {
                                            vx=0;
                                  }
                                  else if (event.keyCode==Keyboard.DOWN || event.keyCode==Keyboard.UP)
                                  {
                                  vy=0;
                                  }
                        }
                        function onEnterFrame(event:Event):void
                        {
                                  //Move the player
                                  player.x+=vx;
                                  player.y+=vy;
      
                                  //collision detection
                                  if (stone.hitTestObject(player))
                        { 
                                  player.gotoAndStop(3);
                                  health.meter.width-=2;
                                  if (! collisionHasOccurred)
                                  {
                                            score++;
                                            messageDisplay.text=String(score);
                                            collisionHasOccurred=true;
                                  }
                        }
              }
                        else
                        {
                                  player.gotoAndStop(1);
                                  collisionHasOccurred=false;
                        }
    
    
    
    

    Your code seems to only the target object, identified as "stone".  If there are more stones, then you must test each of them.  What did you do to make each stone unique targetable?  You can place references to these in an array and loop through the array, as in...

    var stones: Array = new Array (stone1, stone2, stone3);

    for (var i: uint = 0; i

    {if (Stones [i] .hitTestObject (Player)}

    process hit

    }

    }

    but then, you could also probably just something in the sense of...

    collision detection

    If (stone1.hitTestObject (player): stone2.hitTestObject (player) |)

    STONE3.hitTestObject (Player))

Maybe you are looking for

  • Problem with the upgrade to version 37.0.1 - update just "hangs".

    I am currently in Firefox 36.0.4 on a Windows 7 Pro computer. I tried twice to move to Firefox 37.0.1 WITHOUT success. Once the software is downloaded and start the upgrade, the upgrade appears just "hang" - nothing happens after 15 minutes, which is

  • How can I remove the connection to Ubuntu

    When sending large files links Thunderbird in Ubuntu. I prefer to use another system. How can I disable this automatic connection.

  • 7247cl ACHI support?

    FIRST: ENVY 7247cl dv7 BIOS supports ACHI? The BIOS is "INSYDE' version F.2D I am replacing the SATA FDI with a 1 TB disk Samsung SSD 840EVO and must set the BIOS IDE SATA AHCI.If it does not support can 'I' swap on the BIOS? SECONDLY: How/where can

  • I need Microsoft TCP/IP version 4 (XP Edition service pack 4 family)

    I need Microsoft TCP/IP version 4 for my Office XP service pack 3. did someone know how I can get that, somehow, it has been deleted and I can't. Without it, I can't connect to the internet

  • Problems after update 4.3 android Xperia V

    1. in the volume control, a gray box appears instead of the actual sound level icon. 2. the phone restarts when you try to change the default keyboard. I tried reseting that my phone, but these 2 questions continue to be committed. Need advice on pos