Beispiel #1
0
        public void Move(List<Movement> m, Map map)
        {
            if (m.Contains(Movement.Up)) { relevance.Y += 5; rotation = (float)Math.PI * 180f / 180f; }
            if (m.Contains(Movement.Down)) { relevance.Y -= 5; rotation = (float)Math.PI * 0f / 180f; }
            if (m.Contains(Movement.Left)) { relevance.X += 5; rotation = (float)Math.PI * 90f / 180f; }
            if (m.Contains(Movement.Right)) { relevance.X -= 5; rotation = (float)Math.PI * 270f / 180f; }

            // Advanced Rotation
            if (m.Contains(Movement.Up) && m.Contains(Movement.Down))
            {
                rotation = (float)Math.PI * 0f / 180f;
            }
            else if (m.Contains(Movement.Left) && m.Contains(Movement.Up))
            {
                rotation = (float)Math.PI * 135f / 180f;
            }
            else if (m.Contains(Movement.Right) && m.Contains(Movement.Up))
            {
                rotation = (float)Math.PI * 225 / 180f;
            }
            else if (m.Contains(Movement.Down) && m.Contains(Movement.Left))
            {
                rotation = (float)Math.PI * 45f / 180f;
            }
            else if (m.Contains(Movement.Down) && m.Contains(Movement.Right))
            {
                rotation = (float)Math.PI * 315f / 180f;
            }

            // Collision Detection. Checks the tile at a location, then it checks if the tile is solid, and undos the movement if it is.
            if (Blocks.Solid(map.GetTile(new Vector2(coord.X - texture.Width / 2,
                    coord.Y - texture.Height / 2))) &&
                Blocks.Solid(map.GetTile(new Vector2(coord.X + texture.Width / 2,
                    coord.Y - texture.Height / 2))))
            { relevance.Y += -5; }

            if (Blocks.Solid(map.GetTile(new Vector2(coord.X - texture.Width / 2,
                    coord.Y + texture.Height / 2))) &&
                Blocks.Solid(map.GetTile(new Vector2(coord.X + texture.Width / 2,
                    coord.Y + texture.Height / 2))))
            {
                relevance.Y -= -5;
            }
            if (Blocks.Solid(map.GetTile(new Vector2(coord.X - texture.Width / 2,
                                coord.Y - texture.Height / 2))) &&
                            Blocks.Solid(map.GetTile(new Vector2(coord.X - texture.Width / 2,
                                coord.Y + texture.Height / 2))))
            { relevance.X += -5; }

            if (Blocks.Solid(map.GetTile(new Vector2(coord.X + texture.Width / 2,
                      coord.Y - texture.Height / 2))) &&
                  Blocks.Solid(map.GetTile(new Vector2(coord.X + texture.Width / 2,
                      coord.Y + texture.Height / 2))))
            { relevance.X -= -5; }
        }
Beispiel #2
0
 public void Update(KeyboardState keyboard, GraphicsDeviceManager graphics, Map map)
 {
     coord.X = graphics.GraphicsDevice.Viewport.Width / 2 - relevance.X;
     coord.Y = graphics.GraphicsDevice.Viewport.Height / 2 - relevance.Y;
     List<Movement> moves = new List<Movement>();
     if (keyboard.IsKeyDown(Keys.W)) { moves.Add(Movement.Up); }
     if (keyboard.IsKeyDown(Keys.S)) { moves.Add(Movement.Down); }
     if (keyboard.IsKeyDown(Keys.A)) { moves.Add(Movement.Left); }
     if (keyboard.IsKeyDown(Keys.D)) { moves.Add(Movement.Right); }
     Move(moves, map);
 }
Beispiel #3
0
        public void Update(Map m)
        {
            if(attk < 0)
                attk--;

            List<Mob> pts = new List<Mob>();
            foreach (Mob mob in pts) // fix this line in the future
            {
                if (!(mob is Monster))
                {
                    if (Math.Sqrt(Math.Pow(getPos().X - mob.getPos().X, 2) + Math.Pow(getPos().Y - mob.getPos().Y, 2)) < 512)
                    {
                        pts.Add(mob);
                    }
                }
            }

            if (!pts.Contains(lastDamager))
            {
                foreach (Mob pt in pts)
                {
                    if (!(pt.GetHealth() > health * 2))
                    {
                        target = pt;
                        break;
                    }
                }
            }
            else
            {
                target = lastDamager;
            }

            if (attk == 0 && Math.Sqrt(Math.Pow(getPos().X - target.getPos().X, 2) + Math.Pow(getPos().Y - target.getPos().Y, 2)) < range)
            {
                target.Damage(stats);
            }
            List<Movement> move = new List<Movement>();

            if (getPos().X - target.getPos().X <= 0)
            {
                move.Add(Movement.Left);
            }
            else
            {
                move.Add(Movement.Right);
            }
            if (getPos().Y - target.getPos().Y <= 0)
            {
                move.Add(Movement.Up);
            }
            else
            {
                move.Add(Movement.Down);
            }
            Move(move, m);
        }
Beispiel #4
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            cursor = Content.Load<Texture2D>("cursor");

            // Tile Loading
            Texture2D[] tiles = new Texture2D[7];
            tiles[0] = new Texture2D(graphics.GraphicsDevice, 64, 64);
            tiles[1] = Content.Load<Texture2D>("grass");
            tiles[2] = Content.Load<Texture2D>("icebrick");
            Blocks.SetTextures(tiles);

            // Loading character
            main = new Player(Content.Load<Texture2D>("character"), new Vector2(64, 64));

            // Makes a fake file for map processing.
            string[] list = new string[7];
            list[0] += "Blocks:iiiiiiiii";
            list[1] += "Blocks:igggggggi";
            list[2] += "Blocks:igggggggi";
            list[3] += "Blocks:igggigggi";
            list[4] += "Blocks:igggggggi";
            list[5] += "Blocks:igggggggi";
            list[6] += "Blocks:iiiiiiiii";

            map = MapLoader.GetMap(list);
        }