Thursday 22 October 2015

Pong Game Development

As a starter to Unity we were given a two-player Pong game template for us to analyse, but with certain aspects purposely broken or tweaked for us to modify. For example, the controls for player 1 were Q and Z to move the paddle up and down, rather than the conventionally used W and S that most PC games have as their standard control scheme. I modified the values of the C# code in MonoDevelop to change the keybindings, and the controls work much better for both players now.
The Game and Scene view of the modified game.
Likewise the original colour scheme for the game were mainly washed-out and hard to see colours like a greyed-out green. I changed this to make each object standout and be instantly recognisable, such as making the ball a bright green, and the bats red for player 1 and blue for player 2. This is to match the conventional player-coordinated colour schemes used in many local-multiplayer video games across the industry, such as the Mario Party series. It's gotten to a point in the industry where red and blue are standard player 1 and 2 colours, where even PS4 remote control light bars switch their LED light to match the standard colours and let the player instantly know what player they are (without having 1-4 dots light up on a Wii Remote for example and be much more visually pleasant). I also changed the walls to a light cyan colour so they're visibly clear to see, as the default dark colour blended into the background too much.

The default game also moved at a slow pace and the ball commonly got stuck behind the bats. To remedy this I moved the bats further back towards the wall so the ball couldn't get behind them. I then tripled the ball's vertical movement speed but kept the horizontal movement (code extract thisBody.AddForce(new Vector2(forceAmnt * 150, 50));), this was to help prevent the ball constantly bouncing up and down when moving sideways at a slow pace, bogging down the gameplay. I also upped the force of the bats to push the ball faster and stop the ball naturally slowing down due to friction.

Thursday 15 October 2015

Conditional Statements

At its core "a conditional statement is a set of rules performed if a certain condition is met." (Computer Hope, 2015) So essentially you could think of it like a checklist or flowchart the software uses to keep track of what the player does. Here's a simple example I came up with that software could actually check for: Did the player collide with an enemy's hitbox? If yes, kill the player and restart the level and if no, check again see see if they hit it. They are incredibly useful for seperating code into segments for decision-making. Here's an example flowchart below using conditional statements:

Here's a basic conditional statement in flowchart-form, with varying outcomes. (Center for Experimental for Social Science, 2015)
Conditional statements can branch out code in both UE4 with both Blueprints and C++, this helps add variety to the game, from in-depth decision making all the way down to whether or not a player collected an object. In UE4 in particular, the 'Branch' node (shown below) can help games with decision making involved via true and false statements using Boolean data types. It can separate the decisions into two independent outcomes for the user to add depth of choice to their game. (Docs.unrealengine b, 2015) Blueprints also have Switch nodes alongside Branch nodes which serve a different function, and as stated by (Docs.unrealengine b, 2015): "A switch node reads in a data input, and based on the value of that input, sends the execution flow out of the matching (or optional default) execution output. There are several types of switches available: Int, String, Name, and Enum." 


An example of the branch node in UE4, used to separate out Blueprints for conditional statements. (Docs.unrealengine c, 2015)

In C++ there are both 'if...else' and 'switch' statements, both with a different purpose. Firstly, as supported by (W3schools, 2015) if...else statements are used to do different tasks depending on the different scenarios in your code, and there are different types of this statement used in another programming software, Java. And as quoted by (W3schools, 2015): "Very often when you write code, you want to perform different actions for different decisions.
You can use conditional statements in your code to do this.
In JavaScript we have the following conditional statements:
  • Use if to specify a block of code to be executed, if a specified condition is true
  • Use else to specify a block of code to be executed, if the same condition is false
  • Use else if to specify a new condition to test, if the first condition is false
  • Use switch to specify many alternative blocks of code to be executed".
Next-up are switch statements, where as mentioned above can mentioned multiple pieces of code to be used instead of a singular piece instead. This is very useful for typing code efficiently as you can affect multiple segments at once, without having to separate them all out with if statements.

Tuesday 13 October 2015

Variables

