Game Jammin’, the antisocial way (3)

It’s been a couple of days since the last update, and I’m making good progress so far!

shmup2

The game looks mostly like I want it to look (except for the player ship that’s going to get a reworking tomorrow). Collision detection works, garbage collection works, the basic game script is in place. I’m still missing the final boss, and also the miniboss I’ve got so far is probably the easiest opponent in the whole game.

The whole thing can be played through in about two minutes – that’ll probably go up a bit with said final boss, maybe to three minutes. But I don’t think somebody who has never played a shmup before will beat it on the first try.

What’s still also missing is a scoring system that actually produces reasonable results and makes getting a high score actually challenging. So far, every run that makes it to the end will have exactly the same score – that’s not really interesting.

Kongregate statistics integration is mostly there and already debugged. Music is in place, as are some sound effects – though one or two of those are still missing.

In total, I have spent about 10 hours with this project, which is less than I hoped to do, but I’m still dealing with The Move™ and searching a job, which takes up some time as well and is the reason I gave me a whole week of time for this. Five hours or so are still missing until the whole thing is finished, I guess.

On a side note, the script that spawns enemies is probably the worst bit of code I ever wrote and I really, really have to share it with you.

using UnityEngine;
using System.Collections;

public class GameScript : MonoBehaviour {

    public GameObject starryThingPrefab;
    public GameObject magnetThingPrefab;

    public GameObject minibossBannerPrefab;

    private float timeElapsed = 0;

    private bool encounter1triggered = false;

    private bool encounter2triggered = false;
    private float encounter2time = 0.0f;

    private bool encounter3triggered = false;
    private float encounter3time = 0.0f;

    private bool minibossBannerTriggered = false;
    private float minibossBannerTime = 0.0f;

    private bool minibossTriggered = false;

    private bool encounter1Atriggered = false;
    private float encounter1Atime = 0.0f;

    private bool encounter2Atriggered = false;
    private float encounter2Atime = 0.0f;

    private bool encounter3Atriggered = false;
    private float encounter3Atime = 0.0f;

    private bool finalBossTriggered = false;

    private bool scriptFinished = false;

    public void Update()
    {

        if (scriptFinished) return;

        timeElapsed += Time.deltaTime;
        if (!encounter1triggered)
        {
            TriggerEncounter1();
            return;
        }

        if (!encounter2triggered)
        {
            if (timeElapsed >= 5)
            {
                TriggerEncounter2();
            }
            return;
        }

        if (!encounter3triggered)
        {
            if (GameObject.FindObjectOfType<Enemy>() == null) // no more enemies!
            {
                TriggerEncounter3();
            }
            return;
        }

        if (!minibossBannerTriggered)
        {
            if (GameObject.FindObjectOfType<Enemy>() == null) // no more enemies!
            {
                Instantiate(minibossBannerPrefab);
                minibossBannerTriggered = true;
                minibossBannerTime = timeElapsed;
            }
            return;
        }

        if (!minibossTriggered)
        {
            if(timeElapsed > minibossBannerTime + 5) // no more enemies!
            {
                TriggerMiniboss();
            }
            return;
        }

        if (!encounter1Atriggered)
        {
            if (GameObject.FindObjectOfType<Enemy>() == null) // no more enemies!
            {
                TriggerEncounter1A();
            }
            return;
        }
        if (!encounter2Atriggered)
        {
            if (timeElapsed > encounter1Atime + 5)
            {
                TriggerEncounter2A();
            }
            return;
        }
        if (!encounter3Atriggered)
        {
            if (timeElapsed > encounter1Atime + 10)
            {
                TriggerEncounter3A();
            }
        }

        // check if game is finished
        if (GameObject.FindObjectOfType<Enemy>() == null) // no more enemies!
        {
            GameObject.FindObjectOfType<PlayerShip>().Victory();
            scriptFinished = true;
        }
    }

