コード例 #1
0
ファイル: NetBase.cs プロジェクト: Shard/Blueprint-Client
 public void Draw(SpriteBatch spriteBatch, Camera camera)
 {
     foreach (var player in Players)
     {
         //player.Draw(spriteBatch, camera);
     }
 }
コード例 #2
0
ファイル: NpcPackage.cs プロジェクト: Shard/Blueprint-Client
 public void Draw( SpriteBatch spriteBatch, Camera camera, SpriteFont font )
 {
     foreach (ActiveNpc npc in ActiveNpcs)
     {
         npc.Type.Race.Animation.Draw(spriteBatch, camera, npc.Type.Race.Texture);
     }
 }
コード例 #3
0
        public void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            #region Draw held animations

            if (Player != null)
            {
                spriteBatch.Draw(WeaponTexture, Player.Movement.Area, Color.White);
            }

            #endregion

            #region Draw live weapons

            foreach (var weapon in LiveWeapons)
            {
                if (weapon.Weapon.Type.Name == "Sword")
                {
                    Vector2 center = new Vector2(weapon.Weapon.Sprite.Center.X, weapon.Weapon.Sprite.Bottom);
                    spriteBatch.Draw(WeaponTexture, camera.FromRectangle(new Rectangle((int)weapon.Location.X, (int)weapon.Location.Y, weapon.Weapon.Sprite.Width, weapon.Weapon.Sprite.Height)), weapon.Weapon.Sprite, Color.White, weapon.Rotation, center, SpriteEffects.None, 0);
                    // Draw hitboxes
                    //spriteBatch.Draw(WeaponTexture, camera.FromRectangle(new Rectangle((int)weapon.currentLocation.UpperLeftCorner().X, (int)weapon.currentLocation.UpperLeftCorner().Y, 5, 5)), Color.White);
                    //spriteBatch.Draw(WeaponTexture, camera.FromRectangle(new Rectangle((int)weapon.currentLocation.UpperRightCorner().X, (int)weapon.currentLocation.UpperRightCorner().Y, 5, 5)), Color.White);
                    //spriteBatch.Draw(WeaponTexture, camera.FromRectangle(new Rectangle((int)weapon.currentLocation.LowerLeftCorner().X, (int)weapon.currentLocation.LowerLeftCorner().Y, 5, 5)), Color.White);
                    //spriteBatch.Draw(WeaponTexture, camera.FromRectangle(new Rectangle((int)weapon.currentLocation.LowerRightCorner().X, (int)weapon.currentLocation.LowerRightCorner().Y, 5, 5)), Color.White);
                }
                else if (weapon.Weapon.Type.Name == "Arrow")
                {
                    float angle = (float)Geometry.Angle(Vector2.Zero, weapon.Movement.Velocity);
                    spriteBatch.Draw(ArrowTexture, camera.FromRectangle(weapon.Movement.Area), ArrowTexture.Bounds, Color.White, MathHelper.ToRadians(angle + 90f), new Vector2(weapon.Movement.Area.Width / 2, weapon.Movement.Area.Height / 2), SpriteEffects.None, 0);
                }
            }

            #endregion
        }
コード例 #4
0
 public LiveProjectile(Weapon weapon, Vector2 location, float force, Control control, Camera camera)
     : base(weapon, location)
 {
     Movement = new Movement(location, 24, 6);
     Movement.Gravity = 0.15f;
     Movement.Drag = 0.06f;
     Movement.PushbackFrom(new Vector2(control.currentMouse.X - camera.X, control.currentMouse.Y - camera.Y), force);
     TimeToLive = 250;
 }
コード例 #5
0
ファイル: TextHelper.cs プロジェクト: Shard/Blueprint-Client
        public static void DrawString(
            SpriteBatch spriteBatch,
            SpriteFont font,
            string text,
            Vector2 position,
            Color color,
            float scale = 1f,
            bool shadow = true,
            string align = "left",
            string valign = "top",
            Camera camera = null,
            int width_wrap = 0
        )
        {
            if (width_wrap > 0)
            {
                string[] lines = SplitWrap(text, width_wrap, font, scale);
                Vector2 measure = font.MeasureString("s");
                int y_offset = 0;
                foreach (string line in lines)
                {
                    DrawString(spriteBatch, font, line, new Vector2(position.X, position.Y + y_offset), color, scale, shadow, align, camera:camera);
                    y_offset += (int)measure.Y -4;
                }
                return;
            }

            // Camera offset
            if (camera != null)
                position -= camera.ToVector2();

            // Alignment
            if (align == "right")
                position.X -= font.MeasureString(text).X * scale;
            else if (align == "center")
                position.X -= (font.MeasureString(text).X * scale) * 0.5f;

            if (valign == "center")
                position.Y -= (font.MeasureString(text).Y * scale) * 0.5f;
            else if (valign == "bottom")
                position.Y -= font.MeasureString(text).Y * scale;

            if (shadow)
            {
                spriteBatch.DrawString(font, text, new Vector2(position.X + (scale * 1), position.Y + (scale * 1)), new Color(20, 20, 20, color.A), 0f, Vector2.Zero, scale, SpriteEffects.None, 0);
            }
            spriteBatch.DrawString(font, text, position, color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0);
        }
