Tuesday, June 12, 2012

Isometric 3d Game part 1

In this post I am going to talk about implementing a self playing isometric tank game client. First of all lets focus on what is isometric means?. In the context of gaming, isometric refers to some sort of parallel projection. View point of the game will be rotated and will show a side view of the game. This technique can be used to create a 3d game using 2d game programming features. Following is an image of an isometric view. In an isometric view, camera is angled from 60 degrees to all three xy,yz,zx planes.

This game is a multilayer game. Game has a server which will send game initialization, ending and update messages.
In this post I am describing how to implement  game client. Game client will play the game itself by deciding on messages received by the game server.








                                                       
 A screenshot of game UI. 

                                                         


    Network Layer

    Layers of my game
    In communication layer there is a server that is sending messages and in my game client, there is communicator class which communicates with the server according to a protocol. Follwoing is the protocol specification for the network layer.

    Game Protocol


     Joining the game
     The client will have to send a request to the Server saying  JOIN#

    The server will reply with one of the following replies

    • Join accept message (explained in the next slide)
    • PLAYERS_FULL# - The maximum number of players are already added 
    • ALREADY_ADDED# - The player is already added 
    • GAME_ALREADY_STARTED# - The player tries to join an already started game

     Joining the game – Acceptance
            If the client’s request can be honoured, the server replies with a message in the following format.  S:P: < player location  x>,< player location  y>:#

              For an example the first player to register in a game instance may get a message like,     
              S:P1: 1,1:0#



    Game Initiation
    • A timer gets initiated when the first player resister for a game.
    • When the 5th player joins the game or in the event of the timer expiring, the server will issue the game starting message to all the players that are already registered with the server.
    • As discussed before, any join request by a client hereafter until the end of the game instance will be rejected.
    • The game will be played in a 20x20 grid.
    •   All other map details vary with each game instance and will be sent in the following format
      I:P1; < player location  x>,< player location  y>;: ...: P5< player location  x>,< player location  y>;: < x>,;< x>,;< x>,…..< x>,: < x>,;< x>,;< x>,…..< x>,: < x>,;< x>,;< x>,…..< x>,#
      Moving and Shooting

      Once per second the server will broadcast a global update to all the clients documenting its internal variables about the clients
      G:P1;< player location  x>,< player location  y>;;< whether shot>;;< coins>;< points>: …. P5;< player location  x>,< player location  y>;;< whether shot>;;< coins>;< points>: < x>,,;< x>,,;< x>,,;< x>,,…..< x>,,

    Acquiring coins
    The server will send the following message to signal the appearing event of a pile of coins.

    C:,::#

    • x - <int>
    • y - <int>
    • LT -<int> the time that the pile of coins will be on the map before it automatically disappears
    • Val – value of the coins

    Life Packs
     The server will send the following message to signal the appearing event of a Life Pack.

    L:,:#

    • x - <int>
    • y - <int>
    • LT -<int> the time that the life pack will be on the map before it automatically disappears













    Sunday, June 10, 2012

    Isometric 3d Game part 2

    Communicator Class


    For communicator class i have used a TCPListner class in .net framework. This class has two methods. Read() and sendData().  Read will call in a separate thread which will be called from main thread in main class of the game. 

    Saturday, June 9, 2012

    Isometric 3d Game part 5

    Handling tiles according to the results from AI.

    When considering the XNA game studio architecture, there are two methods called Run() and Update(). Run method is used to initialize the game and start processing events of the game. Game.Update method is where we used to determining the game logic.  This method will be called by the XNA engine itself with a high rate to make sure that there will not be a lagging. 

    Following is my game class which is the controlling class of the game.

    Isometric 3d Game part 3

    I have used an AI to generate the optimal path for movements of the tank. I have adopted A* algorithm for that. Cost of 1 second will be accounted for both turning the tank and moving the tank to a new block.  Path is generated after each movement of the tank. Then only tank can pickup newly appeared coins or life packs near to current position of the tank..

    Thursday, June 7, 2012

    Isometric 3d Game part 4


    Tiles and tile placing




    Ground Tiles






      Object Tiles





    All of these are isometric tiles in 128 128. Following image describes how the real tile image is placed inside the 128x128 image.


     When placing tiles we must calculate the tile positions in proper way. Then it will appears as a 3d grid.
    Suppose we placed a tile with the coordinates a,a for top left corner of the tile, the next tile must be placed down in (a+64,a-32) and up in (a+64,a+32). All the tiles will be represented as a 2d array.

     In the 5th post you will find the code for main game class which includes the algorithm for placing tiles.