コード例 #1
0
ファイル: LocationTests.cs プロジェクト: tzachshabtay/MonoAGS
		public float Constructor_GetZ_Test(float y, float? z)
		{
			AGSLocation location = new AGSLocation (15f, y, z);
			Assert.AreEqual(15f, location.X);
			Assert.AreEqual(y, location.Y);
			return location.Z;
		}
コード例 #2
0
        private IEnumerable <ILocation> getWalkPoints(ILocation destination)
        {
            if (!isWalkable(_obj.Location))
            {
                return(new List <ILocation> ());
            }
            List <PointF> closestPoints = new List <PointF> (_obj.Room.Areas.Count + 1);

            if (isWalkable(destination))
            {
                closestPoints.Add(destination.XY);
            }

            closestPoints.AddRange(getClosestWalkablePoints(destination.XY));
            if (closestPoints.Count == 0)
            {
                return(new List <ILocation> ());
            }

            bool[][] mask = getWalkableMask();
            _pathFinder.Init(mask);
            foreach (var closest in closestPoints)
            {
                destination = new AGSLocation(closest, destination.Z);
                var walkPoints = _pathFinder.GetWalkPoints(_obj.Location, destination);
                if (walkPoints.Any())
                {
                    return(walkPoints);
                }
            }
            return(new List <ILocation> ());
        }
コード例 #3
0
		private async Task onMouseDown(object sender, MouseButtonEventArgs e)
		{
			if (!_state.Player.Enabled)
				return;

			if (e.Button == MouseButton.Left)
			{
				if (_state.Player.Inventory == null || 
					_state.Player.Inventory.ActiveItem == null)
				{
					AGSLocation location = new AGSLocation(e.X, e.Y, _state.Player.Z);
					await _state.Player.WalkAsync(location).ConfigureAwait(true);
				}
				else
				{

				}
			}
			else if (e.Button == MouseButton.Right)
			{
				IInventory inventory = _state.Player.Inventory;
				if (inventory == null) return;
				if (inventory.ActiveItem == null)
				{
					IObject hotspot = _state.Room.GetObjectAt(e.X, e.Y);
					if (hotspot == null) return;
				}
				else
				{
					inventory.ActiveItem = null;
				}
			}
		}
コード例 #4
0
        private static ISprite getDefaultSprite(IImage image, IGraphicsFactory factory)
        {
            ISprite sprite = factory.GetSprite();

            sprite.Image    = image;
            sprite.Location = AGSLocation.Empty();
            return(sprite);
        }
コード例 #5
0
ファイル: AGSTranslate.cs プロジェクト: jeancallisti/MonoAGS
 public AGSTranslate()
 {
     _location     = AGSLocation.Empty();
     _argsX        = new PropertyChangedEventArgs(nameof(X));
     _argsY        = new PropertyChangedEventArgs(nameof(Y));
     _argsZ        = new PropertyChangedEventArgs(nameof(Z));
     _argsLocation = new PropertyChangedEventArgs(nameof(Location));
 }
コード例 #6
0
        private async Task onMouseDown(MouseButtonEventArgs e)
        {
            IGameState state = _game.State;

            if (!state.Player.Enabled)
            {
                return;
            }

            if (e.Button == MouseButton.Left)
            {
                if (state.Player.Inventory == null ||
                    state.Player.Inventory.ActiveItem == null)
                {
                    Vector2     xy       = e.MousePosition.GetProjectedPoint(state.Viewport, state.Player);
                    AGSLocation location = new AGSLocation(xy.X, xy.Y, state.Player.Z);
                    await state.Player.WalkAsync(location).ConfigureAwait(true);
                }
                else
                {
                }
            }
            else if (e.Button == MouseButton.Right)
            {
                IInventory inventory = state.Player.Inventory;
                if (inventory == null)
                {
                    return;
                }
                if (inventory.ActiveItem == null)
                {
                    IObject hotspot = _game.HitTest.ObjectAtMousePosition;
                    if (hotspot == null)
                    {
                        return;
                    }
                }
                else
                {
                    inventory.ActiveItem = null;
                }
            }
        }
コード例 #7
0
        private async Task onMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (!_state.Player.Enabled)
            {
                return;
            }

            if (e.Button == MouseButton.Left)
            {
                if (_state.Player.Inventory == null ||
                    _state.Player.Inventory.ActiveItem == null)
                {
                    AGSLocation location = new AGSLocation(e.X, e.Y, _state.Player.Z);
                    await _state.Player.WalkAsync(location).ConfigureAwait(true);
                }
                else
                {
                }
            }
            else if (e.Button == MouseButton.Right)
            {
                IInventory inventory = _state.Player.Inventory;
                if (inventory == null)
                {
                    return;
                }
                if (inventory.ActiveItem == null)
                {
                    IObject hotspot = _state.Room.GetObjectAt(e.X, e.Y);
                    if (hotspot == null)
                    {
                        return;
                    }
                }
                else
                {
                    inventory.ActiveItem = null;
                }
            }
        }
