Beispiel #1
0
        public override void Update(GameTime gameTime)
        {
            /*Rectangle enemy = new Rectangle((int)(Position.X - 30 + Velocity.X), (int)(Game1.ScreenSize.Y - Position.Y - Size.Y), (int)(Size.X + 60), (int)(Size.Y));
             * Rectangle rightDown = new Rectangle((int)(Position.X - 30 + Velocity.X+70), (int)(Game1.ScreenSize.Y - Position.Y - Size.Y+10), (int)(Size.X + 60), (int)(Size.Y));
             * Rectangle leftDown = new Rectangle((int)(Position.X - 30 + Velocity.X-70), (int)(Game1.ScreenSize.Y - Position.Y - Size.Y+10), (int)(Size.X + 60), (int)(Size.Y));
             *
             * if (!EntityManager.currentEntityManager.hasRoom(enemy, null) || (!fly && (EntityManager.currentEntityManager.hasRoom(rightDown, null) || EntityManager.currentEntityManager.hasRoom(leftDown, null))))
             * {
             *  Velocity.X = -Velocity.X;
             *  enemyAnimation.direction = Velocity.X > 0 ? "right" : "left";
             * }*/
            if (behaviours.Count == 0)
            {
                Init();
            }

            if (!dead)
            {
                ApplyBehaviours();
            }

            Position += Velocity;

            if (IsExpired && !dead)
            {
                IsExpired  = false;
                Velocity.X = 0;
                dead       = true;
                image      = Art.GetContent <Texture2D>("art/enemies/" + type + "/" + enemyAnimation.direction + "/dead");
            }

            if (dead)
            {
                elapsed += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (elapsed >= 0.5)
                {
                    IsExpired = true;
                }
            }

            enemyAnimation.Update(gameTime);
        }
Beispiel #2
0
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(Image, Rect, Color.White);

            if (selected)
            {
                int   thisIndex = 0;
                float x         = 10;
                foreach (Entity thisItem in Items)
                {
                    thisItem.Position = new Vector2(x, Game1.ScreenSize.Y - 65 - 70) + EntityManager.currentEntityManager.cameraPosition;
                    thisItem.Draw(spriteBatch);
                    x += thisItem.Bounds.Width + 20;
                    if (selectedItem == thisIndex)
                    {
                        spriteBatch.Draw(Art.GetContent <Texture2D>("art/UI/Editor/selected"), new Rectangle((int)thisItem.Position.X, (int)Game1.ScreenSize.Y - (int)thisItem.Position.Y - 70, 70, 70), Color.White);
                    }
                    thisIndex++;
                }
            }
        }
Beispiel #3
0
        /*public static Enemy CreateFish(Vector2 position)
         * {
         *  Enemy fish = new Enemy();
         *  fish.type = "fish";
         *  fish.image = Art.GetContent<Texture2D>("art/enemies/fish/right/anim1");
         *  fish.Position = position;
         *  fish.enemyAnimation = new EnemyAnimation("fish","right");
         *  fish.fly = true;
         *  fish.Strength = 1;
         *  return fish;
         * }
         *
         * public static Enemy CreateFly(Vector2 position)
         * {
         *  Enemy fly = new Enemy();
         *  fly.type = "fly";
         *  fly.image = Art.GetContent<Texture2D>("art/enemies/fly/right/anim1");
         *  fly.Position = position;
         *  fly.enemyAnimation = new EnemyAnimation("fly", "right");
         *  fly.fly = true;
         *  fly.Strength = 1;
         *  return fly;
         * }
         *
         * public static Enemy CreateSlime(Vector2 position)
         * {
         *  Enemy slime = new Enemy();
         *  slime.type = "slime";
         *  slime.image = Art.GetContent<Texture2D>("art/enemies/slime/right/anim1");
         *  slime.Position = position;
         *  slime.enemyAnimation = new EnemyAnimation("slime", "right");
         *  slime.fly = false;
         *  slime.Strength = 1;
         *  return slime;
         * }
         *
         * public static Enemy CreateSpinner(Vector2 position)
         * {
         *  Enemy spinner = new Enemy();
         *  spinner.type = "spinner";
         *  spinner.image = Art.GetContent<Texture2D>("art/enemies/spinner/right/anim1");
         *  spinner.Position = position;
         *  spinner.enemyAnimation = new EnemyAnimation("spinner", "right");
         *  spinner.fly = false;
         *  spinner.Strength = 1;
         *  return spinner;
         * }*/

        private void Init()
        {
            this.image          = Art.GetContent <Texture2D>("art/enemies/" + type + "/right/anim1");
            this.enemyAnimation = new EnemyAnimation(type, "right");
            if (type == "fly" || type == "fish")
            {
                this.fly = true;
            }
            else
            {
                this.fly = false;
            }

            this.Strength = 1;

            switch (type)
            {
            case "fish":
                AddBehaviour(MoveSideways(2, 5));
                break;

            case "fly":
                AddBehaviour(MoveSideways(3, 6));
                break;

            case "slime":
                AddBehaviour(MoveSideways(1, 3));
                break;

            case "spinner":
                AddBehaviour(MoveSideways(5, 8));
                break;

            default:
                break;
            }
        }
