Exemplo n.º 1
0
        public Hud(ContentManager Content, GraphicsDevice graphicsDevice, Player player, World world, NPC_Manager npcManager)
        {
            this.graphicsDevice = graphicsDevice;
            this.player = player;
            this.world = world;
            this.npcManager = npcManager;

            smallFont = Content.Load<SpriteFont>(@"Fonts/Font-PF Ronda Seven");

            debugBG = Content.Load<Texture2D>(@"debugRec");
            debugBG_R = new Rectangle(10, 10, 300, 150);

            curser = Content.Load<Texture2D>("HUD/curser");

            smallPlayerInfoBG = Content.Load<Texture2D>("HUD/smallPlayerInfoBG");
            smallPlayerInfoBG_R = new Rectangle(5, graphicsDevice.Viewport.Height - smallPlayerInfoBG.Height - 5, smallPlayerInfoBG.Width, smallPlayerInfoBG.Height);

            largePlayerInfoBG = Content.Load<Texture2D>("HUD/largePlayerInfoBG");
            largePlayerInfoBG_R = new Rectangle(5, graphicsDevice.Viewport.Height - smallPlayerInfoBG.Height - 10 - largePlayerInfoBG.Height, largePlayerInfoBG.Width, largePlayerInfoBG.Height);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
            Vector2 playerStartPos = new Vector2(43, 2);

            Camara.screenResWidth = screenResWidth;
            Camara.screenResHeight = screenResHeight;
            Camara.zoom = 1f;

            input = new InputHandler(this);
            //groundTiles = new tileSet(TileSizeWidth, TileSizeHeight, Content.Load<Texture2D>(@"tileSets/groundTiles"));
            gameWorld = new World(Content, "TheWorld", ChunkSizeWidth, ChunkSizeHeight, TileSizeWidth, TileSizeHeight, playerStartPos);
            player = new Player(Content, gameWorld);
            player.Position = playerStartPos;// gameWorld.playerStartTile();

            npcManager = new NPC_Manager(Content, gameWorld);

            hud = new Hud(Content, GraphicsDevice, player, gameWorld, npcManager);

            Camara.Location.X = (player.Position.X) - screenResWidth / 2;
            Camara.Location.Y = (player.Position.Y) - screenResHeight / 2;
        }
Exemplo n.º 3
0
        private void meleeAttack(double FacingDeg, NPC_Manager npcManager)
        {
            List<NPC> npcList;
            if (FacingDeg >= 135 | FacingDeg <= -135) // Facing up
                attackArea = new Rectangle((int)PixelPosition.X - Width, (int)PixelPosition.Y - ((Height / 2) + Height - 5), Width + Width, Height - (Height / 4));
            else if (FacingDeg >= -45 & FacingDeg <= 45) // facing down
                attackArea = new Rectangle((int)PixelPosition.X - Width, (int)PixelPosition.Y - (Height / 2) + 5, Width + Width, Height - (Height / 4));
            else if (FacingDeg >= -135 & FacingDeg <= -45) //Facing Left.
                attackArea = new Rectangle((int)PixelPosition.X - (Width / 2 + Width / 4), (int)PixelPosition.Y - ((Height / 4) + Height + 5), Width - (Width / 4), Height + Height);
            else if (FacingDeg <= 135 & FacingDeg >= 45) // facing right
                attackArea = new Rectangle((int)PixelPosition.X, (int)PixelPosition.Y - ((Height / 4) + Height + 5), Width - (Width / 4), Height + Height);
            else
                attackArea = new Rectangle((int)PixelPosition.X, (int)PixelPosition.Y, Width, Height);

            npcList = npcManager.getNPCsInBox(attackArea);
            foreach (NPC npc in npcList)
            {
                npc.attacked(5);
               // System.Console.WriteLine(npc);
            }
        }
Exemplo n.º 4
0
        public void Update(GameTime gameTime, NPC_Manager npcManager, InputHandler input)
        {
            Vector2 MouseDirection = Vector2.Zero;
            double MouseDeg;
            Vector2 MousePosition = Vector2.Zero;

            NPC npc ;

            //get mouse location
            MousePosition = input.mousePos();
            MousePosition = (MousePosition + Camara.Location);

            MouseDirection = (MousePosition - Position);
            MouseDirection.Normalize();
            MouseDeg = Math.Atan2(MouseDirection.X, MouseDirection.Y);
            MouseDeg = MouseDeg * 180 / Math.PI;

            if (input.mouseLeftHold())
            {
                state = State.freeMoving;
            }
            else if (input.mouseLeftClick())
            {
                npc = npcManager.getNPCatPos(MousePosition);
                if (npc != null) // CLICKED ON NPC
                {
                    if (Vector2.Distance(Position, npc.getPosition()) <= 20)
                    {
                        state = State.meleeAttack;
                    }

                }
                else
                {
                    cellPath = pathfinder.FindCellPath(Position, MousePosition);
                    if (cellPath != null)
                        state = State.movingToPoint;
                    else
                        state = State.idle;
                }
            }
            else if (input.mouseRightClick())
            {
                state = State.meleeAttack;
            }
            else if (input.mouseLeftRelease() && state == State.freeMoving)
            {
                state = State.idle;
            }

            if (state == State.freeMoving)
            {
                Direction = MouseDirection;
                FacingDeg = MouseDeg;
                Position += Direction * (float)gameTime.ElapsedGameTime.TotalSeconds * speed;
            }
            else if (state == State.meleeAttack)
            {
                if (attackTimer == attackTimerBase)
                {
                    FacingDeg = MouseDeg;
                    meleeAttack(FacingDeg, npcManager);
                   // System.Console.WriteLine("ATTACK");
                }

                attackTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (attackTimer <= 0)
                {
                    state = State.idle;
                    attackTimer = attackTimerBase;
                }
            }
            else if (state == State.movingToPoint)
            {
                MoveToPos = cellPath[0].pixelPositionCenter;
                if (Vector2.Distance(Position, MoveToPos) > 1)
                {
                    Direction = MoveToPos - Position;
                    Direction.Normalize();
                    FacingDeg = Math.Atan2(Direction.X, Direction.Y);
                    FacingDeg = FacingDeg * 180 / Math.PI;
                    Position += Direction * (float)gameTime.ElapsedGameTime.TotalSeconds * speed;
                }
                else
                {
                    cellPath[0].color = Color.White;
                    cellPath.RemoveAt(0);
                }
                if (cellPath.Count == 0)
                {
                    state = State.idle;
                }
            }
            else if (state == State.idle)
            {
                FacingDeg = MouseDeg;
            }

            updateAnimation(gameTime);
        }