Sunday 14 May 2017

Space shooting Game

Here's a small space shooting game that I made. The final result looks like this:


1. The game currently runs on resolution : 1440*2560

2. For debugging purpose, you can choose either use keyboard "ASDW" or joystick mode by enabling or disabling the [Use Joy Stick ]on PlayerControl.cs.
3. basic layout:
    Joy stick is always on the left corner. It shows up when touch the screen on mobile     device or left click on pc platform,


When all lives are used. Game is over, high score and player's score are shown. The player will have the choices of either restart the game or exit the game.



3. Bug logic:
    When player survives for 15 seconds, bugs will be released. 
    Bugs can damage player either by touching the player or releasing projectiles.
    Every 5 seconds the bug dashes to player, every 5 seconds the bug releases      projectiles.
    Projectiles released by bug can be destroyed by player's projectiles.


    When the bug takes damage, some pixels on the bug are darken, if all the          pixels are darken, the bug is dead.

   Player can not gain score by killing the bugs, however, player can picked up the    heart that is dropped by a dead bug. In this way, player gains more live to continue   with the game.

The project files are available for downloading here

The concept psd file is also included.

Wednesday 3 May 2017

small cat ui game

This small ui game let you play with your friend.

The final winner is the one with more pieces on board


you can download the project here

4 hours's shooting Game

This game is created in 4 hours.

The spaceship can be control by the joystick on the bottom.

The spaceship shoot projectile automatically.

Rock can be killed by projectile, once killed, player gain a point.

The player can be killed by rock.

At the end of the game, the UI shows up to let the player see the total score and highest score.

Rocks are randomly generated.


you can find refined version in this blog as well

Fish Feeding Game

This is a quick game creating challenge for 8 hours.

The process includes all the assets making and scripting.

The main gameplay includes:

1. A fish swims randomly in screen area.

2. When feed button clicked fish food is dropped in the tank. When the fish detects the food, it will accelerate and trace food until it eats the food.

3. when feed button is not clicked, click and drag can pan camera.

the final result is here:


source code and art asset can be download here 

There's also a apk file in the folder that can be run on an android device. (only 2560 * 1440 resolution tested).

Tuesday 18 April 2017

Map Generator in Unity C# _ 3 Connecting rooms

There are 2 kinds of  tiles in the map matrix:
1.  not walk-able ,value 1;  2. walk-able, value 0;  
The target is make a walk-able rout, value 0 on the map matrix to  connect all rooms so that they are all accessible.

Normal way of doing it is calculating the distance between two tiles from two rooms and pick the nearest two to make route from as shown on the image below.
But I used another way to do it.
The thought is very simple: each time, enlarge the room by 1 unit until the room meet other rooms. From the contact unit, find the rout. 
To illustrate it: 
Expand the edge tiles
As can be seen. The edge units expand by 1, if there's no contacts, the units created by last expand expand again. This process repeats until all routs are found. Then we come across with another problem: when do we know we have all the routs and stop expanding?

numbers of routs
the target is : making all the rooms accessible, this means all rooms are connected into one area. 
If we have n rooms, at least n-1 routs should be used to connect them. Can we say, if we have n-1 routs all rooms are connected ? Yes, with one condition : not routs are redundant. But what is a redundant rout? A redundant rout is a rout that connects two rooms which are already connected in other way. Here's an example: 

A B C D are four rooms. The line between two rooms stand for a rout. 

As can be seen, in the left example, 1 2 3 connect all four rooms, but in the right example, 1 2 4 can not connect four rooms. D is isolated. Because 4 is a redundant rout that connects room C and B which are already connected through 1 2 and A.
To implement this is very simple. When a new rout is created, two rooms which are connected by the rout is marked as connected. Before creating another new rout, check the two rooms that will be connected by the rout. If there is at least one unconnected room, this is not a redundant rout and can be created.

Illustrate this with the right side example: red rooms are connected rooms. When rout 1 is created , A and B are marked, when rout 2 is created, C is marked as well. Before making new rout 4,  B and C are checked for connected mark, but as B and C are all marked as connected, so rout 4 is not a valid rout, need to find another room.


get the rout from contact point
There is still one problem need to be solve before I can start with designing the functions: 
When we get the contact tile, how to find out other tiles on the rout.
When enlarging the room, a tile get the four neighbor tiles around it. if the neighbor tiles do not belong to the room, they are added to the enlarge list. In other word, each expanded tile has base tiles from where it is created. Thus it is possible to search back all the tiles until we meet the room. The contact tile will have two base tiles. 

