Пример #1
0
        public bool AddLizard(Lizard lizard)
        {
            if (this.lizard == null)
            {
                this.lizard = lizard;
                lizard.tile = this;
                UpdatePassability();
                return true;
            }

            return false;
        }
Пример #2
0
        public static Lizard addLizard(Vector2 position)
        {
            if (Lizard.lizTex == null)
            {
                return null;
            }

            Lizard lizard = new Lizard(position);

            if (!lizard.tile.AddLizard(lizard))
            {
                Console.Out.WriteLine("Failure");
            }

            if (lizard != null)
            {
                player.lizards.Add(lizard);
            }

            return lizard;
        }
Пример #3
0
        public static Lizard addLizard(Vector2 position)
        {
            if (Lizard.lizTex == null)
            {
                return(null);
            }

            Lizard lizard = new Lizard(position);

            if (!lizard.tile.AddLizard(lizard))
            {
                Console.Out.WriteLine("Failure");
            }

            if (lizard != null)
            {
                player.lizards.Add(lizard);
            }

            return(lizard);
        }
Пример #4
0
        private Lizard getLizardAtMouse()
        {
            Lizard retLizard = null;

            float currDiff = 999f;

            float testDiff;

            Vector2 wsm = worldSpaceMouse();

            foreach (Lizard lizard in this.lizards)
            {
                testDiff = (lizard.position - wsm).Length();
                if (currDiff > testDiff && testDiff < TileMap.TILESIZE)
                {
                    currDiff  = (lizard.position - wsm).Length();
                    retLizard = lizard;
                }
            }


            return(retLizard);
        }
Пример #5
0
        public bool RemoveLizard(Lizard lizard)
        {
            if (this.lizard != null)
            {
                this.lizard = null;
                UpdatePassability();
                return true;
            }

            return false;
        }
Пример #6
0
        public void Update(GameTime gameTime)
        {
            UpdateCursor();
            HandleCamera();

            currMouse = Mouse.GetState();
            KeyboardState currKeys = Keyboard.GetState();

            if (currMouse.LeftButton == ButtonState.Pressed && lastMouse.LeftButton == ButtonState.Released)
            {
                Lizard lizard = getLizardAtMouse();

                if (lizard != null)
                {
                    //unselect old
                    if (selected != null)
                    {
                        selected.isSelected = false;
                    }

                    selected = lizard;
                    selected.isSelected = true;
                }
                else if (selected != null)
                {
                    selected.isSelected = false;
                    selected = null;
                }
            }

            if (currMouse.RightButton == ButtonState.Pressed && lastMouse.RightButton == ButtonState.Released && !currKeys.IsKeyDown(Keys.LeftShift))
            {
                if (selected != null)
                {
                    selected.pickupBlock = null;

                    Tile attempt = TileMap.getTileAtPos(worldSpaceMouse());

                    //if attempt is valid, path there
                    if (attempt != null && attempt.lizard == null && attempt.Passable)
                    {
                        if ((attempt == selected.path.Last() || (selected.dropTile != null && attempt == selected.dropTile)) && selected.block != null)//clicking twice on a place when carrying a block drops
                        {
                            List<Tile> places = new List<Tile>();
                            places.Add(TileMap.getTileByIndex((int)attempt.index.X - 1, (int)attempt.index.Y));
                            places.Add(TileMap.getTileByIndex((int)attempt.index.X + 1, (int)attempt.index.Y));
                            places.Add(TileMap.getTileByIndex((int)attempt.index.X, (int)attempt.index.Y - 1));
                            places.Add(TileMap.getTileByIndex((int)attempt.index.X, (int)attempt.index.Y + 1));

                            selected.Path(places);
                            selected.dropTile = attempt;
                        }
                        else
                        {
                            selected.Path(attempt);
                        }

                    }
                    else if (attempt.block != null && this.selected.block == null)//if there is a block there, pick it up
                    {
                        selected.pickupBlock = attempt.block;
                        selected.Path(attempt);
                    }
                }
            }

            if (currMouse.MiddleButton == ButtonState.Pressed )//&& lastMouse.MiddleButton == ButtonState.Released)
            {

                Tile tile = TileMap.getTileAtPos(worldSpaceMouse());

                if (tile != null && tile.lizard == null && tile.block == null)
                {
                    //find index to add at
                    Vector2 offset = worldSpaceMouse() - tile.position;

                    world.AddBlock(new TreeBlock(tile.position), false);
                }

            }

            if (Keyboard.GetState().IsKeyDown(Keys.RightControl) && Keyboard.GetState().IsKeyDown(Keys.I))
            {
                world.SaveLevel("new.txt");
            }

            lastMouse = currMouse;
        }
Пример #7
0
        public void Update(GameTime gameTime)
        {
            UpdateCursor();
            HandleCamera();

            currMouse = Mouse.GetState();
            KeyboardState currKeys = Keyboard.GetState();


            if (currMouse.LeftButton == ButtonState.Pressed && lastMouse.LeftButton == ButtonState.Released)
            {
                Lizard lizard = getLizardAtMouse();

                if (lizard != null)
                {
                    //unselect old
                    if (selected != null)
                    {
                        selected.isSelected = false;
                    }

                    selected            = lizard;
                    selected.isSelected = true;
                }
                else if (selected != null)
                {
                    selected.isSelected = false;
                    selected            = null;
                }
            }



            if (currMouse.RightButton == ButtonState.Pressed && lastMouse.RightButton == ButtonState.Released && !currKeys.IsKeyDown(Keys.LeftShift))
            {
                if (selected != null)
                {
                    selected.pickupBlock = null;

                    Tile attempt = TileMap.getTileAtPos(worldSpaceMouse());

                    //if attempt is valid, path there
                    if (attempt != null && attempt.lizard == null && attempt.Passable)
                    {
                        if ((attempt == selected.path.Last() || (selected.dropTile != null && attempt == selected.dropTile)) && selected.block != null)//clicking twice on a place when carrying a block drops
                        {
                            List <Tile> places = new List <Tile>();
                            places.Add(TileMap.getTileByIndex((int)attempt.index.X - 1, (int)attempt.index.Y));
                            places.Add(TileMap.getTileByIndex((int)attempt.index.X + 1, (int)attempt.index.Y));
                            places.Add(TileMap.getTileByIndex((int)attempt.index.X, (int)attempt.index.Y - 1));
                            places.Add(TileMap.getTileByIndex((int)attempt.index.X, (int)attempt.index.Y + 1));

                            selected.Path(places);
                            selected.dropTile = attempt;
                        }
                        else
                        {
                            selected.Path(attempt);
                        }
                    }
                    else if (attempt.block != null && this.selected.block == null)//if there is a block there, pick it up
                    {
                        selected.pickupBlock = attempt.block;
                        selected.Path(attempt);
                    }
                }
            }



            if (currMouse.MiddleButton == ButtonState.Pressed) //&& lastMouse.MiddleButton == ButtonState.Released)
            {
                Tile tile = TileMap.getTileAtPos(worldSpaceMouse());

                if (tile != null && tile.lizard == null && tile.block == null)
                {
                    //find index to add at
                    Vector2 offset = worldSpaceMouse() - tile.position;

                    world.AddBlock(new TreeBlock(tile.position), false);
                }
            }

            if (Keyboard.GetState().IsKeyDown(Keys.RightControl) && Keyboard.GetState().IsKeyDown(Keys.I))
            {
                world.SaveLevel("new.txt");
            }

            lastMouse = currMouse;
        }