public SpriteObject(Texture2D sprite, int id, int entitytype, Coordinates position)
 {
     Sprite = sprite;
     ID = id;
     EntityType = entitytype;
     Position = position;
 }
Exemple #2
0
 public SimpleObject(int _SpriteID, Coordinates spawnPos, int realid = 0, int zorder = 0)
 {
     SpriteID = _SpriteID;
     Position = spawnPos;
     RealID = realid;
     Z_order = zorder;
 }
Exemple #3
0
 public SpriteObject(Texture2D sprite, int id, int entitytype, string name, Coordinates ButtonPosition = null, int realid = 0)
 {
     Sprite = sprite;
     ID = id;
     EntityType = entitytype;
     Position = ButtonPosition;
     Name = name;
     RealID = realid;
 }
Exemple #4
0
 public Tile(string name, int spriteID, Coordinates pos, int tileID, bool visible = true, bool walkable = true)
 {
     Name = name;
     ID = tileID;
     Position = pos;
     SpriteID = spriteID;
     Visible = visible;
     Walkable = walkable;
 }
Exemple #5
0
 public Tile(string name, int spriteID, Coordinates pos, Coordinates drawPos, int tileID, bool visible = true, bool walkable = true, int zorder = 0)
 {
     Name = name;
     ID = tileID;
     Position = pos;
     drawPosition = drawPos;
     SpriteID = spriteID;
     Visible = visible;
     Walkable = walkable;
     EntityType = Entity.TileEntity;
     Z_order = zorder;
 }
Exemple #6
0
 public Entity(string name, Coordinates pos, bool visible = true)
 {
     Name = name; Position = pos; Visible = visible;
 }
Exemple #7
0
 public Entity(string name, Coordinates pos)
 {
     Name = name; Position = pos;
 }
Exemple #8
0
 public bool SamePosition(Coordinates Source, Coordinates Destination)
 {
     return (Source.X == Destination.X && Source.Y == Destination.Y);
 }
