Tuesday, October 27, 2015

Dev Update #16 Speed, Tweaked UI, Modified Player Pause, P and M Key, Random Pausing, Build Mode

Changed Button Presses So They Don't Interfere With Typing

I set the "M" key press to only work when the game is paused.  This prevents "M" from pausing the music when typing a todo.  I had to entirely disable the "P" key press for pausing the game, because there was no elegant way to change it using the current code. There's probably some way to do it involving the AddTodo field focus, but it's relatively minor and I'm just going to leave it out for now.

Modified The Way Player is Paused During Level Loading

I was disabling the Player object during board setup, and then reenabling when board setup was finished. I have suspected that having the player game object disabled may interfere somewhat with the movement of the enemies.  It gives me no errors, but just to be sure, I decided to disable just the sprite and then set the Player script to paused.  I wasn't able to access the Player.player.paused(player is a reference to the instance) variable from BoardManager, even though I can access it fine from other scripts.  I get a "null reference error" - this gave me a lot of grief in the past.  I suspect it has something to do with the BoardManager being instantiated, whereas the other scripts that are accessing Player.player.paused are not being instantiated.  They just exist within the scene.

So, instead, I used:

        playerObj = GameObject.Find("Player");
        playerScript = playerObj.GetComponent<Player>();
        playerScript.paused = true;

 It's less elegant than "Player.player.paused = true;", but it works.  I'm not sure if it makes any difference.  The enemies do seem a little more responsive in their attacks, but it's hard to tell. They still seem to move in roughly the same pattern.

Tweaked UI elements

I tweaked a lot of the different UI elements - adding padding and slightly modifying shape.  I changed the font on many UI elements to PressStart2P-Regular, that came with the Unity Rogue 2d Tutorial.  I chose to continue using Arial on the Todos, because Arial looks better at a smaller font size, and I didn't want to make the fonts big enough to look good use the PressStart font.  I made the text darker on the todos and the other UI elements with grey backgrounds

Random Pausing Fixed

I fixed the Inputfield from (seemingly randomly) being selected while you're moving the character.  It turns out is wasn't random at all, it was the UI navigating between UI elements until it hit the input field.  I turned the input field navigation to off, which should solve that.

Speed

I added a speed modal.  It sets each todo to complete 1, 2, 3, or 4 tiles when they are checked.  I would go into more detail about how I did this, but the actual creation of the modal was a bit complex.  It's not really a modal as much as a configuration window that pops up on the right panel.  In order to activate and deactivate the  modal, I had to create a separate script that mostly just keeps track of the "speed" variable, that is never deactivated.

Build Mode

I also added an image and text that says "Build Mode" instead of "Paused" when the level is building.


What's Next

I think I'm going to add some kind of instructions.  I'm debating whether or not I want to implement any kind of deleting or editing of todos before release.



Tuesday, October 20, 2015

Dev Update #15 - Almost Done. Exit Game Button. Confirmation Dialog Boxes

Exit Game Button

10/18/2015 I added an Exit game button using Application.Quit(); and also moved the Right Panel Buttons off of a Scrollview that wasn't doing anything and redid the anchors for the buttons so they would scale correctly.

Confirmation Dialog Boxes (Modal Windows)

10/20/2015   I added some Modal windows for 6 Reset Game and Exit Game.  I started by watching the part 1 of 3 of the Unity tutorial/live session UI TOOLS: MAKING A GENERIC MODAL WINDOW, and then decided I didn't need such a complex solution for just 2 modal windows, so I hacked together some panels and buttons, copied them, and then modified my original Exit Game and Reset Game button scripts.

The ExitGame script looks like this:

using UnityEngine;
using System.Collections;
public class ExitButton : MonoBehaviour
{
    public GameObject exitModal;
    public GameObject resetModal;
     public void ExitGamePressed()
        {
            if (resetModal.activeSelf == false)
            exitModal.SetActive(true);
        }
     public void ExitGame()
     {
         Application.Quit();
   
     }
     public void ClosePanel()
     {
         exitModal.SetActive(false);
     }
}