In the following example, the contact tile where B and C meet is marked with thick outline. The arrows between the tiles shows from which tile the new tile is created. The number on the tiles stand for index of the tile.  For room C, tile 0 expand to tile 1, tile 1 expand to tile 3 which is the contact tile. To search back, tile 3 's base tile is tile 2, tile 2's base tile is tile 1, tile 1 's base class is tile 0, tile 0 belong to room C. So the rout connect room C and B on C's side is [tile 1, tile 2, tile 3]  

To store this structure, just add two properties to the already existed CoordTile class (The CoordTile class is used to store information for each tiles includes coordinator of the tile, walk-ability of the tile)
CoordTile parent1;
CoordTile parent2;
Use these two properties to store from which tile this tile is enlarged.


Design the functions
1. makeRout : iterate through a list of routs, get each tile from the rout and make                               the tile 0 (walkable) on the map matrix
2. getRoutList : get route by enlarging all rooms until all routs are found
3. swellRoom : enlarge all the rooms by one unit, if there are any contact point, get                             the rout from that point
4. getRoutViaTile : from the contact point search back for all the tiles on the rout.

The result
I close the function of deleting small isolated room, as I want more rooms to test.
As can be seen, all the rooms are connected even it only has one tile.

The Code

you can find the source here:


Monday 10 April 2017

Map Generator in Unity C# _ 2

When to use recursive. 

I have been working on the map generation project / tutorial for a while. My way of doing the tutorial is briefly understand how to solve a problem and then try to figure out the functions / class / structure myself and then go back to read the tutorial code to see if there are any differences.

As I was working on identifying connected area in the map, I broke down my question to several layers:

Function1 : A function that return a list of connected area list.
void getAreaList(int[,] myMap, List<List<CoordTitle>> targetList )
the function iterates map[,], get the unchecked tiles, get the area list that connected to the given tile(Function2)

Function2:  get the area list that connected to the given tile
void getAreaTile(CoordTitle myRefTile, List<CoordTitle> resultTileList)

I started to think about recursive function here, as the algorithm is quite straight forward.  The function search the four neighbor tiles around it, and add the target tiles in the list, then iterate each result tile in the list, call the same function (recursive).

My first try is the recursive function :


It does the job. However I notice that in the tutorial, the author used a queue to store all the target tiles and do the checking process to all that in the queue. 

Here's the new function I made using the tutorial's algorithm.



So I asked myself, why not using recursive but queue in this situation. I did some research on other situations when recursive is the only solution : Tower of Hanoi, Fibonacci Sequence.

One key different element in connecting tiles problem is that : 
the calculation result of tile(n) does not rely on the result of tile(n-1). Instead of recursive, the connecting tiles function does the same thing to a collection, while the elements of collection is changing over time. The key problem to solve is pushing and popping correct elements from the collection.

The source code can be found here

both two functions can be found in the code.

Also, please forgive my Chinese comment, most of the Chinese comment are pseudocode written for myself before implementing the real functions.

Thursday 6 April 2017

map Generator in Unity C# _1

I am currently working on a map generator project.

The generator can generate different setting of maps each time when play is clicked. The setting of the map , eg, width, height, size of the walk-able space can be adjust in the public parameter.

It uses random function to generate a matrix of on and off nodes,
smooth the value of the nodes according to its surround nodes, and finally use Unity mesh generator to create floor and walls.



It is still in a WIP stage.

Thursday 30 March 2017

Use prototype to illustrate your UI design

It is always good if you have the chance to test out the user experience during design stage.

A prototype design specially for design does not require the same amount of consideration on back end hook, however, you can develop  quite a lot of reusable components which can be easily modified into a production components.

Here's a User interface prototype I made. Similar to the final product the prototype is using MCV design pattern to implement, although most of the contents are in the View. Please find the distributed exe file and some of the source code in this following link:

ui prototype and source code






Friday 24 March 2017

Let's steal chickens! - chapter one -chicken chain

Do you remember the old Mario game on GBA that the little green Yoshi taking a long queue of egges and throwing them at the enemies?

I was having a lot of fun of collecting different colours and types of eggs.


I am making same feature in my game in an evil version (evilly smile)

So what's this feature about?

Instead of collecting egges, you collect little birds. You will be able to steal eggs from their mother bird. When your hp is low, you eat them to gain hp (poor chickens!).

Let's take a loot at our chicken in close!


The mother bird is able to generate chickens who follow their mom. When the player attack the chicken, the chicken will be stunned.  Then the player can steal the chicken. The chicken starts follow the player.

To achieve the effect of chicken chain, the chicken need to follow her [target] either the previous chicken in the chain or, if there's no previous chicken, the player or mother bird.

