Exemplo n.º 1
0
 public bool intersects(Location otherLocation)
 {
     if(otherLocation.getWorld().getName().Equals(world)){
         return Math.Floor(this.getX()) - Math.Floor(otherLocation.getX()) == 0 && Math.Floor(this.getY()) - Math.Floor(otherLocation.getY()) == 0;
     }
     return false;
 }
Exemplo n.º 2
0
        public Block getBlockAt(Location coordinates)
        {
            int x = (int)Math.Floor(coordinates.getX());
            int y = (int)Math.Ceiling(coordinates.getY());

            if (!blocks.ContainsKey(x.ToString() + "," + y.ToString())) {
                if (coordinates.getY() > -1) {
                    blocks.Add(x.ToString() + "," + y.ToString(), new Block(Material.AIR));
                }
                else if (coordinates.getY() == -1) {
                    blocks.Add(x.ToString() + "," + y.ToString(), new Block(Material.GRASS));
                }
                else if (coordinates.getY() == -2) {
                    Random rnd = new Random();

                    if (rnd.Next(0, 2) == 0) {
                        blocks.Add(x.ToString() + "," + y.ToString(), new Block(Material.DIRT));
                    }
                    else {
                        blocks.Add(x.ToString() + "," + y.ToString(), new Block(Material.STONE));
                    }
                }
                else if (coordinates.getY() < -2) {
                    blocks.Add(x.ToString() + "," + y.ToString(), new Block(Material.STONE));
                }
                blocks[x.ToString() + "," + y.ToString()].setLocation(coordinates);
            }

            return blocks[x.ToString() + "," + y.ToString()];
        }
Exemplo n.º 3
0
 public bool intersects(Location otherLocation)
 {
     if (otherLocation.getWorld().getName().Equals(world))
     {
         return(Math.Floor(this.getX()) - Math.Floor(otherLocation.getX()) == 0 && Math.Floor(this.getY()) - Math.Floor(otherLocation.getY()) == 0);
     }
     return(false);
 }
Exemplo n.º 4
0
        public void draw()
        {
            Location upperExtreme = new Location(Math.Floor(SideCraft.player.coordinates.getX()) + xLength / 2 + 1, Math.Ceiling((SideCraft.player.coordinates.getY() + yLength / 2) + 1), this.getName());
            Location lowerExtreme = new Location(Math.Floor(SideCraft.player.coordinates.getX()) - xLength / 2 - 1, Math.Ceiling((SideCraft.player.coordinates.getY() - yLength / 2) - 1), this.getName());

            int xDistance = (int)Math.Abs(upperExtreme.getX() - lowerExtreme.getX());
            int yDistance = (int)Math.Abs(upperExtreme.getY() - lowerExtreme.getY());

            for (int x = 0; x <= xDistance; x++) {
                for (int y = 0; y <= yDistance; y++) {
                    double xCoord = upperExtreme.getX() + increment(x, (int)upperExtreme.getX(), (int)lowerExtreme.getX());
                    double yCoord = upperExtreme.getY() + increment(y, (int)upperExtreme.getY(), (int)lowerExtreme.getY());

                    getBlockAt(new Location(xCoord, yCoord, getName())).draw();
                }
            }

            for (int x = 0; x < entities.Count; x++) {
                entities[x].draw();
            }
        }
Exemplo n.º 5
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CadetBlue);

            player.getWorld().draw();
            player.Draw(spriteBatch);

            Location mouseCoords     = Location.valueOf(Mouse.GetState().X, Mouse.GetState().Y);
            Location mouseroofCoords = new Location(mouseCoords.getX(), Math.Ceiling(mouseCoords.getY()));

            if (Math.Abs(mouseCoords.getX() - player.coordinates.getX()) <= 4 && Math.Abs(mouseCoords.getY() - player.coordinates.getY()) <= 4)
            {
                Screen.render(player.getWorld().getBlockAt(mouseCoords).getLocation(), selectionTile, Settings.BLOCK_SIZE, Settings.BLOCK_SIZE, false);
            }

            if (Settings.DEBUG)
            {
                Screen.renderString(font, SideCraft.player.getLocation().toString() + Environment.NewLine + mouseCoords.toString() + Environment.NewLine + "Mouse position" + mouseCoords.toVector2().ToString(), new Vector2(10, 10), Color.Black);
                Screen.renderString(font, "0", new Location(0, 0).toVector2(), Color.White);
            }
            base.Draw(gameTime);
        }
