Creating a grid of objects

Here’s some stripped down code I use to create a grid of objects in Unity. I’ve used this setup in my Android game Block Blaze when the level is initialised. It’s attached to a Generator object, which also has some other functionality like determining what type of object is created, whether an object needs to be regenerated if its destroyed, what object types are neighbouring, etc.,

Continue reading

Unity3D Development – Rigidbody Reset Force / Motion Code

In my new game I need to be able to give an object in motion a new force (same magnitude) in a random direction with a button press. Here’s my C# solution using Coroutines.
Its working perfectly for me and solves the weird physics problem with stopping/starting using rigidbody.isKinematic.

All these code snippets are in the script attached to the object:

Continue reading

C# – Object Oriented Programming – Lab 5

You are required to develop an App, which acts as a fashion advisor. The program will have a form where you can type in the colour of your top, your pants and your shoes. The program will then give advice on whether the colours match. The program can use any feedback mechanism desirable.

The rules the program should implement are as follows:

The program only understands the colours black, red, blue, green, pink, brown or orange. The program should generate an error if any other colour is typed.

Black top, pants and shoes are fine
Brown shoes, blue pants and any coloured top is fine
Black shoes, blue pants and any coloured top is fine
Brown shoes, brown pants and blue top is fine
Brown shoes, black pants and red top is fine
Black shoes, brown pants and blue top is fine
Black shoes, black pants and blue top is fine
Any coloured shoes with orange pants are fine
Green shoes with any coloured pants and any coloured top, so long as its not red are fine.
All pink is fine.
Never have pink shoes with green pants, but pink shoes with red pants are fine.

Anything other combinations, the program should indicate that the particular combination of colours is not recommended.

Here’s my solution using a WPF app:

This is what the app looks like:

Here’s my solution for it:

Continue reading

C# – Object Oriented Programming – Lab 4

Here is the scenario we want to test:

– Write a “if else” statement that checks to see if bx and by are INSIDE the box. If the point (bx,by) is inside the box, print “Inside” otherwise print “Not inside”. (Hint use && in your answer)

– Test your IF statements with different values of bx and by

Values for the points:

x1,y1 = 100,100, x2, y2 = 120,150, bx, by = 115, 120

Here’s my solution for it:

Continue reading

C# – Object Oriented Programming – Lab 2 (Equation of a Line)

The equation of a line is given as: y = mx +c. Write a program that asks the user for the start and end points of a line and calculates values for m and c:

m = The slope of the line (y2 – y1) / (x2 – x1)
c = The intercept (where the line intersects the y axis (i.e. Where x = 0)

Here’s my solution for it:
Continue reading