Exemplo n.º 1
0
        private void CheckIfPlayerIsAtEndCondition()
        {
            Placeable placeable = GetCollidingPlaceable(Vector2.Zero);

            if (placeable != null)
            {
                if (placeable.EndCondition)
                {
                    this.atEndCondition = true;
                }
            }
        }
Exemplo n.º 2
0
        private void DoDrilling(GameTime gameTime)
        {
            if (this.drilling)
            {
                Rectangle collider = new Rectangle();
                int       xShift   = 0;
                int       yShift   = 0;
                switch (this.drillingDirection)
                {
                case Direction.Left:
                    xShift = -50;
                    break;

                case Direction.Right:
                    xShift = 50;
                    break;

                case Direction.Down:
                    yShift = 30;
                    break;

                case Direction.Up:
                    yShift = -50;
                    break;
                }

                this.currentDrillRotatingSpeed += gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
                if (this.currentDrillRotatingSpeed >= this.minDrillRotatingSpeedToDrill)
                {
                    collider = new Rectangle((int)this.position.X + xShift, (int)this.position.Y + yShift, 10, 10);

                    Placeable placeable = GetCollidingPlaceable(collider);

                    if (placeable != null)
                    {// Found an placeable
                        // See if it is drillable
                        if (placeable.Drillable)
                        {
                            EffectEngine.GetInstance().AddEffect(game, placeable.Position, placeable.Animation.Texture, 1.0f);
                            placeable.Destroy();
                        }
                    }
                }
            }
            else
            {
                this.currentDrillRotatingSpeed = 0.0f;
            }
        }
Exemplo n.º 3
0
        private void CheckForFallingAndDamagingPlaceables(GameTime gameTime)
        {
            Placeable placeable = this.GetCollidingPlaceable(new Vector2(0, -2));

            if (placeable != null)
            {
                if (placeable.Damage > 0)
                {
                    Console.WriteLine("1 Teh ultimate collision!!!! " + placeable.Position.Y);
                    // Item is falling
                    if (placeable.Velocity.Y > 0)
                    {
                        Console.WriteLine("0 Teh ultimate collision!!!!" + placeable.Position.Y);
                        this.health -= placeable.Damage;
                        EffectEngine.GetInstance().AddEffect(game, placeable.Position, placeable.Animation.Texture, 1.0f);
                        placeable.Destroy();
                    } // Item horribly dangeroud and incollidable
                    else if (placeable.Incollidable)
                    {
                        this.health -= placeable.Damage;
                        EffectEngine.GetInstance().AddEffect(game, placeable.Position, placeable.Animation.Texture, 1.0f);
                        placeable.Destroy();
                    }
                    // See if player died
                    if (this.health <= 0)
                    {
                        this.alive = false;

                        EffectEngine.GetInstance().AddEffect(game, this.Position, this.Animation.Texture, 1.0f);
                        EffectEngine.GetInstance().AddEffect(game, this.spriteDrillFront.Position, this.spriteDrillFront.Animation.Texture, 1.0f);
                        this.Visible = false;
                        this.spriteDrillBack.Visible  = false;
                        this.spriteDrillFront.Visible = false;
                        this.PlayDestroyedSoundEffect();
                    }
                }
                placeable.PlayDialog();
            }
        }
Exemplo n.º 4
0
        public Placeable GetCollidingPlaceable(Vector2 positionShift)
        {
            GameComponentCollection components = game.Components;

            foreach (GameComponent component in components)
            {
                if (!component.Equals(this))
                {
                    if (component.GetType().Equals(typeof(Placeable)))
                    {
                        Placeable placeable = (Placeable)component;
                        Rectangle bouncer   = CreateCollisionRectangle(positionShift);
                        if (bouncer.Intersects(placeable.bouncingBox))
                        {
                            return(placeable);
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 5
0
        public bool GetWillCollideWithOtherGameComponents(Vector2 positionShift)
        {
            GameComponentCollection components = game.Components;
            Rectangle bouncer;

            // See if we are going to go outside the game area's borders, not intersecting with the area borders
            bouncer = CreateCollisionRectangle(positionShift);
            bouncer.Inflate(-this.animation.Width + 1, -this.animation.Height + 1);
            if (!bouncer.Intersects(this.areaBorders))
            {
                return(true);
            }

            // Collisions with game components
            bouncer = CreateCollisionRectangle(positionShift);

            foreach (GameComponent component in components)
            {
                if (!component.Equals(this))
                {
                    if (component.GetType().Equals(typeof(Placeable)))
                    {
                        Placeable placeable = (Placeable)component;
                        // if the object we are colliding with is not incollidable
                        // or the object colliding is incollidable
                        if (!placeable.Incollidable || this.Incollidable)
                        {
                            if (bouncer.Intersects(placeable.bouncingBox))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }