Ejemplo n.º 1
0
        public override void Update(Movement movement, Player player)
        {
            if (movement.Area.Center.X > player.Movement.Area.Center.X)
            {
                movement.Intention.Left = true;
                movement.Intention.Right = false;
            }
            else
            {
                movement.Intention.Left = false;
                movement.Intention.Right = true;
            }

            if (movement.Area.Center.Y > player.Movement.Area.Center.Y + 20)
            {
                movement.Intention.Jumping = true;
            }
            else
            {
                movement.Intention.Jumping = false;
            }

            if (movement.Area.Center.X - player.Movement.Area.X > -40 && movement.Area.Center.X - player.Movement.Area.X < 40)
            {
                movement.Intention.Left = false;
                movement.Intention.Right = false;
                movement.Intention.Jumping = false;
            }
        }
Ejemplo n.º 2
0
 public Camera(GraphicsDevice graphics, Player player)
 {
     Width = graphics.Viewport.Width;
     Height = graphics.Viewport.Height;
     X = (player.Movement.Area.Center.X * -1) + graphics.Viewport.Width / 2;
     Y = (player.Movement.Area.Center.Y * -1) + graphics.Viewport.Height / 2;
 }
Ejemplo n.º 3
0
 public Vector2 startingSwordPosition( Player player, Rectangle weaponArea )
 {
     if (player.Movement.Direction == "right")
     {
         return new Vector2(player.Movement.Area.Center.X, player.Movement.Area.Top);
     } else {
         return new Vector2(player.Movement.Area.Center.X - weaponArea.Width, player.Movement.Area.Top);
     }
 }
Ejemplo n.º 4
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
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
 public abstract void Update(Movement movement, Player player);
Ejemplo n.º 7
0
 public override void Update(Movement movement, Player player)
 {
 }