This means, in the chicken class. There will be a Gameobject_target and a function setTarget(). The target need to be set when the chicken is created. setTarget() function can also be useful when the player is trying to steal her from the mother bird.

With the target set, the chicken chain movement will be easy, the chicken class constantly test the distance between it's target and itself. If the distance is larger than a threshold, +the chicken walk towards it's target.

Here's the effect of chicken chain!


Fun to look at , lol!

Here is the movement class of the chicken.

The following step will be create a simple movement for the mother bird , allow the mother bird to spawns chickens over time.


Thursday 16 March 2017

Python tool : create texture atlas

This is the python tool I made to create texture atlas using python.

It is normal to pack multiple textures into one to reduce the draw calls. 

To avoid doing copy and paste the images one by one in photoshop, I wrote a python tool to do it by one click.

This tool is written in Python 2.7 and PIL. It pack all images of the same size into one atlas. As a result, you will have multiple image atlas in a new created "out" folder that locates in the same folder as the original images. The number of image atlas depends on how many different sizes you have for the original images. 

Here's how you use this tool:

Prepare: 
The tool will need python 2.x version and PIL package installed.
Copy the folder [createArrays] and file [runCreateArrays.bat] into the image folder

To run the tool:
1.double click    runCreateArrays.bat 
2.enter CreateArrays.py in the command line tool


About the tool:
By default, create Texture atlars for same size images that are located in the same folder
with [createArrays] and [runCreateArrays.bat]. 

But you can also target another image folder by using   
CreateArrays.py -sp
In this case, the tool will allow you input the absolute path for the target image folder.
To be notice, if the default image folder does not contain any image files, you have to specify
a valid folder to conitue.
By default the output name will be OutputName_size.extension. You can change the name by using
CreateArrays.py -o imageName

The output files will be located in a [out] folder that is created in the target image folder.

Thank you!


you can download the tool here 

Tuesday 7 March 2017

Apple chip 1

I am planing on a small 3D puzzle game using Unity on mobile platform.

The main idea is bringing 3d puzzle into a game.

The game will work like this :

Player get pieces of a whole 3D model by finishing tasks.
The player's aim is collecting the pieces and organize them in a correct order to build a finished 3D model.

There are a few features I am thinking making to enable the game play.
1. Player should be able to rotate the world.
2. Player should be able to drag the piece around on the screen.
3. Player starts with one piece,  this is consider as the main part (MP).
3. When the piece is on its correct place, the piece should be added to MP.
4. When all piece in places, level clear.

Break down:
1. when not clicking on the pieces, rotate camera. Maybe not rotating along Y axis because I don't want the player flip the world up side down.
2a. The pieces and the world :To make things easier, world are cut into 1*1*1 grid. If you give the pieces box boundaries, all the box boundaries are in the same size. Thus I can use a 3d coordinate system to locate where the piece is related to MP (0,0,0).
2b. Move and grid snapping. When moving pieces, piece snap to the grid on axis that it is moving. The wanted axis and direction should be detected by velocity on (x,y,z) use the max one as the target axis. (2d screen coordinate transfer to 3d world coordinate and then check x,y,z)
3.there should be a array recording the MP.

Tuesday 31 January 2017

Simple solution for instantiate/ recycling Game object in Unity

I have been looking for an efficient way of generating bullets and recycling them in Unity environment for a while. And finally, here's a very good and easy solution for that.

Target:
Different mobs shoot different types of bullets towards player. A reusable solution is needed for managing the bullets instantiation and destroying.

Solution:
Instead of adding a script for the mob to generate and destroy bullets, use a bullet pool to manage the generating and destroying of bullets. Every time a mob shoots, the mob class asks the pool for a new bullet. Pool checks itself for available bullets. If there is a bullet, it is passed to the mob, otherwise a bullet need to be instantiated before it is passed to the mob. When the bullet's life cycle is complete (either time out or hit objects) it returns itself to the pool.

Implementation
1.The Pool :
The Pool is an empty Gameobject on the stage. The Pool class has a stack and two public functions: getObject() and returnObject().
stack:
keeps the instances of bullets.
getObject():
check available bullets, instantiate bullets, pop the required bullet out of stack, and return it to Mob as an Gameobject.
 returnObject():
to push the object back to stack.

2.The Mob class:
The Mob class holds an instance of the pool on the stage. At the Moment of attacking, it calls the getObject() function to acquire a bullet and set the transform of the bullet.

3.The Bullet class:
The Bullet class holds an instance of the pool on the stage. It starts to move forward as soon as it is acquired by the Mob. When it hits something, it hides itself and calls the returnObject () function.

the result:

 

the source code for the pool: