public void InstantiateItem(MoveableItem item, Vector3 position) { GameObject newItem = Instantiate(item.gameObject); newItem.transform.position = position; StatUIManager.instance.RegisterItem(newItem.GetComponent <MoveableItem>()); }
private static string GenerateStatText(MoveableItem item) { string result = Environment.NewLine; if (item.purchaseHealth != 0) { result += "Health " + GetNumberString(item.purchaseHealth) + " "; } if (item.purchaseExcretion != 0) { result += "Excretion " + GetNumberString(item.purchaseExcretion) + " "; } if (item.purchaseHunger != 0) { result += "Hunger " + GetNumberString(item.purchaseHunger) + " "; } if (item.purchaseFilth != 0) { result += "Filth " + GetNumberString(item.purchaseFilth) + " "; } if (item.purchaseSatisfaction != 0) { result += "Satisfaction " + GetNumberString(item.purchaseSatisfaction) + " "; } if (item.satisfactionPerSecond != 0) { result += "Satisfaction per Second " + GetNumberString(item.satisfactionPerSecond) + " "; } return(result); }
private void Form1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Right) { MoveableItem temp = items.First(); temp.Xspeed = 0; items.RemoveAt(0); items.Insert(0, temp); } if (e.KeyCode == Keys.Left) { MoveableItem temp = items.First(); temp.Xspeed = 0; items.RemoveAt(0); items.Insert(0, temp); } if (e.KeyCode == Keys.Up) { MoveableItem temp = items.First(); temp.Yspeed = 0; items.RemoveAt(0); items.Insert(0, temp); } if (e.KeyCode == Keys.Down) { } if (e.KeyCode == Keys.R && GameOver == true) { Restart(); } }
void SpawnEnemy(Object obj, EventArgs e) { Debug.WriteLine("SpawnEnemy"); for (int i = 0; i < random.Next(1, 3); i++) { timeHolder = watch.ElapsedMilliseconds + shotCooldown; PictureBox clone = new PictureBox(); clone.BackgroundImage = enemyPicture.BackgroundImage; clone.BackgroundImageLayout = enemyPicture.BackgroundImageLayout; clone.Width = 50; clone.Height = 50; clone.Location = new Point(random.Next(0, 1150), random.Next(10, 300)); int speed = random.Next(-2, 2); if (speed != 0) { MoveableItem bullet = new MoveableItem(speed, 0, true, false, false, clone); items.Add(bullet); this.Controls.Add(clone); } else { MoveableItem bullet = new MoveableItem(1, 0, true, false, false, clone); items.Add(bullet); this.Controls.Add(clone); } } }
void Update() { accumulatedSatisfaction += ((float)currentSatisfactionPerSecond) * Time.deltaTime; int satInt = Mathf.FloorToInt(accumulatedSatisfaction); Satisfaction += satInt; accumulatedSatisfaction -= satInt; Filth += (currentFilthPerMinute / 60f) * Time.deltaTime; Hunger += hungerPerSecond * Time.deltaTime; Toilet += toiletPerSecond * Time.deltaTime; if (Hunger >= 100) { Health -= hungerHealthLossPerSecond * Time.deltaTime; } if (Toilet >= 100) { MoveableItem itemToCreate = Random.Range(0.0f, 1.0f) > 0.5f ? pissPrefab : crapPrefab; Vector3 instantiateLocation = Player.instance.footTransform.position; instantiateLocation.y -= 0.3f; ComputerUIManager.instance.InstantiateItem(itemToCreate, instantiateLocation); Toilet = 0; AlertCanvasManager.instance.ShowAlert(itemToCreate.purchaseEventText); } if (Health <= 0) { Sprite deadSprite = Player.instance.deadSprite; Player.instance.spriteRenderer.sprite = deadSprite; Destroy(Player.instance); StartCoroutine(DeathMessageEnumerator()); } }
private IEnumerator MoveOnToStack(MoveableItem otherItem) { float y = (itemsOnTop.Count + 1) * 0.2f; Vector3 randomJitter = new Vector3(UnityEngine.Random.Range(-0.1f, 0.1f), UnityEngine.Random.Range(0, 0.1f), 0); Vector3 stackPos = stackingLocation == null ? Vector3.zero : stackingLocation.localPosition; float elapsedTime = 0; float progress = 0; Vector3 startPos = otherItem.t.localPosition; Vector3 endPos = stackPos + new Vector3(0, y, 0) + randomJitter; while (progress <= 1) { elapsedTime += Time.deltaTime; progress = elapsedTime / MOVE_ON_TIME; otherItem.t.localPosition = Vector3.Lerp(startPos, endPos, Easing.easeInOutSine(0, 1, progress)); yield return(null); } otherItem.t.localPosition = endPos; otherItem.partOfStack = true; int previousStackValue = GetStackValue(this, itemsOnTop); itemsOnTop.Add(otherItem); int currentStackValue = GetStackValue(this, itemsOnTop); int valueDiff = currentStackValue - previousStackValue; StatUIManager.instance.Satisfaction += (valueDiff); InfoCirclePool.instance.ShowInfoCircle("Satisfaction " + ItemPanelManager.GetNumberString(valueDiff), t.position); }
void Restart() { for (int i = 0; i < items2.Count; i++) { MoveableItem[] temp = items2.ToArray(); items2.Clear(); if (!temp[i].isPlayer && !i.Equals(gameOverText) && !i.Equals(healthArray[0]) && !i.Equals(healthArray[1]) && !i.Equals(healthArray[2])) { temp[i].picture.Dispose(); temp[i].rectangle.Location = new Point(2000, 2000); } items2 = temp.ToList <MoveableItem>(); } for (int i = 0; i < items.Count; i++) { MoveableItem[] temp = items.ToArray(); items.Clear(); if (!temp[i].isPlayer && !i.Equals(gameOverText) && !i.Equals(healthArray[0]) && !i.Equals(healthArray[1]) && !i.Equals(healthArray[2])) { temp[i].picture.Dispose(); temp[i].rectangle.Location = new Point(2000, 2000); } items = temp.ToList <MoveableItem>(); } for (int i = 0; i < itemsToBeAdded.Count; i++) { MoveableItem[] temp = itemsToBeAdded.ToArray(); itemsToBeAdded.Clear(); if (!i.Equals(player) && !i.Equals(playerBox) && !i.Equals(gameOverText) && !i.Equals(healthArray[0]) && !i.Equals(healthArray[1]) && !i.Equals(healthArray[2])) { temp[i].picture.Location = new Point(2000, 2000); temp[i].rectangle.Location = new Point(2000, 2000); } itemsToBeAdded = temp.ToList <MoveableItem>(); } listSwitch = true; GameOver = false; gameOverText.Visible = false; healthArray[0].Visible = true; healthArray[1].Visible = true; healthArray[2].Visible = true; playerBox = holderBox; playerBox.picture = holderPicture; playerBox.playerHealth = 3; playerBox.picture.Location = new Point(503, 619); playerBox.rectangle.Location = new Point(503, 619); watch.Restart(); watch.Start(); EnemyClock.Start(); Clock.Start(); if (gameOverText.Visible == true) { gameOverText.Visible = false; } }
private void OnCollisionEnter2D(Collision2D collision) { MoveableItem item = collision.gameObject.GetComponent <MoveableItem>(); if (item != null) { Debug.Log("happened"); } }
private static void SetSortOrderBasedOnListOrder(List <IsoSpriteSorting> spriteList) { int orderCurrent = 0; for (int i = 0; i < spriteList.Count; i++) { spriteList[i].RendererSortingOrder = orderCurrent; MoveableItem item = spriteList[i].moveableItem; orderCurrent += (1 + (item == null ? 0 : item.itemsOnTop.Count + 2)); //Make space for stacked things and infoText if present } }
public void RegisterItem(MoveableItem newItem) { activeItems.Add(newItem); Health += newItem.purchaseHealth; Toilet += newItem.purchaseExcretion; Hunger += newItem.purchaseHunger; Filth += newItem.purchaseFilth; Satisfaction += newItem.purchaseSatisfaction; currentFilthPerMinute += newItem.filthPerMinute; currentSatisfactionPerSecond += newItem.satisfactionPerSecond; }
private void FillWithRandomItems(List <MoveableItem> tempItems) { tempItems.AddRange(itemCollection.items); int n = tempItems.Count; while (n > 1) { n--; int k = rng.Next(n + 1); MoveableItem value = tempItems[k]; tempItems[k] = tempItems[n]; tempItems[n] = value; } }
void EnemyFire(MoveableItem enemy) { if (enemy.shotCooldown < watch.ElapsedMilliseconds) { enemy.shotCooldown = watch.ElapsedMilliseconds + 1500; PictureBox clone = new PictureBox(); clone.Width = 10; clone.Height = 10; clone.Location = new Point(enemy.picture.Location.X + enemy.picture.Width / 2, enemy.picture.Location.Y + 15 + enemy.picture.Height); clone.BackColor = Color.Red; MoveableItem bullet = new MoveableItem(0, 5, false, true, false, clone); itemsToBeAdded.Add(bullet); this.Controls.Add(clone); } }
private void ItemPanelClickedHandler(MoveableItem item) { mainObject.SetActive(false); Time.timeScale = 1; if (!seenItemNames.Contains(item.title)) { AlertCanvasManager.instance.ShowAlert(item.purchaseEventText); seenItemNames.Add(item.title); } InstantiateItem(item, instantiationLocation.position); if (item.purchaseSatisfaction != 0) { InfoCirclePool.instance.ShowInfoCircle("Satisfaction " + ItemPanelManager.GetNumberString(item.purchaseSatisfaction), instantiationLocation.position, Color.black, 0.4f); } }
private void PutItemOnTop(MoveableItem otherItem) { if (WillStackFall(itemsOnTop.Count)) { CollapseStack(Player.instance.footTransform.position); } else { lastStackStatusChangeFrame = Time.frameCount; otherItem.lastStackStatusChangeFrame = Time.frameCount; otherItem.DestroyPhysics(); otherItem.isoSorter.Unregister(); otherItem.t.SetParent(t, true); StartCoroutine(MoveOnToStack(otherItem)); } }
private IEnumerator MoveOffOfStack(MoveableItem item, Vector3 collapseVector) { float elapsedTime = 0; float progress = 0; Vector3 startPos = item.t.localPosition; Vector3 endPos = startPos + collapseVector; while (progress <= 1) { elapsedTime += Time.deltaTime; progress = elapsedTime / FALL_OFF_TIME; item.t.localPosition = Vector3.Lerp(startPos, endPos, Easing.easeInOutSine(0, 1, progress)); yield return(null); } item.t.localPosition = endPos; item.RestorePhysics(); item.partOfStack = false; }
public Form1() { InitializeComponent(); Clock.Interval = 25; Clock.Tick += new EventHandler(moveItems); Clock.Start(); EnemyClock.Interval = 4000; EnemyClock.Tick += new EventHandler(SpawnEnemy); EnemyClock.Start(); watch.Start(); playerBox = new MoveableItem(0, 0, true, false, true, player); holderPicture = player; holderBox = playerBox; items.Insert(0, playerBox); gameOverText.Enabled = false; healthArray[0] = Lifebox1; healthArray[1] = Lifebox2; healthArray[2] = Lifebox3; }
private void CollapseStack(Vector3 collapseSource) { lastStackStatusChangeFrame = Time.frameCount; Vector3 collapseDirection = (collapseSource - t.position).normalized; for (int i = 0; i < itemsOnTop.Count; i++) { MoveableItem item = itemsOnTop[i]; item.isoSorter.Register(); item.t.SetParent(null, true); item.lastStackStatusChangeFrame = Time.frameCount; Vector3 collapseVector = (collapseDirection * 1f) * (i + 1); StartCoroutine(MoveOffOfStack(item, collapseVector)); } int stackValue = GetStackValue(this, itemsOnTop); StatUIManager.instance.Satisfaction -= stackValue; InfoCirclePool.instance.ShowInfoCircle("Satisfaction " + ItemPanelManager.GetNumberString(-stackValue), t.position, Color.red); itemsOnTop.Clear(); StatUIManager.instance.Health -= 15; InfoCirclePool.instance.ShowInfoCircle("Health -15", t.position, Color.red, 0.3f); }
void GameOverTransisiton(MoveableItem i) { i.Die(); i.picture.Dispose(); Debug.WriteLine("Hit"); playerBox.playerHealth--; if (playerBox.playerHealth < 0) { playerBox.playerHealth = 0; } healthArray[playerBox.playerHealth].Visible = false; if (playerBox.playerHealth <= 0) { gameOverText.Visible = true; GameOver = true; Debug.WriteLine("GAMEOVER"); EnemyClock.Stop(); Clock.Stop(); watch.Stop(); } }
private void OnCollisionEnter2D(Collision2D collision) { if (Time.frameCount - lastStackStatusChangeFrame > FRAME_WAIT_COUNT) { MoveableItem otherItem = collision.gameObject.GetComponent <MoveableItem>(); if (otherItem != null && !partOfStack && stackable && otherItem.stackable) { if (itemsOnTop.Count == 0 && otherItem.itemsOnTop.Count == 0) { if (!canBeOnTopOfOtherThings && otherItem.canBeOnTopOfOtherThings) { PutItemOnTop(otherItem); } if (canBeOnTopOfOtherThings && otherItem.canBeOnTopOfOtherThings) { Transform pT = Player.instance.transform; float selfToPlayer = Vector3.Distance(t.position, pT.position); float otherToPlayer = Vector3.Distance(otherItem.t.position, pT.position); if (selfToPlayer > otherToPlayer) { PutItemOnTop(otherItem); } } } else if (itemsOnTop.Count == 0 || otherItem.itemsOnTop.Count == 0) { if (itemsOnTop.Count > 0 && otherItem.canBeOnTopOfOtherThings) { PutItemOnTop(otherItem); } } } } }
private static int GetStackValue(MoveableItem baseItem, List <MoveableItem> items) { int result = 0; if (items.Count != 0) { { result += 30 * (int)Mathf.Pow(2, items.Count); visitedItems.Clear(); tempItemList.Clear(); tempItemList.Add(baseItem); tempItemList.AddRange(items); for (int i = 0; i < tempItemList.Count; i++) { MoveableItem item = tempItemList[i]; int value; if (visitedItems.TryGetValue(item.title, out value)) { visitedItems[item.title] = value + 1; } else { visitedItems[item.title] = 1; } } foreach (int count in visitedItems.Values) { if (count > 1) { result += (int)Mathf.Pow(4, count + 1); result += 125 * count; } } } } return(result); }
void Destroy(MoveableItem o) { Controls.Remove(o.picture); o.picture.Dispose(); }
/* * When the user presses a specific key down, the action happens. * RIGHT/LEFT - the player is added to the list at index 0 with its speed going in the specified direction. * When the player releases the key, they are removed from the list. * Spacebar - the player shoots a bullet toward the enemy. Bullet creation is just making a picturebox that * is red, and adding it to a MoveableItem, which is then added to the next list to move items. * Z - The player creates a sheild around them, preventing them from taking damage while it is up. * The sheild is just a picturebox, and a boolean value is activated for the duration. * Once the time specified is over, the sheild fades. * R - Once the game is over, the user can press R to restart. */ private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Right) { MoveableItem temp = items.First(); temp.Xspeed = speed; items.RemoveAt(0); items.Insert(0, temp); } if (e.KeyCode == Keys.Left) { MoveableItem temp = items.First(); temp.Xspeed = -speed; items.RemoveAt(0); items.Insert(0, temp); } if (e.KeyCode == Keys.Up) { MoveableItem temp = items.First(); temp.Yspeed = -speed; items.RemoveAt(0); items.Insert(0, temp); } if (e.KeyCode == Keys.Down) { MoveableItem temp = items.First(); temp.Yspeed = speed; items.RemoveAt(0); items.Insert(0, temp); } if (e.KeyCode == Keys.Space) { if (timeHolder < watch.ElapsedMilliseconds) { timeHolder = watch.ElapsedMilliseconds + shotCooldown; PictureBox clone = new PictureBox(); clone.Width = 40; clone.Height = 40; clone.Location = new Point(playerBox.picture.Location.X + (playerBox.picture.Width / 2) - (clone.Width / 2), playerBox.picture.Location.Y - 25 - playerBox.picture.Height); clone.BackColor = Color.Red; MoveableItem bullet = new MoveableItem(0, -10, false, true, false, clone); items.Add(bullet); this.Controls.Add(clone); } else { Debug.WriteLine(watch.ElapsedMilliseconds); } } if (e.KeyCode == Keys.Z) { if (sheildTimeHolder < watch.ElapsedMilliseconds) { sheildTimeHolder = watch.ElapsedMilliseconds + sheildCooldown; sheildTimeLeft = watch.ElapsedMilliseconds + sheildDuration; isSheilded = true; DoShield(); } else { Debug.WriteLine(watch.ElapsedMilliseconds); } } }
public void UnRegisterItem(MoveableItem itemToRemove) { activeItems.Add(itemToRemove); currentFilthPerMinute -= itemToRemove.filthPerMinute; currentSatisfactionPerSecond -= itemToRemove.satisfactionPerSecond; }