bucc toy project: learn programming through game development

50
BUCC Toy Project: Angry Jolly Birds in 3D (3D game) With Md. Sadaf Noor (@sadaf2605) www.sadafnoor.tk/

Upload: sadaf-noor

Post on 06-Dec-2014

382 views

Category:

Education


2 download

DESCRIPTION

Its the slides I am using for the mentorship of our Bucc Toy Project: Learn programming through Game Development.

TRANSCRIPT

Page 1: Bucc  Toy Project: Learn programming through Game Development

BUCC Toy Project:Angry Jolly Birds in 3D (3D game)WithMd. Sadaf Noor (@sadaf2605)

www.sadafnoor.tk/

Page 2: Bucc  Toy Project: Learn programming through Game Development

PROJECT DETAILS

This is the Desktop 3D version of the game Angry Birds. The complete work of this project is and will be done under the flagship of BRAC University Computer Club by a team comprising of bunch of first semester students and a mentor of BRAC University and BRAC University Computer Club.

Repository:https://github.com/sadaf2605/AngryJollyBirds3D

Page 3: Bucc  Toy Project: Learn programming through Game Development

Want to be a part of the journey? Welcome aboard!

If you are following this series of tutorial and want to contribute, then we would also love to work with you. If you are a new coder like other contributor of this project, then you are welcoming you more coordinately.

You can either contact with me ([email protected]) with your code or you can directly send pull request to our github repository mentioned in the previous page.

Page 4: Bucc  Toy Project: Learn programming through Game Development

Download, Install, Open JME3

1. Download it.Download Link: http://hub.jmonkeyengine.org/downloads/

2. Install it and

3. Then open it

Page 5: Bucc  Toy Project: Learn programming through Game Development

• File> New Project…

Page 6: Bucc  Toy Project: Learn programming through Game Development

Category: JME3Project: BasicGameNext

Page 7: Bucc  Toy Project: Learn programming through Game Development

Project name of your choiceFinish

Page 8: Bucc  Toy Project: Learn programming through Game Development

Click: Your Project name> Source Packages>mygame> main.java

Page 9: Bucc  Toy Project: Learn programming through Game Development

Left click on .java > Properties >

Page 10: Bucc  Toy Project: Learn programming through Game Development

Write new nameENTER

Page 11: Bucc  Toy Project: Learn programming through Game Development

0. Creating a boximport com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

public class HelloJME3 extends SimpleApplication { public static void main(String[] args){ HelloJME3 app = new HelloJME3(); app.start(); // start the game } public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin Geometry geom = new Geometry("Box", b); // create cube geometry from the shape Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material mat.setColor("Color", ColorRGBA.Blue); // set color of material to blue geom.setMaterial(mat); // set the cube's material rootNode.attachChild(geom); // make the cube appear in the scene }}

Page 12: Bucc  Toy Project: Learn programming through Game Development

1. Importing packagesimport com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

Page 13: Bucc  Toy Project: Learn programming through Game Development

1. Importing packages

• When we put 2 files in a same directory, java can find it easily

• But it fails when we use files of multiple directory, so we need to import directory.

• Packages are just directories that contains the location where the class is located.

• Just like Scanner, it is located in java.util.Scanner directory, so we import it in the beginning of the file.

Page 14: Bucc  Toy Project: Learn programming through Game Development

2. Extending what?import com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

public class HelloJME3 extends SimpleApplication {

}

Page 15: Bucc  Toy Project: Learn programming through Game Development

2. Extending what?

Page 16: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance

Page 17: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance

• But the problem with our social life inheritance is that if father posses 5 bundle of coins then each of the 5 son will get 1 bundle of coins.

• Inheritance in programming languages are more broad minded, it gives everything of the father to each and every child

• So probably we should introduce a new example, shall we?

Page 18: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance

Page 19: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance

Probably the Land phone that located in your house is an example. Which can be used by other members of the family.

Page 20: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance

Page 21: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance

I am moving my arrows 180’ because since parent has nothing to lose in inheritance parent does not care who is inheriting him. So its child’s responsibility to chose a good parent(!).

Page 22: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance

Page 23: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance

Page 24: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance

So after inheriting every child and their parent will have their own phone at the same time.

By the way, if one child destroy the phone but yet other user won’t get disturbed by it so it is all alike of using own phone.

Page 25: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (why?)

“We have more in common as humans than difference”

2 point to note: i) Commonii)Difference

Page 26: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (why?)

name

agehobby

jobhaveFun()

Gossip() name

agehobby

jobhaveFun()

Gossip()name

agehobby

jobhaveFun()

Gossip()

name

agehobby

jobhaveFun()

Gossip()name

agehobby

jobhaveFun()

Gossip()

Karate skill money

Fix()arrest() speed

Page 27: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (why?)

name

agehobby

jobhaveFun()

Gossip() name

agehobby

jobhaveFun()

Gossip()name

agehobby

jobhaveFun()

Gossip()

name

agehobby

jobhaveFun()

Gossip()name

agehobby

jobhaveFun()

Gossip()

Page 28: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (why?)

Lets generalize all the common things together in a super class, in the parent class and let’s put all the specialization in the sub class, in the child class.

It will help us to DRY out(Do not Repeat Yourself) our code.

Page 29: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (why?)

name

agehobby

jobhaveFun()

Gossip()

Karate skill money

Fix()arrest() speed

Page 30: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (how?)

Page 31: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (how?)

public class parent{int parentVariable=0;void parentMethod(){

System.out.println(“Shouting…….”);

}

}

Page 32: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (how?)

public class child{int childVariable=0;void childMethod(){

System.out.println(“Please, please, please…….”);

}

}

Page 33: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (how?)

public class parent{int parentVariable=0;void parentMethod(){

System.out.println(“Shouting…….”);

}

}

public class child{int childVariable=0;void childMethod(){

System.out.println(“Please, please, please…….”);

}

}

Page 34: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (how?)public class parent{

int parentVariable=0;void parentMethod(){

System.out.println(“Shouting…….”);

}

}

public class child{int childVariable=0;void childMethod(){

System.out.println(“Please, please, please…….”);

}

}

Page 35: Bucc  Toy Project: Learn programming through Game Development

2. Inheritance (how?)