コード例 #8
0
ファイル: AGSWalkComponent.cs プロジェクト: saizant/MonoAGS
        private IEnumerable <ILocation> getWalkPoints(ILocation destination)
        {
            if (!isWalkable(_translate.Location))
            {
                return(new List <ILocation> ());
            }
            List <PointF> closestPoints = new List <PointF> (_room.Room.Areas.Count + 1);

            if (isWalkable(destination))
            {
                closestPoints.Add(destination.XY);
            }

            closestPoints.AddRange(getClosestWalkablePoints(destination.XY));
            if (closestPoints.Count == 0)
            {
                return(new List <ILocation>());
            }

            Point offset;

            bool[][] mask = getWalkableMask(out offset);
            var      from = _translate.Location;

            from = new AGSLocation(from.X - offset.X, from.Y - offset.Y, from.Z);
            _pathFinder.Init(mask);
            foreach (var closest in closestPoints)
            {
                destination = new AGSLocation(closest.X - offset.X, closest.Y - offset.Y, destination.Z);
                var walkPoints = _pathFinder.GetWalkPoints(from, destination);
                if (walkPoints.Any())
                {
                    return(walkPoints.Select(w => (ILocation) new AGSLocation(w.X + offset.X, w.Y + offset.Y, w.Z)));
                }
            }
            return(new List <ILocation> ());
        }
コード例 #9
0
ファイル: AGSTranslate.cs プロジェクト: ebrucucen/MonoAGS
 public AGSTranslate()
 {
     Location          = AGSLocation.Empty();
     OnLocationChanged = new AGSEvent <AGSEventArgs>();
 }
コード例 #10
0
ファイル: AGSTranslate.cs プロジェクト: OwenMcDonnell/MonoAGS
 public AGSTranslate()
 {
     _location = AGSLocation.Empty();
 }
コード例 #11
0
		private async Task onLeftMouseDown(MouseButtonEventArgs e, IGameState state)
		{
			string mode = CurrentMode;
			IObject hotspot = state.Room.GetObjectAt(e.X, e.Y);

			if (_game.Input.Cursor != _inventoryCursor.Animation)
			{
				if (hotspot != null && hotspot.Room == null) 
				{
					IInventoryItem inventoryItem = state.Player.Inventory.Items.FirstOrDefault(
						i => i.Graphics == hotspot);
					if (inventoryItem != null)
					{
						if (mode != LOOK_MODE)
						{
							if (inventoryItem.ShouldInteract) mode = INTERACT_MODE;
							else
							{
								state.Player.Inventory.ActiveItem = inventoryItem;
								SetInventoryCursor();
								return;
							}
						}
					}
					else return; //Blocking clicks when hovering UI objects
				}

				if (mode == WALK_MODE)
				{
                    AGSLocation location = new AGSLocation (e.X, e.Y, state.Player.Z);
					await state.Player.WalkAsync(location).ConfigureAwait(true);
				}
				else if (mode != WAIT_MODE)
				{
					_handlingClick = true;
					try
					{
						if (hotspot == null) return;

						if (mode == LOOK_MODE)
						{
                            await hotspot.Interactions.OnInteract(AGSInteractions.LOOK).InvokeAsync(this, new ObjectEventArgs (hotspot));
						}
						else if (mode == INTERACT_MODE)
						{
                            await hotspot.Interactions.OnInteract(AGSInteractions.INTERACT).InvokeAsync(this, new ObjectEventArgs (hotspot));
						}
						else
						{
                            await hotspot.Interactions.OnInteract(mode).InvokeAsync(this, new ObjectEventArgs (hotspot));
						}
					}
					finally
					{
						_handlingClick = false;
					}
				}
			}
			else if (hotspot != null)
			{
				if (hotspot.Room == null)
				{
					IInventoryItem inventoryItem = state.Player.Inventory.Items.FirstOrDefault(
						                              i => i.Graphics == hotspot);
					if (inventoryItem != null)
					{
						await state.Player.Inventory.OnCombination(state.Player.Inventory.ActiveItem,
							inventoryItem).InvokeAsync(this, new InventoryCombinationEventArgs (
							state.Player.Inventory.ActiveItem, inventoryItem));
					}
					return;
				}

                await hotspot.Interactions.OnInventoryInteract(AGSInteractions.INTERACT).InvokeAsync(this, new InventoryInteractEventArgs(hotspot,
					state.Player.Inventory.ActiveItem));
			}
		}
