예제 #1
0
        public override void Update()
        {
            if (Input.MouseScrollUp && scroll > 0)
            {
                scroll--;
            }
            if (Input.MouseScrollDown)
            {
                scroll++;
            }
            if (Input.KeyboardTapped(Keys.PageDown))
            {
                scroll += columns;
            }
            if (Input.KeyboardTapped(Keys.PageUp))
            {
                scroll -= columns;
                if (scroll < 0)
                {
                    scroll = 0;
                }
            }

            int xx = (int)Math.Floor((Input.MousePosition.X - position.X) / (size.X / columns));
            int yy = (int)Math.Floor((Input.MousePosition.Y - position.Y) / (size.Y / rows));

            spot = (xx + yy * columns) + scroll;
            if (Input.MousePosition.X > this.position.X && Input.MousePosition.X < this.position.X + this.size.X &&
                Input.MousePosition.Y > this.position.Y && Input.MousePosition.Y < this.position.Y + this.size.Y &&
                spot < keys.Length)
            {
                texture = TextureBin.GetTexture(keys[spot]);
            }
            else
            {
                texture = null;
            }

            if (Input.MouseLeftButtonTapped)
            {
                enterEvent(this);
            }

            base.Update();
        }
예제 #2
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            int w = (int)(size.X / columns);
            int h = (int)(size.Y / rows);

            for (int i = scroll; i < keys.Length && i - scroll < rows * columns; i++)
            {
                int xx = (i - scroll) % columns;
                int yy = (i - scroll) / columns;
                spriteBatch.Draw(TextureBin.GetTexture(keys[i]), new Rectangle(xx * w + (int)this.position.X, yy * h + (int)this.position.Y, w, h), Color.White);
            }
            if (texture != null)
            {
                int xx = (spot - scroll) % columns;
                int yy = (spot - scroll) / columns;
                spriteBatch.DrawString(TextureBin.mainFont, keys[spot], new Vector2(xx * w, yy * h) + position, Color.Red);
                DrawHelper.DrawRectangleOutline(spriteBatch, xx * w + (int)this.position.X, yy * h + (int)this.position.Y, w, h, Color.Red);
            }
        }
예제 #3
0
        private void UpdateDecalMode()
        {
            if (Input.KeyboardTapped(Keys.S))
            {
                textBoxStack.Add(new SelectColorBox(ColorBoxEnter, decalColor));
            }
            if (Input.KeyboardTapped(Keys.U))
            {
                decalsBack.Sort();
                decalsFront.Sort();
            }
            if (Input.KeyboardTapped(Keys.L))
            {
                int num = TextureBin.LoadTexturesFromDirectory("Content\\Decals");
                textBoxStack.Add(new TextBox(null, "Loaded " + num.ToString() + " new textures.", TextBoxEnter));
            }
            if (Input.KeyboardTapped(Keys.Enter))
            {
                textBoxStack.Add(new SelectTextureBox(TextureBoxEnter));
            }
            if (Input.KeyboardTapped(Keys.F))
            {
                System.Diagnostics.Process.Start("explorer.exe", "Content\\Decals");
            }
            if (Input.KeyboardTapped(Keys.H))
            {
                textBoxStack.Add(new TextBox(null, "HOW TO ADD NEW DECALS: Open the decals folder by pressing F.\nThen drag .PNG images into the decals folder.\nThen return to the game, and press L to load the new images into the decals bin.\n\nFURTHER NOTES: Adjust the drift values on decals to make them look like they have depth.\nWhen placing drifting decals, hold LShift to ensure they are properly aligned\nto a grid.\nIf decals are overlapping incorrectly, press U to sort decals by drift.", TextBoxEnter));
            }
            if (Input.KeyboardTapped(Keys.Left))
            {
                decalLayer = DecalLayer.Back;
            }
            if (Input.KeyboardTapped(Keys.Right))
            {
                decalLayer = DecalLayer.Front;
            }
            if (Input.IsKeyDown(Keys.LeftControl))
            {
                if (Input.MouseLeftButtonTapped)
                {
                    foreach (Decal d in decalsFront)
                    {
                        Vector2 decalOnScreen = d.position - (d.origin + (camera - d.origin) * d.drift);
                        if ((decalOnScreen - (Input.MousePosition * zoom)).Length() < 14)
                        {
                            decalsFront.BufferRemove(d);
                        }
                    }
                    foreach (Decal d in decalsBack)
                    {
                        Vector2 decalOnScreen = d.position - (d.origin + (camera - d.origin) * d.drift);
                        if ((decalOnScreen - (Input.MousePosition * zoom)).Length() < 14)
                        {
                            decalsBack.BufferRemove(d);
                        }
                    }
                    decalsFront.ApplyBuffers();
                    decalsBack.ApplyBuffers();
                }
            }
            else
            {
                if (Input.IsKeyDown(Keys.A))
                {
                    if (Input.MouseScrollDown || Input.KeyboardTapped(Keys.Down))
                    {
                        decalAngle -= MathHelper.Pi / 12;
                    }
                    if (Input.MouseScrollUp || Input.KeyboardTapped(Keys.Up))
                    {
                        decalAngle += MathHelper.Pi / 12;
                    }
                }
                else if (Input.IsKeyDown(Keys.D))
                {
                    if (Input.MouseScrollDown || Input.KeyboardTapped(Keys.Down))
                    {
                        decalDrift -= 0.05f;
                    }
                    if (Input.MouseScrollUp || Input.KeyboardTapped(Keys.Up))
                    {
                        decalDrift += 0.05f;
                    }
                }
                else
                {
                    if (Input.MouseScrollDown || Input.KeyboardTapped(Keys.Down))
                    {
                        decalScale -= 0.25f;
                    }
                    if (Input.MouseScrollUp || Input.KeyboardTapped(Keys.Up))
                    {
                        decalScale += 0.25f;
                    }
                }

                if (Input.MouseLeftButtonTapped && decal != null)
                {
                    if (decalLayer == DecalLayer.Front)
                    {
                        this.decalsFront.Add(new Decal(snapMouse, decal, decalOrigin, decalColor, decalScale, decalAngle, decalDrift));
                    }
                    else
                    {
                        this.decalsBack.Add(new Decal(snapMouse, decal, decalOrigin, decalColor, decalScale, decalAngle, decalDrift));
                    }
                }
            }
        }
