Ejemplo n.º 1
0
        public void Update(CollisionObjectsList obstacles, GameTime gameTime, Player player, float camW, float camH)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            timer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            int tries      = 0;
            int treesClose = 0;

            if (timer <= 0)
            {
                Tree tempTree = new Tree(new Vector2(rnd.Next((int)topLeft.X, width), rnd.Next((int)topLeft.Y, height)), treeSprite);
                while (true)
                {
                    tempTree = new Tree(new Vector2(rnd.Next((int)topLeft.X, width), rnd.Next((int)topLeft.Y, height)), treeSprite);
                    if (obstacles.isCollision(tempTree.HitBox) != null && IsOffScreen(tempTree.Position, player, camW, camH))
                    {
                        treesClose = obstacles.getAdjacentObstacles(tempTree.HitPos).Count;
                        if (treesClose >= rnd.Next(1, 4))
                        {
                            obstacles.Add(tempTree);
                            Console.WriteLine("Time: " + (gameTime.TotalGameTime.TotalSeconds - timeSinceLastTree));
                            timeSinceLastTree = gameTime.TotalGameTime.TotalSeconds;
                        }
                        break;
                    }
                    if (tries > 5)
                    {
                        break;
                    }
                    tries++;
                }
                timer = defaultTimer;
            }
        }
