lost Signal

LostSignal is a Game that we made in 3 days as part of the international Educational Game Jame 2022. We were in a team of 4, with 2 developers and 2 artists. Where you play as a spaceship, where you listen to sounds to find the Lost Colonies hidden between the planets and asteroids. Well, you are trying to find the Lost Colonies you will be fighting some alien on your way here. You can find the Lost Colonies by listing the sound that they send out.

What I did

In this project, I was primarily focused on the random generation of the game. I spawn in a radius around the player and make sure they don't overlap. I have reused the same kind of spawning system to spawn in the Lost Colonies and the asteroids.

DATE ENGINE PROGRAMMERS ARTIST
February 22nd Unity Sjoerd David
3 days Niklas Dailyn

CODE

This bit of code is part of the colony spawner. The colony spawner works by first turing a random angel before going a min to max distance. After that it spawns in the colony on its position.

                        
    public void SpawnConley()
    {
        FindRandomSpawn();
        Sprite colonySprite =
            conlenySprites[Random.Range(0, conlenySprites.Length)]; // Gets a random sprite for the colony

        // Spawn a new Conley at the Spawners position
        GameObject newConley = Instantiate(conlenyPerfab, transform.position, quaternion.Euler(Vector3.zero));
        newConley.GetComponent().sprite = colonySprite;
        newConley.transform.localScale = new Vector2(2.5f, 2.5f);
    }

    /// 
    /// turns a random angel before going forward a random amount
    /// 
    private void FindRandomSpawn()
    {
        transform.rotation = quaternion.Euler(0, 0, Random.Range(0, 360));
        transform.position += transform.right * (minSpawnRadius + Random.Range(0, maxExtraRadius));
    }
                        
                    

This code is part of the planet spawner and is also reused for the asteroid spawner. it works by first getting all the variable its need. After that, it will find a random position around the player. This position will be checked if it is not inside the players' screen so the player does not see them being spawned in. After that, it will check if it does not collide with any other planets and their enemies.

                        
    private void SpawnPlanet()
    {
        float randomInt = Random.Range(minPlanetSize, maxPlanetSize);
        Vector2 planetSize = new Vector2(randomInt, randomInt);                          // Get a random size to the planet
        Sprite planetSprite = planetsSprites[Random.Range(0, planetsSprites.Length)];   // Gets a random sprite for the planet

        Vector2 rPos = Random.insideUnitCircle * _spawnRadiusScaleSize;                // Gets a random spawn location around the player
        Vector3 spawnPosition = _camera.transform.position + new Vector3(rPos.x, rPos.y, 0);

        if (!IsInsideCamera(spawnPosition) && HasRoom(spawnPosition))
        {
            // spawn's the planets
            GameObject newPlant = Instantiate(planetPrefab, spawnPosition, Quaternion.Euler(Vector3.zero), transform);
            newPlant.GetComponent().sprite = planetSprite;
            newPlant.transform.localScale = planetSize;

            // Random change to spawn a enemie next to a planet
            if (Random.Range(0, 35) == 2)
                Instantiate(alien, spawnPosition + Vector3.right, Quaternion.Euler(Vector3.zero));
        }

    /// 
    /// checks if the planet is not to close to a different planets
    /// 
    /// The position of were you want to do the check
    /// true if there is noting in the way
    private bool HasRoom(Vector3 position)
    {
        Collider2D[] colliderArray = Physics2D.OverlapCircleAll(position, checkRadius);
        foreach (Collider2D collider2D in colliderArray)
        {
            if (collider2D.CompareTag("Planet"))
                return false;

            if (collider2D.CompareTag("Alien"))
                return false;
        }
        return true;
    }

    /// 
    /// checks if the planet is the camera's view
    /// 
    /// The position of were you want to do the check
    private bool IsInsideCamera(Vector3 position)
    {
        Vector3 screenPos = _camera.WorldToViewportPoint(position);
        if (screenPos.x is >= 1.1f or <= -0.1f) return false;
        if (screenPos.y is < 1.1f and > -0.1f)
            return true;
        return false;
    }
}
                        
                    
Play on Itch.io
Home