コード例 #6
0
        public void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            foreach (Entity entity in Entities)
            {
                if (entity == null) { continue; }
                EntityType type = getType(entity.Type);
                if (type.Function == EntityType.EntityFunction.Door)
                {
                    if(entity.Solid)
                        spriteBatch.Draw(type.Sprite, camera.FromRectangle(entity.Area), new Rectangle(0,0, type.Sprite.Width / 2, type.Sprite.Height), Color.White);
                    else
                        spriteBatch.Draw(type.Sprite, camera.FromRectangle(entity.Area), new Rectangle(type.Sprite.Width / 2, 0, type.Sprite.Width / 2, type.Sprite.Height), Color.White);
                }
                else
                {
                    spriteBatch.Draw(getType(entity.Type).Sprite, camera.FromRectangle(entity.Area), Color.White);
                }

            }
        }
コード例 #7
0
ファイル: Player.cs プロジェクト: Shard/Blueprint-Client
 public void Draw(SpriteBatch spriteBatch, Camera camera)
 {
     Animation.Draw(spriteBatch, camera, PlayerTexture);
 }
コード例 #8
0
        public void Update(Control control, Camera camera, Player player, NpcPackage npcs, Ui.FloatingTextCollection floatingText, ref Map map)
        {
            #region Initialize Weapons

            if (player.Inventory.Quickbar.UsingItem.Type == "useweapon")
            {
                ItemUse use = player.Inventory.Quickbar.UsingItem;
                Weapon weapon = GetWeaponById(int.Parse(use.Value));

                if (weapon.Type.Name == "Sword" && !player.Inventory.Quickbar.IsUsingItem)
                {
                    LiveWeapons.Add(new LiveSword(GetWeaponById(player.Inventory.Quickbar.UsingItem.IntValue),new Vector2(player.Movement.Area.Center.X, player.Movement.Area.Center.Y - 5), player.Movement.Direction));
                    player.Inventory.Quickbar.IsUsingItem = true;
                }

                if (weapon.Type.Name == "Arrow")
                {
                    if(control.currentMouse.LeftButton == ButtonState.Pressed){
                        if(!player.Inventory.Quickbar.IsUsingItem) {
                            player.Inventory.Quickbar.IsUsingItem = true;
                            use.Charge = 10f;
                        } else {
                            use.Charge += 0.1f;
                        }
                    } else {
                        LiveProjectile liveWeapon = new LiveProjectile(Weapons[2], new Vector2(player.Movement.Area.Center.X, player.Movement.Area.Center.Y), (float)use.Charge, control, camera);
                        use.Charge = 0;
                        LiveWeapons.Add(liveWeapon);
                        player.Inventory.Quickbar.IsUsingItem = false;
                        Player = player;
                    }
                }
            }

            #endregion

            #region Update weapons

            for ( int i = 0; i < LiveWeapons.Count; i++)
            {
                if (LiveWeapons[i].Weapon.Type.Name == "Sword")
                {
                    LiveSword weapon = LiveWeapons[i];
                    weapon.Rotation += LiveWeapons[i].Speed;
                    LiveWeapons[i].Location += player.Movement.Moved;
                    if ((LiveWeapons[i].SwingEnd > 0 && LiveWeapons[i].Rotation > LiveWeapons[i].SwingEnd) || (LiveWeapons[i].SwingEnd < 0 && LiveWeapons[i].Rotation < LiveWeapons[i].SwingEnd))
                    {
                        LiveWeapons.RemoveAt(i);
                        player.Inventory.Quickbar.IsUsingItem = false;
                    }
                } else if(LiveWeapons[i].Weapon.Type.Name == "Arrow")
                {
                    LiveProjectile weapon = LiveWeapons[i];
                    if (weapon.Movement.Velocity != Vector2.Zero)
                    {
                        weapon.Movement.Update(map);
                    }
                    else
                    {
                        weapon.TimeToLive -= 1;
                        if (weapon.TimeToLive <= 0) { LiveWeapons.RemoveAt(i); }
                    }
                }
            }

            #endregion

            #region Check for weapon collisions

            // Npc Collisions
            for (int w = 0; w < LiveWeapons.Count; w++)
            {

                var weapon = LiveWeapons[w];
                for (int i = 0; i < npcs.ActiveNpcs.Count; i++)
                {

                    if (weapon.Weapon.Type.Name == "Sword")
                    {
                        LiveSword sword = weapon;
                        if (weapon.currentLocation.Intersects(npcs.ActiveNpcs[i].Movement.Area))
                        {
                            if (npcs.Damage(npcs.ActiveNpcs[i], 10, weapon.Location))
                            {
                                floatingText.Add("10", weapon.Location);
                            }
                        }
                    }
                    else if(weapon.Weapon.Type.Name == "Arrow" && weapon.Movement.Velocity != Vector2.Zero)
                    {
                        LiveProjectile projectile = weapon;
                        if (projectile.Movement.Area.Intersects(npcs.ActiveNpcs[i].Movement.Area))
                        {
                            if (npcs.Damage(npcs.ActiveNpcs[i], 10, weapon.Location))
                            {
                                floatingText.Add("10", new Vector2(projectile.Movement.Area.Center.X, projectile.Movement.Area.Center.Y));
                                LiveWeapons.RemoveAt(w);
                            }
                        }
                    }
                }

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

                for (int x = startx; x < endx; x++)
                {
                    for (int y = starty; y < endy; y++)
                    {

                        Rectangle area = new Rectangle(x * 24, y * 24, 24,24);

                        if (map.Flora.Flora[x, y] != null)
                        {
                            if (weapon.Weapon.Type.Name == "Sword")
                            {
                                if (weapon.currentLocation.Intersects(area)) { map.Flora.Flora[x, y] = null; }
                            }
                            else if (weapon.Weapon.Type.Name == "Arrow")
                            {
                                if (weapon.Movement.Area.Intersects(area)) { map.Flora.Flora[x, y] = null; }
                            }
                        }

                    }
                }

            }

            #endregion
        }