The ResetGame script is mostly the same except with "Reset" in place of "Exit" and instead of Application.Quit, it calls the ResetGame function from BoardManager.  All the code I added to the two scripts is almost the same between both scripts, which seems wasteful and I'm sure there's a better way, but I'm more concerned with getting it functional. I may rewrite later.

The appropriate functions are then assigned to the appropriate button's onClick events and the appropriate GameObjects are assigned to the scripts.  Both exitModal and ResetModal are set to inactive in the editor.

What's Next

I'm pretty much done.  I've made a build and I'm testing it.  Currently the key press "P" will pause/unpause and "M" will pause/unpause the music which is a problem when typing in todos, so I'll fix that.  I'll readjust a few things in the UI to try to make them look a little more professional.  I don't really like the way the text looks. I might try to make that look a little nicer.  Some graphics on the UI elements would be nice, but I don't think I'm going to touch that for the prototype.

There's always more I could do, but as far as I'm concerned, I've accomplished all my goals.  So once, I've polished things up a little, and done a little testing, I'm going to make Windows, Mac OSX, linux, and maybe Android builds and release them all simultaneously on this website.  That should be very soon.
Running in a Build

Saturday, October 17, 2015

Dev Update #14 Reset Button Fixed(Again), Pausing Works, Window Scaling Fixed, Unused Todos Usable

Reset Button Fixed(Again)

In my attempt to get Pause to work today, I discovered in issue with the Reset Button I should have noticed the first time.

I was using a checkedOff variable in my TodosHandler script to pass a variable to the BoardManager script, that manages the game board.  The TodoScript attached to the TodoButton sets the checkedOff variable in the TodosHandler to true.  Update() in BoardManager waits for the checkedOff variable in TodosHandler to be true, and then it sets the "clicked" variable in BoardManager to true.  This signals a while loop to stop, which then loads the next tile in BoardManager.

Originally, I thought this wasn't working when the game was paused because Update() wasn't running when time.TimeScale was set to 0.  This, however was false, but I didn't know that at the time.  To fix this, I gave the TodoScript direct access to the "clicked" variable in the BoardManager script, and let it set "clicked" directly.  This was changing the variable to true, but it did not trigger the while loop to stop.

The reason for this, I eventually discovered, was that I had multiple instances of BoardManager.  I discovered this by using:
Debug.Log("Parent of this BoardManager is " + transform.parent.gameObject);
Debug.Log("Root parent of this BoardManager is " + transform.root.gameObject);

I'm not entirely sure why my previous fix for the ResetButton worked.  I'm guessing that the change I made allowed the ResetButton script to find only one copy of the BoardManager instance instead of two, or maybe it found the correct instance instead of the wrong one.

So I removed the copy of BoardManager from the ResetButton and changed the ResetButton code to:
        BoardManager.boardManager.ResetBoard();
In order to access the variable directly from TodoScript, I had previously added to my list of variables:
    public static BoardManager boardManager = null; 
and then also added, to the "void Awake();" function:

         boardManager = this;
 This allowed me to access the ResetBoard() function directly as well.

However,  after implementing this code, I came to discover that tiles are still not loaded when the game is paused.  Apparently Update() is still called while Time.timeScale is 0, but
while (!clicked)
                {
                    yield return new WaitForSeconds(0.01f);
                                     
                }
never completes, because time has stopped.

Pausing Works

Since setting Time.timeScale to 0 doesn't work with WaitForSeconds, I instead decided to pause the player by making a "paused" variable in the Player script.  I made that variable accessible by other scripts so that those scripts can pause the player.

The player moves through:

            horizontal = (int)Input.GetAxisRaw("Horizontal");
            vertical = (int)Input.GetAxisRaw("Vertical");