Exemplo n.º 6
0
        public void draw()
        {
            Location upperExtreme = new Location(Math.Floor(SideCraft.player.coordinates.getX()) + xLength / 2 + 1, Math.Ceiling((SideCraft.player.coordinates.getY() + yLength / 2) + 1), this.getName());
            Location lowerExtreme = new Location(Math.Floor(SideCraft.player.coordinates.getX()) - xLength / 2 - 1, Math.Ceiling((SideCraft.player.coordinates.getY() - yLength / 2) - 1), this.getName());

            int xDistance = (int)Math.Abs(upperExtreme.getX() - lowerExtreme.getX());
            int yDistance = (int)Math.Abs(upperExtreme.getY() - lowerExtreme.getY());

            for (int x = 0; x <= xDistance; x++)
            {
                for (int y = 0; y <= yDistance; y++)
                {
                    double xCoord = upperExtreme.getX() + increment(x, (int)upperExtreme.getX(), (int)lowerExtreme.getX());
                    double yCoord = upperExtreme.getY() + increment(y, (int)upperExtreme.getY(), (int)lowerExtreme.getY());

                    getBlockAt(new Location(xCoord, yCoord, getName())).draw();
                }
            }

            for (int x = 0; x < entities.Count; x++)
            {
                entities[x].draw();
            }
        }
Exemplo n.º 7
0
        private void updateInteraction(GameTime gameTime)
        {
            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                Location mouseCoords = Location.valueOf(Mouse.GetState().X, Mouse.GetState().Y);

                milliseconds += (long)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (milliseconds >= interval)
                {
                    milliseconds = 0;

                    if (Math.Abs(mouseCoords.getX() - coordinates.getX()) <= 4 && Math.Abs(mouseCoords.getY() - coordinates.getY()) <= 4)
                    {
                        Block block = getWorld().getBlockAt(mouseCoords);

                        if (block.getType() is Air)
                        {
                            return;
                        }

                        getWorld().getBlockAt(mouseCoords).damage(5);
                    }
                }
            }
            else if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                Location mouseCoords = Location.valueOf(Mouse.GetState().X, Mouse.GetState().Y);
                Block    block       = getWorld().getBlockAt(mouseCoords);

                if (canPlaceBlock(block))
                {
                    block.setType(getToolbar().getSelectedObj().getType());
                    getToolbar().getSelectedObj().modifyAmount(-1);

                    if (getToolbar().getSelectedObj().getAmount() <= 0)
                    {
                        getInventory().setAt(getToolbar().getCurrentIndex(), 0, null);
                    }
                }
            }
        }
Exemplo n.º 8
0
        public Block getBlockAt(Location coordinates)
        {
            int x = (int)Math.Floor(coordinates.getX());
            int y = (int)Math.Ceiling(coordinates.getY());

            if (!blocks.ContainsKey(x.ToString() + "," + y.ToString()))
            {
                if (coordinates.getY() > -1)
                {
                    blocks.Add(x.ToString() + "," + y.ToString(), new Block(Material.AIR));
                }
                else if (coordinates.getY() == -1)
                {
                    blocks.Add(x.ToString() + "," + y.ToString(), new Block(Material.GRASS));
                }
                else if (coordinates.getY() == -2)
                {
                    Random rnd = new Random();

                    if (rnd.Next(0, 2) == 0)
                    {
                        blocks.Add(x.ToString() + "," + y.ToString(), new Block(Material.DIRT));
                    }
                    else
                    {
                        blocks.Add(x.ToString() + "," + y.ToString(), new Block(Material.STONE));
                    }
                }
                else if (coordinates.getY() < -2)
                {
                    blocks.Add(x.ToString() + "," + y.ToString(), new Block(Material.STONE));
                }
                blocks[x.ToString() + "," + y.ToString()].setLocation(coordinates);
            }

            return(blocks[x.ToString() + "," + y.ToString()]);
        }
Exemplo n.º 9
0
        public void destroy()
        {
            Material material = this.getType();

            setType(Material.AIR);

            for (int x = 0; x < material.getDropAmount(); x++)
            {
                DropEntity droppedBlock = new DropEntity(material.getDropType(), new Location(location.getX() + 0.6 * x, location.getY()));
            }
        }