bucc toy project: learn programming through game development

Post on 06-Dec-2014

385 Views

Category:

Education

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

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

www.sadafnoor.tk/

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

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 (sadaf2605@gmail.com) with your code or you can directly send pull request to our github repository mentioned in the previous page.

Download, Install, Open JME3

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

2. Install it and

3. Then open it

• File> New Project…

Category: JME3Project: BasicGameNext

Project name of your choiceFinish

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

Left click on .java > Properties >

Write new nameENTER

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 }}

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;

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.

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 {

}

2. Extending what?

2. Inheritance

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?

2. Inheritance

2. Inheritance

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

2. Inheritance

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(!).

2. Inheritance

2. Inheritance

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.

2. Inheritance (why?)

“We have more in common as humans than difference”

2 point to note: i) Commonii)Difference

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

2. Inheritance (why?)

name

agehobby

jobhaveFun()

Gossip() name

agehobby

jobhaveFun()

Gossip()name

agehobby

jobhaveFun()

Gossip()

name

agehobby

jobhaveFun()

Gossip()name

agehobby

jobhaveFun()

Gossip()

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.

2. Inheritance (why?)

name

agehobby

jobhaveFun()

Gossip()

Karate skill money

Fix()arrest() speed

2. Inheritance (how?)

2. Inheritance (how?)

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

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

}

}

2. Inheritance (how?)

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

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

}

}

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…….”);

}

}

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…….”);

}

}

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.}

}

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){

} }

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() {

}

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

} }

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

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

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

}}

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!

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

}}

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);

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 }}

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.

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 }}

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.

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 }}

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 }}

top related