Scripting the Play: GAM 111 Week 10

My game for GAM 111 has come to a point where it is functional and can be played with two players.  While being a draft I believe there will be very little to fix for submission. I constructed the Player and slots to a point where they could spawn monsters, apply attack states, and select ready to continue. Parts of the Game Controller was created during process, but was finished along with the construction of the Game State controller and other core controllers.  The units for the game have become archers, but for consistency I will continue to call them monsters.

Screenshot (42).png

 

To avoid the trouble of me just stating the names of my scripts, I have supplied a list of the created scripts for reference; their names give a rough idea of their use. I know it won’t help understand what they do and what they are for but I aim to cover the core scripts in this post.  A large number of the scripts only include a few lines of code for controlling UI and minor aspects.  

Archers
have replaced monsters as the units to play in the game, this is purely visual and won’t change the mechanics in anyway.  I have found an Asset Pack on the Unity Asset Store that had a variety of archer sprites, animations and prefabs. I chose three sprites from the animations to represent different states of the monster: Idle, Attacking, and Dead. The monsters had a script that mainly controlled their current image, and their stats were stored elsewhere. A specially made database held all the variables and images for each of the monsters. Once created, it could be linked to the monster and its script would find its respective variables.

 

The slots handled all of their own stats calculations, and based its stats off its current monster. Each slot had the same script which controlled it, each slot script was then parented to its owner player. It constantly checks if there is a monster in the slot, see code below, and will update accordingly.

 

    public bool Empty
    {
        get
        {
            return gameObject.GetComponentInChildren<MonsterController>() == null;
        }
    }

 

If this function returns false the slot will gather stats from the current monster, and the menu for selecting the attack state will open, otherwise the stats will all be set to 0.  The three attack states trigger a change in the base stats of the slot and are as follows Attack, Defend, Heal. Here are their functions:

Attack State

Stat Change

Attack Attack Power x 1.5

Defence x 0.75

Defend Attack Power / 2

Defence * 2

Heal Attack = 0

Defence x 3

Adds 100 Health to each other slot

 

The Player Controller is responsible for tracking the player’s game stats such as units left

Screenshot (38)
GameData preview

to spawn, ready to continue and slot conditions. The second player will be a clone of the first player and they will be distinguished as different entities in the Game Data S
cript (this script holds all sort of data and variables that are used in multiple locations).   

 

Screenshot (40)
Spawn Information Struct

The Game Controller takes care of sending messages to the Game State Controller and the combat stage. One of it key functions is spawning the monsters, it will receive a message from the player to spawn a monster attached with a struct that contains all the required info.

 

While my practices may not be the best, I am still learning how to write truly cheap code performance wise. A skill I believe will be learnt as time passes and more projects are completed; more importantly some more reading.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s