public static void BubbleCollision(Bubble bub)
        {
            foreach (GameObjects g in Manager.gameObjs
                     .OfType <GameObjects>())
            {
                if (g is Wall && g.Bounds().Intersects(bub.BodyBox()))
                {
                    bub.Direction    = 0;
                    bub.PositionY    = bub.PreviousSpot.Y;
                    bub.DirectionUp  = 0;
                    bub.BubFinalDest = true;
                }
                if (g is Wall && g.Bounds().Intersects(bub.BodyBox()))
                {
                }
            }
            foreach (Animated a in Manager.gameObjs
                     .OfType <Animated>())
            {
                if (a is Enemy && a.BodyBox().Intersects(bub.BodyBox()) && bub.IsActive)
                {
                    a.Hit       = true;
                    a.PositionX = bub.PositionX;
                    a.PositionY = bub.PositionY;
                }

                if (a is Player && a.BodyBox().Intersects(bub.BodyBox()) && bub.BubFinalDest)
                {
                    BubbleHandler.RemoveBubbles(bub);
                    SuperClass.score += 100;
                }
            }
        }
Exemple #2
0
        public override void Update(GameTime gameTime)
        {
            previousSpot = position;
            if (isActive)
            {
                SpriteAnimator(gameTime);
                if (spriteRec.X == 26)
                {
                    picFrames = 2;
                }

                position.X += direction;

                bubDirtimer -= gameTime.ElapsedGameTime.TotalMilliseconds;
                if (bubDirtimer <= 0)
                {
                    position.Y   += directionUp;
                    direction     = 0;
                    directionUp   = -3;
                    bubDeathTime -= gameTime.ElapsedGameTime.TotalMilliseconds;

                    if (bubFinalDest && bubDeathTime <= 0)
                    {
                        bubDeathAnim -= gameTime.ElapsedGameTime.TotalMilliseconds;
                        spriteRec.Y   = 26;
                        picFrames     = 4;

                        if (bubDeathAnim <= 0)
                        {
                            BubbleHandler.RemoveBubbles(this);
                            isActive  = false;
                            Enemy.hit = false;
                        }
                    }
                }
            }

            CollisionHandler.BubbleCollision(this);
        }
Exemple #3
0
        public override void Update(GameTime gameTime)
        {
            SoundEffectInstance jmp  = Manager.jump.CreateInstance();
            SoundEffectInstance beam = Manager.iceBeam.CreateInstance();

            previousSpot = position;
            kState       = Keyboard.GetState();

            spWidth = 40;

            if (gravity < 6 && !isOnGround)
            {
                gravity += 0.2f;
            }

            // Movement System for player(1)
            if (kState.IsKeyDown(Keys.Left) && isActive)
            {
                spriteFx    = SpriteEffects.FlipHorizontally;
                position.X -= 2;
                direction   = -3;
                SpriteAnimator(gameTime);
            }
            else if (kState.IsKeyDown(Keys.Right) && isActive)
            {
                spriteFx    = SpriteEffects.None;
                position.X += 2;
                direction   = 3;
                SpriteAnimator(gameTime);
            }

            if (kState.IsKeyDown(Keys.Up) && isOnGround && isActive)
            {
                // Om Space trycks ned så ändra spritesektion till hoppa
                // Få player att hoppa
                jmp.Play();
                gravity    = -7;
                isOnGround = false;
            }

            // Om en fiende träffar player, starta respawnTimer och
            // spawna player igen på x: 300, y: 50
            if (!isActive)
            {
                respawnTimer -= gameTime.ElapsedGameTime.TotalMilliseconds;
                if (respawnTimer <= 0)
                {
                    this.position.X = 300;
                    this.position.Y = 50;
                    isActive        = true;
                    respawnTimer    = 1500;
                }
            }
            // En timer för att begränsa antalet bubblor.
            shootCD -= gameTime.ElapsedGameTime.TotalMilliseconds;

            if (kState.IsKeyDown(Keys.Space) && isActive)
            {
                if (shootCD <= 0)
                {
                    BubbleHandler.AddBubbles(this.position, Manager.bTex, direction);
                    beam.Play();
                    isActive = true;
                    shootCD  = cd;
                }
            }

            if (itemPickedUp)
            {
                ItemPickup();
                itemPickedUp = false;
            }

            if (energy == 0)
            {
                Manager.hasLost = true;
            }

            position.Y += gravity;
            isOnGround  = false;

            CollisionHandler.PlayerCollision(this);
        }