protected override void Update() { base.Update(); if (Input.GetButtonDown("Collect")) { if (FPSCharacterController.Instance.lookingAtObject == null) { return; } ICollectable obj = FPSCharacterController.Instance.lookingAtObject.GetComponent(typeof(ICollectable)) as ICollectable; if (obj == null) { return; } obj.Collect(); //TODO the limitation, if collect method needs parameter, I don't know how to pass them properly if (pickEvent != null) { pickEvent(); } } }
public void Collect(ICollectable collectable) { if (collectable is IResourceSet) { AddResources(((IResourceSet)collectable).ExtractResources()); } }
/// <summary> /// IterateAction /// </summary> /// <param name="roomObjects"></param> /// <param name="type"></param> public static void IterateAction(List <Base> roomObjects, Type type) { foreach (var cls in roomObjects) { if (type == typeof(IInteractive)) { if (cls is IInteractive) { IInteractive classou = (IInteractive)cls; classou.Interact(); } } else if (type == typeof(IBreakable)) { if (cls is IBreakable) { IBreakable classou = (IBreakable)cls; classou.Break(); } } else if (type == typeof(ICollectable)) { if (cls is ICollectable) { ICollectable classou = (ICollectable)cls; classou.Collect(); } } } }
private IEnumerator MoveItem(ICollectable collectable) { movingTarget = true; yield return(new WaitForSeconds(0.3f)); var moveTimer = 0f; var moveDuration = 0.43f; var startPosition = collectable.transform.position; while (true) { moveTimer += Time.deltaTime; var progress = moveTimer / moveDuration; collectable.transform.position = Vector3.Lerp(startPosition, Creature.rightHandTransform.position, progress); if (progress >= 1.0f) { collectable.transform.position = Creature.rightHandTransform.position; break; } yield return(null); } collectable.transform.SetParent(Creature.rightHandTransform); collectable.transform.localPosition = Vector3.zero; movingTarget = false; }
public void Deliver(Vector2 deliverLocation, ICollectable corpse) { int index = corpseSpots.IndexOf(corpseSpots.First(x => (Vector2)x.transform.position == deliverLocation)); corpse.IsActive = false; inventory.Add(new KeyValuePair <int, ICollectable>(index, corpse)); }
/// <summary> /// Iterates through a list /// </summary> /// <param name="roomObjects"></param> /// <param name="type"></param> public static void IterateAction(List <Base> roomObjects, Type type) { //if (typeof(IInteractive).IsAssignableFrom(type)) foreach (var item in roomObjects) { if (typeof(IInteractive).IsAssignableFrom(type)) { //dynamic changedObj = Convert.ChangeType(item, type); try { IInteractive changedObj = (IInteractive)item; changedObj.Interact(); } catch {} } if (typeof(IBreakable).IsAssignableFrom(type)) { try { IBreakable changedObj = (IBreakable)item; changedObj.Break(); } catch {} } if (typeof(ICollectable).IsAssignableFrom(type)) { try { ICollectable changedObj = (ICollectable)item; changedObj.Collect(); } catch {} } } }
public void HouseItemCollide(ICollectable item, House house) { Rectangle itemRect = item.GetBoundingBox(); Rectangle houseRect = house.GetBoundingBox(house.position); Rectangle intersection = Rectangle.Intersect(itemRect, houseRect); if (intersection.Height > intersection.Width) { if (itemRect.Right > houseRect.Left && itemRect.Right < houseRect.Right) { item.position = new Vector2(item.position.X - intersection.Width, item.position.Y); item.GoLeft(); } else { item.position = new Vector2(item.position.X + intersection.Width, item.position.Y); item.GoRight(); } } else { if (itemRect.Bottom > houseRect.Top && itemRect.Bottom < houseRect.Bottom) { item.position = new Vector2(item.position.X, item.position.Y - intersection.Height); } else { item.position = new Vector2(item.position.X, item.position.Y + intersection.Height); } } }
public void PipeItemCollide(ICollectable item, Pipe pipe) { Rectangle itemRect = item.GetBoundingBox(); Rectangle pipeRect = pipe.GetBoundingBox(); Rectangle intersection = Rectangle.Intersect(itemRect, pipeRect); if (intersection.Height > intersection.Width) { if (itemRect.Right > pipeRect.Left && itemRect.Right < pipeRect.Right) { item.position = new Vector2(item.position.X - intersection.Width, item.position.Y); item.GoLeft(); } else { item.position = new Vector2(item.position.X + intersection.Width, item.position.Y); item.GoRight(); } } else { if (itemRect.Bottom > pipeRect.Top && itemRect.Bottom < pipeRect.Bottom) { item.position = new Vector2(item.position.X, item.position.Y - intersection.Height); } else { item.position = new Vector2(item.position.X, item.position.Y + intersection.Height); } } }
///<summary>This method allows iteraction with the methods within the objects.</summary> public static void IterateAction(List <Base> roomObjects, Type type) { foreach (var element in roomObjects) { if (type.ToString() == "IInteractive") { if (element is IInteractive) { IInteractive tmp = element as IInteractive; tmp.Interact(); } } else if (type.ToString() == "IBreakable") { if (element is IBreakable) { IBreakable tmp = element as IBreakable; tmp.Break(); } } else if (type.ToString() == "ICollectable") { if (element is ICollectable) { ICollectable tmp = element as ICollectable; tmp.Collect(); } } } }
public void ItemBlockCollide(ICollectable item, Block block) { Rectangle itemRect = item.GetBoundingBox(); Rectangle blockRect = block.GetBoundingBox(); Rectangle intersection = Rectangle.Intersect(itemRect, blockRect); if (intersection.Height > intersection.Width) { if (itemRect.Right > blockRect.Left && itemRect.Right < blockRect.Right) { item.position = new Vector2(item.position.X - intersection.Width, item.position.Y); item.GoLeft(); } else { item.position = new Vector2(item.position.X + intersection.Width, item.position.Y); item.GoRight(); } } else { if (itemRect.Bottom > blockRect.Top && itemRect.Bottom < blockRect.Bottom) { item.position = new Vector2(item.position.X, item.position.Y - intersection.Height); } else { item.position = new Vector2(item.position.X, item.position.Y + intersection.Height); } } }
public static void IterateAction(List <Base> roomObjects, Type type) { foreach (var element in roomObjects) { if (type == typeof(IInteractive)) { IInteractive inter = element as IInteractive; if (inter != null) { inter.Interact(); } } if (type == typeof(ICollectable)) { ICollectable inter = element as ICollectable; if (inter != null) { inter.Collect(); } } if (type == typeof(IBreakable)) { IBreakable inter = element as IBreakable; if (inter != null) { inter.Break(); } } } }
///<summary> method should take a list of all objects, </summary> public static void IterateAction(List <Base> roomObjects, Type type) { foreach (var item in roomObjects) { if (type.ToString() == "IInteractive") { if (item is IInteractive) { IInteractive tmp = item as IInteractive; tmp.Interact(); } } if (type.ToString() == "IBreakable") { if (item is IBreakable) { IBreakable temp = item as IBreakable; temp.Break(); } } if (type.ToString() == "ICollectable") { if (item is ICollectable) { ICollectable temp = item as ICollectable; temp.Collect(); } } } }
/// <summary> /// execute methods depending on what interface that item implements /// </summary> /// <param name="roomObjects">list of objects</param> /// <param name="type">types</param> public static void IterateAction(List <Base> roomObjects, Type type) { foreach (var obj in roomObjects) { switch (type.ToString()) { case "IInteractive": if (obj is IInteractive) { IInteractive instance = (IInteractive)obj; instance.Interact(); } break; case "IBreakable": if (obj is IBreakable) { IBreakable instance = (IBreakable)obj; instance.Break(); } break; case "ICollectable": if (obj is ICollectable) { ICollectable instance = (ICollectable)obj; instance.Collect(); } break; default: break; } } }
public static void IterateAction(List <Base> objects, Type interfaceType) { foreach (var obj in objects) { if (interfaceType == typeof(IInteractive)) { IInteractive ghostObject = obj as IInteractive; if (ghostObject != null) { ghostObject.Interact(); } } else if (interfaceType == typeof(IBreakable)) { IBreakable ghostObject = obj as IBreakable; if (ghostObject != null) { ghostObject.Break(); } } else if (interfaceType == typeof(ICollectable)) { ICollectable ghostObject = obj as ICollectable; if (ghostObject != null) { ghostObject.Collect(); } } } }
private void CollectAndEatFood(ICollectable collectable) { collectable.Disable(); ItemInHand = collectable; Creature.Animator.SetInteger("CollectType", 0); Creature.Animator.SetTrigger("Collect"); }
void OnTriggerEnter2D(Collider2D other) { if (other.tag.Equals(Tags.ENEMY)) { mAudioSource.Stop(); mAudioSource.Play(); isStunned = true; StartCoroutine(resetStun()); return; } ICollectable collectable = other.GetComponent <ICollectable>(); // we only care if we collid with an collectable if (collectable != null) { CollectableType type = collectable.Collect(); if (type == CollectableType.NONE) { return; } if (type == CollectableType.HP_BOBBLE) { mHealthManager.GainHealth(HP_GAIN_VALUE); HighscoreManager.Instance.AddToScore(HighscoreManager.GET_HEALTH); return; } mInventory.AddInventoryItem(type); HighscoreManager.Instance.AddToScore(HighscoreManager.FIND_CORE); } }
void CheckCollactable(RaycastHit hit) { if (hit.collider.CompareTag("Collectable")) { if (toCollect == null) { toCollect = hit.collider.GetComponent <ICollectable>(); toCollect.Highlight(); } else { ICollectable newCollect = hit.collider.GetComponent <ICollectable>(); if (newCollect != toCollect) { toCollect.Unhighlight(); toCollect = newCollect; toCollect.Highlight(); } } } else { if (toCollect != null) { var toFuckingDelete = toCollect; toCollect = null; toFuckingDelete.Unhighlight(); } toCollect = null; } }
public Block(Vector2 location, ICollectable prize, IBlockState state, Game1 game) { this.game = game; this.prize = prize; this.state = state; position = location; }
public static void CollectableCollected(ICollectable collectable) { if (OnCollectableCollected != null) { OnCollectableCollected(collectable); } }
public ICollectable build(CollectableType type, Vector2 location) { factory = new SpriteFactory(); if (type == CollectableType.coin) { product = new Coin(location); } if (type == CollectableType.star) { product = new Star(location); } if (type == CollectableType.oneUp) { product = new OneUpMushroom(location); } if (type == CollectableType.fireFlower) { product = new FireFlower(location); } if (type == CollectableType.superMushroom) { product = new SuperMushroom(location); } if (type == CollectableType.ninja) { product = new Ninja(location); } return(product); }
public override void Spawn(Vector3 position) { if (Random.value <= _chanceToSpawn) { int coinsToSpawn = Random.Range(_amountOfObjectsToSpawn.MinValue, _amountOfObjectsToSpawn.MaxValue); long oneCoinCost; if (_badgeData.CoinsReward >= coinsToSpawn) { oneCoinCost = Mathf.CeilToInt(_badgeData.CoinsReward / coinsToSpawn); } else { coinsToSpawn = 1; oneCoinCost = _badgeData.CoinsReward; } for (int i = 0; i < coinsToSpawn; i++) { GameObject spawnedCoin = _objectPooler.GetPooledObjects(); if (spawnedCoin != null) { spawnedCoin.transform.position = position; spawnedCoin.transform.rotation = _itemToSpawn.transform.rotation; spawnedCoin.SetActive(true); } ICollectable collectableComponent = spawnedCoin.GetComponent <ICollectable>(); SetCoinReward(in oneCoinCost, collectableComponent); } } }
public void Update(ICollectable item, GameTime gameTime) { if ((item.position.Y - oldPos.Y) > positionDifference) { item.physState = new ItemFallingState(item); } oldPos = item.position; }
void SelectAndSpawn() { float rdm = Random.Range(0, 100); spawnedItem = spawnList.Where(x => x.pourcentage <= rdm) .Select(x => x.Item) .FirstOrDefault().Spawn(this.transform.position, this); }
private void OnCollisionEnter(Collision collision) //this checks for the player getting collectables { collectableInstance = collision.transform.GetComponent <ICollectable>(); //sets the collectable item if (collectableInstance != null) { collectableInstance.GetItem(); } }
void Collectable_Collected(ICollectable collectable) { if (collectable.itemID == this.itemID) { this.Current_Amount++; Evaluate(); } }
private static void AddItemsMethod(ICollectable collection, string[] itemsToAdd) { foreach (var itemToAdd in itemsToAdd) { Console.Write(collection.AddItem(itemToAdd) + " "); } Console.WriteLine(); }
public CollectJob(ICollectable collectable, Vector2 location) : base(location, 1, null) { Location = location; this.collectable = collectable; OnJobCompleted += () => { Owner.Collectable = collectable; }; OnJobCompleted += () => { NewDeliverJob(); }; }
public Teno Build(string fileName) { float xCoord = 0, yCoord = 0; StreamReader sr; sr = File.OpenText(fileName); string line; while ((line = sr.ReadLine()) != null) { yCoord += spacingIncrement; xCoord = 0; string[] words = line.Split(','); for (int i = 0; i < words.Length; i++) { int events = 1; if (words[i] == "T") { teno = new Teno(new Vector2(xCoord, yCoord), game); } if (itemDictionary.ContainsKey(words[i])) { ICollectable item = collectableFactory.build(itemDictionary[words[i]], new Vector2(xCoord, yCoord)); level.levelItems.Add(item); } if (backgroundDictonary.ContainsKey(words[i])) { if (words[i] == "ex") { level.exitPosition = new Vector2(xCoord, yCoord); } else { KeyValuePair <IAnimatedSprite, Vector2> item = new KeyValuePair <IAnimatedSprite, Vector2> (factory.build(backgroundDictonary[words[i]]), new Vector2(xCoord, yCoord)); level.levelBackgroundObjects.Add(item); } } if (blockDictionary.ContainsKey(words[i])) { Block block = blockFactory.build(blockDictionary[words[i]], new Vector2(xCoord, yCoord)); level.levelBlock.Add(block); } if (enemyDictionary.ContainsKey(words[i])) { Enemy enemy = enemyFactory.build(enemyDictionary[words[i]], new Vector2(xCoord, yCoord)); level.levelEnemies.Add(enemy); } if (words[i] == "Ch") { level.checkpoint = new Vector2(xCoord, yCoord); } xCoord += spacingIncrement * events; } } return(teno); }
public ConstructionDeliverJob(ICollectable collectable, BuildingPlaceHolder construction, Vector2 location) : base(location, 1, null) { this.collectable = collectable; this.construction = construction; Location = location; OnJobCompleted += () => { construction.AddResource(collectable); }; OnJobCompleted += () => { Owner.Collectable = null; }; }
private void OnTriggerEnter(Collider other) { ICollectable collectable = other.GetComponent <ICollectable>(); if (collectable != null) { collectable.Collect(); } }
public void AddCollectable(ICollectable collectable) { collectable.ContainingRoom = this; switch (collectable.Type) { case CollectableConstants.CoinId: IncrementCoins(); break; case CollectableConstants.TimeBoostId: IncrementTimeBoosts(); break; } }