banner
navBar home resume scripting
progNavBar Programming CPP
Game/Program:
Save The Baby (Jalloo Game Jam 2015)
 

This is what I came up with during the Jalloo Game Jam 2015. I did this one solo so all the art/audio is from opengameart.org and the Unity Asset Store.

The theme was "Is this legal?" so I pretty much went with something super offensive (to the average person who thinks FOX News is actually news). In this game there is a bouncing baby on a path to guranteed mutilation. You can "save" the baby by shooting the dangers ahead of it. That in itself is incredibly wrong. Shooting a firearm in the path of the baby in pretty much any country gets you incarserated at least. However, being a video game it's also equally fun to just sit back and let the baby get destroyed. I can say that with confidence as I was asked multiple times during presentations to play it again and not save the baby. If you're offended, just get off the internet already.

Mechanic-wise, I got the bare minimum of what I wanted to do as I only had 24 hours, zero artists, and no other programmers. The way I have it set up is such that the next steps are introducing more interesting items as obstacles that are also equally or more lethal than the buzzsaw blades. Eventually to be used in combinations. Oh how I wish this was a 48hr jam!

 
BabyLogic.cs
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class BabyLogic : MonoBehaviour
{
    #region ENUMS
    protected enum BLOOD_DECAL_DIRS
    {
        DOWN=0,
        DOWN_FORWARD,
        DOWN_BACKWARD,
        DOWN_LEFT,
        DOWN_RIGHT,
        LENGTH
    };
    #endregion ENUMS

    #region PROPERTIES
    protected Rigidbody _rb;
    public float Force = 1.0f;
    public GameObject BloodDecal;
    public float BloodDecalYOffset = 0.1f;
    protected Ray _ray;
    protected RaycastHit _hit;
    protected LayerMask _lm;
    public bool LimitYVelocity = true;
    public float YVelocityLimit = 15.0f;
    public bool LimitXVelocity = false;
    public float XVelocityLimit = 0.0f;
    public float MaxXVelocity = -5.0f;
    protected List<GameObject> _bloodDecals;
    public int MaxBloodDecals = 10;
    public float BloodDecalOriginOffset = 1.0f;
    protected VolumetricBloodLogic _vbl;
    protected AudioManager _am;
    #endregion PROPERTIES

    #region MONOBEHAVIOR_REFLECTIONS
    void Awake()
    {
        _rb = GetComponent<Rigidbody>();
        _ray = new Ray();
        _hit = new RaycastHit();
        _lm = 1 << LayerMask.NameToLayer("Ground");
        _bloodDecals = new List<GameObject>();
        _vbl = transform.Find("VolumetricBlood").gameObject.GetComponent<VolumetricBloodLogic>();
    }

    void Start()
    {
        _am = AudioManager.Instance;
        _am.Play("Lullaby_BGM", new string[0] { });
        _am.Play("HighGiggle" + (Random.Range(0.0f, 1.0f) > 0.5f ? 1 : 2),
                 new string[7] { "Giggle1", "Giggle2", "HighGiggle1", "HighGiggle2", "Cry1", "Cry2", "Cry3" });
    }
    
    void Update()
    {
        Logic();

        VelocityCap();

        //Debug.LogWarning("_rb.velocity: " + _rb.velocity);
        //Debug.LogWarning("transform.position.y: " + transform.position.y);

        if (transform.position.y>0.0f)
        {
            _am.Play("HighGiggle" + (Random.Range(0.0f, 1.0f) > 0.5f ? 1 : 2),
                     new string[7] { "Giggle1", "Giggle2", "HighGiggle1", "HighGiggle2", "Cry1", "Cry2", "Cry3" });

            //Debug.LogWarning("DING@#&(^$(&#^*&#%^");
        }
    }

    void OnCollisionEnter(Collision c)
    {
        //Debug.LogWarning("c.gameObject.layer: " + c.gameObject.layer);
        //Debug.LogWarning("LayerMask.NameToLayer(\"Ground\"): " + LayerMask.NameToLayer("Ground"));

        if (c.gameObject.layer == LayerMask.NameToLayer("Enemy")) 
        {
            BuzzSawLogic bsl = c.gameObject.GetComponent<BuzzSawLogic>();
            if (bsl != null) { bsl.DropItLikeItsHot(0.0f); }

            Splatter(c.gameObject.transform); 
        }
        else if (c.gameObject.layer == LayerMask.NameToLayer("Ground")) { _am.Play("Thud", new string[0]{}); }
    }
    #endregion MONOBEHAVIOR_REFLECTIONS

    #region METHODS
    protected void Logic()
    {
        if (_rb.velocity.x > MaxXVelocity) { _rb.velocity = new Vector3(MaxXVelocity, _rb.velocity.y, _rb.velocity.z); }
    }

    protected void Splatter(Transform enemy)
    {
        _vbl.ToggleBlood(true);
        _am.Play("Guts" + (Random.Range(0.0f, 1.0f) > 0.5f ? 1 : 2), new string[2] {"Guts1", "Guts2"});
        float rand=Random.Range(0.0f, 1.0f);
        _am.Play("Cry" + (rand > 0.33f ? 1 : (rand > 0.66f ? 2 : 3)),
                 new string[7] { "Giggle1", "Giggle2", "HighGiggle1", "HighGiggle2", "Cry1", "Cry2", "Cry3" });
        
        _ray = new Ray(enemy.position, Vector3.down);
        _hit = new RaycastHit();
        float yPos = 0.0f;

        if (Physics.Raycast(_ray, out _hit, 1000.0f, _lm))
        {
            yPos = _hit.point.y + BloodDecalOriginOffset;
        }
        
        for (BLOOD_DECAL_DIRS iDir = 0; iDir < BLOOD_DECAL_DIRS.LENGTH; iDir++)
        {
            Vector3 dir = Vector3.zero;
            switch(iDir)
            {
                case BLOOD_DECAL_DIRS.DOWN:
                    dir = Vector3.down;
                    break;
                case BLOOD_DECAL_DIRS.DOWN_BACKWARD:
                    dir = Vector3.down - Vector3.back;
                    break;
                case BLOOD_DECAL_DIRS.DOWN_FORWARD:
                    dir = Vector3.down - Vector3.forward;
                    break;
                case BLOOD_DECAL_DIRS.DOWN_LEFT:
                    dir = Vector3.down - Vector3.left;
                    break;
                case BLOOD_DECAL_DIRS.DOWN_RIGHT:
                    dir = Vector3.down - Vector3.right;
                    break;
                default:
                    break;
            } 

            //Debug.DrawRay(transform.position, _ray.direction, Color.red);
            //Debug.LogWarning("DING!@!##$!$");

            _ray = new Ray(new Vector3(enemy.position.x, yPos, enemy.position.z), dir);
            _hit = new RaycastHit();

            if (Physics.Raycast(_ray, out _hit, 1000.0f, _lm))
            {
                GameObject decal = Instantiate(BloodDecal);
                decal.name = "bloodDecal";
                decal.transform.position = new Vector3(_hit.point.x, _hit.point.y + BloodDecalYOffset, _hit.point.z);

                float angle = Random.RandomRange(0.0f, 360.0f) + decal.transform.rotation.eulerAngles.z;
                if (angle >= 360.0f) { angle -= 360.0f; }
                decal.transform.rotation = Quaternion.Euler(decal.transform.rotation.eulerAngles.x,
                                                          decal.transform.rotation.eulerAngles.y,
                                                          decal.transform.rotation.eulerAngles.z + angle);

                _bloodDecals.Add(decal);
                //Debug.LogWarning("_bloodDecals.Count: " + _bloodDecals.Count);
                while (_bloodDecals.Count > MaxBloodDecals)
                {
                    GameObject toDestroy = _bloodDecals[0];
                    _bloodDecals.RemoveAt(0);
                    Destroy(toDestroy);

                    /*Debug.LogWarning("^*%*(%(&^%");*/
                }
            }
        }
    }

    protected void VelocityCap()
    {
        if (LimitYVelocity)
        {
            if (_rb.velocity.y > YVelocityLimit) { _rb.velocity = new Vector3(_rb.velocity.x, YVelocityLimit, _rb.velocity.z); }
        }

        if (LimitXVelocity)
        {
            if (_rb.velocity.x > XVelocityLimit) { _rb.velocity = new Vector3(XVelocityLimit, _rb.velocity.y, _rb.velocity.z); }
        }
    }
    #endregion METHODS
};
VolumetricBloodLogic.cs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class VolumetricBloodLogic : MonoBehaviour
{
    #region PROPERTIES
    public GameObject[] Blood;
    protected Dictionary<UVTextureAnimator, Renderer> _blood;
    public float Duration = 1.0f;
    protected float _timeToToggle;
    public float BloodScale = 3.0f;
    #endregion PROPERTIES

    #region MONOBEHAVIOR_REFLECTIONS
    void Awake()
    {
        _blood = new Dictionary<UVTextureAnimator, Renderer>();
        InitializeChildren();
        _timeToToggle = -0.1f;
    }

    void Update()
    {
        if (_timeToToggle>0.0f)
        {
            _timeToToggle -= Time.deltaTime;
            if (_timeToToggle < 0.0f) { ToggleBlood(false); }
        }
    }
    #endregion MONOBEHAVIOR_REFLECTIONS

    #region METHODS
    protected void InitializeChildren()
    {   
        foreach (Transform child in transform)
        {
            GameObject newblood = Instantiate(Blood[Random.Range(0, Blood.Length - 1)]);
            newblood.transform.parent = child;
            newblood.transform.localPosition = Vector3.zero;
            ExtractUVTA(newblood.transform);
            Destroy(child.gameObject.GetComponent<Renderer>());
        }

        ToggleBlood(false);
    }

    public void ToggleBlood(bool bEnabled)
    {
        foreach (KeyValuePair<UVTextureAnimator, Renderer> kvp in _blood) 
        {
            kvp.Key.enabled = bEnabled;
            kvp.Value.enabled = bEnabled;
        }

        if (bEnabled) { _timeToToggle = Duration; }
    }

    protected void ExtractUVTA(Transform parent)
    {
        UVTextureAnimator uvta = parent.gameObject.GetComponent<UVTextureAnimator>();
        if (uvta != null) 
        {
            //uvta.IsLoop = true;
            _blood.Add(uvta, parent.gameObject.GetComponent<Renderer>());
        }
        else if (parent.gameObject.name == "Offset") { parent.localScale *= BloodScale; }

        foreach (Transform child in parent) { ExtractUVTA(child); }
    }
    #endregion METHODS
};
AudioManager.cs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class AudioManager : MonoBehaviour
{
    #region PROPERTIES
    public static AudioManager Instance = null;
    protected bool _bValid;
    protected Dictionary<string, AudioSource> _audioRegistry;
    #endregion PROPERTIES

    #region MONOBEHAVIOR_REFLECTIONS
    void Awake()
    {
        if (Instance==null)
        {
            Instance = this;
            _bValid = true;
        }
        else
        {
            Debug.LogWarning("THERE CAN BE ONLY ONE INSTANCE! COMPONENT DELETED FROM GO: " + name);
            
            _bValid = false;
            Destroy(this);
            return;
        }

        _audioRegistry = new Dictionary<string, AudioSource>();
        GatherSources();
    }

    void OnDestroy()
    {
        if (_bValid) { Instance = null; }
    }
    #endregion MONOBEHAVIOR_REFLECTIONS

    #region METHODS
    protected void GatherSources()
    {
        foreach (Transform child in transform) 
        {
            _audioRegistry.Add(child.gameObject.name, child.gameObject.GetComponent<AudioSource>());
        }
    }

    public void Play(string source, string[] dontInterupt)
    {
        if (dontInterupt.Length < 1 || (dontInterupt.Length>0 && !IsPlaying(dontInterupt))) { _audioRegistry[source].Play(); }
    }

    protected bool IsPlaying(string[] dontInterupt)
    {
        for (int iPlaying = 0; iPlaying < dontInterupt.Length; iPlaying++ )
        {
            if (_audioRegistry[dontInterupt[iPlaying]].isPlaying) { return true; }
        }

        return false;
    }
    #endregion METHODS
};
 
^RETURN TO TOP^