public class child extends parent{

int childVariable=0;

void childMethod(){

System.out.println(“Please, please, please…….”);

}public static void main(String [] args){

//call any parent method you want.}

}

Page 36: Bucc  Toy Project: Learn programming through Game Development

3. Adding methodsImport com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

public class HelloJME3 extends SimpleApplication { public static void main(String[] args){

} }

Page 37: Bucc  Toy Project: Learn programming through Game Development

3. Adding methods

•Void main method always leadspublic static void main(String[] args){

}

•Other method like this follow its order from the main methods. public void simpleInitApp() {

}

Page 38: Bucc  Toy Project: Learn programming through Game Development

4. Instantiate to start

Import com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

public class HelloJME3 extends SimpleApplication { public static void main(String[] args){ HelloJME3 app = new HelloJME3(); app.start(); // start the game

} }

Page 39: Bucc  Toy Project: Learn programming through Game Development

4. Instantiate to start

What we do when we need to access Scanner.class?

•We make instance of it:Scanner sc= new Scanner(……)

•Then we use its method:sc.nextInt()

•The same trickHelloJME3 app = new HelloJME3();app.start(); // start the game

Page 40: Bucc  Toy Project: Learn programming through Game Development

4. Instantiate to start

So how would we access to our HelloJME3.class?

•We make instance of it: HelloJME3 app = new HelloJME3();

•Then we use its method:app.start(); // start the game

Page 41: Bucc  Toy Project: Learn programming through Game Development

5. Adding Geometryimport com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

public class HelloJME3 extends SimpleApplication { public static void main(String[] args){ HelloJME3 app = new HelloJME3(); app.start(); // start the game } public void simpleInitApp() {

Geometry geom = new Geometry("Box", b); // create cube geometry from the shape

}}

Page 42: Bucc  Toy Project: Learn programming through Game Development

5. Adding Geometry

Geometry geom = new Geometry("Box", b);

Geometry manages all the rendering information such as the material type, how the surface should be shaded and the mesh data such as points, lines, faces and maybe altogether.

BUT b is not defined! What is b? Mesh!

Page 43: Bucc  Toy Project: Learn programming through Game Development

6. Adding Meshimport com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

public class HelloJME3 extends SimpleApplication { public static void main(String[] args){ HelloJME3 app = new HelloJME3(); app.start(); // start the game } public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin Geometry geom = new Geometry("Box", b); // create cube geometry from the shape

}}

Page 44: Bucc  Toy Project: Learn programming through Game Development

6. Adding Mesh

Mesh is used to store rendering data. It is a collection of vertices along with data about how the are connected to each other and the faces they form. In fact all visible elements in a scene are represented

by meshes.

One kind of Mesh is box.Box b = new Box(Vector3f.ZERO, 1, 1, 1);

Page 45: Bucc  Toy Project: Learn programming through Game Development

6. Adding Meshimport com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

public class HelloJME3 extends SimpleApplication { public static void main(String[] args){ HelloJME3 app = new HelloJME3(); app.start(); // start the game } public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin Geometry geom = new Geometry("Box", b); // create cube geometry from the shape

rootNode.attachChild(geom); // make the cube appear in the scene }}

Page 46: Bucc  Toy Project: Learn programming through Game Development

7. Adding to rootNode

Everything you initialize and attach to the rootNode in the simpleInitApp(). simpleInitApp() method is part of the scene at the start of the game. You can rotate, translate, and scale objects by manipulating their parent nodes. The Root Node is special: Only what is attached to the Root Node appears in the scene.

Page 47: Bucc  Toy Project: Learn programming through Game Development

import com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

public class HelloJME3 extends SimpleApplication { public static void main(String[] args){ HelloJME3 app = new HelloJME3(); app.start(); // start the game } public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin Geometry geom = new Geometry("Box", b); // create cube geometry from the shape Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material

rootNode.attachChild(geom); // make the cube appear in the scene }}

Page 48: Bucc  Toy Project: Learn programming through Game Development

7. Defining Material

Material definitions provide the "logic" for the materials. Usually a shader that will handle drawing the object, and corresponding parameters that allow configuration of the shader. Material definitions can be created through J3MD files. The J3MD file abstracts the shader and its configuration away from the user, allowing a simple interface where one can simply set a few parameters on the material to change its appearance and the way its handled.

Page 49: Bucc  Toy Project: Learn programming through Game Development

7. Adding Materialimport com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

public class HelloJME3 extends SimpleApplication { public static void main(String[] args){ HelloJME3 app = new HelloJME3(); app.start(); // start the game } public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin Geometry geom = new Geometry("Box", b); // create cube geometry from the shape Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material

geom.setMaterial(mat); // set the cube's material rootNode.attachChild(geom); // make the cube appear in the scene }}

Page 50: Bucc  Toy Project: Learn programming through Game Development

8. Setting a property to Materialimport com.jme3.app.SimpleApplication;import com.jme3.material.Material;import com.jme3.math.Vector3f;import com.jme3.scene.Geometry;import com.jme3.scene.shape.Box;import com.jme3.math.ColorRGBA;

public class HelloJME3 extends SimpleApplication { public static void main(String[] args){ HelloJME3 app = new HelloJME3(); app.start(); // start the game } public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin Geometry geom = new Geometry("Box", b); // create cube geometry from the shape Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material mat.setColor("Color", ColorRGBA.Blue); // set color of material to blue geom.setMaterial(mat); // set the cube's material rootNode.attachChild(geom); // make the cube appear in the scene }}