Ejemplo n.º 2
0
        public Forest(CollisionObjectsList obstacles, Vector2 tLeft, int w, int h, int columns, int rows, Texture2D tree, Texture2D bush, Texture2D boulder, Texture2D npc)
        {
            timer         = defaultTimer;
            treeSprite    = tree;
            bushSprite    = bush;
            boulderSprite = boulder;
            npcSprite     = npc;
            topLeft       = tLeft;
            width         = w;
            height        = h;

            var rnd = new Random(DateTime.Now.Millisecond);

            for (int x = 0; x < columns - 1; x++)
            {
                for (int y = 0; y < rows - 1; y++)
                {
                    obstacles.Add(new Tree(new Vector2(rnd.Next(x * width / columns + 16, (x + 1) * width / columns) - 16, rnd.Next(y * height / rows + 16, (y + 1) * height / rows - 16)), treeSprite));
                }
            }
            for (int x = 0; x < columns - 1; x += 2)
            {
                for (int y = 0; y < rows - 1; y += 2)
                {
                    Bush tempBush = new Bush(new Vector2(rnd.Next(x * width / columns + 16, (x + 2) * width / columns), rnd.Next(y * height / rows + 16, (y + 1) * height / rows - 16)), bushSprite);
                    if (obstacles.isCollision(tempBush.HitBox) == null)
                    {
                        obstacles.Add(tempBush);
                    }
                }
            }

            for (int x = 0; x < columns - 1; x += 3)
            {
                for (int y = 0; y < rows - 1; y += 3)
                {
                    Boulder tempBoulder = new Boulder(new Vector2(rnd.Next(x * width / columns + 16, (x + 2) * width / columns), rnd.Next(y * height / rows + 16, (y + 1) * height / rows - 16)), boulderSprite);
                    if (obstacles.isCollision(tempBoulder.HitBox) == null)
                    {
                        obstacles.Add(tempBoulder);
                    }
                }
            }

            for (int x = 0; x < columns - 1; x += 3)
            {
                for (int y = 0; y < rows - 1; y += 3)
                {
                    NPC tempNPC = new NPC(new Vector2(rnd.Next(x * width / columns + 16, (x + 2) * width / columns), rnd.Next(y * height / rows + 16, (y + 1) * height / rows - 16)), npcSprite);
                    if (obstacles.isCollision(tempNPC.HitBox) == null)
                    {
                        obstacles.Add(tempNPC);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            _texture = new Texture2D(GraphicsDevice, 1, 1);
            _texture.SetData(new Color[] { Color.DarkSlateGray });

            font = Content.Load <SpriteFont>("Misc/spaceFont");

            placeholderSprite = Content.Load <Texture2D>("Misc/placeholder");

            playerUp        = Content.Load <Texture2D>("Player/BehemothUp");
            playerDown      = Content.Load <Texture2D>("Player/BehemothDown");
            playerLeft      = Content.Load <Texture2D>("Player/BehemothLeft");
            playerRight     = Content.Load <Texture2D>("Player/BehemothRight");
            playerRightDown = Content.Load <Texture2D>("Player/BehemothRightDown");
            playerRightUp   = Content.Load <Texture2D>("Player/BehemothRightUp");
            playerLeftDown  = Content.Load <Texture2D>("Player/BehemothLeftDown");
            playerLeftUp    = Content.Load <Texture2D>("Player/BehemothLeftUp");

            playerUpCharging        = Content.Load <Texture2D>("Player/BehemothUpCharging");
            playerDownCharging      = Content.Load <Texture2D>("Player/BehemothDownCharging");
            playerLeftCharging      = Content.Load <Texture2D>("Player/BehemothLeftCharging");
            playerRightCharging     = Content.Load <Texture2D>("Player/BehemothRightCharging");
            playerRightDownCharging = Content.Load <Texture2D>("Player/BehemothRightDownCharging");
            playerRightUpCharging   = Content.Load <Texture2D>("Player/BehemothRightUpCharging");
            playerLeftDownCharging  = Content.Load <Texture2D>("Player/BehemothLeftDownCharging");
            playerLeftUpCharging    = Content.Load <Texture2D>("Player/BehemothLeftUpCharging");

            playerUpSwing        = Content.Load <Texture2D>("Player/BehemothUpSwing");
            playerDownSwing      = Content.Load <Texture2D>("Player/BehemothDownSwing");
            playerLeftSwing      = Content.Load <Texture2D>("Player/BehemothLeftSwing");
            playerRightSwing     = Content.Load <Texture2D>("Player/BehemothRightSwing");
            playerRightDownSwing = Content.Load <Texture2D>("Player/BehemothRightDownSwing");
            playerRightUpSwing   = Content.Load <Texture2D>("Player/BehemothRightUpSwing");
            playerLeftDownSwing  = Content.Load <Texture2D>("Player/BehemothLeftDownSwing");
            playerLeftUpSwing    = Content.Load <Texture2D>("Player/BehemothLeftUpSwing");


            player.animations[0][0] = new AnimatedSprite(playerRight, 1, 4);
            player.animations[0][1] = new AnimatedSprite(playerRightUp, 1, 4);
            player.animations[0][2] = new AnimatedSprite(playerUp, 1, 4);
            player.animations[0][3] = new AnimatedSprite(playerLeftUp, 1, 4);
            player.animations[0][4] = new AnimatedSprite(playerLeft, 1, 4);
            player.animations[0][5] = new AnimatedSprite(playerLeftDown, 1, 4);
            player.animations[0][6] = new AnimatedSprite(playerDown, 1, 4);
            player.animations[0][7] = new AnimatedSprite(playerRightDown, 1, 4);

            player.animations[1][0] = new AnimatedSprite(playerRightCharging, 1, 4);
            player.animations[1][1] = new AnimatedSprite(playerRightUpCharging, 1, 4);
            player.animations[1][2] = new AnimatedSprite(playerUpCharging, 1, 4);
            player.animations[1][3] = new AnimatedSprite(playerLeftUpCharging, 1, 4);
            player.animations[1][4] = new AnimatedSprite(playerLeftCharging, 1, 4);
            player.animations[1][5] = new AnimatedSprite(playerLeftDownCharging, 1, 4);
            player.animations[1][6] = new AnimatedSprite(playerDownCharging, 1, 4);
            player.animations[1][7] = new AnimatedSprite(playerRightDownCharging, 1, 4);

            player.animations[2][0] = new AnimatedSprite(playerRightSwing, 1, 1);
            player.animations[2][1] = new AnimatedSprite(playerRightUpSwing, 1, 1);
            player.animations[2][2] = new AnimatedSprite(playerUpSwing, 1, 1);
            player.animations[2][3] = new AnimatedSprite(playerLeftUpSwing, 1, 1);
            player.animations[2][4] = new AnimatedSprite(playerLeftSwing, 1, 1);
            player.animations[2][5] = new AnimatedSprite(playerLeftDownSwing, 1, 1);
            player.animations[2][6] = new AnimatedSprite(playerDownSwing, 1, 1);
            player.animations[2][7] = new AnimatedSprite(playerRightDownSwing, 1, 1);

            myMap            = Content.Load <TiledMap>("Misc/gameMap");
            collisionObjects = new CollisionObjectsList(new Vector2(0, 0), myMap.WidthInPixels, myMap.HeightInPixels);

            treeSprite    = Content.Load <Texture2D>("Obstacles/Tree");
            bushSprite    = Content.Load <Texture2D>("Obstacles/bush");
            boulderSprite = Content.Load <Texture2D>("Obstacles/boulder");
            forest        = new Forest(collisionObjects, new Vector2(0, 0), myMap.WidthInPixels, myMap.HeightInPixels, 20, 20, treeSprite, bushSprite, boulderSprite, placeholderSprite);
        }
Ejemplo n.º 4
0
 public void Update(CollisionObjectsList obstacles, GameTime gameTime, Player player)
 {
     active = false;
     obstacles.Swing(position, radius, charged);
 }
Ejemplo n.º 5
0
        public void Update(CollisionObjectsList obstacles, GameTime gameTime, int mapW, int mapH)
        {
            KeyboardState kState = Keyboard.GetState();
            float         dt     = (float)gameTime.ElapsedGameTime.TotalSeconds;

            state = State.Walking;

            hitBox.X = (int)position.X - 13;
            hitBox.Y = (int)position.Y;

            isMoving = false;

            if (kState.IsKeyDown(Keys.Right) && !(kState.IsKeyDown(Keys.Up) || kState.IsKeyDown(Keys.Down)))
            {
                direction = Dir.Right;
                isMoving  = true;
            }

            if (kState.IsKeyDown(Keys.Left) && !(kState.IsKeyDown(Keys.Up) || kState.IsKeyDown(Keys.Down)))
            {
                direction = Dir.Left;
                isMoving  = true;
            }

            if (kState.IsKeyDown(Keys.Up) && !(kState.IsKeyDown(Keys.Left) || kState.IsKeyDown(Keys.Right)))
            {
                direction = Dir.Up;
                isMoving  = true;
            }

            if (kState.IsKeyDown(Keys.Down) && !(kState.IsKeyDown(Keys.Left) || kState.IsKeyDown(Keys.Right)))
            {
                direction = Dir.Down;
                isMoving  = true;
            }
            if (kState.IsKeyDown(Keys.Up) && kState.IsKeyDown(Keys.Left))
            {
                direction = Dir.LeftUp;
                isMoving  = true;
            }
            if (kState.IsKeyDown(Keys.Up) && kState.IsKeyDown(Keys.Right))
            {
                direction = Dir.RightUp;
                isMoving  = true;
            }
            if (kState.IsKeyDown(Keys.Down) && kState.IsKeyDown(Keys.Right))
            {
                direction = Dir.RightDown;
                isMoving  = true;
            }
            if (kState.IsKeyDown(Keys.Down) && kState.IsKeyDown(Keys.Left))
            {
                direction = Dir.LeftDown;
                isMoving  = true;
            }

            if (isMoving)
            {
                CollisionObject tempOb   = null;
                Rectangle       tempRect = hitBox;
                UTurnCheck();
                tempRect.X += (int)Math.Ceiling((speed * dt * Math.Cos((int)direction * Math.PI / 4)));
                if ((tempOb = obstacles.isCollision(tempRect)) == null && tempRect.X < mapW && tempRect.X > 0)
                {
                    position.X += (float)(speed * dt * Math.Cos((int)direction * Math.PI / 4));
                }
                else
                {
                    Collision(tempOb);
                }
                tempRect    = hitBox;
                tempRect.Y -= (int)Math.Ceiling((speed * dt * Math.Sin((int)direction * Math.PI / 4)));
                if ((tempOb = obstacles.isCollision(tempRect)) == null && tempRect.Y < mapH && tempRect.Y > 64)
                {
                    position.Y -= (float)(speed * dt * Math.Sin((int)direction * Math.PI / 4));
                }
                else
                {
                    Collision(tempOb);
                }
            }
            //Player is not moving
            else
            {
            }
            if (kState.IsKeyDown(Keys.LeftShift) && stamina > 0)
            {
                //If the player is actually moving
                if (isMoving && position.X != positionOld.X || position.Y != positionOld.Y)
                {
                    if (speed < maxSpeed)
                    {
                        speed *= 1.01F * dt / 0.0166667F;
                    }
                    if (stamina - dt < 0)
                    {
                        stamina = 0;
                    }
                    else
                    {
                        stamina -= dt;
                    }
                }
                else
                {
                    speed = defaultSpeed;
                }
            }
            else
            {
                speed = defaultSpeed;
            }
            //Spacebar just pressed
            if (kState.IsKeyDown(Keys.Space) && kStateOld.IsKeyUp(Keys.Space))
            {
                if (strength >= 1)
                {
                    strength -= 1;
                    charge   += 0.4f;
                }
            }
            //Spacebar being held
            if (kState.IsKeyDown(Keys.Space) && kStateOld.IsKeyDown(Keys.Space))
            {
                state = State.Charging;
                if (strength >= 1)
                {
                    strength -= 1;
                    charge   += 0.4f;
                }
            }
            //Spacebar released
            if (kState.IsKeyUp(Keys.Space) && kStateOld.IsKeyDown(Keys.Space))
            {
                //MySounds.projectileSound.Play(0.2f, 0.5f, 0f);
                state  = State.Swing;
                swing  = new Swing(position, gameTime, direction, charge);
                charge = 0;
            }
            if (swing != null && !swing.Active)
            {
                swing = null;
            }

            if (stamina > 0 && strength < maxStrength && kState.IsKeyUp(Keys.Space))
            {
                stamina  -= dt * 0.4f;
                strength += dt * 40f;
            }


            anim = animations[(int)state][(int)direction];
            anim.setSpeed(0.25D - (0.2D * speed / maxSpeed));

            if (isMoving)
            {
                anim.Update(gameTime);
            }
            else
            {
                anim.setFrame(0);
            }
            kStateOld    = kState;
            directionOld = direction;
            positionOld  = position;
        }