Beispiel #4
0
        public void getImage()
        {
            string pathCenter     = "";
            string pathMid        = "";
            string pathCliffLeft  = "";
            string pathCliffRight = "";

            switch ((Materials)Material)
            {
            case Materials.Grass:
                pathCenter     = "art/level/grassCenter";
                pathMid        = "art/level/grassMid";
                pathCliffLeft  = "art/level/grassCliffLeft";
                pathCliffRight = "art/level/grassCliffRight";
                break;

            case Materials.Sand:
                pathCenter     = "art/level/sandCenter";
                pathMid        = "art/level/sandMid";
                pathCliffLeft  = "art/level/sandCliffLeft";
                pathCliffRight = "art/level/sandCliffRight";
                break;

            case Materials.Stone:
                pathCenter     = "art/level/stoneCenter";
                pathMid        = "art/level/stoneMid";
                pathCliffLeft  = "art/level/stoneCliffLeft";
                pathCliffRight = "art/level/stoneCliffRight";
                break;

            case Materials.Water:
                pathMid    = pathCliffLeft = pathCliffRight = "art/level/liquidWaterTop_mid";
                pathCenter = "art/level/liquidWater";
                break;

            case Materials.Spikes:
                image = Art.GetContent <Texture2D>("art/level/spikes" + ((upsideDown = blockAbove()) ? "_alt" : ""));
                return;

            case Materials.Exit:
                image = Art.GetContent <Texture2D>("art/level/signExit");
                return;

            case Materials.SignLeft:
                image = Art.GetContent <Texture2D>("art/level/signLeft");
                return;

            case Materials.SignRight:
                image = Art.GetContent <Texture2D>("art/level/signRight");
                return;

            case Materials.Block:
                image = Art.GetContent <Texture2D>("art/level/block");
                return;

            case Materials.Spring:
                image = Art.GetContent <Texture2D>("art/level/springboard" + (isUsed ? "Up" : "Down"));
                return;

            case Materials.Box:
                image = Art.GetContent <Texture2D>("art/level/boxEmpty");
                return;

            case Materials.BoxItem:
                image = Art.GetContent <Texture2D>("art/level/boxItemAlt" + (isUsed ? "_disabled" : ""));
                return;

            case Materials.BoxCoin:
                image = Art.GetContent <Texture2D>("art/level/boxCoinAlt" + (isUsed ? "_disabled" : ""));
                return;

            case Materials.Bush:
                image = Art.GetContent <Texture2D>("art/level/bush");
                return;

            case Materials.Rock:
                image = Art.GetContent <Texture2D>("art/level/rock");
                return;

            case Materials.Plant:
                image = Art.GetContent <Texture2D>("art/level/plant");
                return;

            default:
                image = Art.GetContent <Texture2D>("art/level/block");
                return;
            }

            if (!blockAbove() && !blockBelow() && !blockLeft() && blockRight())
            {
                image = Art.GetContent <Texture2D>(pathCliffLeft);
            }
            else if (!blockAbove() && !blockBelow() && !blockRight() && blockLeft())
            {
                image = Art.GetContent <Texture2D>(pathCliffRight);
            }
            else if (blockAbove())
            {
                image = Art.GetContent <Texture2D>(pathCenter);
            }
            else
            {
                image = Art.GetContent <Texture2D>(pathMid);
            }
        }