예제 #4
0
 public RoomBattle()
 {
     this.Load("Content/Levels/battle.lvl");
     TextureBin.GetTexture("pixel");
     this.FillNodes();
 }
예제 #5
0
        /// <summary>
        /// Loads a room with the specified filename.
        ///
        /// Returns 0 if everything is OK.
        /// Returns 2 if cannot find the file.
        /// Returns 3 if it had to load new textures.
        /// Returns 4 if we are missing textures.
        /// Returns -1 if the file is corrupt.
        /// </summary>
        /// <param name="fname">The filename to load from.</param>
        /// <returns>A code indicating error or success.</returns>
        public int Load(string fname)
        {
            // Reads in the entire file.
            string[] lines;
            try
            {
                lines = System.IO.File.ReadAllLines(fname);
            }
            catch
            {
                return(2);
            }

            Reset();

            // Sets file index to 10 (skip header)
            int i = 0;

            name = lines[i++];
            this.boundsTopLeft.X     = float.Parse(lines[i++]);
            this.boundsTopLeft.Y     = float.Parse(lines[i++]);
            this.boundsBottomRight.X = float.Parse(lines[i++]);
            this.boundsBottomRight.Y = float.Parse(lines[i++]);
            i = 10;
            int flag = 0;

            while (i < lines.Length)
            {
                string type = lines[i++];
                switch (type)
                {
                case "Floor":
                    floors.Add(new Floor(new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++]))));
                    break;

                case "Block":
                    blocks.Add(new Block(new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++]))));
                    break;

                case "TopBlock":
                    blocks.Add(new Block(new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), true));
                    break;

                case "Player":
                    Player p = new Player(new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), this);
                    objects.Add(p);
                    this.cameraTarget = p;
                    break;

                case "WorldObject":
                    objects.Add(new WorldObject(new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])), TextureBin.GetTexture(lines[i++]), this));
                    break;

                case "Node":
                    nodes.AddNode(lines[i++], new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++])));
                    break;

                case "Decal":
                    bool    isFront = (lines[i++] == "F");
                    Vector2 pos     = new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++]));
                    Color   col     = new Color(int.Parse(lines[i++]), int.Parse(lines[i++]), int.Parse(lines[i++]), int.Parse(lines[i++]));
                    Vector2 ori     = new Vector2(float.Parse(lines[i++]), float.Parse(lines[i++]));

                    Texture2D tex;
                    if (!TextureBin.GetDictionary.ContainsKey(lines[i]))
                    {
                        if (TextureBin.LoadTextureFromStream("Content\\Decals\\" + lines[i] + ".png") == 0)
                        {
                            tex  = TextureBin.GetTexture(lines[i]);
                            flag = 3;
                        }
                        else
                        {
                            tex  = TextureBin.Pixel;
                            flag = 4;
                        }
                    }
                    else
                    {
                        tex = TextureBin.GetTexture(lines[i]);
                    }
                    i++;

                    Decal d = new Decal(pos, tex, ori, col, float.Parse(lines[i++]), float.Parse(lines[i++]), float.Parse(lines[i++]));
                    if (isFront)
                    {
                        decalsFront.Add(d);
                    }
                    else
                    {
                        decalsBack.Add(d);
                    }
                    break;

                default:
                    i    = lines.Length;
                    flag = -1;
                    break;
                }
            }

            return(flag);
        }
예제 #6
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     TextureBin.LoadTextures(this.Content);
 }