Sunday, 28 June 2015

A bit of background

Self learning ain't easy

Being a self taught programmer and game designer is definitely not going to be easy, I am already finding the task of finding good material to learn from to be a problem. Often when I am finished with one resource, the next either assumes a greater level of knowledge or falls back to basics.

My main resources for learning Java have so far been:
  • Codecademy: My first look at coding was the Javascript track which I began playing with just from curiosity. While this is not the best track to learn programming, at the time this was the only one available. Ruby and Python came later with redesigned tracks to support the programming route as a whole.
  • CS106A Stanford Programming Methodology: Lectures by Professor Mehran Sahami
    This series of lectures is available on Youtube and has assignment material available via the Stanford website. This course first introduced me to Java with Karel, the little robot.
  • Java - An introduction to Problem Solving and Programming: Walter Savitch (5th Edition)
    This textbook was donated to me by a work colleague who had taken the course as part of her university education but had no interest in pursuing it further. The book helped me to move away from the safe environment of Stanford's custom Java work space and onto making my own applications within Eclipse. I am currently using Eclipse Luna version 4.4.1
  • TheCherno: Youtube Game Programming series
    This series was a love/hate one, I enjoyed the coding and following along with a project and being able to tinker was very fun, but I think while the aim was for newer programmers to use this series as an introduction to game programming, it sometimes left me wondering what the heck I was doing. I stopped following this series after about 60 episodes but it definitely contributed to inspiring my continuation of studies.
  • After a period of stagnation and loss of direction, I finally found Head First Java, which took a couple of attempts for me to work with. At first I found the quirky sense of humor to be annoying and tired of it. It took another couple of months before I gave it another try (following some reddit advice) and got through my brick wall.

Recently my studies in Java and Android have also been accompanied by a read through of Fundamentals of Game Design by Ernest Adams. Reading this has helped me to pin down the vocabulary I need for my designs and also given me new ways to examine the games I draw inspiration from. So far I'm into the third chapter. I plan to give the book a good read through and then return to it when I put my ideas down to make sure I am doing what I need in an industry standard way.

The game I am working on designing and coding is an economic simulation in a food service setting. My ideas have been littered around my apartment in different forms without any direction, but the book is helping me to organize my approach. It's still important to write down or doodle my ideas, but I am now trying to keep the wild "this feature would be amazing!" type ideas from taking up too much time. Once I have a working prototype and my core mechanics working properly, then the features will be tested and discarded or developed as necessary.

I have also been looking into keeping an offline private wiki as a means to keep all ideas and documents I write accessible from one place. For this I have started learning to use a program called Wikidpad. With such little organization so far, there's not much to put into a wiki but as I bring my design ideas together and throw away the garbage, I intend to post snippets of wiki pages for people to read here too.

Simulations

My main interest is in simulations, and as I have gained new skills I have done my best to create small scenarios in code that behave in ways typical of simulations. For instance, once I learned about ArrayList and the QueueBlocking Arrays, I put together a background service in the mini restaurant testing program I have to create parties of guests at random intervals, assigning them to different Queues based on the size of the party, and limiting the combined total number of queueing parties. When a "table" became available, the service (nicknamed the Hostess) would assign an appropriate sized party to the empty table and free up a space in the queue.

More recently, while learning about serialization techniques, I created a mini simulation based on the classic fantasy triangle of damage. Warrior > Ranger > Magic User > Warrior. This is a common strengths/weakness model, most notably for me found in Runescape. The simulation pitted armies of each type into a war where each of the three types is randomly paired into a skirmish with a member of one of the other armies. Their fight gave an outcome and eventually all members of an army died and the results were saved out to a text file.

An example of the output is shown to the right, of a battle between 50 "mobs" per army. It was very fun to tweak some of the stats I had given each class to see how the outcome was affected. Getting the numbers to become pretty fair was surprisingly sensitive, as even a slight increase or decrease to a stat sometimes swung the outcome a completely different direction.

This type of simulation taught me a lot about how to work with arrays and random number generation. Having to check the arrays for "dead" mobs and delete them, creating damage and damage absorption that is calculated on the fly in each skirmish and even adding in a dodge and accuracy stat really mixed up the outcomes.