Beispiel #5
0
        public override void Draw(SpriteBatch spriteBatch, float scale = 1f)
        {
            if (characterAnimation == null)
            {
                characterAnimation = new CharacterAnimation(playerIndex);
            }
            characterAnimation.Draw(spriteBatch, Position, Size, color, scale, Orientation);

            if (Position.X + Size.X < EntityManager.currentEntityManager.cameraPosition.X || Position.Y + Size.Y < EntityManager.currentEntityManager.cameraPosition.Y)
            {
                spriteBatch.Draw(HUD, new Vector2(((Position.X - Size.X / 2) > EntityManager.currentEntityManager.cameraPosition.X ?Position.X:(EntityManager.currentEntityManager.cameraPosition.X + 40)), ((Position.Y) > EntityManager.currentEntityManager.cameraPosition.Y ? (Game1.ScreenSize.Y - Position.Y - Size.Y / 2) : Game1.ScreenSize.Y - EntityManager.currentEntityManager.cameraPosition.Y - HUD.Height / 2)), null, Color.White, 0f, new Vector2(HUD.Width, HUD.Height) / 2, this.scale, 0, 0);
            }

            if (playerIndex == 0)
            {
                spriteBatch.Draw(HUD, new Vector2(63 + EntityManager.currentEntityManager.cameraPosition.X, 63 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                spriteBatch.Draw(Art.GetContent <Texture2D>("art/HUD/coin"), new Vector2((148 + EntityManager.currentEntityManager.cameraPosition.X), 69 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                spriteBatch.Draw(Art.GetContent <Texture2D>("art/HUD/" + String.Format("{0:000}", Score).Substring(0, 1)), new Vector2((188 + EntityManager.currentEntityManager.cameraPosition.X), 72 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                spriteBatch.Draw(Art.GetContent <Texture2D>("art/HUD/" + String.Format("{0:000}", Score).Substring(1, 1)), new Vector2((210 + EntityManager.currentEntityManager.cameraPosition.X), 72 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                spriteBatch.Draw(Art.GetContent <Texture2D>("art/HUD/" + String.Format("{0:000}", Score).Substring(2, 1)), new Vector2((232 + EntityManager.currentEntityManager.cameraPosition.X), 72 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);

                int remainingLives = lives;
                for (int i = 0; i < (lives / 2 > 3?lives / 2:3); i++)
                {
                    Texture2D texture = Art.HeartEmpty;
                    if (remainingLives > 1)
                    {
                        texture = Art.HeartFull;
                    }
                    else if (remainingLives == 1)
                    {
                        texture = Art.HeartHalf;
                    }

                    spriteBatch.Draw(texture, new Vector2((37 * i + 148 + EntityManager.currentEntityManager.cameraPosition.X), 103 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                    remainingLives -= 2;
                }
            }
            else if (playerIndex == 1)
            {
                spriteBatch.Draw(HUD, new Vector2(Game1.ScreenSize.X - 142 + EntityManager.currentEntityManager.cameraPosition.X, 63 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                spriteBatch.Draw(Art.GetContent <Texture2D>("art/HUD/coin"), new Vector2((Game1.ScreenSize.X - 179 + EntityManager.currentEntityManager.cameraPosition.X), 69 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                spriteBatch.Draw(Art.GetContent <Texture2D>("art/HUD/" + String.Format("{0:000}", Score).Substring(2, 1)), new Vector2((Game1.ScreenSize.X - 208 + EntityManager.currentEntityManager.cameraPosition.X), 72 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                spriteBatch.Draw(Art.GetContent <Texture2D>("art/HUD/" + String.Format("{0:000}", Score).Substring(1, 1)), new Vector2((Game1.ScreenSize.X - 230 + EntityManager.currentEntityManager.cameraPosition.X), 72 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                spriteBatch.Draw(Art.GetContent <Texture2D>("art/HUD/" + String.Format("{0:000}", Score).Substring(0, 1)), new Vector2((Game1.ScreenSize.X - 252 + EntityManager.currentEntityManager.cameraPosition.X), 72 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                int remainingLives = lives;
                for (int i = 0; i < (lives / 2 > 3 ? lives / 2 : 3); i++)
                {
                    Texture2D texture = Art.HeartEmpty;
                    if (remainingLives > 1)
                    {
                        texture = Art.HeartFull;
                    }
                    else if (remainingLives == 1)
                    {
                        texture = Art.HeartHalfRight;
                    }

                    spriteBatch.Draw(texture, new Vector2((Game1.ScreenSize.X - (37 * i + 184 - EntityManager.currentEntityManager.cameraPosition.X)), 103 - EntityManager.currentEntityManager.cameraPosition.Y), Color.White);
                    remainingLives -= 2;
                }
            }
            //spriteBatch.DrawString(Art.Font, "Player" + playerIndex +"Position: " + Position.X + ", " + Position.Y, new Vector2(0, 50*playerIndex), Color.Black);
            //base.Draw(spriteBatch, scale);
            //spriteBatch.Draw(Art.GetContent<Texture2D>("art/rect"), Bounds, Color.White);
        }