28
Project: Angry Jolly Birds in 3D (3D game) Day II with MD. SADAF NOOR (sadaf2605) www.sadafnoor.tk

Bucc Toy Project: Learn programming through Game Development

Embed Size (px)

Citation preview

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

BUCC Toy Project:Angry Jolly Birds in 3D (3D game) Day IIwith

MD. SADAF NOOR (sadaf2605)www.sadafnoor.tk

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

PROJECT DETAILSThis 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

Re-cap# We are familiar with methods

# We know little bit about inheritance

# We know how to instantiate

# We have created a box using our JME3

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

Re-capimport 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 6: Bucc Toy Project: Learn programming through Game Development

Why are we so interested about boxes?Simple answer! Not only because it is so simple

to create but also because our Angry and Jolly Birds will love to hit them more often.

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

Why are we so interested about boxes?

How many boxes are there?

Ahh.. Don’t waste your valuable time counting boxes…

Not less than 86 boxes there is.

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

But our boxes are not cool!So lets make it cool first!

How can we make them look cool?

Changing material color to yellow? mat.setColor("Color", ColorRGBA.Yellow);

But it is not enough cool for us, or is it? NO, IT SIMPLY DOES NOT!

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

AssetsSo as you can see there is a “Project Assets” in

each JME3 project by default.

To make our box beautiful we will add textures and as you can see there is a Texture folder in the assets directory. We will keep all the beautiful things in this directory.

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

Assets

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

Setting today's goalMumit Sir always taught us to keep our goal

and our current state together side by side so that we never get misleaded.

In fact:“You can’t reach your goal unless you have one”

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

Setting today's goalSo what’s our goal? And where are we?

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

TextureLets draw an image file similar to their box,

box.jpeg and put in the Texture directory.

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

TextureThere is no magic I said earlier, so it won’t

appear like this, we need to modify our code to make it happen.

We need to get the assets and then add it with the materials. So 2 steps:

i)Getting texture asset

ii)Adding texture to the material

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

Texturei)Get the asset:

Texture t = assetManager.loadTexture("Textures/BrickWall.jpg");

ii) Adding it:

mat.setTexture("ColorMap",t);

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

Textureimport 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;import com.jme3.texture.Texture;

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

Texture t = assetManager.loadTexture("Textures/box.jpg");

mat.setTexture("ColorMap",t);

       //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 17: Bucc Toy Project: Learn programming through Game Development
Page 18: Bucc Toy Project: Learn programming through Game Development

SizeNow resize our box to make it even better!

We are using this code to create a box:

 Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create cube shape at the origin

Vector3f.ZERO is the location of its originAnd rest of the 1,1,1 are its size in x,y,z

coordinate. Lets resize it 3ce in y coordinate.

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

Sizeimport 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;import com.jme3.texture.Texture;

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, 3, 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

Texture t = assetManager.loadTexture("Textures/box.jpg");

mat.setTexture("ColorMap",t);

       //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 20: Bucc Toy Project: Learn programming through Game Development

SizeLets copy our code and give them different

variable names as otherwise it won’t work since we already know how to change size lets apply our knowledge. Make its width 3 times bigger in width rather than in height.

 Box b = new Box(Vector3f.ZERO, 3, 1, 1); // create cube shape at the origin

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

Sizepackage mygame;

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

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

HelloJME3 app = new HelloJME3();app.start();

}

public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 3, 1);Geometry geom = new Geometry("Box", b);Box b2 = new Box(Vector3f.ZERO, 3, 1, 1);Geometry geom2 = new Geometry("Box", b2); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");Texture t = assetManager.loadTexture("Textures/box.jpg");mat.setTexture("ColorMap",t);//mat.setColor("Color", ColorRGBA.Blue);geom.setMaterial(mat);geom2.setMaterial(mat);rootNode.attachChild(geom2); rootNode.attachChild(geom);

}

}

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

LocationIt produces a cross because We forgot to

change the origin Vector3f.ZERO

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

Location

Vector3f.ZERO are nothing but the short hand of writing (0,0,0) as a origin.

If we would have written instead of Vector3f.ZERO then the origin would not have been the same:

new Vector3f(x,y,z)

Box b2 = new Box(new Vector3f(4,4,0), 4, 1, 1);

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

Locationpackage mygame;

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

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

HelloJME3 app = new HelloJME3();app.start();

}

public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 3, 1);Geometry geom = new Geometry("Box", b);Box b2 = new Box(new Vector3f(4,4,0), 4, 1, 1);Geometry geom2 = new Geometry("Box", b2); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");Texture t = assetManager.loadTexture("Textures/box.jpg");mat.setTexture("ColorMap",t);//mat.setColor("Color", ColorRGBA.Blue);geom.setMaterial(mat);geom2.setMaterial(mat);rootNode.attachChild(geom2); rootNode.attachChild(geom);

}

}

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

Locationpackage mygame;

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

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

HelloJME3 app = new HelloJME3();app.start();

}

public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 3, 1);Geometry geom = new Geometry("Box", b);Box b2 = new Box(new Vector3f(4,4,0), 4, 1, 1);Geometry geom2 = new Geometry("Box", b2);Box b3 = new Box(new Vector3f(8,0,0), 1, 3, 1);Geometry geom3 = new Geometry("Box", b3); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");Texture t = assetManager.loadTexture("Textures/box.jpg");mat.setTexture("ColorMap",t);//mat.setColor("Color", ColorRGBA.Blue);geom.setMaterial(mat);geom2.setMaterial(mat);geom3.setMaterial(mat); rootNode.attachChild(geom3); rootNode.attachChild(geom2); rootNode.attachChild(geom);

}

}

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

It is said that:“if you can’t make it, Fake it.”

At this moment we can’t create beautiful pigs in the screen, we will create 3D object next time but lets fill it with something. Maybe a sphere?

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

Adding Spherepackage mygame;

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

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

HelloJME3 app = new HelloJME3();app.start();

}

public void simpleInitApp() { Box b = new Box(Vector3f.ZERO, 1, 3, 1);Geometry geom = new Geometry("Box", b);Box b2 = new Box(new Vector3f(4,4,0), 4, 1, 1);Geometry geom2 = new Geometry("Box", b2);Box b3 = new Box(new Vector3f(8,0,0), 1, 3, 1);Geometry geom3 = new Geometry("Box", b3); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");Texture t = assetManager.loadTexture("Textures/box.jpg");mat.setTexture("ColorMap",t);//mat.setColor("Color", ColorRGBA.Blue);geom.setMaterial(mat);geom2.setMaterial(mat);geom3.setMaterial(mat);

Material pig_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

pig_mat.setColor("Color", ColorRGBA.Green);

pig_geo.setMaterial(pig_mat);

rootNode.attachChild(pig_geo);

pig_geo.setLocalTranslation(new Vector3f(2,6,0));

rootNode.attachChild(geom3); rootNode.attachChild(geom2); rootNode.attachChild(geom);

}

}

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

Compare

“A goal properly set is halfway reached.”-Zig Ziglar