As talked about by (Gotealeaf, 2015), a Variable is essentially a name or symbol in computer programming that holds and represents a value (like the number 10, or if something's true or false). Value is what Variable is short for, and it can be further changed or altered in software like Unreal 4 to suit the user's needs. In order to follow professional working practices, good-use of naming conventions must be used when using them, ensuring all the names of variables are similar to each other in format (such as having Time_Start and Time_End, keeping the underscore) and allowing the user to quickly type in each variable when programming, without forgetting how it's set out and referring back and forth to each variable name, thus wasting time.
An easy-to-understand diagram showing what a variable is. It's simple purpose is to hold your information and data, and can be easily swapped out at will! (Learn Programming Language Step By Step, 2012)
In Unreal 4 a user normally creates a Variable inside a Blueprint or C++ class, and can then set their data type (talked about below) and then program in their functions using either the Blueprint or C++ scripting languages. Variables in Blueprints are much easier to access and use due to the natural, visual structure it provides. However C++ is much more flexible and capapble when it comes to using Variables, but it has a very intimidating interface with Microsoft's Visual Studio, putting off a lot of beginners and potential users. (Wiki.unrealengine, 2015)

There are a variety of data types for Variables, ranging from Boolean (true or false statements), to Integers (a number). Here's a table below as provided by (cplusplus, 2015) showing all of the data types for C++ and their functions:


GroupType names*Notes on size / precision
Character typescharExactly one byte in size. At least 8 bits.
char16_tNot smaller than char. At least 16 bits.
char32_tNot smaller than char16_t. At least 32 bits.
wchar_tCan represent the largest supported character set.
Integer types (signed)signed charSame size as char. At least 8 bits.
signed short intNot smaller than char. At least 16 bits.
signed intNot smaller than short. At least 16 bits.
signed long intNot smaller than int. At least 32 bits.
signed long long intNot smaller than long. At least 64 bits.
Integer types (unsigned)unsigned char(same size as their signed counterparts)
unsigned short int
unsigned int
unsigned long int
unsigned long long int
Floating-point typesfloat
doublePrecision not less than float
long doublePrecision not less than double
Boolean typebool
Void typevoidno storage
Null pointerdecltype(nullptr)

It means the user should always pick the right Variable type for the job since they all have their uses for different scenarios. For example; if a game wanted the player character to open a door when they move near it, the Boolean Variable in the door for whether or not it's closed should be set to true, but when they move within range of its hitbox the Variable will then change to false, and thus he door will open. This will be until the player has left the range of the hitbox and aren't constantly colliding with it anymore, changing the value to true again and closing the door.

Each type has a specific purpose and aren't really interchangeable, which is why you must use certain ones. If you're counting a score in a game and keeping track of a specific number that's constantly changing as the player progresses, an int datatype is compulsory to use as "The int keyword denotes an integral type that stores values according to the size and range shown in the following table." (Msdn.microsoft a, 2015) So it would be unwise to use a float datatype instead, since they serve a different purpose and the code simply wouldn't work, because: "The float keyword signifies a simple type that stores 32-bit floating-point values. The following table shows the precision and approximate range for the float type". (Msdn.microsoft b, 2015)


Thursday 8 October 2015

Blueprints vs C++ in Unreal 4 and vs C# in Unity



An alternative to the visually-based flowchart design of Blueprints-based programming, is the code and text-based C++, with both forms being available in Unreal Engine 4 (Unreal 4 b, 2015) they both have their own advantages and disadvantages for a games developer to use. The main big difference is Blueprints are around ten times slower than C++ (JamesG, 2015) and work less efficiently, but because you can actually see a visual representation of the programming in your game with Blueprints, it’s a much more “user-friendly interface for Blueprint visual scripting and other systems” (Unreal 4 c, 2015) and easier to learn. 

The Blueprints System from Unreal 4, screenshotted from (Chad Reddick, 2014)

An Unreal 4 project can contain both C++ and Blueprint programming, as Blueprints are really a friendly exposure of C++ that is easier to grasp. This allows professional developers to efficiently code their games using the most efficient and effective way possible, without just sticking to one style for the entire game project. (cmb, 2014) Overall though both programming methods are efficient, deep and complex enough to get the job done for a variety of games and situations, but with C++ still having the upper-hand when it comes to the high skill-floor and skill-ceiling in more advanced level coding and complexity. (Browett.T, 2014)

The C++ Coding Screen in Unreal 4 (RuBa1987, 2014)
Finally we have another form of programming outside of these two I mentioned, which is Unity's main programming language and is unable to be used in UE4. It's is C#! (pronounced C-sharp, not C-hash!) It can be used for a variety of applications outside of just games like in Java and Microsoft's .NET Development Environments, (Csharp.net-informations, 2015) giving it an edge over the strictly games-based Blueprints scripting. Plus those who are experienced in C++ will be able to pick up C# much faster, as the two are similar in some regards, such as them both: "having large API's and documentation online" and "both having strict compiler conditions which are checked such as array  indexes, initialisation of variables before use, etc." (Tiwari, 2015)

It's also easier to edit code in Unity as a whole than it is in Unreal 4. As when you create a C# script in Unity you can get a preview for what the whole code contains in the Inspector, rather than having to switch to Microsoft's Visual Studio in Unreal 4 just to see the code of each C++ class. Visual Studio as a whole is more inconvenient too, as most PCs will have to install the software separately (usually when suddenly creating a new C++ class being a big hassle), as compared to Unity's MonoDevelop which has a much simpler interface and comes installed with the software too!

Unity's MonoDevelop, a streamlined interface with less clutter than Visual Studio. (Zwodnik, 2015)

Flowcharts and Activity Diagrams



Today we used flowcharts and activity diagrams to draft out a 2d game and collectathon 3d platformer. These are incredibly useful tools to use when planning a game as they allow you to draft out how your project is specifically going to work and also really make you consider how it’s going to be put together. As explained by (sad111463042,2013), these diagrams demand quite a lot of detail when inputting data, and therefore allow you to simulate how the actual programming code for your game will work, as each command leads to the next with various decisions, separations and progression boxes along the way. So once you’ve finished your drafting you’ll end-up with a clear and concise idea of how your game will play out, and it’ll be much easier to write out and insert your programming into the game engine, as you’ll know specifically what to do! Flowcharts also help you communicate your ideas and designs to other people in a clear, visual and readable manner, and are a great way to document all of your ideas before you start.
A flowchart about testing lamp working
A basic example of how a flowchart can be laid out. (Conceptdraw, 2015)



An example of the Blueprint programming interface in Unreal 4- note the very similar design to flowcharts and activity diagrams allowing for a clear view of how the game's logic flows.  (Staraban, 2014)

Some programming systems like Unreal 4’s Blueprints even follow a visually-based flowchart design for programming, making the process even easier, this is listed on Unreal 4’s dedicated AnswerHub (Unreal 4 a, 2015). I will discuss more about Blueprints and their uses compared to C++ in the next post!

Overall upon reflection though I found these planning methods incredibly useful to use and would like to use them further on in the future in order to draft a plan for a game's programming, even though complicated games can be very time consuming when planning this way. I could use other planning methods instead like Pseudo-code. These planning tools should be used by every programmer before they even touch software like Unreal 4, as rather than blindly hooking together blueprints or typing code in C++ with no clear direction, and a vague goal or outcome, the programmer will know exactly what they want to achieve and in what order to do it too simply by following their own plans. That way they can adapt their charts into a code-based form that follows a similar formula.

Bibliography:



sad111463042. 2013. Advantages and Disadvantages of Flowchart. [ONLINE] Available at:https://eternalsunshineoftheismind.wordpress.com/2013/02/20/advantages-and-disadvantages-of-flowchart/. [Accessed 01 October 15].

Unreal 4 a. 2015. Blueprints Visual Scripting. [ONLINE] Available at:https://docs.unrealengine.com/latest/INT/Engine/Blueprints/index.html. [Accessed 01 October 15].

Unreal 4 b. 2015. C++ and Blueprints. [ONLINE] Available at:https://docs.unrealengine.com/latest/INT/Gameplay/ClassCreation/CodeAndBlueprints/index.html. [Accessed 03 October 15].

James.G, 2015. Blueprint Performance Benchmark?. [ONLINE] Available at:https://forums.unrealengine.com/showthread.php?1105-Blueprint-Performance-Benchmark. [Accessed 03 October 15].

Unreal 4 c. 2015. FREQUENTLY ASKED QUESTIONS (FAQ). [ONLINE] Available at:https://www.unrealengine.com/faq. [Accessed 03 October 15].

cmb. 2014. Can I use in one project C++ and Blueprints together ?. [ONLINE] Available at:https://answers.unrealengine.com/questions/19488/can-i-use-in-one-project-c-and-blueprints-together.html. [Accessed 03 October 15].

Browett.T, 2014. WHAT CAN YOU DO WITH BLUEPRINT?. [ONLINE] Available at:https://www.unrealengine.com/blog/what-can-you-do-with-blueprints. [Accessed 03 October 15].


Chad Reddick . 2014. Unreal Engine 4 C++ Tutorial Version 4.0.2: Basic Artificial Intelligence . [ONLINE] Available at: https://www.youtube.com/watch?v=VxvahnKYB8E. [Accessed 08 October 15].
  

RuBa1987 . 2014. C++ Cannot make Int. [ONLINE] Available at: https://answers.unrealengine.com/questions/59762/c-cannot-make-int.html. [Accessed 08 October 15].

Conceptdraw, (2015). Samples of Flowchart. [online] Available at: http://www.conceptdraw.com/How-To-Guide/samples-of-flowchart [Accessed 22 Oct. 2015].

Gotealeaf, (2015). What is a variable in computer programming?. [online] Available at: http://www.gotealeaf.com/books/ruby/read/variables [Accessed 13 Oct. 2015].

Learn Programming Language Step By Step, (2012). Java variable naming rules - Java Tutorials - c4learn.com. [online] Available at: http://www.c4learn.com/java/java-variable-naming-rules/ [Accessed 13 Oct. 2015].

Wiki.unrealengine, (2015). Blueprints, Creating Variables in C++ For Use In BP - Epic Wiki. [online] Available at: https://wiki.unrealengine.com/Blueprints,_Creating_Variables_in_C%2B%2B_For_Use_In_BP [Accessed 13 Oct. 2015].

cplusplus, (2015). Variables and types. [online] Available at: http://www.cplusplus.com/doc/tutorial/variables/ [Accessed 15 Oct. 2015].

Computer Hope, (2015). What is conditional statement?. [online] Available at: http://www.computerhope.com/jargon/c/contstat.htm [Accessed 15 Oct. 2015]. 

Docs.unrealengine b, (2015). Flow Control | Unreal Engine. [online] Available at: https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/FlowControl/index.html#branch [Accessed 15 Oct. 2015]. 

Center for Experimental for Social Science, (2015). III. Conditional Statement and Loops | CESS. [online] Available at: http://cess.nyu.edu/cess-experiments/z-tree-cheat-sheet/ii-conditional-statements-and-loops/ [Accessed 15 Oct. 2015]. 

Csharp.net-informations, (2015). C# Tutorial , C# Help , C# Source Code. [online] Available at: http://csharp.net-informations.com/ [Accessed 18 Oct. 2015].

Tiwari, G. (2015). How similar are C# and C++? - Quora. [online] Quora.com. Available at: https://www.quora.com/How-similar-are-C-and-C++ [Accessed 18 Oct. 2015].

Docs.unrealengine c, (2015). Flow Control | Unreal Engine. [online] Available at: https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/FlowControl/index.html [Accessed 19 Oct. 2015].

W3schools, (2015). JavaScript If...Else Statements. [online] Available at: http://www.w3schools.com/js/js_if_else.asp [Accessed 19 Oct. 2015].

Msdn.microsoft a, (2015). int (C# Reference). [online] Available at: https://msdn.microsoft.com/en-us/library/5kzh1b5w.aspx [Accessed 20 Oct. 2015].

Msdn.microsoft b, (2015). float (C# Reference). [online] Available at: https://msdn.microsoft.com/en-us/library/b1e65aza.aspx [Accessed 20 Oct. 2015].

Staraban.com, (2014). Unreal Engine 4 overview. Features, cons and pros | SERGEY TARABAN. Game developer. | Programming, computer graphics, games and entertainment. [online] Available at: http://staraban.com/en/undeal-engine-4-overview-features-cons-and-pros/ [Accessed 20 Oct. 2015].

Zwodnik, (2015). MonoDevelop. [online] Available at: http://www.zwodnik.com/software/windows/monodevelop/ [Accessed 21 Oct. 2015].

Visual-paradigm a, (2015). Class Diagram - UML. [online] Available at: http://www.visual-paradigm.com/VPGallery/diagrams/Class.html [Accessed 6 Nov. 2015].

Green Apple. (2015). What's the difference between attributes and behaviours?. [online] Uk.answers.yahoo.com. Available at: https://uk.answers.yahoo.com/question/index?qid=20140325103347AAcA7dk [Accessed 6 Nov. 2015].

Visual-paradigm b, (2015). Sequence Diagram - UML Diagrams. [online] Available at: http://www.visual-paradigm.com/VPGallery/diagrams/Sequence.html [Accessed 6 Nov. 2015].

Nishada. (2012). The Complete Guide to UML Diagram Types with Examples. [online] The Creately Blog. Available at: http://creately.com/blog/diagrams/uml-diagram-types-examples/ [Accessed 7 Nov. 2015].

Creately Blog | Diagramming Articles and Tips on How to Draw Diagrams, (2012). UML Diagram Types With Examples. [online] Available at: http://creately.com/blog/diagrams/uml-diagram-types-examples/#CommDiagram [Accessed 7 Nov. 2015].

Codingbat, (2015). Java Arrays and Loops. [online] Available at: http://codingbat.com/doc/java-array-loops.html [Accessed 9 Nov. 2015].

Msdn.microsoft c, (2015). Loops. [online] Available at: https://msdn.microsoft.com/en-us/library/f0e10e56%28v=vs.90%29.aspx?f=255&MSPPError=-2147217396 [Accessed 9 Nov. 2015].

Csharp.net-tutorials, (2015). Introduction to debugging. [online] Available at: http://csharp.net-tutorials.com/debugging/introduction/ [Accessed 12 Nov. 2015].

Msdn.microsoft d, (2015). Error Types (Visual Basic). [online] Available at: https://msdn.microsoft.com/en-us/library/shz02d41.aspx [Accessed 14 Nov. 2015].

Msdn.microsoft e, (2015). try-catch (C# Reference). [online] Available at: https://msdn.microsoft.com/en-GB/library/0yd65esw.aspx [Accessed 14 Nov. 2015].

IgorAherne. (2015). How to make an object kill the player???? - Unity Answers. [online] Answers.unity3d.com. Available at: http://answers.unity3d.com/questions/497465/how-to-make-an-object-kill-the-player.html [Accessed 17 Nov. 2015].

HarshadK, d. (2015). [C#]Collision whit lava kills player (Unity2D) - Unity Answers. [online] Answers.unity3d.com. Available at: http://answers.unity3d.com/questions/805109/ccollision-whit-lava-kills-player-unity2d.html [Accessed 17 Nov. 2015].

TutorialsPoint, (2015). Pointers in C. [online] Available at: http://www.tutorialspoint.com/cprogramming/c_pointers.htm [Accessed 19 Nov. 2015].

Richard.R, 2013. Understanding and Using C Pointers. 1st ed. Sebastapol, CA 95472: O' Reilly. 

Unity3d, (2015). Unity - Sound Effects & Scripting. [online] Available at: https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/sound-effects-scripting [Accessed 24 Nov. 2015].

Docs.unity3d, (2015). Unity - Scripting API:. [online] Available at: http://docs.unity3d.com/ScriptReference/AudioSource.Play.html [Accessed 24 Nov. 2015].

aldonaletto. (2015). Sound Trigger - Unity Answers. [online] Answers.unity3d.com. Available at: http://answers.unity3d.com/questions/297779/sound-trigger.html [Accessed 24 Nov. 2015].

Kryptos. (2015). How to change volume on many audio objects with specific tag ? - Unity Answers. [online] Answers.unity3d.com. Available at: http://answers.unity3d.com/questions/306684/how-to-change-volume-on-many-audio-objects-with-sp.html [Accessed 24 Nov. 2015].

RayCast (2015). Unity - Scripting API:. [online] Docs.unity3d.com. Available at: http://docs.unity3d.com/ScriptReference/Physics.Raycast.html [Accessed 25 Nov. 2015].

AudioSource. (2015). Unity - Scripting API:. [online] Docs.unity3d.com. Available at: http://docs.unity3d.com/ScriptReference/AudioSource.html [Accessed 28 Nov. 2015].

AudioClip, (2015). Unity - Manual: Audio Clip. [online] Available at: http://docs.unity3d.com/Manual/class-AudioClip.html [Accessed 28 Nov. 2015].

AudioListener, (2015). Unity - Manual: Audio Listener. [online] Available at: http://docs.unity3d.com/Manual/class-AudioListener.html [Accessed 29 Nov. 2015].

AudioMixer. (2015). Unity - Manual: Audio Mixer. [online] Docs.unity3d.com. Available at: http://docs.unity3d.com/Manual/AudioMixer.html [Accessed 29 Nov. 2015].

ankit.tiks007. (2015). Player takes damage on collision with an enemy - Unity Answers. [online] Answers.unity3d.com. Available at: http://answers.unity3d.com/questions/412836/player-takes-damage-on-collision-with-an-enemy.html [Accessed 29 Nov. 2015].

Grayson, N. (2015). Pac-Man Ghosts Are Smarter Than You Think. [online] Kotaku. Available at: http://kotaku.com/pac-man-ghosts-are-smarter-than-you-think-1683857357 [Accessed 29 Nov. 2015].

WhatIs, (2015). What is fuzzy logic? - Definition from WhatIs.com. [online] Available at: http://whatis.techtarget.com/definition/fuzzy-logic [Accessed 2 Dec. 2015].

Simpson, C. (2014). Gamasutra: Chris Simpson's Blog - Behavior trees for AI: How they work. [online] Gamasutra. Available at: http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php [Accessed 2 Dec. 2015].

TutorialsPoint b, (2015). Artificial Intelligence Neural Networks. [online] Available at: http://www.tutorialspoint.com/artificial_intelligence/artificial_intelligence_neural_networks.htm [Accessed 10 Dec. 2015].

duck. (2010). Where are the rules of capitalization documented? - Unity Answers. [online] Answers.unity3d.com. Available at: http://answers.unity3d.com/questions/10571/where-are-the-rules-of-capitalization-documented.html [Accessed 8 Dec. 2015].

clunk47. (2015). How to detect collisions in C# - Unity Answers. [online] Answers.unity3d.com. Available at: http://answers.unity3d.com/questions/372595/how-to-detect-collisions-in-c.html [Accessed 14 Dec. 2015].

animationanalyst. (2015). How to detect collisions in C# - Unity Answers. [online] Answers.unity3d.com. Available at: http://answers.unity3d.com/questions/372595/how-to-detect-collisions-in-c.html [Accessed 14 Dec. 2015].

Unity3d, (2015). Unity - Enemy AI. [online] Available at: https://unity3d.com/learn/tutorials/projects/stealth/enemy-ai [Accessed 26 Dec. 2015].

SceneManager. (2016). Unity - Scripting API:. [online] Docs.unity3d.com. Available at: http://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html [Accessed 4 Jan. 2016].