Ejemplo n.º 1
0
        public override void Update()
        {
            base.Update ();
            if (Engine.Scene != null && !initialized) {
                Map map = new Map(50, 20);

                Debug.Log (Core.playerManager.players.Count);
                Hero hero = new Hero();
                hero.Position.x = 1 * Config.GRID;
                hero.Position.y = 1 * Config.GRID;
                Engine.Scene.Add(hero);

                initialized = true;
            }
        }
Ejemplo n.º 2
0
        public void Update(GameTime gameTime, Hero gameHero)
        {
            // Target our hero's position
            // Because we want the hero to be in the center of the screen, we subtract half the viewport's size
            Target = gameHero.Position - new Vector2(viewPort.Width/2, viewPort.Height/2);

            // Clamp our camera to our map boundary
            // Becuase the camera position is top left, we subtract the vewport's width and height (our screen resolution) from the bottom right of our map boundary
            Target = Vector2.Clamp(Target, new Vector2(Bounds.Left, Bounds.Top), new Vector2(Bounds.Right, Bounds.Bottom) - new Vector2(viewPort.Width, viewPort.Height));

            // Linearly intERPolate between our current position and our target
            Position = Vector2.Lerp(Position, Target, speed);

            // Update the camera' visible area
            VisibleArea = new Rectangle((int)Position.X, (int)Position.Y, viewPort.Width, viewPort.Height);
        }
Ejemplo n.º 3
0
        public static bool LoadGame(ref Hero gameHero)
        {
            try
            {
                string heroJson = File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Saved Games", "Platformer", "hero.txt"));
                string enemyJson = File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Saved Games", "Platformer", "enemies.txt"));

                gameHero = JsonConvert.DeserializeObject<Hero>(heroJson);
                EnemyManager.Instance.Enemies = JsonConvert.DeserializeObject<List<Enemy>>(enemyJson);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Ejemplo n.º 4
0
        public static bool SaveGame(Hero gameHero)
        {
            IsSaving = false;
            try
            {
                string heroJson = JsonConvert.SerializeObject(gameHero, Formatting.Indented);
                string enemyJson = JsonConvert.SerializeObject(EnemyManager.Instance.Enemies, Formatting.Indented);

                Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Saved Games", "Platformer"));
                File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Saved Games", "Platformer", "hero.txt"), heroJson);
                File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Saved Games", "Platformer", "enemies.txt"), enemyJson);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            gameFont = content.Load<SpriteFont>("gamefont");

            if (loadingGame)
            {
                enemyManager = new EnemyManager();
                enemyManager.LoadContent(content);

                gameMap = Map.Load("map.txt", content);

                LoadSaveManager.LoadGame(ref gameHero);

                gameHero.LoadContent(content);
            }
            else
            {
                enemyManager = new EnemyManager();
                enemyManager.LoadContent(content);

                gameMap = Map.Load("map.txt", content);

                gameHero = new Hero(gameMap.PlayerSpawn);
                gameHero.LoadContent(content);
            }

            /// CAMERA STUFF: instantiate the camera, passing in the game's viewport (our visible draw surface)
            gameCamera = new Camera(ScreenManager.Game.GraphicsDevice.Viewport);

            ScreenManager.Game.ResetElapsedTime();
        }