Ejemplo n.º 1
0
        void DrawCell(GifCube cube, int x, int y, int z, Vector2 pos, Vector2 size)
        {
            ColorRGB color = cube[x, y, z];

            spriteBatch.Draw(whiteTexture, pos.ToRectangle(size), cube[x, y, z].ToXNAColor());
            spriteBatch.DrawString(font, ColorToString(color), pos, GetContrastingColor(color));
        }
Ejemplo n.º 2
0
        void DrawCell(GifCube cube, int x, int y, int z, Vector2 pos, Vector2 size)
        {
            ColorRGB color = cube[new ColorRGB((byte)(x * 17), (byte)(y * 17), (byte)(z * 17))];

            DrawRectangle(pos.ToRectangle(size), color.ToXNAColor());
            DrawString(ColorToString(color), pos, GetContrastingColor(color));
        }
Ejemplo n.º 3
0
 private void Render(Vector2 position)
 {
     //gfx.DrawUserIndexedPrimitives(PrimitiveType.TriangleList,
     //								   triangles, 0, 4,
     //								   indexData, 0, 2);
     GameServices.SpriteBatch.DrawRectangle(position.ToRectangle(GameServices.ScreenSize), Color.Transparent);
 }
Ejemplo n.º 4
0
        void DrawCube(GifCube cube, int frame, ColorRGB highlightPos, Vector2 pos, Vector2 size)
        {
            for (int x = 0; x < 16; ++x)
            {
                DrawString("" + GetHexChar(x), new Vector2(pos.X + 16 + x * size.X, pos.Y - 20), new Color(x * 16, 0, 0));
                DrawString("" + GetHexChar(x), new Vector2(pos.X + 16 + x * size.X, pos.Y + 10 + 16 * size.Y), showingPosition.B16 == x? Color.Yellow: new Color(0, 0, x * 16));
            }

            for (int y = 0; y < 16; ++y)
            {
                DrawString("" + GetHexChar(y), new Vector2(pos.X - 16, pos.Y + 10 + y * size.Y), new Color(0, y * 16, 0));
            }
            Vector2 size_ = size;

            DrawRectangle(pos.ToRectangle(size_ * 16), Color.Black);
            size_ = size;
            DrawRectangle(new Vector2(pos.X + highlightPos.R16 * size_.X - 1, pos.Y + highlightPos.G16 * size_.Y - 1).ToRectangle(new Vector2(size_.X + 2, size_.Y + 2)), Color.White);
            for (int x = 0; x < 16; ++x)
            {
                for (int y = 0; y < 16; ++y)
                {
                    DrawCell(cube, x, y, frame, new Vector2(pos.X + x * size.X, pos.Y + y * size.Y), new Vector2(size.X - 1, size.Y - 1));
                }
            }

            foreach (Breakpoint b in breakpoints)
            {
                if (b.cube == showingCube && b.position.B16 == showingPosition.B16)
                {
                    DrawImage(breakpointTexture, new Vector2(pos.X + b.position.R16 * size.X + 35, pos.Y + b.position.G16 * size.Y + 18));
                }
            }

            foreach (ColorRGB register in interestingRegisters)
            {
                GifCube registerCube = gifScriptState.GetRegisterTarget(register);
                if (cube == registerCube)
                {
                    ColorRGB registerPos = gifScriptState.GetRegisterPosition(register);
                    if (registerPos.B16 == frame)
                    {
                        DrawPointer(register, new Vector2(pos.X + registerPos.R16 * size.X, pos.Y + registerPos.G16 * size.Y), size);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        protected override void LoadContent()
        {
            this.Content.RootDirectory = CONTENT_ROOT_DIRECTORY;
            this.SpriteBatch           = new SpriteBatch(this.GraphicsDevice);
            this.BlankTexture          = new Texture2D(this.GraphicsDevice, width: 1, height: 1);
            this.BlankTexture.SetData(new[] { Color.White });
            this.Font = this.Content.Load <SpriteFont>("Graphics/Alphabet/saga");

            var dependency = Dependency.Start(this);

            dependency.Register(this.Content);
            dependency.Register(this.Client);
            dependency.Register(this.SpriteBatch);
            dependency.Register(this.BlankTexture);
            dependency.Register(this.Font);
            dependency.Register <FramerateHelper>();
            this.Input         = dependency.Register <InputHelper>();
            this.Architect     = dependency.Register <Architect>();
            this.Configuration = dependency.Register <ConfigurationHelper>();
            this.Stage         = dependency.Register <StageHelper>();

            // TODO implement loading from config.ini file
            this.Configuration.Load();

            if (this.Configuration.StartInFullscreen)
            {
                this.Client.ToggleFullscreen();
            }

            // var stageContainer = new Rectangle(new Point(240, 50), (BASE_WINDOW_SIZE / 1.55f).ToPoint());
            var stageContainer = BASE_MAP_PANEL_SIZE.ToRectangle();

            this.Stage.Arrange(stageContainer, this.GetStagePath("plateau"));

            // temporary panel stuff
            {
                this.PanelTexture = this.Content.Load <Texture2D>("Graphics/panel");
                this.YesTexture   = this.Content.Load <Texture2D>("Graphics/buttonYes");
                this.NoTexture    = this.Content.Load <Texture2D>("Graphics/buttonNo");

                var exitConfirmationPanelSize      = new Vector2(400, 100);
                var exitConfirmationPanelLocation  = (BASE_WINDOW_SIZE / 2) - (exitConfirmationPanelSize / 2);
                var exitConfirmationPanelRectangle = new Rectangle(exitConfirmationPanelLocation.ToPoint(), exitConfirmationPanelSize.ToPoint());
                this.ExitConfirmation = new Panel(exitConfirmationPanelRectangle);
                this.ExitConfirmation.Append(new Basic(BASE_WINDOW_RECTANGLE, this.BlankTexture, new Color(100, 100, 100, 100)));
                this.ExitConfirmation.Append(new Patch(exitConfirmationPanelRectangle, this.PanelTexture, 13));

                var exitConfirmationText         = "Are you sure you want to quit?";
                var exitConformationTextScale    = 1.5f;
                var exitConformationTextSize     = this.Font.MeasureString(exitConfirmationText) * exitConformationTextScale;
                var exitConformationTextLocation = (BASE_WINDOW_SIZE / 2) - (exitConformationTextSize / 2) - new Vector2(0, 30);
                this.ExitConfirmation.Append(new Label(new Rectangle(exitConformationTextLocation.ToPoint(), exitConformationTextSize.ToPoint()), this.Font, exitConfirmationText, exitConformationTextScale));

                var noYesButtonSize  = new Vector2(40);
                var noButtonLocation = (BASE_WINDOW_SIZE / 2) - new Vector2(noYesButtonSize.X, 0) * 1.5f;
                var noButton         = new Button(new Rectangle(noButtonLocation.ToPoint(), noYesButtonSize.ToPoint()), this.NoTexture, new Color(200, 0, 0));
                noButton.WithInput(this.Input);
                noButton.OnClick += button =>
                {
                    this.ExitConfirmation.Toggle();
                    this.ExitConfirmation.SetPrevent(this.ExitConfirmation.IsActive);
                };
                this.ExitConfirmation.Append(noButton);

                var yesButtonLocation = (BASE_WINDOW_SIZE / 2) + new Vector2(noYesButtonSize.X, 0) / 1.5f;
                var yesButton         = new Button(new Rectangle(yesButtonLocation.ToPoint(), noYesButtonSize.ToPoint()), this.YesTexture, new Color(0, 200, 0));
                yesButton.WithInput(this.Input);
                yesButton.OnClick += button => this.Exit();
                this.ExitConfirmation.Append(yesButton);

                this.Log  = new StringBuilder();
                this.Side = new Panel(new Rectangle());
                this.Side.Append(new Patch(new Rectangle(970, 10, 300, 700), this.PanelTexture, 13, Color.BurlyWood));
                this.SideLabel = new Label(new Rectangle(980, 500, 280, 200), this.Font, () => this.Log.ToString());
                this.Side.Append(this.SideLabel);

                var toggleSize     = new Vector2(40);
                var toggleLocation = new Vector2(1220, 20);
                this.Toggle = new Button(new Rectangle(toggleLocation.ToPoint(), toggleSize.ToPoint()), this.PanelTexture, Color.BurlyWood);
                this.Toggle.WithInput(this.Input);
                this.Toggle.OnClick += button => this.Side.Toggle();

                var exitWrapper = new PhasedWrapper <CriticalUpdate, MenuDraw>(this.ExitConfirmation.Update, this.ExitConfirmation.Draw);
                this.Attach(exitWrapper);
                this.Attach(this.Side);
                this.Attach(this.Toggle);
            }

            var clientWindowWrapper = new PhasedUpdateWrapper <NormalUpdate>(gametime =>
            {
                if (this.Input.KeyPressed(Keys.F11) || (this.Input.KeyPressed(Keys.Enter) && this.Input.KeysDownAny(Keys.LeftAlt, Keys.RightAlt)))
                {
                    this.Client.ToggleFullscreen();
                }

                if (!this.Client.IsFullscreen)
                {
                    if (this.Input.KeyPressed(Keys.D0))
                    {
                        this.Client.CenterWindow();
                    }
                    if (this.Input.KeyPressed(Keys.R))
                    {
                        this.Client.Resize(BASE_WINDOW_SIZE);
                    }
                    if (this.Input.KeyPressed(Keys.OemPlus))
                    {
                        this.Client.Resize(this.Client.CurrentResolution + BASE_WINDOW_INCREMENT);
                    }
                    if (this.Input.KeyPressed(Keys.OemMinus))
                    {
                        this.Client.Resize(this.Client.CurrentResolution - BASE_WINDOW_INCREMENT);
                    }
                }
            });

            this.Attach(clientWindowWrapper);

            this.Attach(new PhasedUpdateWrapper <CriticalUpdate>(gametime => Static.Memo.Clear()));
        }
Ejemplo n.º 6
0
 public Obstacle(Texture2D tex, Vector2 size, Vector2 pos,
                 bool inSpiritRealm = false)
     : this(new Sprite(tex), pos, size.ToRectangle(), inSpiritRealm)
 {
 }
Ejemplo n.º 7
0
 void DrawColorBlock(ColorRGB color, Vector2 pos, Vector2 size)
 {
     DrawRectangle(pos.ToRectangle(size), color.ToXNAColor());
     DrawString(GetHexString(color), pos, GetContrastingColor(color));
 }
Ejemplo n.º 8
0
 void DrawColorBlock(ColorRGB color, Vector2 pos, Vector2 size)
 {
     spriteBatch.Draw(whiteTexture, pos.ToRectangle(size), color.ToXNAColor());
     spriteBatch.DrawString(font, GetHexString(color), pos, GetContrastingColor(color));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Places a <see cref="MapGrh"/> on the map.
        /// </summary>
        /// <param name="map">The map to place the <see cref="MapGrh"/> on.</param>
        /// <param name="worldPos">The world position to place the <see cref="MapGrh"/>.</param>
        /// <param name="useTileMode">If TileMode should be used.</param>
        /// <param name="gd">The <see cref="GrhData"/> to place. Set to null to attempt to use the <see cref="GrhData"/> that is
        /// currently selected in the <see cref="GlobalState"/>.</param>
        /// <returns>The <see cref="MapGrh"/> instance that was added, or null if the the <see cref="MapGrh"/> could not be
        /// added for any reason.</returns>
        public static MapGrh PlaceMapGrhAtWorldPos(Map map, Vector2 worldPos, bool useTileMode, GrhData gd = null)
        {
            // Get the GrhData to place from the global state
            if (gd == null)
                gd = GlobalState.Instance.Map.GrhToPlace.GrhData;

            // Ensure we have a GrhData to place
            if (gd == null)
                return null;

            worldPos = GridAligner.Instance.Align(worldPos, useTileMode).Round();

            // Cache some other values
            var selGrhGrhIndex = gd.GrhIndex;
            var layer = GlobalState.Instance.Map.Layer;
            var depth = GlobalState.Instance.Map.LayerDepth;
            var drawPosArea = worldPos.ToRectangle(new Vector2(2), true);

            if (!useTileMode)
            {
                // Make sure the same MapGrh doesn't already exist at that position
                if (map.Spatial.Contains<MapGrh>(drawPosArea, x =>
                    x.Grh.GrhData.GrhIndex == selGrhGrhIndex && x.MapRenderLayer == layer &&
                    Math.Round(x.Position.QuickDistance(worldPos)) <= 1))
                {
                    return null;
                }
            }
            else
            {
                // Make sure the same MapGrh doesn't already exist at that position on the same layer
                if (map.Spatial.Contains<MapGrh>(drawPosArea, x =>
                    x.Grh.GrhData.GrhIndex == selGrhGrhIndex && x.MapRenderLayer == layer &&
                    Math.Round(x.Position.QuickDistance(worldPos)) <= 1))
                {
                    return null;
                }

                // In TileMode, do not allow ANY MapGrh at the same position and layer depth. And if it does exist, instead of aborting,
                // delete the existing one.
                var existingMapGrhs = map.Spatial.GetMany<MapGrh>(drawPosArea, x =>
                    x.LayerDepth == depth && x.MapRenderLayer == layer && Math.Round(x.Position.QuickDistance(worldPos)) <= 1);

                foreach (var toDelete in existingMapGrhs)
                {
                    Debug.Assert(toDelete != null);
                    if (log.IsDebugEnabled)
                        log.DebugFormat("TileMode caused MapGrh `{0}` to be overwritten.", toDelete);

                    map.RemoveMapGrh(toDelete);
                }
            }

            // Create the new MapGrh and add it to the map
            var g = new Grh(gd, AnimType.Loop, map.GetTime());
            var mg = new MapGrh(g, worldPos) { LayerDepth = depth, MapRenderLayer = layer };
            map.AddMapGrh(mg);

            return mg;
        }
Ejemplo n.º 10
0
        private void DrawBackground(Graphics.Graphics graphics)
        {
            var texture = graphics.GetTexture2DByName("terrain");
            int tx, ty;
            tx = (int)Math.Ceiling((double)graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Width / 32);
            ty = (int)Math.Ceiling((double)graphics.GetGraphicsDeviceManager().GraphicsDevice.Viewport.Height / 32);

            Vector2 textureIndex = new Vector2(13 * Constants.SpriteSize, 7 * Constants.SpriteSize);

            for (int x = 0; x < tx; x++)
                for (int y = 0; y < ty; y++)
                    graphics.GetSpriteBatch().Draw(texture, new Vector2(x * Constants.TileSize, y * Constants.TileSize).ToRectangle(),
                        textureIndex.ToRectangle(Constants.SpriteSize), Color.White);
        }
Ejemplo n.º 11
0
 public MovingPlatform MovingPlatform(List <Vector2> path, Vector2 size,
                                      float speed = 3f, bool startActive = true)
 {
     return(new MovingPlatform(assets.Stripy(size), path[0],
                               size.ToRectangle(), false, path, speed, startActive));
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Places a <see cref="MapGrh"/> on the map.
        /// </summary>
        /// <param name="map">The map to place the <see cref="MapGrh"/> on.</param>
        /// <param name="worldPos">The world position to place the <see cref="MapGrh"/>.</param>
        /// <param name="useTileMode">If TileMode should be used.</param>
        /// <param name="gd">The <see cref="GrhData"/> to place. Set to null to attempt to use the <see cref="GrhData"/> that is
        /// currently selected in the <see cref="GlobalState"/>.</param>
        /// <returns>The <see cref="MapGrh"/> instance that was added, or null if the the <see cref="MapGrh"/> could not be
        /// added for any reason.</returns>
        public static MapGrh PlaceMapGrhAtWorldPos(Map map, Vector2 worldPos, bool useTileMode, GrhData gd = null)
        {
            // Get the GrhData to place from the global state
            if (gd == null)
            {
                gd = GlobalState.Instance.Map.GrhToPlace.GrhData;
            }

            // Ensure we have a GrhData to place
            if (gd == null)
            {
                return(null);
            }

            worldPos = GridAligner.Instance.Align(worldPos, useTileMode).Round();

            // Cache some other values
            var selGrhGrhIndex = gd.GrhIndex;
            var layer          = GlobalState.Instance.Map.Layer;
            var depth          = GlobalState.Instance.Map.LayerDepth;
            var drawPosArea    = worldPos.ToRectangle(new Vector2(2), true);

            if (!useTileMode)
            {
                // Make sure the same MapGrh doesn't already exist at that position
                if (map.Spatial.Contains <MapGrh>(drawPosArea, x =>
                                                  x.Grh.GrhData.GrhIndex == selGrhGrhIndex && x.MapRenderLayer == layer &&
                                                  Math.Round(x.Position.QuickDistance(worldPos)) <= 1))
                {
                    return(null);
                }
            }
            else
            {
                // Make sure the same MapGrh doesn't already exist at that position on the same layer
                if (map.Spatial.Contains <MapGrh>(drawPosArea, x =>
                                                  x.Grh.GrhData.GrhIndex == selGrhGrhIndex && x.MapRenderLayer == layer &&
                                                  Math.Round(x.Position.QuickDistance(worldPos)) <= 1))
                {
                    return(null);
                }

                // In TileMode, do not allow ANY MapGrh at the same position and layer depth. And if it does exist, instead of aborting,
                // delete the existing one.
                var existingMapGrhs = map.Spatial.GetMany <MapGrh>(drawPosArea, x =>
                                                                   x.LayerDepth == depth && x.MapRenderLayer == layer && Math.Round(x.Position.QuickDistance(worldPos)) <= 1);

                foreach (var toDelete in existingMapGrhs)
                {
                    Debug.Assert(toDelete != null);
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("TileMode caused MapGrh `{0}` to be overwritten.", toDelete);
                    }

                    map.RemoveMapGrh(toDelete);
                }
            }

            // Create the new MapGrh and add it to the map
            var g  = new Grh(gd, AnimType.Loop, map.GetTime());
            var mg = new MapGrh(g, worldPos)
            {
                LayerDepth = depth, MapRenderLayer = layer
            };

            map.AddMapGrh(mg);

            return(mg);
        }