Upload
sadaf-noor
View
201
Download
0
Embed Size (px)
Citation preview
BUCC Toy Project:Angry Jolly Birds in 3D (3D game) Day IIwith
MD. SADAF NOOR (sadaf2605)www.sadafnoor.tk
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
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.
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
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 }}
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.
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.
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!
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.
Assets
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”
Setting today's goalSo what’s our goal? And where are we?
TextureLets draw an image file similar to their box,
box.jpeg and put in the Texture directory.
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
Texturei)Get the asset:
Texture t = assetManager.loadTexture("Textures/BrickWall.jpg");
ii) Adding it:
mat.setTexture("ColorMap",t);
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 }}
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.
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 }}
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
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);
}
}
LocationIt produces a cross because We forgot to
change the origin Vector3f.ZERO
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);
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);
}
}
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);
}
}
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?
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);
}
}
Compare
“A goal properly set is halfway reached.”-Zig Ziglar