コード例 #9
0
ファイル: Animations.cs プロジェクト: Shard/Blueprint-Client
        public void Draw(SpriteBatch spriteBatch, Camera camera, Texture2D texture)
        {
            // Flip the animation if needed
            SpriteEffects effects = SpriteEffects.FlipHorizontally;
            if (CurrentDirection == "right")
                effects = SpriteEffects.None;

            spriteBatch.Draw(texture, camera.FromRectangle(CurrentLocation), CurrentFrame.ToRectangle(), Color.White, 0f, Vector2.Zero, effects, 0f);
        }
コード例 #10
0
ファイル: Game1.cs プロジェクト: Shard/Blueprint-Client
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {

            // Loading Screen
            font = Content.Load<SpriteFont>("Misc/system");

            // Load Remote Texutres
            Texture2D mapTexture = Package.RemoteTexture("/maps/sprite/" + Config.MapId, GraphicsDevice);

            ShotgunSound = Content.Load<SoundEffect>("Sounds/shotgun");

            // Load Local Textures
            Cursor = Content.Load<Texture2D>("Ui/cursor");

            // Initialize
            Control.Initialize(Content.Load<Texture2D>("Ui/cursor"));
            Wallpaper = Content.Load<Texture2D>("Wallpaper/wallpaper");
            Map.Initialize(mapTexture, Package, Config, GraphicsDevice, Content);
            Player.Initialize(Package.LocalTexture("C:\\blueprint\\player.png", GraphicsDevice), Content.Load<Texture2D>("Ui/bars"), Package, Map.Spawn);
            Camera = new Camera(GraphicsDevice, Player);
            WeaponPackage.Initialize(Content.Load<Texture2D>("Weapons/sword"),Content.Load<Texture2D>("Weapons/arrow"));
            ItemPackage.mock(Map.Types, WeaponPackage.Weapons);
            ItemPackage.Initialize(Content.Load<Texture2D>("items"));
            Player.Inventory.Initialize(Content.Load<Texture2D>("Ui/buttons"), ItemPackage);
            NpcPackage.Initialize(Content, Package, Content.Load<Texture2D>("Ui/ui"));
            Chat.Initialize(Content.Load<Texture2D>("Ui/chat"));
            Lighting.LoadContent(GraphicsDevice);

            WorldBatch = new SpriteBatch(GraphicsDevice);
            UiBatch = new SpriteBatch(GraphicsDevice);

            if (Config.Hosting) { Server = new Server(Config); Server.Initialize(Content.Load<Texture2D>("player"), Content.Load<Texture2D>("Ui/bars")); } else { Server = null; }
            if (Config.Join != null) { Client = new Client(Config); Client.Initialize(Content.Load<Texture2D>("player"), Content.Load<Texture2D>("Ui/bars")); } else { Client = null; }

        }
コード例 #11
0
ファイル: Game1.cs プロジェクト: Shard/Blueprint-Client
 /// <summary>Called on window resize</summary>
 void Window_ClientSizeChanged(object sender, EventArgs e)
 {
     Camera = new Camera(GraphicsDevice, Player);
 }
