示例#1
0
 public void resolveCollisionWithObject(int type, Player p)
 {
     if (type != 0 && !isReleasing)
     {
         hasNinja = true;
         p.Action_RopeSwing(this);
     }
     else
     {
         hasNinja = false;
     }
 }
示例#2
0
        /// <summary>
        /// Move the enemy
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(int timeElapsed, Player n)
        {
            if (deathEffectEmitter != null)
            {
                deathEffectEmitter.Update();
                if (deathEffectEmitter.atMaxParticles())
                    deathEffectEmitter.isEmitting = false;
            }

            if (state == LifeState.Dead) return;

            if (patrol != null)
                velocity = patrol.getCurrentVector(timeElapsed);

            Point c = Center();

            if(shoots)
            {
                if(facingLeft)
                {
                    if (new Rectangle(c.X - visionrange, c.Y, visionrange, 1).Intersects(n.drawRect))
                    {
                        projectiles.Add(new Projectile(c, new Vector2(-6, Game1.RapperRandomDiggityDawg.Next(-3, 3)), projectileTexture));
                    }
                }

               else
                {
                   if (new Rectangle(c.X, c.Y, visionrange, 1).Intersects(n.drawRect))
                   {
                       projectiles.Add(new Projectile(c, new Vector2(6, Game1.RapperRandomDiggityDawg.Next(-3, 3)), projectileTexture));
                   }
                }

                List<Projectile> hitlist = new List<Projectile>();

                foreach (Projectile p in projectiles)
                {
                    p.Update();
                    if (p.lifespan < 0)
                        hitlist.Add(p);
                    else if (p.Contains(n.drawRect))
                        n.villainDeath();
                }
                foreach (Projectile p in hitlist)
                    projectiles.Remove(p);
            }

            if (velocity.X == 0 && velocity.Y == 0)
            {
                actionState = EnemyActionState.Standing;
            }
            else if( Math.Abs(velocity.X) > 0 || Math.Abs(velocity.Y) > 0)
            {
                actionState = EnemyActionState.Running;
                facingLeft = velocity.X < 0;
            }

            switch (actionState)
            {
                case EnemyActionState.Standing:

                    break;
                case EnemyActionState.Running:
                    running[(int)myType].Update(timeElapsed);
                    break;
                case EnemyActionState.Attacking:
                    attacking[(int)myType].Update(timeElapsed);
                    break;
                case EnemyActionState.Dying:

                    break;
            }

            base.Update(timeElapsed);
        }
示例#3
0
        public void CommandCollisions(Player ninja, LinkedList<Platform> listOfWorldPlatforms)
        {
            if (ninja.ninjaLifeState == LifeState.Alive)
            {

                //Tests for collision between ninja and all commands
                foreach (Command c in listOfWorldCommands)
                {
                    //only bother with this command if it still has charges
                    if (c.charges <= 0) continue;

                    //if there is a collision with command, get the player ready to execute it
                    if (ninja.Contains(c.drawRect))
                    {
                        switch (c.getCommandType())
                        {
                            case CommandType.MoveLeft:
                                if (ninja.facingLeft == false)
                                {
                                    ninja.Action_Move(true);
                                    c.charges--;
                                }
                                break;
                            case CommandType.MoveRight:
                                if (ninja.facingLeft == true)
                                {
                                    ninja.Action_Move(false);
                                    c.charges--;
                                }
                                break;
                            case CommandType.Jump:
                                if (ninja.Action_Jump()) c.charges--;
                                break;
                            case CommandType.WallJump:
                                if (ninja.positionMask != PositionState.OnFloor)
                                {
                                    livingWallConnect(c, listOfWorldPlatforms);
                                    if (ninja.Action_WallJump(c)) c.charges--;
                                }
                                break;
                            case CommandType.WallSlide:
                                livingWallConnect(c, listOfWorldPlatforms);
                                if (ninja.Action_WallSlide(c)) c.charges--;
                                break;
                            case CommandType.LedgeClimb:
                                livingWallConnect(c, listOfWorldPlatforms);
                                if (ninja.Action_LedgeClimb(c, listOfWorldPlatforms)) c.charges--;
                                break;
                            case CommandType.ObjectThrow:
                                if (ninja.Action_ThrowItem(c)) c.charges--;
                                break;
                            default:
                                throw new Exception("Invalid CommandType Exception: WorldObjectManager.UpdateAll()");
                        }
                    }
                }
            }
        }
示例#4
0
 /// <summary>
 /// Return a copy of the existing player. Used to create a ghost player for wall slide.
 /// </summary>
 /// <returns></returns>
 public Player Copy()
 {
     Player ret = new Player(drawRect.Location);
     ret.ninjaLifeState = ninjaLifeState;
     ret.velocity = velocity;
     ret.hasGravity = hasGravity;
     return ret;
 }