static void Main(string[] args) { // Initializes the handlers that need initializing ScreenHandler.Init(CONFIG_SCREEN); GameHandler.Init(); // To allow the esc button to be used as a pause button, // F12 have been set as the exit key. Raylib.SetExitKey(key: KeyboardKey.KEY_F12); while (!Raylib.WindowShouldClose()) { Raylib.BeginDrawing(); // Default color if it is not overbidden by a background in any stage. Raylib.ClearBackground(Color.BLANK); // GameHandler is a static class. StageHandler.Run(); GameHandler.Run(); Raylib.EndDrawing(); } Raylib.CloseWindow(); // When the game closes, it saves the config. // ScreenHandler.SaveCurrentConfiguration(); }
public void Die() { // Don't accidentally spawn multiple pickups if (!dead) { dead = true; // Play death sound SFXHandler.PlaySound("enemydeath"); // Spawn pickups while (scoreValue > 0 && powerValue > 0) { if (scoreValue > 0) { StageHandler.SpawnPickup(0, transform.position, (Vector2)transform.position + (Random.insideUnitCircle + Vector2.up) * .5f, .2f); scoreValue--; } if (powerValue > 0) { StageHandler.SpawnPickup(1, transform.position, (Vector2)transform.position + (Random.insideUnitCircle + Vector2.up) * .5f, .2f); powerValue--; } } // Destroy object Destroy(gameObject); } }
private void InitStageChain() { int tempLv = 1; StageHandler handler1 = new NormalStageHandler(this, tempLv++, 3, typeof(EnemyElf), typeof(WeaponGun), 3, spawnPosList[Random.Range(0, spawnPosList.Count - 1)]); StageHandler handler2 = new NormalStageHandler(this, tempLv++, 6, typeof(EnemyElf), typeof(WeaponRifle), 3, spawnPosList[Random.Range(0, spawnPosList.Count - 1)]); StageHandler handler3 = new NormalStageHandler(this, tempLv++, 9, typeof(EnemyElf), typeof(WeaponRocket), 3, spawnPosList[Random.Range(0, spawnPosList.Count - 1)]); StageHandler handler4 = new NormalStageHandler(this, tempLv++, 13, typeof(EnemyOgre), typeof(WeaponGun), 4, spawnPosList[Random.Range(0, spawnPosList.Count - 1)]); StageHandler handler5 = new NormalStageHandler(this, tempLv++, 17, typeof(EnemyOgre), typeof(WeaponRifle), 4, spawnPosList[Random.Range(0, spawnPosList.Count - 1)]); StageHandler handler6 = new NormalStageHandler(this, tempLv++, 21, typeof(EnemyOgre), typeof(WeaponRocket), 4, spawnPosList[Random.Range(0, spawnPosList.Count - 1)]); StageHandler handler7 = new NormalStageHandler(this, tempLv++, 26, typeof(EnemyTroll), typeof(WeaponGun), 5, spawnPosList[Random.Range(0, spawnPosList.Count - 1)]); StageHandler handler8 = new NormalStageHandler(this, tempLv++, 31, typeof(EnemyTroll), typeof(WeaponRifle), 5, spawnPosList[Random.Range(0, spawnPosList.Count - 1)]); StageHandler handler9 = new NormalStageHandler(this, tempLv++, 36, typeof(EnemyTroll), typeof(WeaponRocket), 5, spawnPosList[Random.Range(0, spawnPosList.Count - 1)]); handler1.SetNext(handler2) .SetNext(handler3) .SetNext(handler4) .SetNext(handler5) .SetNext(handler6) .SetNext(handler7) .SetNext(handler8) .SetNext(handler9); rootHandler = handler1; }
static public void Init() { // Add all stages that should be loaded at start time. // NOTE: The first added will be the first loaded and drawn. StageHandler.AddStage(new MainMenu("MainMenu")); StageHandler.AddStage(new CoopMenu("Coop")); }
// The update function is the logical loop, here all logic goes. public override void Update() { // Loop through all of the uiElements, and check what button is being pressed, // Act accordingly. for (int i = 0; i < uiElements.Length; i++) { if (uiElements[i].IsClicked()) { switch (uiElements[i].ID) { case 0: // Join Client.Connect(); break; case 1: // Host Host.InitHost(); break; case 2: // Back StageHandler.SetCurrentStage("MainMenu"); break; case 3: Client.Broadcast(); break; } } } }
public void Awake() { if (gameControl == null) { DontDestroyOnLoad(gameObject); gameControl = this; } else if (gameControl != this) { Destroy(gameObject); } ui = GetComponent <UIController> (); dialog = GetComponent <DialogController> (); gameEnd = GetComponent <GameEndHandler> (); stage = GetComponent <StageHandler> (); scene = GetComponent <SceneHandler> (); enemySpawner = GetComponent <EnemySpawner> (); spriteLib = GetComponent <SpriteLibrary> (); enemyLib = GetComponent <EnemyLib> (); pause = GetComponent <PauseController> (); stats = GetComponent <PlayerStats> (); sound = soundObject.GetComponent <SoundController> (); menu = GetComponent <MenuController> (); menu.InitMenu(); sound.InitSound(); scene.CheckScene(); }
void Update() { if (hasAi && StageHandler.InStageBounds(transform.position)) { if (!ai.inBounds) { ai.nextFire = Time.time; ai.inBounds = true; } } else { ai.inBounds = false; } if (hitOnFrame) { SFXHandler.PlaySound("enemyhit_loop", true); hitOnFrame = false; } else { SFXHandler.StopSound("enemyhit_loop"); } }
// The update function is the logical loop, here all logic goes. public override void Update() { // Loop through all of the buttons, and check what button is being pressed, // Act accordingly. for (int i = 0; i < uiElements.Length; i++) { if (uiElements[i].IsClicked()) { switch (uiElements[i].ID) { case 0: // New Game StageHandler.LoadStage(new MainGame("Game")); break; case 2: // Coop if (StageHandler.StageExists("Coop")) { StageHandler.SetCurrentStage("Coop"); } else { StageHandler.LoadStage(new CoopMenu("Coop")); } break; case 5: // Exit Raylib.CloseWindow(); Environment.Exit(1); break; } } } }
// After delay seconds: Kill all enemies and convert all enemy bullets to score pickups, then collect them private IEnumerator BombEffect(float delay) { yield return(new WaitForSeconds(delay)); StageHandler.KillAllEnemies(); BulletHandler.BulletsToScore(); StageHandler.CollectAllPickups(useConstantScore: true); }
static public void Run() { // This will act as the pause menu, when not in the main menu. if (Raylib.IsKeyPressed(key: KeyboardKey.KEY_ESCAPE) && StageHandler.currentStageID != 0) { StageHandler.UnloadCurrentStage(); } }
// Spawns two enemies from side and shoots circle spray // Negative centerDistance spreads enemies equally public IEnumerator TaskBurst3(int id, BulletData bulletData, int count = 40, float waitTimeMs = 500f, float shootTimeMs = 500f, float moveTimeMs = 5000f, float enterDistance = 3f, float centerDistance = -1f) { GameObject[] enemies = new GameObject[2]; float spread; if (centerDistance < 0) { spread = StageSpread(2) / 2; } else { spread = centerDistance; } for (int i = 0; i < 2; i++) { int sign; if (i == 0) { sign = -1; } else { sign = 1; } // Spawn enemies enemies[i] = StageHandler.SpawnEnemy(id, new Vector3( StageHandler.center.x + sign * (StageHandler.size.x / 2 + 1), StageHandler.topRight.y - enterDistance ), false); // Position where the enemy stops Vector3 endPos = new Vector3( StageHandler.center.x + sign * centerDistance, enemies[i].transform.position.y ); // Change position and rotation of shot BulletData newBulletData = bulletData; newBulletData.pos = endPos; newBulletData.rot = BulletHandler.AngleToPlayer(enemies[i].transform.position); // Actions List <IEnumerator> actions = new List <IEnumerator>() { StageHandler.MoveObjectSmooth(moveTimeMs, enemies[i], endPos), BulletHandler.ShootSpiral(newBulletData, count, shootTimeMs / 1000), WaitMs(waitTimeMs), ToggleEnemyAI(enemies[i], true) }; StageHandler.StartSequentialCoroutine(actions, enemies[i]); } yield return(null); }
void OnTriggerEnter2D(Collider2D collider) { // Only take damage when on-screen if (collider.CompareTag("Friendly") && StageHandler.InStageBounds(transform.position)) { hitOnFrame = true; TakeDamage(PlayerController.instance.damage); } }
void Start() { this.stageHandler = StageHandler.Handler; Stage currentStage = stageHandler.CurrentStage; Debug.Log(currentStage.Hint); Text description = GameObject.Find("Description").GetComponent <Text>(); Text Hint = GameObject.Find("Hint").GetComponent <Text>(); description.text = currentStage.Description; Hint.text = currentStage.Hint; }
private IEnumerator TaskBurst1(int id, int count, float spawnTimeMs = 1000f, float moveTimeMs = 10000f, float waitTimeMs = 200f, float stopDistance = 2f, bool reverse = false) { GameObject[] enemies = new GameObject[count]; // Calculate spread of enemies float distance = StageSpread(count); for (int i = 0; i < count; i++) { // Spawn enemy Vector3 pos; if (reverse) { pos = new Vector3( // Skip last "slot" (i+1) StageHandler.topRight.x - (i + 1) * distance, StageHandler.topRight.y + 1 ); } else { pos = new Vector3( // Skip first "slot" (i+1) StageHandler.bottomLeft.x + (i + 1) * distance, StageHandler.topRight.y + 1 ); } enemies[i] = StageHandler.SpawnEnemy(id, pos, true); // Actions exeucted for each enemy List <IEnumerator> actions = new List <IEnumerator>() { StageHandler.MoveObjectSmooth(moveTimeMs * stopDistance / 13, enemies[i], enemies[i].transform.position + stopDistance * Vector3.down), WaitMs(waitTimeMs), StageHandler.MoveObjectSmooth(moveTimeMs * (13 - stopDistance) / 13, enemies[i], enemies[i].transform.position + (13 - stopDistance) * Vector3.down), DeleteEnemy(enemies[i]) }; // Pyramid formation //float distance = 2f*(2-(3))/(count-1) * Mathf.Abs(i - (count-1)/2f)+(3); //Debug.Log(distance); // Run actions for enemy asynchronously and wait StageHandler.StartSequentialCoroutine(actions, enemies[i]); yield return(new WaitForSeconds(spawnTimeMs / count / 1000)); } yield return(null); }
// Spawn two enemies // Negative centerDistance spreads enemies equally public IEnumerator TaskBurst2(int id, float moveTimeMs = 5000f, float waitTimeMs = 300f, float stopDistance = 3f, float centerDistance = -1f) { GameObject[] enemies = new GameObject[2]; float spread; if (centerDistance < 0) { spread = StageSpread(2) / 2; } else { spread = centerDistance; } for (int i = 0; i < 2; i++) { // Spawn first enemy to the left and the second to the right int sign; if (i == 0) { sign = -1; } else { sign = 1; } enemies[i] = StageHandler.SpawnEnemy(id, new Vector3( StageHandler.center.x + sign * spread, StageHandler.topRight.y + 1 ), true); List <IEnumerator> actions = new List <IEnumerator>() { StageHandler.MoveObjectSmooth(moveTimeMs, enemies[i], enemies[i].transform.position + stopDistance * Vector3.down), WaitMs(waitTimeMs), StageHandler.MoveObjectSmooth(moveTimeMs, enemies[i], new Vector3( StageHandler.center.x + sign * StageHandler.size.x / 2, enemies[i].transform.position.y - 2 * stopDistance )), DeleteEnemy(enemies[i]) }; StageHandler.StartSequentialCoroutine(actions, enemies[i]); } yield return(null); }
void FixedUpdate() { if (hasAi && StageHandler.InStageBounds(transform.position)) { if (ai.inBounds) { while (Time.time > ai.nextFire) { ai.Shoot(); ai.nextFire += ai.firedelay; } } } }
void Awake() { instance = this; background = GetComponent <SpriteRenderer>(); // Stages stage1 = GetComponent <Stage1>(); // Stage bounds bottomLeft = Camera.main.ScreenToWorldPoint(new Vector3(32, 16, 0)); topRight = Camera.main.ScreenToWorldPoint(new Vector3(32 + 384, 16 + 448, 0)); center = new Vector2((bottomLeft.x + topRight.x) / 2, (bottomLeft.y + topRight.y) / 2); size = new Vector2(Mathf.Abs(bottomLeft.x - topRight.x), Mathf.Abs(bottomLeft.y - topRight.y)); pixelSize = new Vector2(384, 448); transform.position = center; }
private bool isCorrect() { StageHandler stageHandler = StageHandler.Handler; HashSet <string> correctItems = stageHandler.CurrentStage.AnswerItems; if (correctItems.Count != Inventory.Count) { return(false); } foreach (KeyValuePair <int, CustomItemAndGo> pair in Inventory) { string name = Inventory[pair.Key].TheItem.name; if (!correctItems.Contains(name)) { return(false); } } return(true); }
private void DropPower(Vector3 startPos, float amount) { // Calculate number of big and small pickups needed // Large pickup = .12 power, small pickup = .03 power // TODO: Get pickup values in Start()? int bigPickup = Mathf.FloorToInt(amount / .12f); int smallPickup = Mathf.FloorToInt((amount - .12f * bigPickup) / .03f); // Spawn pickups above player while (smallPickup > 0 && bigPickup > 0) { if (smallPickup > 0) { StageHandler.SpawnPickup(1, startPos, Random.insideUnitCircle + StageHandler.center + 1.5f * Vector2.up, .2f); smallPickup--; } if (bigPickup > 0) { StageHandler.SpawnPickup(3, startPos, Random.insideUnitCircle + StageHandler.center + 1.5f * Vector2.up, .2f); bigPickup--; } } }
// Turn all bullets to score pickups (for bombs, spell cards, etc.) public static void BulletsToScore() { GameObject[] bullets = new GameObject[instance.transform.childCount]; int i = 0; foreach (Transform bullet in instance.transform) { if (bullet.CompareTag("Enemy")) { bullets[i] = bullet.gameObject; i++; StageHandler.SpawnPickup(4, bullet.position); } } // Can't destroy bullets while looping through them foreach (GameObject bullet in bullets) { Destroy(bullet); } }
void FixedUpdate() { // Move if not paralyzed if (paralyzed) { rb.velocity = Vector2.zero; } else { rb.velocity = movement * Time.fixedDeltaTime; } // Clamp position to screen transform.position = new Vector3( Mathf.Clamp(transform.position.x, movementRangeMin.x, movementRangeMax.x), Mathf.Clamp(transform.position.y, movementRangeMin.y, movementRangeMax.y) ); // Loop instead of if, for firerates higher than the framerate while (shooting && Time.time > nextFire) { // Update velocity and position bulletData.velocity = shotSpeed; bulletData.pos = transform.position + Vector3.up * 0.3f; HandleShot(bulletData, power); nextFire += 1 / firerate; // TODO: Change to firedelay } // Collect all pickups if above collection line if (transform.position.y > collectionLineY) { StageHandler.CollectAllPickups(); } }
void FixedUpdate() { // Follows enemies, i.e. it only works for friendly bullets if (follow) { GameObject target = StageHandler.GetClosestEnemy(transform.position); if (target != null) { // The magnitude of the cross product provides rotation amount float rot = Vector3.Cross(transform.up, Vector3.Normalize(target.transform.position - transform.position)).z; transform.Rotate(Vector3.forward, rot * rotSpeed * Time.fixedDeltaTime); } } // Use Vector3 instead of transform.right because of the relativeTo parameter transform.Translate(Vector3.up * speed * Time.fixedDeltaTime); // Kill if out of bounds, more reliable than edge colliders if (!StageHandler.InStageBounds(transform.position)) { Object.Destroy(gameObject); } }
// Set background image protected IEnumerator SetBackground(int id) { StageHandler.SetBackground(id); yield return(null); }
public MessageController(StageHandler stageHandler, CallbackHandler callbackHandler) { this.stageHandler = stageHandler; this.callbackHandler = callbackHandler; bot = Bot.Get(); // todo - inject singleton }
public StageHandler SetNext(StageHandler handler) { nextHandler = handler; return(nextHandler); }
protected IEnumerator SpawnEnemy(int id, Vector3 pos, bool hasAi = false, float hpOverride = -1f) { StageHandler.SpawnEnemy(id, pos, hasAi: hasAi, hpOverride: hpOverride); yield return(null); }
protected IEnumerator DeleteEnemy(GameObject enemy, float t = 0f) { StageHandler.DestroyEnemy(enemy, t); yield return(null); }