コード例 #12
0
ファイル: Control.cs プロジェクト: Shard/Blueprint-Client
        public void Update(KeyboardState keyboard, MouseState mouse, Camera camera )
        {
            State = CursorStates.Default;

            previousKeyboard = currentKeyboard;
            currentKeyboard = keyboard;
            previousMouse = currentMouse;
            currentMouse = mouse;

            AtTileX = (currentMouse.X - (int)camera.X) / 24;
            AtTileY = (currentMouse.Y - (int)camera.Y) / 24;

            if (MouseLock == true && MouseLockCounter > 0)
                MouseLockCounter--;
            else if (MouseLock == true)
                MouseLock = false;
        }
コード例 #13
0
        public void Update(Control control, Camera camera)
        {
            foreach (Entity item in Entities)
            {
                if (item == null) { continue; }

                EntityType type = getType(item.Type);
                if (type.Function == EntityType.EntityFunction.Door)
                {
                    if (camera.FromRectangle(item.Area).Intersects(control.MousePos))
                    {
                        control.State = Control.CursorStates.Interact;
                        if (control.currentMouse.RightButton == ButtonState.Pressed && control.previousMouse.RightButton == ButtonState.Released)
                        {
                            if (item.Solid) { item.Solid = false; } else { item.Solid = true; }
                        }
                    }
                }
                else
                {
                    #region Custom Entities
                    foreach (Event e in item.Events)
                    {

                        // Proccess Triggers
                        switch (e.Trigger)
                        {
                            case Event.Triggers.PlayerInteract:
                                if (control.previousMouse.RightButton == ButtonState.Released && control.currentMouse.RightButton == ButtonState.Pressed)
                                {
                                    if (Rectangle.Intersect(item.Area, camera.FromRectangle(new Rectangle(control.currentMouse.X, control.currentMouse.Y, 1, 1))) != Rectangle.Empty)
                                    {
                                        e.TriggerEvent();
                                    }
                                }
                                break;
                        }

                        // Proccess Conditions

                        // Proccess Actions
                        if (e.Active)
                        {
                            switch (e.Action)
                            {
                                case Event.Actions.Solid:
                                    if (e.ActionData == "toggle")
                                    {
                                        if (item.Solid) { item.Solid = false; } else { item.Solid = true; }
                                    }
                                    break;
                                case Event.Actions.Animation:
                                    if (item.AltSprite) { item.AltSprite = false; } else { item.AltSprite = true; }
                                    break;
                            }
                            e.Active = false; // Finish Firing Event
                        }

                    }
                    #endregion
                }

            }
        }
コード例 #14
0
        public void Update(Camera camera, Control control, SpriteFont font)
        {
            #region Setup Dialog Area

            if (State == NpcInteractionState.Intro || State == NpcInteractionState.Gossip)
            {
                // Calculate dialog area
                CurrentLines = TextHelper.SplitWrap(CurrentText, 330, font, 0.75f).Length;
                CurrentBody = camera.FromRectangle(new Rectangle(Subject.Movement.Area.Center.X - Width / 2, Subject.Movement.Area.Top - Height - 20, Width, Height));
                CurrentHeader = camera.FromRectangle(new Rectangle(Subject.Movement.Area.Center.X - Width / 2, Subject.Movement.Area.Top - Height - 52, Width, 32));
                Height = 30 + (int)(font.MeasureString("S").Y - 4) * (CurrentLines + 1);

                if (control.MousePos.Intersects(CurrentBody))
                    control.MouseLock = true;
            }

            #endregion

            #region Intro

            if (State == NpcInteractionState.Intro)
            {

                // Actions
                Vector2 footer_offset = new Vector2(CurrentBody.X + 10, CurrentBody.Y + Height - 25);
                CurrentSelection = "";
                Vector2 current_font;

                // if shop
                current_font = font.MeasureString("Shop") * ScaleActions;
                if (control.MousePos.Intersects(new Rectangle((int)footer_offset.X, (int)footer_offset.Y, (int)current_font.X, (int)current_font.Y)))
                {
                    CurrentSelection = "Shop";
                    if (control.Click()) { State = NpcInteractionState.Shop; }
                }
                footer_offset.X += (int)(font.MeasureString("Shop").X * 0.7f) + 10;

                // if gossip
                current_font = font.MeasureString("Gossip") * ScaleActions;
                if (control.MousePos.Intersects(new Rectangle((int)footer_offset.X, (int)footer_offset.Y, (int)current_font.X, (int)current_font.Y)))
                {
                    CurrentSelection = "Gossip";
                    if (control.Click()) { State = NpcInteractionState.Gossip; CurrentText = Subject.Type.Dialog.Get(State).Line; }
                }
                footer_offset.X += (int)(font.MeasureString("Gossip").X * 0.7f) + 10;

                // if follow
                current_font = font.MeasureString("Follow Me") * ScaleActions;
                if (control.MousePos.Intersects(new Rectangle((int)footer_offset.X, (int)footer_offset.Y, (int)current_font.X, (int)current_font.Y)))
                {
                    CurrentSelection = "Follow Me";
                    if (control.Click()) { State = NpcInteractionState.None; }
                }
                footer_offset.X += (int)(font.MeasureString("Follow Me").X * 0.7f) + 10;

            }

            #endregion
        }
