コード例 #1
0
ファイル: Form1.cs プロジェクト: thomaswp/ImmersionGame
        private void Form1_Load_1(object sender, EventArgs e)
        {
            editorState = new EditorState(new GameData(), this.pictureBoxWorld.Size);
            uiHandler = new UIHandler(editorState);
            mapRenderer = new MapRenderer(editorState);

            String lastSave = Properties.Settings.Default.lastSave;
            if (File.Exists(lastSave))
            {
                LoadData(lastSave);
            }
            else
            {
                NewGame();
            }
        }
コード例 #2
0
ファイル: MapRenderer.cs プロジェクト: thomaswp/ImmersionGame
 public MapRenderer(EditorState editorState)
 {
     this.editorState = editorState;
 }
コード例 #3
0
ファイル: UIHandler.cs プロジェクト: thomaswp/ImmersionGame
 public UIHandler(EditorState editorState)
 {
     this.editorState = editorState;
 }
コード例 #4
0
ファイル: Game1.cs プロジェクト: nanmon/itchy-parakeet
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState keyState = Keyboard.GetState ();
            if (keyState.IsKeyDown (Keys.LeftControl) || keyState.IsKeyDown (Keys.RightControl)) {
                prevtile = TileMap.MapSquares [cursor];
                prevground = TileMap.Foreground [cursor];
            }
            // For Mobile devices, this logic will close the Game when the Back button is pressed
            if (keyState.IsKeyDown (Keys.Enter) && keyState.IsKeyDown (Keys.LeftAlt) && lastState.IsKeyUp (Keys.Enter))
            {
                graphics.IsFullScreen = !graphics.IsFullScreen;
                graphics.ApplyChanges ();
                lastState = keyState;
                return;
            }
            switch(editorState){
            case EditorState.Background:
                if (keyState.IsKeyDown (Keys.PageUp) && lastState.IsKeyUp (Keys.PageUp)) {
                    ++TileMap.Background.Index;
                } else if (keyState.IsKeyDown (Keys.PageDown) && lastState.IsKeyUp (Keys.PageDown)) {
                    --TileMap.Background.Index;
                } else if (keyState.IsKeyDown (Keys.C) && lastState.IsKeyUp (Keys.C)) {
                    editorState = EditorState.Foreground;
                } else if (keyState.IsKeyDown (Keys.X) && lastState.IsKeyUp (Keys.X)) {
                    editorState = EditorState.Clean;
                } else if (keyState.IsKeyDown (Keys.Escape) && lastState.IsKeyUp (Keys.Escape)) {
                    editorState = EditorState.Options;
                }
                repositionCamera ();
                break;
            case EditorState.Foreground:
                if (keyState.IsKeyDown (Keys.Up) && lastState.IsKeyUp (Keys.Up)) {
                    if (cursor.Y > 0)
                        --cursor.Y;
                } else if (keyState.IsKeyDown (Keys.Down) && lastState.IsKeyUp (Keys.Down)) {
                    if (cursor.Y < TileMap.MapHeight - 1)
                        ++cursor.Y;
                } else if (keyState.IsKeyDown (Keys.Left) && lastState.IsKeyUp (Keys.Left)) {
                    if (cursor.X > 0)
                        --cursor.X;
                } else if (keyState.IsKeyDown (Keys.Right) && lastState.IsKeyUp (Keys.Right)) {
                    if (cursor.X < TileMap.MapWidth - 1)
                        ++cursor.X;
                } else if (keyState.IsKeyDown (Keys.PageUp) && lastState.IsKeyUp (Keys.PageUp)) {
                    ++TileMap.Foreground [cursor];
                } else if (keyState.IsKeyDown (Keys.PageDown) && lastState.IsKeyUp (Keys.PageDown)) {
                    --TileMap.Foreground [cursor];
                } else if (keyState.IsKeyDown (Keys.Delete) && lastState.IsKeyUp (Keys.Delete)) {
                    TileMap.Foreground [cursor] = 0;
                } else if (keyState.IsKeyDown (Keys.Z) && lastState.IsKeyUp (Keys.Z)) {
                    editorState = EditorState.Background;

                }else if (keyState.IsKeyDown (Keys.X) && lastState.IsKeyUp (Keys.X)) {
                    editorState = EditorState.Clean;
                }else if (keyState.IsKeyDown (Keys.Escape) && lastState.IsKeyUp (Keys.Escape)) {
                    editorState = EditorState.Options;
                }else if (keyState.IsKeyDown (Keys.I) && lastState.IsKeyUp (Keys.I)) {
                    --TileMap.MapHeight;
                }else if (keyState.IsKeyDown (Keys.K) && lastState.IsKeyUp (Keys.K)) {
                    ++TileMap.MapHeight;
                }else if (keyState.IsKeyDown (Keys.J) && lastState.IsKeyUp (Keys.J)) {
                    --TileMap.MapWidth;
                }else if (keyState.IsKeyDown (Keys.L) && lastState.IsKeyUp (Keys.L)) {
                    ++TileMap.MapWidth;
                }
                if (keyState.IsKeyDown (Keys.LeftControl) || keyState.IsKeyDown (Keys.RightControl)) {
                    TileMap.Foreground[cursor] = prevground;
                }
                repositionCamera ();
                break;
            //case EditorState.Map:
            case EditorState.Clean:
            case EditorState.Drugged:
                if (keyState.IsKeyDown (Keys.Up) && lastState.IsKeyUp (Keys.Up)) {
                    if (cursor.Y > 0)
                        --cursor.Y;
                } else if (keyState.IsKeyDown (Keys.Down) && lastState.IsKeyUp (Keys.Down)) {
                    if (cursor.Y < TileMap.MapHeight -1)
                        ++cursor.Y;
                } else if (keyState.IsKeyDown (Keys.Left) && lastState.IsKeyUp (Keys.Left)) {
                    if (cursor.X > 0)
                        --cursor.X;
                } else if (keyState.IsKeyDown (Keys.Right) && lastState.IsKeyUp (Keys.Right)) {
                    if (cursor.X < TileMap.MapWidth -1)
                        ++cursor.X;
                } else if (keyState.IsKeyDown (Keys.PageUp) && lastState.IsKeyUp (Keys.PageUp)) {
                    ++TileMap.MapSquares[cursor][(int)editorState-1, 2];
                } else if (keyState.IsKeyDown (Keys.PageDown) && lastState.IsKeyUp (Keys.PageDown)) {
                    --TileMap.MapSquares[cursor][(int)editorState-1, 2];
                } else if (keyState.IsKeyDown (Keys.Enter) && lastState.IsKeyUp (Keys.Enter)) {
                    editorState = EditorState.CellCode;
                    currentString = TileMap.MapSquares[cursor].CodeValue;
                    TileMap.MapSquares[cursor].CodeValue = "";
                    //currentLayer = -1;
                }else if (keyState.IsKeyDown (Keys.Space) && lastState.IsKeyUp (Keys.Space)) {
                    TileMap.MapSquares[cursor].TogglePassable ((int)editorState-1);
                }else if (keyState.IsKeyDown (Keys.Delete) && lastState.IsKeyUp (Keys.Delete)) {
                    TileMap.MapSquares[cursor] = null;
                }else if (keyState.IsKeyDown (Keys.Escape) && lastState.IsKeyUp (Keys.Escape)) {
                    editorState = EditorState.Options;
                }else if (keyState.IsKeyDown (Keys.Z) && lastState.IsKeyUp (Keys.Z)) {
                    editorState = EditorState.Background;
                }else if (keyState.IsKeyDown (Keys.C) && lastState.IsKeyUp (Keys.C)) {
                    editorState = EditorState.Foreground;
                }else if (keyState.IsKeyDown (Keys.A) && lastState.IsKeyUp (Keys.A)) {
                    editorState = EditorState.Both;
                }else if (keyState.IsKeyDown (Keys.S) && lastState.IsKeyUp (Keys.S)) {
                    editorState = EditorState.Clean;
                }else if (keyState.IsKeyDown (Keys.D) && lastState.IsKeyUp (Keys.D)) {
                    editorState = EditorState.Drugged;
                }else if( keyState.IsKeyDown (Keys.D1) && lastState.IsKeyUp(Keys.D1)){
                    TileMap.MapSquares[cursor].Copy ( predefined [0]);
                }else if( keyState.IsKeyDown (Keys.D2) && lastState.IsKeyUp(Keys.D2)){
                    TileMap.MapSquares[cursor].Copy ( predefined [1]);
                }else if( keyState.IsKeyDown (Keys.D3) && lastState.IsKeyUp(Keys.D3)){
                    TileMap.MapSquares[cursor].Copy ( predefined [2]);
                }else if (keyState.IsKeyDown (Keys.I) && lastState.IsKeyUp (Keys.I)) {
                    --TileMap.MapHeight;
                }else if (keyState.IsKeyDown (Keys.K) && lastState.IsKeyUp (Keys.K)) {
                    ++TileMap.MapHeight;
                }else if (keyState.IsKeyDown (Keys.J) && lastState.IsKeyUp (Keys.J)) {
                    --TileMap.MapWidth;
                }else if (keyState.IsKeyDown (Keys.L) && lastState.IsKeyUp (Keys.L)) {
                    ++TileMap.MapWidth;
                }
                if (keyState.IsKeyDown (Keys.LeftControl) || keyState.IsKeyDown (Keys.RightControl)) {
                    TileMap.MapSquares[cursor] = prevtile;
                }
                repositionCamera ();
                break;
            case EditorState.Both:
                if (keyState.IsKeyDown (Keys.Up) && lastState.IsKeyUp (Keys.Up)) {
                    if (cursor.Y > 0)
                        --cursor.Y;
                } else if (keyState.IsKeyDown (Keys.Down) && lastState.IsKeyUp (Keys.Down)) {
                    if (cursor.Y < TileMap.MapHeight -1)
                        ++cursor.Y;
                } else if (keyState.IsKeyDown (Keys.Left) && lastState.IsKeyUp (Keys.Left)) {
                    if (cursor.X > 0)
                        --cursor.X;
                } else if (keyState.IsKeyDown (Keys.Right) && lastState.IsKeyUp (Keys.Right)) {
                    if (cursor.X < TileMap.MapWidth -1)
                        ++cursor.X;
                } else if (keyState.IsKeyDown (Keys.PageUp) && lastState.IsKeyUp (Keys.PageUp)) {
                    ++TileMap.MapSquares[cursor][0, 1];
                } else if (keyState.IsKeyDown (Keys.PageDown) && lastState.IsKeyUp (Keys.PageDown)) {
                    --TileMap.MapSquares[cursor][0, 1];
                } else if (keyState.IsKeyDown (Keys.Enter) && lastState.IsKeyUp (Keys.Enter)) {
                    editorState = EditorState.CellCode;
                    currentString = TileMap.MapSquares[cursor].CodeValue;
                    TileMap.MapSquares[cursor].CodeValue = "";
                    //currentLayer = -1;
                }else if (keyState.IsKeyDown (Keys.Space) && lastState.IsKeyUp (Keys.Space)) {
                    TileMap.MapSquares[cursor].TogglePassable (2);
                }else if (keyState.IsKeyDown (Keys.Delete) && lastState.IsKeyUp (Keys.Delete)) {
                    TileMap.MapSquares[cursor] =  null;
                }else if (keyState.IsKeyDown (Keys.Escape) && lastState.IsKeyUp (Keys.Escape)) {
                    editorState = EditorState.Options;
                }else if (keyState.IsKeyDown (Keys.Z) && lastState.IsKeyUp (Keys.Z)) {
                    editorState = EditorState.Background;
                }else if (keyState.IsKeyDown (Keys.C) && lastState.IsKeyUp (Keys.C)) {
                    editorState = EditorState.Foreground;
                }else if (keyState.IsKeyDown (Keys.S) && lastState.IsKeyUp (Keys.S)) {
                    editorState = EditorState.Clean;
                }else if (keyState.IsKeyDown (Keys.D) && lastState.IsKeyUp (Keys.D)) {
                    editorState = EditorState.Drugged;
                }else if( keyState.IsKeyDown (Keys.D1) && lastState.IsKeyUp(Keys.D1)){
                    TileMap.MapSquares[cursor] = predefined [0];
                }else if( keyState.IsKeyDown (Keys.D2) && lastState.IsKeyUp(Keys.D2)){
                    TileMap.MapSquares[cursor] = predefined [1];
                }else if( keyState.IsKeyDown (Keys.D3) && lastState.IsKeyUp(Keys.D3)){
                    TileMap.MapSquares[cursor] = predefined [2];
                }else if (keyState.IsKeyDown (Keys.I) && lastState.IsKeyUp (Keys.I)) {
                    --TileMap.MapHeight;
                }else if (keyState.IsKeyDown (Keys.K) && lastState.IsKeyUp (Keys.K)) {
                    ++TileMap.MapHeight;
                }else if (keyState.IsKeyDown (Keys.J) && lastState.IsKeyUp (Keys.J)) {
                    --TileMap.MapWidth;
                }else if (keyState.IsKeyDown (Keys.L) && lastState.IsKeyUp (Keys.L)) {
                    ++TileMap.MapWidth;
                }
                if (keyState.IsKeyDown (Keys.LeftControl) || keyState.IsKeyDown (Keys.RightControl)) {
                    TileMap.MapSquares[cursor] = prevtile;
                }
                repositionCamera ();
                break;
            case EditorState.CellCode:
                if(keyState.IsKeyDown (Keys.Enter) && lastState.IsKeyUp (Keys.Enter)){
                    editorState = EditorState.Clean;
                    TileMap.MapSquares[cursor].CodeValue = currentString;
                }if(keyState.IsKeyDown (Keys.Back) && lastState.IsKeyUp (Keys.Back)){
                    if(currentString.Length > 0) currentString = currentString.Substring (0, currentString.Length - 1);
                    break;
                }
                foreach (Keys key in keyState.GetPressedKeys ()){
                    bool repeated = false;
                    foreach (Keys kay in lastState.GetPressedKeys ()){
                        if (key == kay){
                            repeated = true;
                            break;
                        }
                    }
                    if (!repeated && key.ToString ().Length == 1)
                        currentString += key.ToString ();
                }
                break;
            case EditorState.Options:
                if (keyState.IsKeyDown (Keys.Escape) && lastState.IsKeyUp (Keys.Escape)) {
                    editorState = EditorState.Clean;
                } else if (keyState.IsKeyDown (Keys.Enter) && lastState.IsKeyUp (Keys.Enter)) {
                    switch (currentOption) {
                    case 0:
                        LoadMap (currentMap);
                        editorState = EditorState.Clean;
                        break;
                    case 1:
                        SaveMap (currentMap);
                        editorState = EditorState.Clean;
                        break;
                    case 2:
                        Exit ();
                        break;
                    }
                } else if (keyState.IsKeyDown (Keys.Down) && lastState.IsKeyUp (Keys.Down)) {
                    if (currentOption < 2)
                        ++currentOption;
                } else if (keyState.IsKeyDown (Keys.Up) && lastState.IsKeyUp (Keys.Up)) {
                    if (currentOption > 0)
                        --currentOption;
                } else if (keyState.IsKeyDown (Keys.PageUp) && lastState.IsKeyUp (Keys.PageUp)) {
                    if (currentMap < 999)
                        ++currentMap;
                    else
                        currentMap = 0;
                } else if (keyState.IsKeyDown (Keys.PageDown) && lastState.IsKeyUp (Keys.PageDown)) {
                    if (currentMap > 0)
                        --currentMap;
                    else
                        currentMap = 999;
                }
                break;
            }

            lastState = keyState;
            base.Update(gameTime);
        }