コード例 #1
0
ファイル: Game1.cs プロジェクト: elegantlytragic/isaac
 protected override void Update(GameTime gameTime)
 {
     KeyboardState keys = Keyboard.GetState();
     GamePadState pad = GamePad.GetState(PlayerIndex.One);
     help.Update();
     if (pad.Buttons.Back == ButtonState.Pressed || keys.IsKeyDown(Keys.Escape)) this.Exit();
     switch (gameState)
     {
         #region MainMenu
         case GameState.MainMenu:
             if (keys.IsKeyDown(Keys.P) || pad.IsButtonDown(Buttons.A)) gameState = GameState.Game;
             if (keys.IsKeyDown(Keys.E) || pad.IsButtonDown(Buttons.X)) gameState = GameState.EditorSelect;
             break;
         #endregion
         #region Game
         case GameState.Game:
             p1.Update(keys);
             p2.Update(pad);
             r.Update(players);
             break;
         #endregion
         #region EditorSelect
         case GameState.EditorSelect:
             levelName.focused = true;
             levelName.Update(keys.GetPressedKeys());
             if (keys.IsKeyDown(Keys.Enter) || pad.IsButtonDown(Buttons.A))
             {
                 int w, h;
                 Functions.CreateLevel(levelName.value, 10, 10);
                 if (File.Exists(levelName.value + ".dat"))
                 {
                     Functions.LoadHeader(levelName.value, out w, out h);
                     editor = new Room(levelName.value, w, h, Content.Load<Texture2D>("tileset"));
                 }
                 else
                 {
                     Functions.LoadHeader(levelName.value, out w, out h);
                     Functions.CreateLevel(levelName.value, 10, 10);
                     editor = new Room(levelName.value, 10, 10, Content.Load<Texture2D>("tileset"));
                 }
                 gameState = GameState.Editor;
             }
             break;
         #endregion
         #region Editor
         case GameState.Editor:
             switch(editorState)
             {
                 case EditorState.Tiles:
                     if (help.IsNewPress(Keys.W) || help.IsNewPress(Buttons.DPadUp)) { if (tileSelected.Y >= 1) tileSelected.Y--; }
                     if (help.IsNewPress(Keys.S) || help.IsNewPress(Buttons.DPadDown)) { if (tileSelected.Y <= editor.height - 2) tileSelected.Y++; }
                     if (help.IsNewPress(Keys.D) || help.IsNewPress(Buttons.DPadRight)) { if (tileSelected.X <= editor.width - 2) tileSelected.X++; }
                     if (help.IsNewPress(Keys.A) || help.IsNewPress(Buttons.DPadLeft)) { if (tileSelected.X >= 1) tileSelected.X--; }
                     if (help.IsNewPress(Keys.Space) || help.IsNewPress(Buttons.A)) editor.data[(int)tileSelected.Y, (int)tileSelected.X] = editSelected;
                     if (help.IsNewPress(Keys.E) || help.IsNewPress(Buttons.X)) editorState = EditorState.Grid;
                     if (help.IsNewPress(Keys.C) || help.IsNewPress(Buttons.Y)) editorState = EditorState.Collision;
                     break;
                 case EditorState.Grid:
                     if (help.IsNewPress(Keys.W) || help.IsNewPress(Buttons.DPadUp)) { if (editSelected >= 6) editSelected -= 6; }
                     if (help.IsNewPress(Keys.S) || help.IsNewPress(Buttons.DPadDown)) { if (editSelected <= 41) editSelected += 6; }
                     if (help.IsNewPress(Keys.A) || help.IsNewPress(Buttons.DPadLeft)) { if (editSelected > 1) editSelected--; }
                     if (help.IsNewPress(Keys.D) || help.IsNewPress(Buttons.DPadRight)) { if (editSelected < 47) editSelected++; }
                     if (help.IsNewPress(Keys.E) || help.IsNewPress(Buttons.X)) editorState = EditorState.Tiles;
                     if (help.IsNewPress(Keys.C) || help.IsNewPress(Buttons.Y)) editorState = EditorState.Collision;
                     break;
                 case EditorState.Collision:
                     if (help.IsNewPress(Keys.W) || help.IsNewPress(Buttons.DPadUp)) { if (tileSelected.Y >= 1) tileSelected.Y--; }
                     if (help.IsNewPress(Keys.S) || help.IsNewPress(Buttons.DPadDown)) { if (tileSelected.Y <= editor.height - 2) tileSelected.Y++; }
                     if (help.IsNewPress(Keys.D) || help.IsNewPress(Buttons.DPadRight)) { if (tileSelected.X <= editor.width - 2) tileSelected.X++; }
                     if (help.IsNewPress(Keys.A) || help.IsNewPress(Buttons.DPadLeft)) { if (tileSelected.X >= 1) tileSelected.X--; }
                     if (help.IsNewPress(Keys.D0) || help.IsNewPress(Buttons.B)) editor.col[(int)tileSelected.X, (int)tileSelected.Y] = 0;
                     if (help.IsNewPress(Keys.D1) || help.IsNewPress(Buttons.A)) editor.col[(int)tileSelected.X, (int)tileSelected.Y] = 1;
                     if (help.IsNewPress(Keys.E) || help.IsNewPress(Buttons.X)) editorState = EditorState.Tiles;
                     break;
             }
             if (help.IsNewPress(Keys.F1) || help.IsNewPress(Buttons.Start))
             {
                 editor.Save();
                 gameState = GameState.MainMenu;
             }
             break;
         #endregion
     }
     base.Update(gameTime);
 }
コード例 #2
0
ファイル: Game1.cs プロジェクト: elegantlytragic/isaac
 protected override void Initialize()
 {
     base.Initialize();
     help = new InputHelper();
     players = new List<Player>();
     p1 = new KeyboardPlayer(Content.Load<Texture2D>("p1"), new Rectangle(300, 300, 50, 50));
     p2 = new GamepadPlayer(Content.Load<Texture2D>("p2"), new Rectangle(300, 350, 50, 50));
     players.Add(p1);
     players.Add(p2);
     r = new Room("deer", 10, 10, Content.Load<Texture2D>("tileset"));
     levelName = new Textbox(font, "deer", Color.White, Vector2.Zero);
 }