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 static void render(Location location, Texture2D texture, int width, int height, bool center)
        {
            SideCraft.spriteBatch.Begin();
            Rectangle position = location.toRectangle(width, height);

            if (center) {
                position = new Rectangle(position.Center.X, position.Bottom, width, height);
            }

            SideCraft.spriteBatch.Draw(texture, position, Color.White);
            SideCraft.spriteBatch.End();
        }
Exemplo n.º 4
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.º 5
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.º 6
0
 public void setLocation(Location newc)
 {
     this.location = newc;
 }