Quantcast
Channel: Adobe Community : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 238792

Collision problem

$
0
0

Now i doing a game like the player need dodge the falling stone(i animate it in timeline) from sky...and when get hited, the health bar will decrease. However, when i duplicate the stone into 3 stones, when hit the player, player only will decrease health bar life with among one stone only. Can i know why this happening?why other two stones not working??This is what my code look 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;                    }

Viewing all articles
Browse latest Browse all 238792

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>