Starting simulation: Number of Combatants per army = 500
Ending simulation: Number of Skirmishes = 2806
Time taken: 0.279sec


Moving forward

My intention with this blog is to create a place for new programmers to look to see my trials and tribulations. If anyone can gather any knowledge, resources or inspiration from me then this blog will have served a purpose. For my own needs, I want to use this as a place to summarize my studies, hold myself accountable, and also to see where I was at a particular stage of my journey. Please feel free to get in touch if you have any questions or comments. Thanks for reading!

Saturday, 22 November 2014

Github, the Git and The Table State

At the suggestion of a guest at my own place of work, I got myself looking at Git this week. While I admit so far I have been using it as a GUI based, upload my work when I fancy it machine with no branches, I do plan to make fuller use of it soon. While in the super early stages of my concept, I have no need of branches as I am literally treating my gamedev environment as a bouncy house for programming. I'm having fun creating and solving problems and the future is still hazy as to the end product. While I would love for the program to be a success, I have not given myself any promises that this will be a masterpiece. Should my interest head in a different direction based on what I learn during the course of this work, I'm happy to let it go and move on.

While unfinished work is probably the biggest time waste for many programmers, I have taken the view that any time spent working on my project is constructive. Any ideas that make it into the program are successes and the failed ones are lessons.

So, this week I have been working a lot IRL so my time has been spent planning the Table Service aspect of my game. Working with time in Java was an initial hurdle but didn't require too much googling to ensure I was getting the numbers I needed in the format that worked for me. Each guest will be able to generate a set of times which state how long an aspect of their stay will take. John might take two minutes to eat, but Sally might take twenty five. Using this knowledge, the game is able to check for an "all ready" like state, by comparing the state of each guest and acting when all of them match. Using this system requires a set of enum types for the Guest and also for the Table to use as state markers which can be looked at by the other Entities. States in this way happen to be far more effective for the long list of possible states than boolean values had been, as rather than turning one value to true and another to false, the overall state simply switches. This makes a list of instructions much more safe to run as the state can only be one at a time, and no accidentally crosslined booleans will throw me off.


 if(!isActive){  
return;
}
elapsedTime = timeSat + System.currentTimeMillis();

if(state == guestState.sat){
if(startOrderTimer <= 0) startOrderTimer = System.currentTimeMillis();
if(startDrinkOrderTimer <= 0){
startDrinkOrderTimer = System.currentTimeMillis();
}
if(System.currentTimeMillis() - startDrinkOrderTimer > drinkOrderTime){
state = guestState.drinkOrderReady;
}
} else {
return;
}

if(state == guestState.drinkOrderReady){
// when Orders system implemented, fill in order creation here
}


if(state == guestState.drinkOrderTaken){
if(startOrderTimer <= 0){
startOrderTimer = System.currentTimeMillis();
}
if(System.currentTimeMillis() - startOrderTimer >= orderTime){
state = guestState.foodOrderReady;
}
}
In this early example of a guests update method you can see that the state is modified when criteria are met such as an elapsed time and manage progression through a typical service by acting as flags that the table can look for in each guest to create a Task that can then be acted upon by a Staff entity.

The table itself is able to scan through any number of occupying guests in order to check that all guests are in the same state, as shown here.
 private void getGuestStates() {  
if(guests[0].getState() == guestState.sat){
return;
}
Guest.guestState[] states = new Guest.guestState[guests.length];
for (int i = 0; i < guests.length; i++) {
states[i] = guests[i].getState();
}

Guest.guestState temp1 = guests[0].getState();
for (Guest.guestState state : states) {
Guest.guestState temp = state;
if (temp1 == temp) {
temp1 = temp;
} else {
return;
}

System.out.println("Table has determined that all guests' states match: " + state);
}
}
The initial state of guestState.sat will progress from within the Guest so if this state is in place then we save cpu time by exiting the getGuestStates() method. Checking against a fixed array index guests[0] is not a problem as a guests array is not able to have fewer than 1 entry, as 1 is the minimum number of guests in a group (which seems redundant to have a group of 1, but this is simply a container for the guests to proceed into the restaurant queuing system).

