protected override IEnumerator AttackCoroutine(Vector2 direction) { int idx = Random.Range(0, 3); SoundManager.PlaySound(BigSounds[idx]); SoundManager.PlaySound(SoundManager.Sound.Fireball); Vector3 instantiation_point = transform.position + VUtils.Vec2ToVec3(direction).normalized *ProjectileLeeway; GameObject fireball = Instantiate(FireballProjectiles, instantiation_point, Quaternion.identity); Rigidbody2D rb = fireball.GetComponent <Rigidbody2D>(); rb.velocity = direction.normalized * ProjectileSpeed; yield return(null); }
static IEnumerator ShakeScreenCoroutine(float duration, float intensity) { float timer = 0; // int num_shakes = 0; // float shake_freq = 0; while (timer < duration) { timer += TimeManager.deltaTime; main.follow_offset = VUtils.Vec2ToVec3(Random.insideUnitCircle * intensity); yield return(null); } main.follow_offset = Vector3.zero; }
void Spawn() { switch (toastText) { case 1: toast.ShowToast(("Grapple and throw enemies into the priests on the floating islands!", 6)); toastText = 0; break; case 2: toast.ShowToast(("Remember to drink mead with LB if you're running low on health! But beware -- it will slow movement!", 6)); toastText = 0; break; case 4: toast.ShowToast(("Grapple and throw enemies into the health crystals to stop Geminator from regenerating health!", 7)); toastText = 0; break; default: break; } float val = Random.Range(0f, total); GameObject spawn = enemies[0]; for (int i = 0; i < enemies.Length; i++) { if (val <= enemy_weights[i]) { spawn = enemies[i]; break; } else { val -= enemy_weights[i]; } } SoundManager.PlaySound(SoundManager.Sound.Fireball); Vector3 spawn_point = VUtils.Vec2ToVec3(Random.insideUnitCircle) * 2 + transform.position; Instantiate(SpawnEffect, spawn_point, Quaternion.identity); GameObject enemy = Instantiate(spawn, spawn_point, Quaternion.identity); enemy.transform.parent = transform; remainingEnemies++; counter = 0; }
public void DrawMap() { Color c = Color.blue; foreach (KeyValuePair <Vector2, NavNode> entry in NodeDict) { for (int i = 0; i < 8; ++i) { if (GetDir(entry.Value, i) != p_null) { Debug.DrawLine( VUtils.Vec2ToVec3(entry.Key), VUtils.Vec2ToVec3(GetDir(entry.Value, i)), c, 0, false ); } } } }
public static List <Vector3> NavBetween(Vector3 start_pos, Vector3 end_pos, int search_depth) { var path = new List <Vector3>(); Vector2 start = main.NavMap.GetNearestNode(VUtils.Vec3ToVec2(start_pos)); Vector2 end = main.NavMap.GetNearestNode(VUtils.Vec3ToVec2(end_pos)); if (start == NodeMap.p_null || end == NodeMap.p_null) { Debug.Log("Out of Boundaries"); return(path); } if (start.Equals(end)) { path.Add(VUtils.Vec2ToVec3(end)); return(path); } var open = new PriorityQueue <AStarNode>(AStarNodeComparator); // This hash function is arbitrary. However it must always return nonnegative values. var closed = new Dictionary <Vector2, AStarNode>(); Vector2[] successors; open.Add(new AStarNode { coords = start, f = 0F, g = 0F }); AStarNode finalNode = null; int searched_nodes = 0; while (open.Count > 0 && finalNode == null) { searched_nodes++; AStarNode cur = open.Pop(); Vector2 curCoords = cur.coords; // Generate successors and set parents to cur successors = main.NavMap.GetNeighbors(curCoords); // For each successor: foreach (Vector2 s in successors) { // If goal, stop // Debug.DrawLine( // VUtils.Vec2ToVec3(s), // VUtils.Vec2ToVec3(curCoords), // Color.magenta, // 0, // false // ); AStarNode next = new AStarNode { coords = s, parent = cur, g = cur.g + Vector2.Distance(s, curCoords) }; if (next.coords.Equals(end)) { finalNode = next; break; } if (Vector2.Distance(next.coords, end) < 0.3f) { Debug.Log(next.coords); } next.h = Vector2.Distance(next.coords, end); next.f = next.g + next.h; // If the tile is already in open, only keep the lower f Profiler.BeginSample("open find"); (int existingIndex, AStarNode existingOpen) = open.FindIndex(next); Profiler.EndSample(); if (existingIndex >= 0) { if (next.f < existingOpen.f) { open.ChangeKey(existingIndex, next); } continue; } // If noxel is already in closed with a lower f, skip if (closed.ContainsKey(next.coords)) { AStarNode c = closed[next.coords]; if (next.f < c.f) { closed.Remove(next.coords); } else { continue; } } // Add node to the open list open.Add(next); } closed.Add(cur.coords, cur); if (search_depth > 0 && searched_nodes >= search_depth) { break; } } if (finalNode == null) { // Path not found Debug.Log("No path found"); // Debug.Log("Nodes searched: " + searched_nodes.ToString()); return(path); } // Debug.Log("PATH FOUND!"); // Walk back along the path starting from final and store it in the return list AStarNode node = finalNode; while (!node.coords.Equals(start)) { path.Add(VUtils.Vec2ToVec3(node.coords)); node = node.parent; } path.Reverse(); // Debug.Log("Nodes searched: " + searched_nodes.ToString()); return(path); }