    private void TriggerEncounter1()
    {
        encounter1triggered = true;
        GameObject enemyA = (GameObject)Instantiate(starryThingPrefab);
        GameObject enemyB = (GameObject)Instantiate(starryThingPrefab);

        enemyA.transform.position = new Vector3(3.5f, -7, 0);
        enemyA.GetComponent<StarryThing>().targetPosition = new Vector2(3, -2);
        enemyA.GetComponent<StarryThing>().rotationSpeed = 0;
        enemyA.GetComponent<StarryThing>().firingCooldownInit = 0.5f;

        enemyB.transform.position = new Vector3(3.5f, 7, 0);
        enemyB.GetComponent<StarryThing>().targetPosition = new Vector2(3, 2);
        enemyB.GetComponent<StarryThing>().rotationSpeed = 0;
        enemyB.GetComponent<StarryThing>().firingCooldownInit = 0.5f;
    }

    private void TriggerEncounter2()
    {
        encounter2triggered = true;
        encounter2time = timeElapsed;
        GameObject enemyA = (GameObject)Instantiate(starryThingPrefab);
        GameObject enemyB = (GameObject)Instantiate(starryThingPrefab);

        enemyA.transform.position = new Vector3(3.5f, -7, 0);
        enemyA.GetComponent<StarryThing>().targetPosition = new Vector2(1, -2);

        enemyB.transform.position = new Vector3(3.5f, 7, 0);
        enemyB.GetComponent<StarryThing>().targetPosition = new Vector2(1, 2);
    }

    private void TriggerEncounter3()
    {
        encounter3triggered = true;
        encounter3time = timeElapsed;

        GameObject enemyA = (GameObject)Instantiate(starryThingPrefab);
        GameObject enemyB = (GameObject)Instantiate(starryThingPrefab);

        enemyA.transform.position = new Vector3(3.5f, -7, 0);
        enemyA.GetComponent<StarryThing>().targetPosition = new Vector2(1, -2);

        enemyB.transform.position = new Vector3(3.5f, 7, 0);
        enemyB.GetComponent<StarryThing>().targetPosition = new Vector2(1, 2);

        GameObject enemyC = (GameObject)Instantiate(magnetThingPrefab);
        enemyC.transform.position = new Vector3(8, 0, 0);
        enemyC.GetComponent<MagnetThing>().targetPosition = new Vector2(3, 0);
    }

    private void TriggerMiniboss()
    {
        minibossTriggered = true;
        GameObject miniboss = (GameObject)Instantiate(starryThingPrefab);
        miniboss.GetComponent<StarryThing>().targetPosition = new Vector2(3, 2);
        miniboss.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
        miniboss.GetComponent<StarryThing>().rotationSpeed = 45;
        miniboss.GetComponent<StarryThing>().firingCooldownInit = 0.05f;
        miniboss.GetComponent<StarryThing>().hitpoints = 10;
        miniboss.GetComponent<StarryThing>().bulletSpeed = 3;
    }

    private void TriggerEncounter1A()
    {
        encounter1Atriggered = true;
        encounter1Atime = timeElapsed;

        GameObject enemyA = (GameObject)Instantiate(magnetThingPrefab);
        enemyA.transform.position =  new Vector3(3.5f, -7, 0);
        enemyA.GetComponent<MagnetThing>().targetPosition = new Vector2(3.5f, 0);
    }

    private void TriggerEncounter2A()
    {
        encounter2Atriggered = true;
        encounter2Atime = timeElapsed;

        GameObject enemyA = (GameObject)Instantiate(magnetThingPrefab);
        enemyA.transform.position = new Vector3(3.5f, -7, 0);
        enemyA.GetComponent<MagnetThing>().targetPosition = new Vector2(2f, -2);

        GameObject enemyB = (GameObject)Instantiate(magnetThingPrefab);
        enemyB.transform.position = new Vector3(3.5f, 7, 0);
        enemyB.GetComponent<MagnetThing>().targetPosition = new Vector2(2f, 2);
    }

    private void TriggerEncounter3A()
    {
        encounter3Atriggered = true;
        GameObject enemyA = (GameObject)Instantiate(magnetThingPrefab);
        enemyA.transform.position = new Vector3(3.5f, -7, 0);
        enemyA.GetComponent<MagnetThing>().targetPosition = new Vector2(4f, -2);

        GameObject enemyB = (GameObject)Instantiate(magnetThingPrefab);
        enemyB.transform.position = new Vector3(3.5f, 7, 0);
        enemyB.GetComponent<MagnetThing>().targetPosition = new Vector2(4f, 2);
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s