Once the basic framework for the states is finished I will make all new table placeholder sprites to help show the state visually. This may be a layered approach using the base table and then an "items on table" type layer such as is used in RPGMaker, but that will come in its own time. I have 3 days booked off this coming week and hope to spend a good chunk of them coding. Until then!

Sunday, 16 November 2014

Mouse Input and UI Ideas

Today I managed to finish implementing a simple mouse tracker for my game. It takes the location of the mouse on the game window, applies the offset made by the "player" movement, and adjusts for the scale of the game (since the game is a small scale and scaled up into a larger window).

An issue I was having was that as the update method for each table is run at 60 Updates per second, the actions taken when the mouse is clicked were also happening 60 times. To avoid this I added a clickLock, which disables a table from being clicked again for a second. The update method then decreases the lock each cycle until it hits zero.

           if(Mouse.getButton() == 1 && clickLock <= 0){  
if(Mouse.getX() + Screen.getxOffset() >= x
&& Mouse.getX() + Screen.getxOffset() < x + sprite.SIZE
&& Mouse.getY() + Screen.getyOffset() >= y
&& Mouse.getY() + Screen.getyOffset() < y + sprite.SIZE){
timer += 300;
clickLock += 60;
}
}

This snippet is my way of debug adding a state change to the table that is clicked. At the moment the tables update based on an increment per update and switched based on time passed in this manner. In future the tables cycle will update state based on the time and the personal preferences of the guests.
Each guest will be created with a set of randomly generated times such as how long it takes them to make an order, to eat and any "sitting and chilling" time after the service ends. These numbers will create some variation between tables as they will not all sit and end in a predictable pattern. If your group consists of two guests and one takes longer to order, they will both have to wait for an order to be placed. If you have a table of four people and they all decide quickly, the amount of time before an order can be made could be much shorter. In many games based on "cafe" or "restaurant" settings, the guests are very copy paste and fall into guest "types". I would rather have a guest be defined by their own set of preferences and also variables such as cash on hand and time available. A guest who is trying to get a quick bite should be seen to be ordering, eating and leaving quicker than a guest who is in for a social meal.

My noteboook, ideas on UI and button themes
My first notebook page was taken up by some brief ideas on how to add buttons to my UI. I had been playing around with MouseListener and when I hit a bump (NOO! Don't run that code nine thousand times a second!) I took some time off to doodle down some ideas. I hadn't given much thought to the buttons layout yet since I started this project off wanting to make an android app with touch controls (and notably smaller screen space for UI). When I began to narrow down what my influences for the game were, I thought about the way those games handled buttons. The left column of my notes tackle how I can keep a status bar accessible at all times for the player to see general information. Things like a clock and a rating, a countdown timer for timed goals, maybe even an income target and percentage to target bar. While some information is useful in all views, I had the idea that it could present slightly tailored information depending on the object or actor in focus. For example, if I click a manager, or a bartender, or a guest I should see different information that relates to their role and state. If i have nothing selected, a rating bar could show my overall rating, for a waiter, their individual performance rating for the day/week/month, and for a guest perhaps a rating on their experience so far.

Keeping this information in the lower left will keep it away from the main action in center screen but not out of the way enough to be a hindrance to glance at. Keeping status related, non-interactive information at the base of the screen should be natural for many users, while any modifiable or quick changing status on the upper portion of the screen.

The right side of the page was a few ideas I had about button types(management, lists, menu edits etc), while the next doodle was an idea I had about using Aura Buttons such as in World of Warcraft and other RPG games to switch between styles of play. For example a moving around mode, an inspection and statistics mode or simply a way to switch between controls relating to staff, management and logistics. This may add a way to switch input without having to find and select certain actor types, and instead control the game as a whole. An example of this could be that in "waiter" mode, you are able to click on flagged tables and service stations to prompt a staff member to act sooner on that task, while in management mode you are able to dish out morale or efficiency buffs to staff and boost the happiness of a group of guests with some fun product knowledge.