コード例 #15
0
ファイル: Inventory.cs プロジェクト: Shard/Blueprint-Client
 public void Update(Camera camera, Control control)
 {
     Quickbar.Update(camera, control, ref HeldItem);
     Bag.Update(camera, control, ref HeldItem);
 }
コード例 #16
0
ファイル: Quickbar.cs プロジェクト: Shard/Blueprint-Client
        public void Update(Camera camera, Control control, ref Item held_item)
        {
            #region Scrolling and Hotkeys

            if (control.currentMouse.ScrollWheelValue > control.previousMouse.ScrollWheelValue)
            { Selected++; if (Selected > Size - 1) { Selected = Size - 1; } }
            if (control.currentMouse.ScrollWheelValue < control.previousMouse.ScrollWheelValue)
            { Selected--; if (Selected < 0) { Selected = 0; } }

            if (!control.Typing){
                if (control.currentKeyboard.IsKeyDown(Keys.D1) && control.previousKeyboard.IsKeyUp(Keys.D1) && Size >= 1){ Selected = 0; }
                if (control.currentKeyboard.IsKeyDown(Keys.D2) && control.previousKeyboard.IsKeyUp(Keys.D2) && Size >= 2) { Selected = 1; }
                if (control.currentKeyboard.IsKeyDown(Keys.D3) && control.previousKeyboard.IsKeyUp(Keys.D3) && Size >= 3) { Selected = 2; }
                if (control.currentKeyboard.IsKeyDown(Keys.D4) && control.previousKeyboard.IsKeyUp(Keys.D4) && Size >= 4) { Selected = 3; }
                if (control.currentKeyboard.IsKeyDown(Keys.D5) && control.previousKeyboard.IsKeyUp(Keys.D5) && Size >= 5) { Selected = 4; }
                if (control.currentKeyboard.IsKeyDown(Keys.D6) && control.previousKeyboard.IsKeyUp(Keys.D6) && Size >= 6) { Selected = 5; }
                if (control.currentKeyboard.IsKeyDown(Keys.D7) && control.previousKeyboard.IsKeyUp(Keys.D7) && Size >= 7) { Selected = 6; }
                if (control.currentKeyboard.IsKeyDown(Keys.D8) && control.previousKeyboard.IsKeyUp(Keys.D8) && Size >= 8) { Selected = 7; }
                if (control.currentKeyboard.IsKeyDown(Keys.D9) && control.previousKeyboard.IsKeyUp(Keys.D9) && Size >= 9) { Selected = 8; }
                if (control.currentKeyboard.IsKeyDown(Keys.D0) && control.previousKeyboard.IsKeyUp(Keys.D0) && Size >= 10) { Selected = 9; }
            }

            #endregion

            #region Positioning

            if (Layout == "horizontal")
            {
                Area.Height = 64;
                Area.Width = Size * (64 + Margin);
            }
            else
            {
                Area.Width = 64;
                Area.Height = Size * (64 + Margin);
            }

            if (Horizontal == "left")
                { Area.X = (int)Offset.X; }
            else if (Horizontal == "right")
                { Area.X = (int)(camera.Width - (Offset.X + Area.Width)); }
            else
                { Area.X = (int)(camera.Width - (Offset.X + Area.Width)) / 2; }

            if (Vertical == "top")
                { Area.Y = (int)Offset.Y; }
            else if (Vertical == "bottom")
                { Area.Y = (int)(camera.Height - (Offset.Y + Area.Height)); }
            else
                { Area.Y = (int)(camera.Height - (Offset.Y + Area.Height)) / 2; }

            #endregion

            #region Selection and item management

            bool locked_use = false;

            // Calculate if the mouse is hovering over any buttons or not
            if (Area.Intersects(control.MousePos))
            {
                locked_use = true;
                int innerpos = 0;
                if (Layout == "horizontal")
                {
                    int mousepos = Math.DivRem(control.currentMouse.X - Area.X, 64 + Margin, out innerpos);
                    if (innerpos <= 64) { MouseOver = mousepos; } else { MouseOver = -1; }
                }
                else
                {
                    int mousepos = Math.DivRem(control.currentMouse.Y - Area.Y, 64 + Margin, out innerpos);
                    if (innerpos <= 64) { MouseOver = mousepos; } else { MouseOver = -1; }
                }
            } else { MouseOver = -1; }

            // Check if the user just clicked their mouse, if so mark the button as being currently mouse downed on
            if ( MouseOver > -1 && control.currentMouse.LeftButton == ButtonState.Pressed && control.previousMouse.LeftButton == ButtonState.Released)
                { MouseDown = MouseOver; }

            // If the mouse is down on a button and it leaves the button, start dragging the item
            if (MouseDown > -1)
            {
                if (MouseDown != MouseOver && Items.Items[MouseDown] != null)
                {
                    held_item = Items.Items[MouseDown];
                    Items.Items[MouseDown] = null;
                }
            }

            // If the mouse was down and the user has now released the left mouse button
            if (MouseDown > -1 && control.currentMouse.LeftButton == ButtonState.Released && control.previousMouse.LeftButton == ButtonState.Pressed)
            {
                if (held_item != null && MouseOver > -1) // Holding and item and hovering over a button
                {
                    Item swapItem = Items.Items[MouseOver];
                    Items.Items[MouseOver] = held_item;
                    held_item = swapItem;
                }
                else if (held_item != null) // Holding an item and not overing over any other button
                {
                    Selected = MouseOver;
                }
                else if (MouseDown == MouseOver)
                {
                    Selected = MouseOver;
                }
                MouseDown = -1;
            }

            #endregion

            // Using Items
            if (!locked_use && Selected > -1 && control.currentMouse.LeftButton == ButtonState.Pressed && control.MouseLock == false && Items.Items[Selected] != null)
                { UsingItem.Update(Items.Items[Selected].Type.Use); }
            else if(control.currentMouse.LeftButton == ButtonState.Released && control.previousMouse.LeftButton == ButtonState.Pressed){
                // Wait up, some weapons want to finish
            }
            else { UsingItem.Clear(); }
        }
