예제 #1
0
파일: GameLoader.cs 프로젝트: ruxeom/Kirby
        public Stage LoadStage(string propertyfile, Rectangle viewport)
        {
            Dictionary<String,String> props = PropReader.ReadPropertieFile(propertyfile);
            Stage stage = new Stage();

            stage.Length = Convert.ToInt32(props["length"]) * 50;
            stage.Height = Convert.ToInt32(props["height"]) * 50;

            string[] terrain = props["terrain"].Split(' ');

            for(int i = 0; i < terrain.Length; i++)
            {
                string[] pair = props[terrain[i]].Split(' ');

                for (int j = 0; j < pair.Length; j++)
                {
                    string[] coords = pair[j].Split(',');
                    Vector2 realcoords = GetRealCoordenates(coords, viewport.Bottom);
                    stage.AddTerrain(new GameObject(realcoords, Content.Load<Texture2D>("Sprites\\Terrain\\" + terrain[i])));
                }
            }

            string[] enemies = props["enemy"].Split(' ');
            for (int i = 0; i < enemies.Length; i++)
            {
                Dictionary<String, String> enemyprops = PropReader.ReadPropertieFile("GameProperties\\" + enemies[i] + ".txt");
                Texture2D enemysprite = Content.Load<Texture2D>("Sprites\\Enemies\\" + enemies[i]);
                string[] pair = props[enemies[i]].Split(' ');
                Enemy enemy;
                for (int j = 0; j < pair.Length; j++)
                {
                    string[] coords = pair[j].Split(',');

                    Vector2 realcoords = GetRealCoordenates(coords, viewport.Bottom);
                    enemy = new Enemy(realcoords, enemysprite);
                    stage.AddEnemy(LoadEnemy(enemy, enemyprops));
                }
            }

            string[] startposition = props["start-position"].Split(',');
            stage.StartPosition = GetRealCoordenates(startposition, viewport.Bottom);

            return stage;
        }
예제 #2
0
 public void ManageViewPortStates(Stage stage, Character player, ref Rectangle viewport)
 {
     if (stage.HasState(State.FACELEFT))
     {
         int dx = (int)(player.Center.X - viewport.Center.X);
         if (dx > 0)
         {
             stage.ScreenDisplacement.X -= dx;
             viewport.X += dx;
             stage.RemoveState(State.FACELEFT);
         }
         else if (player.Position.X < 0)
             player.Position.X = 0;
     }
     else if (stage.HasState(State.FACERIGHT))
     {
         int dx = (int)(player.Center.X - viewport.Center.X);
         if (dx < 0)
         {
             stage.ScreenDisplacement.X -= dx;
             viewport.X += dx;
             stage.RemoveState(State.FACERIGHT);
         }
         else if (player.Position.X > stage.Length - player.Width)
             player.Position.X = stage.Length - player.Width;
     }
     else
     {
         if (player.Center.X < viewport.Width / 2)
         {
             stage.AddState(State.FACELEFT);
             stage.ScreenDisplacement.X = viewport.X = 0;
         }
         else if (player.Center.X > stage.Length - viewport.Width / 2)
         {
             stage.AddState(State.FACERIGHT);
             viewport.X = stage.Length - viewport.Width;
             stage.ScreenDisplacement.X = viewport.Width - stage.Length;
         }
         else
         {
             int dx = (int)(player.Center.X - viewport.Center.X);
             stage.ScreenDisplacement.X -= dx;
             viewport.X += dx;
         }
     }
 }
예제 #3
0
파일: KirbyGame.cs 프로젝트: ruxeom/Kirby
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            Batch = new SpriteBatch(GraphicsDevice);
            Viewport = new Rectangle(
               Graphics.GraphicsDevice.Viewport.X,
               Graphics.GraphicsDevice.Viewport.Y,
               Graphics.GraphicsDevice.Viewport.Width,
               Graphics.GraphicsDevice.Viewport.Height);

            GameLoader loader = new GameLoader(this.Content);
            Manager = new StateManager();

            this.Stage = loader.LoadStage("GameProperties\\Stage1.txt", this.Viewport);
            Player = new Character(Stage.StartPosition, Content.Load<Texture2D>("Sprites\\Kirby\\KirbyStanding"));
            Player.Move(0, -Player.Height);
            Player.MaxHealth = Player.CurrentHealth = 100;
            Player.ContactDamage = 10;
        }