and some other scripts in Update() of the Player script, so I added "if (!paused)" before that.

I then added code to the Pause button script to set Player.player.pause to true or false and I added an "Event Trigger" component to the Todo field.  I then added a Select and Deselect even to the event trigger, added a PausePlayer and UnpausePlayer function to the Pause script, and assigned those to Select and Deselect so that the player is paused when the field is selected and unpaused when the field is deselected.  This keeps the player movement from being effected when typing in todo names and keeps todos from being typed in when the player is moving.

I also added a black image, with an alpha, with the word "Paused" overlayed on top of the game as a visual queue.


I also added a gameActive variable to the boardManager so that the pause scripts can check to see if the game is Active.  The game is by default, paused when the level is loading, so this prevents the scripts from trying to unpause the game when the level is still loading.

Currently music doesn't pause with the game, but it can be paused separately by clicking the music button.  I did this intentionally to give players more control over whether the music is, or is not playing.  The music does start by default when the level is finished loading.

Window Scaling Fixed(sort of)

I (sort of) fixed scaling.  I set the aspect ratio to 16:9 and then set the windows to stretch vertically, with their anchors set to the bound of the panel.  This makes the panels scale correctly.  However, the aspect ratio is stuck at 16:9

Unused Todos

Previously, all todos you did while the game was active would not be counted.  I changed this, so that there is now a counter in BoardManager that keeps track of those unused todos.  There is also a panel that tell you how many unused todos you have, and a button you can click that will use those unused todo points as if they were a todo you were clicking on the left panel.  I could give more technical information, but this post is already a bit long.

What's Next

I may add some kind of confirmation popup for the Reset Game button that asks whether you are sure you want to reset the game, and maybe some hover over tooltips if that's possible, but that's the only thing I can think of right now. 

I'll take a little time to think about whether there is anything else I want to add before release.  I'll also do some testing and make some builds.  Then I will release a working build for everyone to download.





Friday, October 16, 2015

Dev Update #13 Fixed Reset Game Bug

Fixed Reset Game Bug

I set out to fix the reset game bug, today, and was successful.

After resetting the game, the tiles would continue to load even after the game had started.  I thought this might be caused by having a second instance of the BoardManager script attached to the ResetButton script.  I did that, because assigning the BoardManager script, that was already in the scenne to the ResetButton script wasn't working.  First, I tried uncommenting my previous code to see why it didn't work and it worked perfectly fine.  I don't have a clue why it didn't work the first time, I'm just glad it's working now.

The code looks like this:
boardScript = FindObjectOfType(typeof(BoardManager)) as BoardManager;

Next up: Bug Fixing Pause 

Next up, I need to get some sort of pausing of the game working.  Currently, pausing the game prevents tiles from being loaded when they're checked off.  Currently, to pause the game, I'm using:
if (Time.timeScale == 1)
             {
                 Time.timeScale = 0;
                 AudioListener.pause = true;
             }
             else
             {
                 Time.timeScale = 1;
                 AudioListener.pause = false;
             }
this prevents all of the Update() events from triggering in the game.  The code that triggers the next tile to be loaded looks like this:

    void Update()
    {
        if (TodosHandler.todosHandler.checkedOff)
            clicked = true;
    }

And this is why tiles are not loaded when the game is paused.  I now have to either rewrite my code so that I am not using Update() to wait for a checkedOff event, or I have to rewrite the pause so that the player is turned off.  I know how to do that latter.  I have a vague idea about how to do the former.  I'm not sure which is best.  I was going to work on that today, but then I had personal matters to attend to.

On the Backburner: Window Scaling (yet again)

As it turns out, though I thought I had fixed the window scaling, in the last post, it turns out I had only fixed the gaps when scaling the game window horizontally.  When scaling vertically they reappeared.  I'm not entirely sure how to fix this.  I think I may need to make an actual build of the game, which I haven't done yet, and then see how scaling the window works in the actual build.  I would like to make the game fully scalable in all directions, with a limit on how small the window can get, however I may have the make the game a fixed aspect ratio.   Hopefully I won't have the make the game a fixed resolution/resolutions.

