Exemplo n.º 1
0
 public void update(GameTime gameTime, Player player)
 {
     NPC npc;
     for (int i = 0; i < NPCs.Count; i++)
     {
         npc = NPCs[i];
         npc.update(gameTime, player);
         if (npc.dead)
             NPCs.Remove(npc);
     }
 }
Exemplo n.º 2
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.º 3
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.º 4
0
        public void update(GameTime gameTime, Player player)
        {
            if (HP() <= 0)
            {
                dead = true;
            }
            else
            {

                float distanceToPlayer = Vector2.Distance(player.Position, npcData.Position);
                Vector2 walktopos;

                if (distanceToPlayer <= npcData.visiblityRange)
                {
                    CurrentState = state.walkingToPlayer;
                }
                if (distanceToPlayer <= attackRange)
                {
                    CurrentState = state.attacking;
                }

                if (CurrentState == state.walkingToPlayer)
                {
                    if (world.getCellFromPixelPos(player.Position) != currentPlayerCell)
                    {
                        randomStep = rand.Next(-15, 15);
                        currentPlayerCell = world.getCellFromPixelPos(player.Position);
                        cellPath = pathfinder.FindCellPath(npcData.Position, player.Position);
                        if (cellPath != null)
                            cellPath.RemoveAt(0);
                    }

                    if (cellPath != null && cellPath.Count > 0)
                    {

                        walktopos = new Vector2(cellPath[0].pixelPositionCenter.X + randomStep, cellPath[0].pixelPositionCenter.Y + randomStep);
                        if (Vector2.Distance(walktopos, npcData.Position) > 1)
                        {
                            npcData.Direction = walktopos - npcData.Position;
                            npcData.Direction.Normalize();
                        }
                        else
                            cellPath.RemoveAt(0);

                        npcData.Position += npcData.Direction * ((float)gameTime.ElapsedGameTime.TotalSeconds * (npcData.speed + randomSpeed));
                    }
                }
                if (CurrentState == state.idle)
                {
                    npcData.Direction = Vector2.Zero;
                }
                if (CurrentState == state.attacking)
                {
                    npcData.Direction = Vector2.Zero;
                    attackSpeedTimer = attackSpeedTimer - (float)gameTime.ElapsedGameTime.TotalSeconds;

                    if (attackSpeedTimer <= 0)
                    {
                        player.attacked(attackRoll());
                        attackSpeedTimer = attackSpeed;

                    }
                }

            }
        }