コード例 #17
0
ファイル: Bag.cs プロジェクト: Shard/Blueprint-Client
        public void Update(Camera camera, Control control, ref Item held_item)
        {
            // Toggle backpack
            if (control.previousKeyboard.IsKeyUp(Keys.B) && control.currentKeyboard.IsKeyDown(Keys.B))
            {
                if (Open) { Open = false; } else { Open = true; }
            }

            if (Open)
            {

                // Check if the mouse is within the bag area
                int offsetx = (camera.Width - (AreaWidth + OffsetX)) / 2;
                int offsety = camera.Height - (AreaHeight + OffsetY);
                Rectangle bounds = new Rectangle(offsetx - 10, offsety - 10, AreaWidth + 20, AreaHeight + 20);
                Rectangle innerBounds = new Rectangle(offsetx, offsety, AreaWidth, AreaHeight);

                if (bounds.Intersects(new Rectangle(control.currentMouse.X, control.currentMouse.Y, 1, 1)))
                {

                    // Mouse is inside the inventory area
                    int col_remainder;
                    int row_remainder;
                    int current_col = Math.DivRem( control.currentMouse.X - offsetx, IconWidth + IconMargin, out col_remainder);
                    int current_row = Math.DivRem(control.currentMouse.Y - offsety, IconWidth + IconMargin, out row_remainder);

                    // Check if mouse landed within the icon area
                    if (col_remainder <= IconWidth && row_remainder <= IconWidth && col_remainder >= 0 && row_remainder >= 0)
                    {

                        int position = current_col + current_row * Width;
                        if (innerBounds.Intersects(new Rectangle(control.currentMouse.X, control.currentMouse.Y, 1, 1)))
                            { MouseOver = (int)MathHelper.Clamp(position, 0, Items.Size); } else { MouseOver = -1; }

                        // Mousedown on button
                        if (MouseOver > -1 && control.currentMouse.LeftButton == ButtonState.Pressed && control.previousMouse.LeftButton == ButtonState.Released)
                        {
                            MouseDown = MouseOver;
                        }

                        // Mouseup
                        if (MouseDown > -1 && control.currentMouse.LeftButton == ButtonState.Released && control.previousMouse.LeftButton == ButtonState.Pressed)
                        {
                            if (held_item != null && MouseOver > -1) // Drop on quickbar, moving its position
                            {
                                Item swapItem = Items.Items[MouseOver];
                                Items.Items[MouseOver] = held_item;
                                held_item = swapItem;
                            }
                            else if (held_item != null)
                            {
                                Selected = MouseOver;
                            }
                            MouseDown = -1;
                        }
                    }
                    else
                    {
                        MouseOver = -1;
                    }
                    // While hovering
                    if (MouseDown > -1)
                    {
                        if (MouseDown != MouseOver && Items.Items[MouseDown] != null) // If the player is now dragging the item
                        {
                            held_item = Items.Items[MouseDown];
                            Items.Items[MouseDown] = null;
                        }
                    }
                }
                else
                {
                    MouseOver = -1;
                }

            }
        }