Tuesday, October 13, 2015

Dev Update # 12: Pausing Audio, UI Elements Correctly Scaling


I've decided to add  more pictures and more technical information into my dev updates.  I've also decided to do a write up on my progress/lack thereof immediately after I've made the progress/lack thereof.  Instead of making a lot of dev updates, I will add to them until I feel like I have enough material before posting.

10/12/2015 I found a way to pause and play the music in the game, using "AudioListener.pause" instead of turning on and off the SoundManager object. One benefit to this, is that the music will begin playing where it left off instead of restarting every time. Also, Unity can't find an object when it's not active, and this is why the sound breaks using my current "reset game" code. One downside the AudioListener pauses all of the audio including the music and sound effects. Apparently can "set the ignoreListenerPause property" to true for sound effects, to prevent this, but I'm not entirely sure how to do this yet. A snippet of my code is below. This is the body of a function I have that runs when the music button is pressed, or the "M" button is pressed.
if (AudioListener.pause == false)
        { AudioListener.pause = true; }
        else
        { AudioListener.pause = false; }

10/13/2015  I readjusted some of the UI elements that weren't scaling with everything else, so they would scale correctly.  I changed the anchors to top horizontal stretch(not sure if the top part is important, but I know that adding vertical stretch will generally break everything. see Image 1).  Anchors and pivots with the new UI system are a bit confusing.  I think maybe I'm starting to understand them a little.

I was having trouble getting the left and right panels to scale with the game board in the middle.  I created a panel that mimics the game board, to make it easier.  The game board is always square, 1x1, so as the window scales the game board gets bigger or smaller in the middle.  Initially, the left and right panels stayed the same width, because there was no width scaling which would create large black areas on the left and right of the game board(see image 2), or the panels would overlap the game board.  Every time I changed the anchors, the panels would scale, but they would scale incorrectly.

To fix this, after a LOT of trial and error, I set the inside anchors to the middle of the screen.  Don't ask me why this works or how I thought of trying it.  I have a very vague idea, but I couldn't explain it.
Success!!! UI Elements scale correctly.

Image 1: vertical scaling breaking UI elements, before I fixed it

Image 2: Gaps between Game Board and Panels

Sunday, October 11, 2015

Tech info: ArrayPrefs2



09/28  I added saving and loading of the todoList array today.
I'm using PlayerPrefs to save and load single variables and ArrayPrefs2 to save and load arrays.  Since I'm using Lists, I have to convert the lists to and from arrays when using ArrayPrefs2, but I plan on creating a more robust system later.  Possibly using XML.  Ideally, I would save individual entries in the todoList, instead of the entire array, but saving the whole array every time a todoList item is removed or added may not be too resource intensive.  I'm really not sure.  Right now I'm mainly focused on getting everything running and released.  I'll focus on optimization later.


Dev Update #11 - Continuing work on Productivity Game - Rogue-Like Prototype

Game in mid-level load

Game on Day 2
What works:
-Adding and completing tasks.
-Completing a task adds a tile to the level.
-The level can then be played once all tiles are complete.
-Todo buttons fit the size of their text.
-The level, the number of tiles added to the level, and the remaining todos are all saved when the game is closed and reopened.
-  The actual game portion works

What doesn't work:
I added those buttons along the right side to test some features.  Currently they're all a little broken.  I'm pretty sure I know how to fix the music button to turn music on and off.  The pause button technically works, but tiles are not added to the level when a todo is completed, when paused, which defeats the purpose of the pause.  The reset game button resets the game, but you also have to immediately turn the game off and back on again or it will break all kinds of things.

So, I'm basically just bug fixing right now.

I thought I made at least one post, if not multiple posts since the last one, but they don't appear to exist :/