Esempio n. 1
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);
        }
Esempio n. 2
0
        public override void Update(GameTime gameTime)
        {
            previousSpot = position;
            SpriteAnimator(gameTime);

            // Räkna ner på jumptimers!
            miniJumpTimer -= gameTime.ElapsedGameTime.TotalMilliseconds;
            JumpTimer     -= gameTime.ElapsedGameTime.TotalMilliseconds;

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

            if (JumpTimer <= 0 && isOnGround)
            {
                gravity       = -7;
                isOnGround    = false;
                JumpTimer     = 2250;
                miniJumpTimer = 225;
            }
            else if (miniJumpTimer <= 0 && isOnGround)
            {
                gravity       = -3;
                isOnGround    = false;
                miniJumpTimer = 225;
            }

            while (direction == 0)
            {
                EnemyMovement();
            }

            position.X += direction;
            position.Y += gravity;
            isOnGround  = false;

            CollisionHandler.EnemyCollision(this);
        }
Esempio n. 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);
        }