コード例 #12
0
        private async Task onLeftMouseDown(MouseButtonEventArgs e, IGameState state)
        {
            string  mode    = CurrentMode;
            IObject hotspot = state.Room.GetObjectAt(e.X, e.Y);

            if (_game.Input.Cursor != _inventoryCursor.Animation)
            {
                if (hotspot != null && hotspot.Room == null)
                {
                    IInventoryItem inventoryItem = state.Player.Inventory.Items.FirstOrDefault(
                        i => i.Graphics == hotspot);
                    if (inventoryItem != null)
                    {
                        if (mode != LOOK_MODE)
                        {
                            if (inventoryItem.ShouldInteract)
                            {
                                mode = INTERACT_MODE;
                            }
                            else
                            {
                                state.Player.Inventory.ActiveItem = inventoryItem;
                                SetInventoryCursor();
                                return;
                            }
                        }
                    }
                    else
                    {
                        return;                      //Blocking clicks when hovering UI objects
                    }
                }

                if (mode == WALK_MODE)
                {
                    AGSLocation location = new AGSLocation(e.X, e.Y, state.Player.Z);
                    await state.Player.WalkAsync(location).ConfigureAwait(true);
                }
                else if (mode != WAIT_MODE)
                {
                    _handlingClick = true;
                    try
                    {
                        if (hotspot == null)
                        {
                            return;
                        }

                        if (mode == LOOK_MODE)
                        {
                            await hotspot.Interactions.OnInteract(AGSInteractions.LOOK).InvokeAsync(this, new ObjectEventArgs(hotspot));
                        }
                        else if (mode == INTERACT_MODE)
                        {
                            await hotspot.Interactions.OnInteract(AGSInteractions.INTERACT).InvokeAsync(this, new ObjectEventArgs(hotspot));
                        }
                        else
                        {
                            await hotspot.Interactions.OnInteract(mode).InvokeAsync(this, new ObjectEventArgs(hotspot));
                        }
                    }
                    finally
                    {
                        _handlingClick = false;
                    }
                }
            }
            else if (hotspot != null)
            {
                if (hotspot.Room == null)
                {
                    IInventoryItem inventoryItem = state.Player.Inventory.Items.FirstOrDefault(
                        i => i.Graphics == hotspot);
                    if (inventoryItem != null)
                    {
                        await state.Player.Inventory.OnCombination(state.Player.Inventory.ActiveItem,
                                                                   inventoryItem).InvokeAsync(this, new InventoryCombinationEventArgs(
                                                                                                  state.Player.Inventory.ActiveItem, inventoryItem));
                    }
                    return;
                }

                await hotspot.Interactions.OnInventoryInteract(AGSInteractions.INTERACT).InvokeAsync(this, new InventoryInteractEventArgs(hotspot,
                                                                                                                                          state.Player.Inventory.ActiveItem));
            }
        }