コード例 #18
0
ファイル: Map.cs プロジェクト: Shard/Blueprint-Client
        public void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            #region Draw Blocks

            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 + 2; y++)
                {
                    Vector2 position = new Vector2(camera.X + x * 24, camera.Y + y * 24);
                    if (Walls[x, y] != null)
                    {
                        spriteBatch.Draw(WallTexture, position, Walls[x, y].Type.Sprite, Color.White);
                    }
                    if (Blocks[x, y] != null) {
                        BlockFrame frame = GetSpriteIndex(x,y);
                        spriteBatch.Draw(BlockTexture, new Rectangle((int)position.X + 12, (int)position.Y + 12, 24,24), Blocks[x, y].Type.Slices[frame.Index], Color.White, frame.Rotate, new Vector2(12,12), SpriteEffects.None, 0);

                        // Draw Block Damage
                        if (Blocks[x, y].Health < 10) { spriteBatch.Draw(BlockState, position, new Rectangle(8 * 24, 24, 24, 24), Color.Gray); } else
                        if (Blocks[x, y].Health < 20) { spriteBatch.Draw(BlockState, position, new Rectangle(7 * 24, 24, 24, 24), Color.Gray); } else
                        if (Blocks[x, y].Health < 30) { spriteBatch.Draw(BlockState, position, new Rectangle(6 * 24, 24, 24, 24), Color.Gray); } else
                        if (Blocks[x, y].Health < 40) { spriteBatch.Draw(BlockState, position, new Rectangle(5 * 24, 24, 24, 24), Color.Gray); } else
                        if (Blocks[x, y].Health < 50) { spriteBatch.Draw(BlockState, position, new Rectangle(4 * 24, 24, 24, 24), Color.Gray); } else
                        if (Blocks[x, y].Health < 60) { spriteBatch.Draw(BlockState, position, new Rectangle(3 * 24, 24, 24, 24), Color.Gray); } else
                        if (Blocks[x, y].Health < 70) { spriteBatch.Draw(BlockState, position, new Rectangle(2 * 24, 24, 24, 24), Color.Gray); } else
                        if (Blocks[x, y].Health < 80) { spriteBatch.Draw(BlockState, position, new Rectangle(1 * 24, 24, 24, 24), Color.Gray); } else
                        if (Blocks[x, y].Health < 90) { spriteBatch.Draw(BlockState, position, new Rectangle(0, 24, 24, 24), Color.Gray); }

                    }
                    if (Flora.Flora[x, y] != null)
                    {
                        spriteBatch.Draw(Flora.Sprite, position, Flora.Flora[x, y].Type.Sprite, Color.White);
                    }
                }
            }

            #endregion

            Entities.Draw(spriteBatch, camera);
        }
コード例 #19
0
ファイル: Map.cs プロジェクト: Shard/Blueprint-Client
        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
        }
コード例 #20
0
ファイル: Lighting.cs プロジェクト: Shard/Blueprint-Client
        public void Update(GameTime gameTime, Control control, Camera camera, EntityPackage entities)
        {
            Sun.X = 100 * 24;
            Sun.Y = -500 * 24;

            for (int i = 0; i < entities.Entities.Count; i++)
            {
                if (entities.Entities[i] == null) { continue; }
                if (entities.Entities[i].Light == null)
                {
                    entities.Entities[i].Light = new Light2D()
                    {
                        Texture = Light,
                        Range = 100f,
                        Color = new Color(255,255,255),
                        X = camera.FromRectangle(entities.Entities[i].Area).Center.X,
                        Y = camera.FromRectangle(entities.Entities[i].Area).Center.Y,
                        Angle = MathHelper.TwoPi * 1f,
                        Intensity = 2222f,
                    };
                    krypton.Lights.Add(entities.Entities[i].Light);
                }
                else
                {
                    entities.Entities[i].Light.X = camera.FromRectangle(entities.Entities[i].Area).Center.X;
                    entities.Entities[i].Light.Y = camera.FromRectangle(entities.Entities[i].Area).Center.Y;
                }
            }
        }
