예제 #1
0
        public BlueprintGame(string[] args)
        {
            
            // Graphics Setup
            graphics = new GraphicsDeviceManager(this);
            this.graphics.PreferredBackBufferWidth = 1280;
            this.graphics.PreferredBackBufferHeight = 720;
            this.graphics.SynchronizeWithVerticalRetrace = true;
            Content.RootDirectory = "Content";
            this.Window.AllowUserResizing = true;
            this.Window.ClientSizeChanged += new EventHandler<EventArgs>(Window_ClientSizeChanged);

            // Setup a few classes
            Config = new Config(args);
            Package = new Package(Config);
            Lighting = new Lighting(this);
            Loading = new Loading();

        }
예제 #2
0
        public void Update( Control control, Quickbar quickbar, Camera camera, Lighting lighting, Player player )
        {
            Fluids.Update(this);
            Entities.Update(control, camera);

            #region Flora

            // Grow Flora
            GrowCounter++;
            if (GrowCounter > 1000)
            {
                Flora.Update(this);
                GrowCounter = 0;
            }

            #endregion

            #region Using Items

            // preview
            Entities.Preview = null;
            if (quickbar.CurrentItem != null && Geometry.Range(camera.FromRectangle(player.Movement.Area), control.MousePos) < 6)
            {
                ItemUse use = new ItemUse(quickbar.CurrentItem.Type.Use);
                if (use.Type == "placeentity" && CanPlaceEntity(Entities.getType(use.IntValue), control.AtTileX, control.AtTileY))
                {
                    Entities.Preview = new Entity(Entities.getType(int.Parse(use.Value)), control.AtTileX, control.AtTileY);
                }
            }

            if (quickbar.UsingItem.Type == "placeblock" && Geometry.Range(camera.FromRectangle(player.Movement.Area), control.MousePos) < 6)
            {
                if (placeBlock(control.AtTileX, control.AtTileY, GetBlockType(quickbar.UsingItem.IntValue)))
                    { quickbar.useItem(quickbar.Selected); }
            }

            if (quickbar.UsingItem.Type == "placewall" && Geometry.Range(camera.FromRectangle(player.Movement.Area), control.MousePos) < 6)
            {
                if (placeWall(control.AtTileX, control.AtTileY, GetWallType(quickbar.UsingItem.IntValue)))
                    { quickbar.useItem(quickbar.Selected); }
            }

            if (quickbar.UsingItem.Type == "mineblock" && Geometry.Range(camera.FromRectangle(player.Movement.Area), control.MousePos) < 6)
            {
                if (mineBlock(control.AtTileX, control.AtTileY))
                    { quickbar.useItem(quickbar.Selected); }
            }

            if (quickbar.UsingItem.Type == "removewall" && Geometry.Range(camera.FromRectangle(player.Movement.Area), control.MousePos) < 6)
            {
                if (RemoveWall(control.AtTileX, control.AtTileY))
                { quickbar.useItem(quickbar.Selected); }
            }

            if (quickbar.UsingItem.Type == "placeentity" && Geometry.Range(camera.FromRectangle(player.Movement.Area), control.MousePos) < 6 && CanPlaceEntity(Entities.getType(quickbar.UsingItem.IntValue), control.AtTileX, control.AtTileY))
            {
                if( Entities.Add(control.AtTileX, control.AtTileY, quickbar.UsingItem.IntValue) )
                    { quickbar.useItem(quickbar.Selected); }
            }

            if (quickbar.UsingItem.Type == "removeentity" && Geometry.Range(camera.FromRectangle(player.Movement.Area), control.MousePos) < 6)
            {
                if( Entities.Damage(control.AtTileX, control.AtTileY))
                    { quickbar.useItem(quickbar.Selected); }
            }

            #endregion

            #region Lighting

            lighting.ClearShadows();

            int startx = (int)MathHelper.Clamp(camera.X * -1 / 24f, 0, this.SizeX);
            int endx = startx + camera.Width / 24;
            int starty = (int)MathHelper.Clamp(camera.Y * -1 / 24f, 0, this.SizeY);
            int endy = starty + camera.Height / 24;

            for (int x = startx; x <= endx + 2; x++)
            {
                for (int y = starty; y <= endy; y++)
                {
                    if (Blocks[x, y] != null)
                    {
                        lighting.AddShadow(camera.FromRectangle(new Rectangle(x * 24, y * 24,24,24)));
                    }
                    if (Fluids.Water.Blocks[x, y] > 18)
                    {
                        lighting.AddShadow(camera.FromRectangle(new Rectangle(x * 24, y * 24, 24, 24)));
                    }
                }
            }

            #endregion
        }