Example #1
0
 public void AddTile(int x, int y, TerrainType type)
 {
     if(InXRange(x) && InYRange(y)) {
         if(!map.ContainsKey(new Point(x, y))) {
             switch(type) {
                 case TerrainType.PLATFORM:
                     map.Add(new Point(x, y), new Platform(x, y, this));
                     break;
                 case TerrainType.PORTAL:
                     map.Add(new Point(x, y), new Portal(x, y, this));
                     break;
             }
         } else {
             if(map[new Point(x, y)] is Platform) {
                 if(type == TerrainType.PORTAL) {
                     map[new Point(x, y)] = new Portal(x, y, this);
                 }
             } else if(map[new Point(x, y)] is Portal) {
                 if(type == TerrainType.PLATFORM) {
                     map[new Point(x, y)] = new Platform(x, y, this);
                 }
             }
         }
     }
 }
Example #2
0
        /// <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)
        {
            // Allows the game to exit
            if(GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            MouseState mState = Mouse.GetState();

            mouseLoc = new Vector2(mState.X, mState.Y);

            left = (mState.LeftButton == ButtonState.Pressed);
            right = (mState.RightButton == ButtonState.Pressed);

            if(left) {
                foreach(Button alpha in buttons) {
                    if(alpha.CheckClicked(mState.X, mState.Y)) {
                        left = false;
                    }
                }
            } else {
                foreach(Button alpha in buttons) {
                    alpha.Last = false;
                }
            }
            if(left) {
                foreach(Area alpha in areas) {
                    if(alpha.ButtonClicked(mState.X, mState.Y)) {
                        currArea = alpha;
                        editName = false;
                        left = false;
                        break;
                    }
                }
            }

            IsMouseVisible = !left && !right;

            if(currArea != null && !IsMouseVisible) {
                int x = mState.X - (mState.X % 32) + 32;
                x /= 32;
                int y = mState.Y - (mState.Y % 32) - 60;
                y /= 32;
                if(left) {
                    if(currType == TerrainType.PORTAL) {
                        if(currArea.GetPortal(x, y) == null) {
                            if(toLink == null) {
                                currArea.AddTile(x, y, currType);
                                toLink = currArea.GetPortal(x, y);
                            } else {
                                currArea.AddTile(x, y, currType);
                                toLink.MakeLink(currArea.GetPortal(x, y));
                                toLink = null;
                            }
                        } else {
                            if(currArea.GetPortal(x, y).Link == null) {
                                if(toLink != null && toLink != currArea.GetPortal(x, y)) {
                                    toLink.MakeLink(currArea.GetPortal(x, y));
                                    toLink = null;
                                } else {
                                    toLink = currArea.GetPortal(x, y);
                                }
                            }
                        }
                    } else {
                        currArea.AddTile(x, y, currType);
                    }
                } else if(right) {
                    if(currArea.GetPortal(x, y) != null) {
                        if(toLink != null) {
                            toLink = null;
                        }
                        Portal linkedPortal = currArea.GetPortal(x, y).Link;
                        if(linkedPortal != null) {
                            linkedPortal.MyArea.RemoveTile(linkedPortal.Location.X, linkedPortal.Location.Y);
                        }
                    }
                    currArea.RemoveTile(x, y);
                }
            }

            if(editName && currArea != null) {
                ProcessEditName();
            }

            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Example #3
0
 public void MakeLink(Portal to)
 {
     to.Link = this;
     Link = to;
 }