コード例 #21
0
        public void Draw(SpriteBatch spriteBatch, SpriteFont font, Camera camera, Texture2D uiTexture)
        {
            #region Other

            if (SkipFrame == true)
            {
                SkipFrame = false;
                return;
            }

            // Setup Dialog Box
            Rectangle npc_area;
            Rectangle sprite;
            Rectangle bust_dest;
            Rectangle bust_source;

            if (State == NpcInteractionState.Intro || State == NpcInteractionState.Gossip)
            {
                // Setup the dialog box
                npc_area = Subject.Movement.Area;
                sprite = Subject.Type.Race.Animation.CurrentFrame.ToRectangle();
                bust_dest = new Rectangle(CurrentHeader.X + 5, CurrentHeader.Y + CurrentHeader.Height - sprite.Height / 2, sprite.Width, sprite.Height / 2);
                bust_source = new Rectangle(sprite.X, sprite.Y, sprite.Width, sprite.Height / 2);

                // Draw the dialog box
                spriteBatch.Draw(Subject.Type.Race.Texture, bust_dest, bust_source, Color.White); // Bust
                TextHelper.DrawString(spriteBatch, font, Subject.Name, new Vector2(CurrentHeader.X + 20 + bust_dest.Width, CurrentHeader.Y + 10), Color.White); // Nametag
                //spriteBatch.Draw(uiTexture, CurrentHeader, new Rectangle(50, 0, 50, 50), Color.White); // CurrentHeader gradient
                spriteBatch.Draw(uiTexture, new Rectangle(CurrentBody.Center.X - 25, CurrentBody.Bottom, 50, 50), new Rectangle(100, 0, 50, 50), Color.White); // Spearch bubble arrow
                spriteBatch.Draw(uiTexture, CurrentBody, new Rectangle(0, 0, 50, 50), Color.White);
            }

            #endregion

            #region Intro

            if (State == NpcInteractionState.Intro)
            {

                TextHelper.DrawString(spriteBatch, font, CurrentText, new Vector2(CurrentBody.X + 10, CurrentBody.Y + 10), Color.White, 0.75f, width_wrap: 330);

                // Footer actions
                Vector2 footer_offset = new Vector2(CurrentBody.X + 10, CurrentBody.Y + Height - 25);
                Color color;

                // If shop
                if (CurrentSelection == "Shop") { color = Color.DeepSkyBlue; } else { color = Color.White; }
                TextHelper.DrawString(spriteBatch, font, "Shop", footer_offset, color, 0.7f);
                footer_offset.X += (int)(font.MeasureString("Shop").X * 0.7f) + 10;

                // If gossip
                if (CurrentSelection == "Gossip") { color = Color.DeepSkyBlue; } else { color = Color.White; }
                TextHelper.DrawString(spriteBatch, font, "Gossip", footer_offset, color, 0.7f);
                footer_offset.X += (int)(font.MeasureString("Gossip").X * 0.7f) + 10;

                // If follow
                if (CurrentSelection == "Follow Me") { color = Color.DeepSkyBlue; } else { color = Color.White; }
                TextHelper.DrawString(spriteBatch, font, "Follow Me", footer_offset, color, 0.7f);
                footer_offset.X += (int)(font.MeasureString("Follow Me").X * 0.7f) + 10;
            }

            #endregion

            #region Gossip

            if (State == NpcInteractionState.Gossip)
            {
                TextHelper.DrawString(spriteBatch, font, CurrentText, new Vector2(CurrentBody.X + 10, CurrentBody.Y + 10), Color.White, 0.75f, width_wrap: 330);
            }

            #endregion

            #region Shop

            if (State == NpcInteractionState.Shop)
            {
                TextHelper.DrawString(spriteBatch, font, "Shop open", new Vector2(100, 100), Color.White);
            }

            #endregion
        }
コード例 #22
0
ファイル: NpcPackage.cs プロジェクト: Shard/Blueprint-Client
        public void Update( Map map, Player player, Control control, Camera camera, SpriteFont font )
        {
            for (int i = 0; i < ActiveNpcs.Count; i++)
            {
                //ActiveNpcs[i].Npc.Ai.Update(ActiveNpcs[i].Movement, player); ai off

                ActiveNpc npc = ActiveNpcs[i];

                // Follow the path
                if (npc.CurrentPath != null)
                {
                    if (npc.CurrentDestination == Point.Zero)
                        npc.CurrentDestination = npc.CurrentPath.Pop();

                    if (npc.Movement.Area.Intersects(new Rectangle(npc.CurrentDestination.X * 24, npc.CurrentDestination.Y * 24, 24, 24)))
                    {
                        if (npc.CurrentPath.Count > 0)
                            { npc.CurrentDestination = npc.CurrentPath.Pop(); }
                        else
                            { npc.CurrentPath = null; npc.CurrentDestination = Point.Zero; }

                    }
                }

                if (npc.CurrentDestination != Point.Zero)
                    MovementChase(npc.Movement, npc.CurrentDestination);
                else
                    npc.Movement.Intention.Stop();

                ActiveNpcs[i].Movement.Update(map);
                ActiveNpcs[i].Type.Race.Animation.Update(ActiveNpcs[i].Movement);

                #region Interaction

                if (control.MousePos.Intersects(camera.FromRectangle(npc.Movement.Area)))
                {
                    control.State = Control.CursorStates.Interact;
                    if (control.Click(false))
                        Interaction.Start(npc);
                }

                if (Interaction.State != NpcInteraction.NpcInteractionState.None)
                {
                    if (Geometry.Range(player.Movement.Area, npc.Movement.Area) > 7)
                        Interaction.End();
                }

                Interaction.Update(camera, control, font);

                #endregion

                #region Damage / Combat

                if(npc.Movement.Area.Intersects(player.Movement.Area))
                {
                    player.Damage(5);
                }

                #endregion

                ActiveNpcs[i].Invunerable -= 1;
            }
        }