Exemple #9
0
 public Coordinates(int x, int y, int z, int h, int g, Coordinates parent)
 {
     X = x; Y = y; Z = z; H = h; G = g; F = h + g; Parent = parent;
 }
        private void DoKeyboardEvents(GameTime gameTime)
        {
            // TODO: Put all keyboard checks in here

            if (Keyboard.GetState().GetPressedKeys().Length < 1)
            {
                lastKeyHash = -1;
            }

            if (FocusedTextbox != No_Focused_Textbox)
            {
                if ((gameTime.TotalGameTime.TotalMilliseconds > TimeOfLastKeyPress + 5 && lastKeyPress.GetHashCode() != Keyboard.GetState().GetHashCode()) || (gameTime.TotalGameTime.TotalMilliseconds > TimeOfLastKeyPress + 1050 && lastKeyPress.GetHashCode() == Keyboard.GetState().GetHashCode()))
                {
                    lastKeyPress = Keyboard.GetState();
                    Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys();
                    if (pressedKeys.Length > 0 && lastKeyHash != pressedKeys[0].GetHashCode())
                    {
                        if (pressedKeys[0] == Keys.Back)
                        {
                            string tmpText = GetTextboxByID(FocusedTextbox).Text;
                            if (tmpText.Length > 0)
                            {
                                GetTextboxByID(FocusedTextbox).Text = tmpText.Substring(0, tmpText.Length - 1);
                            }
                        }
                        /*else if(pressedKeys[i] == Keys.Space)
                        {
                            GetTextboxByID(FocusedTextbox).Text += " ";
                        }*/
                        else
                        {
                            if (GetTextboxByID(FocusedTextbox).Text.Length < GetTextboxByID(FocusedTextbox).MaxChars)
                            {
                                if ((pressedKeys[0].GetHashCode() > 95 && pressedKeys[0].GetHashCode() < 106))
                                {
                                    GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(6);
                                }
                                else if ((pressedKeys[0].GetHashCode() > 47 && pressedKeys[0].GetHashCode() < 58))
                                {
                                    GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(1);
                                }
                            }
                            lastKeyHash = pressedKeys[0].GetHashCode();
                        }
                        TimeOfLastKeyPress = (int)gameTime.TotalGameTime.TotalMilliseconds;
                    }
                }
                else if (gameTime.TotalGameTime.TotalMilliseconds > TimeOfLastKeyPress + 450 && lastKeyPress.GetHashCode() == Keyboard.GetState().GetHashCode())
                {
                    lastKeyPress = Keyboard.GetState();
                    Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys();
                    if (pressedKeys.Length > 0)
                    {
                        if (pressedKeys[0] == Keys.Back)
                        {
                            string tmpText = GetTextboxByID(FocusedTextbox).Text;
                            if (tmpText.Length > 0)
                            {
                                GetTextboxByID(FocusedTextbox).Text = tmpText.Substring(0, tmpText.Length - 1);
                            }
                        }
                        //else if(pressedKeys[i] == Keys.Space)
                        //{
                        //    GetTextboxByID(FocusedTextbox).Text += " ";
                        //}
                        else
                        {
                            if (GetTextboxByID(FocusedTextbox).Text.Length < GetTextboxByID(FocusedTextbox).MaxChars)
                            {
                                if ((pressedKeys[0].GetHashCode() > 95 && pressedKeys[0].GetHashCode() < 106))
                                {
                                    GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(6);
                                }
                                else if ((pressedKeys[0].GetHashCode() > 47 && pressedKeys[0].GetHashCode() < 58))
                                {
                                    GetTextboxByID(FocusedTextbox).Text += pressedKeys[0].ToString().Substring(1);
                                }
                            }
                        }
                        lastKeyHash = pressedKeys[0].GetHashCode();
                    }
                    if (lastKeyPress.GetHashCode() != Keyboard.GetState().GetHashCode())
                        TimeOfLastKeyPress = (int)gameTime.TotalGameTime.TotalMilliseconds;
                }
            }

            if (gameTime.TotalGameTime.TotalMilliseconds - TimeOfLastMovement > 250)
            {
                if (this.IsActive)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.Right))
                    {
                        if (!OutOfBoundaries(new Coordinates(CurrentPosition.X + 1, CurrentPosition.Y)))
                        {
                            CurrentPosition = new Coordinates(CurrentPosition.X + 1, CurrentPosition.Y);
                            TimeOfLastMovement = (int)gameTime.TotalGameTime.TotalMilliseconds;
                        }
                    }
                    else if (Keyboard.GetState().IsKeyDown(Keys.Left))
                    {
                        if (!OutOfBoundaries(new Coordinates(CurrentPosition.X - 1, CurrentPosition.Y)))
                        {
                            CurrentPosition = new Coordinates(CurrentPosition.X - 1, CurrentPosition.Y);
                            TimeOfLastMovement = (int)gameTime.TotalGameTime.TotalMilliseconds;
                        }
                    }
                    else if (Keyboard.GetState().IsKeyDown(Keys.Up))
                    {
                        if (!OutOfBoundaries(new Coordinates(CurrentPosition.X, CurrentPosition.Y - 1)))
                        {
                            CurrentPosition = new Coordinates(CurrentPosition.X, CurrentPosition.Y - 1);
                            TimeOfLastMovement = (int)gameTime.TotalGameTime.TotalMilliseconds;
                        }
                    }
                    else if (Keyboard.GetState().IsKeyDown(Keys.Down))
                    {
                        if (!OutOfBoundaries(new Coordinates(CurrentPosition.X, CurrentPosition.Y + 1)))
                        {
                            CurrentPosition = new Coordinates(CurrentPosition.X, CurrentPosition.Y + 1);
                            TimeOfLastMovement = (int)gameTime.TotalGameTime.TotalMilliseconds;
                        }
                    }
                }
            }
        }
        private void DoLeftClickEvents(GameTime gameTime)
        {
            if (this.IsActive)
            {
                if (Mouse.GetState().LeftButton == ButtonState.Pressed && LeftClicked && currentSprite.ID == 72000)
                {
                    //GetTextboxByName("GoToX").Text = "Moving";
                    int newPosX = (oldMousePos.Position.X - Mouse.GetState().Position.X) / 10;
                    int newPosY = (oldMousePos.Position.Y - Mouse.GetState().Position.Y) / 10;
                    if (!OutOfBoundaries(new Coordinates(CurrentPosition.X + newPosX, CurrentPosition.Y + newPosY)))
                    {
                        CurrentPosition.X += newPosX;
                        CurrentPosition.Y += newPosY;
                    }

                    oldMousePos = Mouse.GetState();
                }
                if (Mouse.GetState().LeftButton == ButtonState.Pressed && !LeftClicked)
                {
                    int x = Mouse.GetState().X, y = Mouse.GetState().Y;
                    SpriteObject tmpSprite = GetToolbarByMousePosition(x, y);
                    if (tmpSprite.ID == 51000)
                    {
                        if (currentTileset < 2)
                        {
                            if (currentTileset == Tileset_Items)
                            {
                                ClearTilesetPositions(Entity.ItemEntity);
                            }
                            else if (currentTileset == Tileset_Tiles)
                            {
                                ClearTilesetPositions(Entity.TileEntity);
                            }
                            else if (currentTileset == Tileset_Creatures)
                            {
                                ClearTilesetPositions(Entity.CreatureEntity);
                            }
                            currentTileset++;
                        }
                    }
                    else if (tmpSprite.ID == 52000)
                    {
                        if (currentTileset > 0)
                        {
                            if (currentTileset == Tileset_Items)
                            {
                                ClearTilesetPositions(Entity.ItemEntity);
                            }
                            else if (currentTileset == Tileset_Tiles)
                            {
                                ClearTilesetPositions(Entity.TileEntity);
                            }
                            else if (currentTileset == Tileset_Creatures)
                            {
                                ClearTilesetPositions(Entity.CreatureEntity);
                            }
                            currentTileset--;
                        }
                    }
                    else if (tmpSprite.ID == 53000)
                    {
                        if (currentZ < Utility.MaxZ)
                            currentZ++;
                    }
                    else if (tmpSprite.ID == 54000)
                    {
                        if (currentZ > Utility.MinZ)
                            currentZ--;
                    }
                    else if (tmpSprite.ID == 55000)
                    {
                        if (currentZ_order < Utility.MaxZ_Order)
                            currentZ_order++;
                    }
                    else if (tmpSprite.ID == 56000)
                    {
                        if (currentZ_order > Utility.MinZ_Order)
                            currentZ_order--;
                    }
                    else if (tmpSprite.ID == 57000)
                    {
                        int textX = int.Parse(GetTextboxByName("GoToX").Text);
                        int textY = int.Parse(GetTextboxByName("GoToY").Text);
                        if (textX < 12) { textX = 12; }
                        if (textY < 8) { textY = 8; }
                        CurrentPosition = new Coordinates(textX, textY, currentZ);
                    }

                    Textbox clickedTextbox = GetTextboxByMousePosition(x, y);
                    if (clickedTextbox.ID != -1)
                    {
                        FocusedTextbox = clickedTextbox.ID;
                    }
                    else
                    {
                        FocusedTextbox = No_Focused_Textbox;
                    }

                    Window.Title = FocusedTextbox.ToString();

                    LeftClicked = true;
                }
                if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    int mx = Mouse.GetState().X, my = Mouse.GetState().Y;
                    oldMousePos = Mouse.GetState();
                    int x = (mx / 32) * 32;
                    int y = (my / 32) * 32;
                    int z = currentZ;
                    int newx = CurrentPosition.X + (x / 32) - 12;
                    int newy = CurrentPosition.Y + (y / 32) - 8;
                    //Window.Title = "Total number of tiles: " + Tiles.Count + " Coordinates of last touched tile: " + newx + ", " + newy;
                    lastTouchedPosition = new Coordinates(newx, newy, currentZ);
                    if (currentSprite.EntityType == Entity.TileEntity)
                    {
                        if (currentSprite.ID != -1 && GetTileByMousePosition(x, y).ID == -1 && currentSprite.ID < 49000 && x < Coordinates.UI_Step * 26)
                        {
                            if (GetSpriteByID(currentSprite.ID).Height == 64 && GetSpriteByID(currentSprite.ID).Width != 64)
                            {
                                Tiles.Add(new Tile("grass", currentSprite.ID, new Coordinates(newx, newy, z), new Coordinates(newx, newy - 1, z), Tiles.Count, true, false, currentZ_order));
                            }
                            else if (GetSpriteByID(currentSprite.ID).Width == 64 && GetSpriteByID(currentSprite.ID).Height != 64)
                            {
                                Tiles.Add(new Tile("grass", currentSprite.ID, new Coordinates(newx, newy, z), new Coordinates(newx - 1, newy, z), Tiles.Count, true, false, currentZ_order));
                            }
                            else if (GetSpriteByID(currentSprite.ID).Width == 64 && GetSpriteByID(currentSprite.ID).Height == 64)
                            {
                                Tiles.Add(new Tile("grass", currentSprite.ID, new Coordinates(newx, newy, z), new Coordinates(newx - 1, newy - 1, z), Tiles.Count, true, false, currentZ_order));
                            }
                            else
                            {
                                Tiles.Add(new Tile("grass", currentSprite.ID, new Coordinates(newx, newy, z), new Coordinates(newx, newy, z), Tiles.Count, true, false, currentZ_order));
                            }
                        }
                    }
                    else if(currentSprite.EntityType == Entity.CreatureEntity)
                    {
                        Texture2D sprite = GetSpriteByID(currentSprite.ID);
                        if (GetCreatureByMousePosition(x, y).SpriteID == -1)
                        {
                            //if (sprite.Height == 32 && sprite.Width == 32)
                            //{
                                Creatures.Add(new SimpleObject(currentSprite.ID, new Coordinates(newx, newy, z), currentSprite.RealID));
                            //}
                            /*if (sprite.Height == 64 && sprite.Width == 64)
                            {
                                Creatures.Add(new SimpleObject(currentSprite.ID, new Coordinates(newx - 1, newy - 1, z), currentSprite.RealID));
                            }*/
                        }
                    }
                    else if(currentSprite.EntityType == Entity.ItemEntity)
                    {
                        if (GetItemByMousePosition(x, y).SpriteID == -1)
                        {
                            Items.Add(new SimpleObject(currentSprite.ID, new Coordinates(newx, newy, z), currentSprite.RealID, currentZ_order));
                        }
                    }

                    if (currentSprite.ID == 60000)
                    {
                        if (currentTileset == Tileset_Tiles)
                        {
                            int tmpint = GetTileIndexByMousePosition(x, y);
                            if (tmpint > -1)
                            {
                                if (LastRemovedTime + 250 < gameTime.TotalGameTime.TotalMilliseconds)
                                {
                                    Tiles.Remove(GetTopItemFromTile(new Coordinates(newx, newy, z)));
                                    LastRemovedTime = (int)gameTime.TotalGameTime.TotalMilliseconds;
                                }
                            }
                        }
                        else if(currentTileset == Tileset_Creatures)
                        {
                            int tmpint = GetCreatureIndexByMousePosition(x, y);
                            if (tmpint > -1)
                            {
                                if (LastRemovedTime + 250 < gameTime.TotalGameTime.TotalMilliseconds)
                                {
                                    Creatures.RemoveAt(tmpint);
                                    LastRemovedTime = (int)gameTime.TotalGameTime.TotalMilliseconds;
                                }
                            }
                        }
                        else if (currentTileset == Tileset_Items)
                        {
                            int tmpint = GetItemIndexByMousePosition(x, y);
                            if (tmpint > -1)
                            {
                                if (LastRemovedTime + 250 < gameTime.TotalGameTime.TotalMilliseconds)
                                {
                                    Items.Remove(GetTopNotTileItemFromTile(new Coordinates(newx, newy, z)));
                                    LastRemovedTime = (int)gameTime.TotalGameTime.TotalMilliseconds;
                                }
                            }
                        }
                    }

                    // For debug purposes: Window.Title = map.Players[0].TargetID.ToString();*/
                    // For debug purposes: Window.Title = x.ToString() + " " + y.ToString();
                }
            }
        }
 internal bool OutOfBoundaries(Coordinates Coordinates)
 {
     return !(Coordinates.X >= 12 && Coordinates.Y >= 8 && Coordinates.X < Utility.MaxX && Coordinates.Y < Utility.MaxY);
 }
 private bool SamePosition(Coordinates Source, Coordinates Destination, bool CheckZ = true)
 {
     if (CheckZ)
         return (Source.X == Destination.X && Source.Y == Destination.Y && Source.Z == Destination.Z);
     else
         return (Source.X == Destination.X && Source.Y == Destination.Y);
 }
 private SimpleObject GetTopNotTileItemFromTile(Coordinates Tile)
 {
     List<SimpleObject> TileItems = new List<SimpleObject>();
     for (int i = 0; i < Items.Count; i++)
     {
         if (SamePosition(Items[i].Position, Tile))
         {
             TileItems.Add(Items[i]);
         }
     }
     if (TileItems.Count > 0)
     {
         TileItems.Sort((a, b) => a.Z_order.CompareTo(b.Z_order));
         return Items[Items.Count - 1];
     }
     return new SimpleObject();
 }
 private Tile GetTopItemFromTile(Coordinates Tile)
 {
     List<Tile> TileItems = new List<Tile>();
     for (int i = 0; i < Tiles.Count; i++)
     {
         if (SamePosition(Tiles[i].Position, Tile))
         {
             TileItems.Add(Tiles[i]);
         }
     }
     if (TileItems.Count > 0)
     {
         TileItems.Sort((a, b) => a.Z_order.CompareTo(b.Z_order));
         return TileItems[TileItems.Count - 1];
     }
     return new Tile("null");
 }
        /// <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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            // TODO: Add your update logic here

            if (Mouse.GetState().RightButton == ButtonState.Released && RightClicked)
            {
                RightClicked = false;
            }

            if (this.IsActive)
            {
                if (Mouse.GetState().RightButton == ButtonState.Pressed && !RightClicked)
                {
                    int x = Mouse.GetState().X, y = Mouse.GetState().Y;
                    currentSprite = GetToolbarByMousePosition(x, y);
                    if(currentSprite.ID == 5)
                    {
                        Window.Title = "Saving...";
                        SaveMap();
                        Window.Title = "Elysian Fields - Map Editor";
                    }
                    // For debug purposes: Window.Title = map.Players[0].TargetID.ToString();
                    RightClicked = true;
                }
            }

            /*if (Mouse.GetState().LeftButton == ButtonState.Released && LeftClicked)
            {
                LeftClicked = false;
            }*/

            if (this.IsActive)
            {
                if (Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    int mx = Mouse.GetState().X, my = Mouse.GetState().Y;
                    int x = (mx / 32) * 32;
                    int y = (my / 32) * 32;
                    Coordinates target = new Coordinates(x, y);
                    if (currentSprite.ID != -1 && GetTileByMousePosition(x, y).ID == -1 && currentSprite.ID != 3 && currentSprite.ID != 5)
                    {
                        Tiles.Add(new Tile("grass", currentSprite.ID, target, 1));
                    }
                    else if(currentSprite.ID == 3)
                    {
                        int tmpint = GetTileIndexByMousePosition(x, y);
                        if (tmpint > -1)
                        {
                            Tiles.RemoveAt(tmpint);
                        }
                    }

                    // For debug purposes: Window.Title = map.Players[0].TargetID.ToString();*/
                    // For debug purposes: Window.Title = x.ToString() + " " + y.ToString();
                }
            }

            base.Update(gameTime);
        }