Bucc Toy Project: Learn programming through Game Development
1. BUCC Toy Project:
Angry Jolly Birds
in 3D (3D game)
Day II
with
MD. SADAF NOOR (sadaf2605)
www.sadafnoor.tk
2. 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/Angry
JollyBirds3D
3. 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.
4. 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
5. Re-cap
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
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
}
}
6. 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.
7. 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.
8. 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!
9. Assets
So 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.
11. Setting today's goal
Mumit 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”
13. Texture
Lets draw an image file similar to their box,
box.jpeg and put in the Texture directory.
14. Texture
There 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
15. Texture
i)Get the asset:
Texture t =
assetManager.loadTexture("Textures/BrickWa
ll.jpg");
ii) Adding it:
mat.setTexture("ColorMap",t);
16. Texture
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;
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
}
}
17.
18. Size
Now 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 origin
And rest of the 1,1,1 are its size in x,y,z
coordinate. Lets resize it 3ce in y
coordinate.
19. Size
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;
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
}
}
20. Size
Lets 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
21. Size
package 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);
}
}
23. 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);
24. Location
package 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);
}
}
25. Location
package 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);
26. 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?
27. Adding Sphere
package 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);
}
}