public override void OnCollisionEnter(GameObject other) { base.OnCollisionEnter(other); if (other is Player) { var player = (Player)other; // Kill the boots and give player run abillity player.EnableRunning(); // Destroy and give seconds. done = true; TimePiece.SpawnParticles(_timeToGive, collisionBox == null ? transform.position : collisionBox.middle, GameObjectManager.playerInstance); // Instantiate Dialogue Box var dialogueBox = new DialogueBox(new List <string>() { "you've got the running boots! \n\npress [ RT / SHIFT ]\nto activate.", "it will drain your time faster \nthough, so use carefully!" }); dialogueBox.SetEndAction(() => GameObjectManager.ResumeEveryone(null)); GameObjectManager.AddObject(dialogueBox); GameObjectManager.PauseEveryone(new List <GameObject>() { dialogueBox }); } }
public override void OnCollision(GameObject other) { base.OnCollisionEnter(other); if (doesDamage && other.tags.Contains("player")) { var inflicted = ((Player)other).TakeHit(damage); if (inflicted <= 0) { return; } var repelDir = Vector2.Zero; if (transform.direction == Vector2.Zero) { // if enemy is still, try to use the other GO's direction. if (other.transform.direction == Vector2.Zero) { var dir = other.transform.position - transform.position; // First try to use the direction between the two GOs // positions. If that is zero, use the other GO's // facing direction. if (dir == Vector2.Zero) { var physics = other.GetComponent <APhysics>(); if (physics != null) { repelDir = -physics.facingDirection; } } else { dir.Normalize(); repelDir = dir; } } else { repelDir = -other.transform.direction; } } else { repelDir = transform.direction; } other.GetComponent <APhysics>().velocity = repelDir * repelSpeed; timePiecesSpawned = TimePiece.SpawnParticles( (int)inflicted, other.collisionBox == null ? other.transform.position : other.collisionBox.middle, null, 8); ((Camera)GameObjectManager.FindObjectWithTag("camera")).AddShake(0.1); } }
public static List <TimePiece> SpawnParticles(int amount, Vector2 position, GameObject follow = null, byte col = 9) { List <TimePiece> l = new List <TimePiece>(); for (int i = 0; i < amount; ++i) { var angle = GameManager.random.NextDouble() * Math.PI + Math.PI / 2; var dir = new Vector2((float)Math.Sin(angle), (float)Math.Cos(angle)); var tp = new TimePiece(position, dir, 1, follow, col); l.Add((TimePiece)GameObjectManager.AddObject(tp)); } return(l); }
public override void OnCollision(GameObject other) { base.OnCollision(other); if (other.tags.Contains("attackable")) { // // TODO(matheusmortatti) remove time from enemy and give to the player. // var inflicted = ((Enemy)other).TakeHit(Damage); if (inflicted <= 0) { return; } // // Camera shake, brief pause and time particles. // ((Camera)GameObjectManager.FindObjectWithTag("camera"))?.AddShake(0.1); if (other.lifeTime <= 0) { GameObjectManager.AddPause(0.2f); } TimePiece.SpawnParticles((int)Math.Ceiling(inflicted / timeGivenAdjustment), other.collisionBox == null ? other.transform.position : other.collisionBox.middle, GameObjectManager.playerInstance); Debug.Log($"Damage Inflicted to {other.GetType().FullName} : {Math.Ceiling(inflicted).ToString()}"); // // Add force to repel enemy. // Vector2 repelDir = transform.direction; var physics = other.GetComponent <APhysics>(); if (physics == null) { Debug.Log($"{other.GetType().FullName} does not have a physics component. Attacking it does not send it back."); } else { physics.velocity = (repelDir * _repelSpeed); } } }
public TimePieceStateMachine(TimePiece tp) : base(TimePieceStates.Exploding) { this.tp = tp; }
private void FollowingStateInit(string prev) { TimePiece.SpawnParticles(timeToGive, collisionBox == null ? transform.position : collisionBox.middle, GameObjectManager.playerInstance); }