コード例 #13
0
		public void WalkTest(float fromX, float fromY, bool fromWalkable, 
			                 float toX, float toY, bool toWalkable, 
			                 float closeToX, float closeToY, bool hasCloseToWalkable)
		{
			//Setup:
			Mock<IObject> obj = new Mock<IObject> ();
			Mock<IHasOutfit> outfitHolder = new Mock<IHasOutfit> ();
			Mock<IOutfit> outfit = new Mock<IOutfit> ();
			Mock<IPathFinder> pathFinder = new Mock<IPathFinder> ();
			Mock<IFaceDirectionBehavior> faceDirection = new Mock<IFaceDirectionBehavior> ();
			Mock<IObjectFactory> objFactory = new Mock<IObjectFactory> ();
			Mock<IRoom> room = new Mock<IRoom> ();
            Mock<IViewport> viewport = new Mock<IViewport>();
			Mock<IArea> area = new Mock<IArea> ();
            Mock<IWalkableArea> walkableArea = new Mock<IWalkableArea>();
			Mock<IMask> mask = new Mock<IMask> ();
			Mock<ICutscene> cutscene = new Mock<ICutscene> ();
			Mock<IGameState> gameState = new Mock<IGameState> ();
            Mock<IGame> game = new Mock<IGame>();
            Mock<IGameEvents> gameEvents = new Mock<IGameEvents>();
            Mock<IGLUtils> glUtils = new Mock<IGLUtils>();

			gameEvents.Setup(g => g.OnRepeatedlyExecute).Returns(_onRepeatedlyExecute);
            game.Setup(g => g.State).Returns(gameState.Object);
            game.Setup(g => g.Events).Returns(gameEvents.Object);
			gameState.Setup(s => s.Cutscene).Returns(cutscene.Object);
			room.Setup(r => r.Areas).Returns(new List<IArea> { area.Object });
            room.Setup(r => r.Viewport).Returns(viewport.Object);
            walkableArea.Setup(w => w.IsWalkable).Returns(true);
			area.Setup(a => a.Enabled).Returns(true);
			area.Setup(a => a.IsInArea(It.Is<AGS.API.PointF>(p => p.X == fromX && p.Y == fromY))).Returns(fromWalkable);
			area.Setup(a => a.IsInArea(It.Is<AGS.API.PointF>(p => p.X == toX && p.Y == toY))).Returns(toWalkable);
			area.Setup(a => a.IsInArea(It.Is<AGS.API.PointF>(p => p.X == closeToX && p.Y == closeToY))).Returns(hasCloseToWalkable);
			area.Setup(a => a.Mask).Returns(mask.Object);
            area.Setup(a => a.GetComponent<IWalkableArea>()).Returns(walkableArea.Object);
			float distance = 1f;
			area.Setup(a => a.FindClosestPoint(It.Is<AGS.API.PointF>(p => p.X == toX && p.Y == toY), out distance)).Returns(new AGS.API.PointF (closeToX, closeToY));
			mask.Setup(m => m.Width).Returns(10);

			outfitHolder.Setup(o => o.Outfit).Returns(outfit.Object);

			float x = fromX;
			float y = fromY;
			obj.Setup(o => o.Room).Returns(room.Object);
			obj.Setup(o => o.X).Returns(() => x);
			obj.Setup(o => o.Y).Returns(() => y);
			obj.Setup(o => o.Location).Returns(() => new AGSLocation (x, y));
			obj.SetupSet(o => o.X = It.IsAny<float>()).Callback<float>(f => x = f);
			obj.SetupSet(o => o.Y = It.IsAny<float>()).Callback<float>(f => y = f);

			ILocation toLocation = new AGSLocation (toX, toY);
			ILocation closeLocation = new AGSLocation (closeToX, closeToY);

			pathFinder.Setup(p => p.GetWalkPoints(It.Is<ILocation>(l => l.X == fromX && l.Y == fromY),
				It.Is<ILocation>(l => l.X == toX && l.Y == toY))).Returns(toWalkable ? new List<ILocation> {toLocation} : new List<ILocation>());

			pathFinder.Setup(p => p.GetWalkPoints(It.Is<ILocation>(l => l.X == fromX && l.Y == fromY),
				It.Is<ILocation>(l => l.X == closeToX && l.Y == closeToY))).Returns(hasCloseToWalkable ? new List<ILocation> {closeLocation} : new List<ILocation>());
			
			AGSWalkBehavior walk = new AGSWalkBehavior (obj.Object, pathFinder.Object, faceDirection.Object,
                                                        outfitHolder.Object, objFactory.Object, game.Object, glUtils.Object) { WalkStep = new PointF(4f, 4f), MovementLinkedToAnimation = false };

			bool walkShouldSucceed = fromWalkable && (toWalkable || hasCloseToWalkable);

			//Act:
			bool walkSucceded = walk.Walk(toLocation);

			//Test:
			Assert.AreEqual(walkShouldSucceed, walkSucceded);

			if (walkShouldSucceed)
			{				
				Assert.AreEqual(toWalkable ? toX : closeToX, x, 0.1f);
				Assert.AreEqual(toWalkable ? toY : closeToY, y, 0.1f);
			}				
		}
コード例 #14
0
		private bool testPathFinder(IPathFinder pathFinder, bool[][] array, float fromX, float fromY, float toX, float toY)
		{
			if (array != null) pathFinder.Init(array);
			AGSLocation from = new AGSLocation (fromX, fromY);
			AGSLocation to = new AGSLocation (toX, toY);
			IEnumerable<ILocation> points = pathFinder.GetWalkPoints(from, to);
			if (!points.Any()) return false;
			foreach (ILocation point in points)
			{
				Assert.IsTrue(array[(int)point.X][(int)point.Y]);
			}
			return true;
		}
コード例 #15
0
		private IEnumerable<ILocation> getWalkPoints(ILocation destination)
		{
			if (!isWalkable(_obj.Location))
				return new List<ILocation> ();
			List<PointF> closestPoints = new List<PointF> (_obj.Room.Areas.Count + 1);
			if (isWalkable(destination))
			{
				closestPoints.Add(destination.XY);
			}

			closestPoints.AddRange(getClosestWalkablePoints (destination.XY));
			if (closestPoints.Count == 0)
				return new List<ILocation> ();
			
			bool[][] mask = getWalkableMask ();
			_pathFinder.Init (mask);
			foreach (var closest in closestPoints)
			{
				destination = new AGSLocation (closest, destination.Z);
				var walkPoints = _pathFinder.GetWalkPoints(_obj.Location, destination);
				if (walkPoints.Any()) return walkPoints;
			}
			return new List<ILocation> ();
		}