Esempio n. 1
0
 public void FlyWithRocket()
 {
     if (!this.fainting && this.flyingTool == FlyingTool.None)
     {
         this.velocity      = new Point(this.velocity.X, 60);
         this.flyingTime    = 120;
         this.flyingTool    = FlyingTool.Rocket;
         this.shieldingTime = 160;
     }
 }
Esempio n. 2
0
 public void FlyWithHat()
 {
     if (!this.fainting && this.flyingTool == FlyingTool.None)
     {
         this.velocity      = new Point(this.velocity.X, 40);
         this.flyingTime    = 80;
         this.flyingTool    = FlyingTool.Hat;
         this.shieldingTime = 120;
     }
 }
Esempio n. 3
0
    public void  setFlyintTool(int state)
    {
        FlyingTool temp = (FlyingTool)state;

        activeTool = temp;
    }
Esempio n. 4
0
        public override void Step()
        {
            // log previous data
            int oldTop = this.MaxHeight;
            int oldY   = this.position.Y;

            // move player
            this.position.X += this.velocity.X;
            this.position.Y += this.velocity.Y;
            if (this.shieldingTime > 0)
            {
                this.shieldingTime -= 1;
            }
            if (!this.fainting && this.flyingTime > 0)
            {
                this.flyingTime -= 1;
                if (this.flyingTime == 0)
                {
                    this.flyingTool = FlyingTool.None;
                }
            }
            else
            {
                this.velocity.Y -= 1;
            }
            if (!this.pressingDirectionKey)
            {
                if (this.velocity.X < 0)
                {
                    this.velocity.X += 2;
                }
                else if (this.velocity.X > 0)
                {
                    this.velocity.X -= 2;
                }
            }

            // correct X value
            if (this.position.X < -this.Bounds.Width)
            {
                this.position.X = this.world.Size.Width + this.position.X + this.Bounds.Width;
            }
            else if (this.position.X >= this.world.Size.Width)
            {
                this.position.X = this.position.X - this.Bounds.Width - this.world.Size.Width;
            }

            // game over if player falls out of the screen
            this.MaxHeight = Math.Max(this.MaxHeight, this.position.Y);
            if (this.position.Y <= this.world.WorldTop - this.world.Size.Height)
            {
                throw new WorldCrashException();
            }
            if (oldTop != this.MaxHeight)
            {
                this.world.CreateWorldObjects(oldTop, this.world.WorldTop);
            }

            // fall and collide
            const int blank = 13;

            int         y1             = oldY - this.Bounds.Height;
            int         y2             = this.position.Y - this.Bounds.Height;
            WorldObject collidedObject = null;

            if (y2 < y1)
            {
                Rectangle walkingArea = new Rectangle(this.position.X + blank, y2, this.Bounds.Width - blank * 2, y1 - y2 + 1);
                collidedObject = this.world.Objects
                                 .Where(o => o != this && o.Bounds.Top <= y1 && o.Bounds.IntersectsWith(walkingArea))
                                 .OrderBy(o => o.Bounds.Top)
                                 .LastOrDefault();
                if (collidedObject != null && collidedObject.ContactPlayer(true))
                {
                    collidedObject.ContactPlayer(true);
                }
            }

            // collide
            Rectangle playerBounds = this.Bounds;

            playerBounds.X     += blank;
            playerBounds.Width -= blank * 2;
            foreach (var obj in this.world.Objects)
            {
                if (obj != this && obj.Bounds.IntersectsWith(playerBounds))
                {
                    obj.ContactPlayer(false);
                }
            }
        }