Tuesday, 28 January 2014

Endless Runner(Part 2)


Ok time to get your hands dirty with code. In game we will have small class to represent cell properties.We will be doing most of the code in one script(Using JS). Lastly I am not saying it is the best approach which I will share, this is what I know there could be better other solutions too.

Create a new JS script name it GameController . First of all we will declare few enumeration type variables for representing directions and type of cell.


enum direction { N, E, W, S, NS, EW}
enum cellType {run,jump,jumpObstacle,duck,left,right}


now create an inner class in GameController name it "CellProperties".  It will hold the information about the cell that will be displayed on screen. The member variables in class will be position,dir,type,model,neighbours,coins,spikes and visited bool.

class CellProperties

{

var position:Vector3;
var dir:direction;
var type:cellType;
var model:GameObject;

var neighbourN:CellProperties;
    var neighbourE:CellProperties;
    var neighbourW:CellProperties;
    var neighbourS:CellProperties;
    var visited=false;
    var coins = new ArrayList();
    var spikes = new ArrayList();
    
    function setValues( cPosition:Vector3,  cDir:direction, cType:cellType)
    {
   
    this.position  = cPosition;
this.dir = cDir;
this.type = cType;
this.neighbourN = null;
this.neighbourE = null;
this.neighbourW = null;
this.neighbourS = null;
    }

};

This is the structure of cell class. In next part I will setup the scene and make the prefebs for the cells. 
Thank you.

Here you can find the source code : https://dl.dropboxusercontent.com/u/79608708/CellClass.js

Monday, 27 January 2014

Endless Runner (Part1):

Ok so lets start with runner game as mentioned in last post. Here is the basic intro for such kind of game.


  • You need to decide camera view.
  • You need an algo to create path dynamically 
  • You need to decide obstacles.
  • You need to decide animations/actions of player e.g run,jump,slide down etc.
For character animations download the max character from unity asset store it is free (https://www.assetstore.unity3d.com/#/content/3012)

The most interesting part would be creating path dynamically. Roughly it would be like you will show specific number of cells/bridges/steps on screen let suppose the number is 10. Now you will track the index of cell on which the player is present. If it is more than 5 you create next 10 cells on screen and delete the 5 cells that are behind the player. In this way you will keep on creating endless path.

I will start posting the code and screenshots from the next post.I hope readers have the  basic understanding of Unity and scripting in C# and JS.
Meanwhile you can update me regarding your queries.

Thank you.
Before getting into any kind of field one should get familiarized with jargon of respective area. Here is a great source for learning basic terminologies of game dev.

http://en.wikipedia.org/wiki/User:Jreynaga/Books/3D_Graphics_Terms

Thank you.
I will be sharing small tutorials regarding game dev in unity in this blog. You can reach me out anytime by dropping an email at h.hassanalikhan@gmail.com

My first game tutorial series would be based on endless runner theme.

Thank you.