<< Chapter < Page Chapter >> Page >

Complete program listings

Complete listings of the code discussed in this module are provided in Listing 10 and Listing 11 .

Listing 10 . Source code for the program named Slick0200.
/*Slick0200.java Copyright 2013, R.G.BaldwinThis program shows a baseball coach being attacked by a swarm of vicious ladybugs.This program uses the class named Sprite01 to populate the game window with 1000 ladybug sprites in differentcolors with different sizes that fly around the game window in different directions with different speeds.Tested using JDK 1.7 under WinXP *********************************************************/import org.newdawn.slick.AppGameContainer; import org.newdawn.slick.BasicGame;import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics;import org.newdawn.slick.Image; import org.newdawn.slick.SlickException; import org.newdawn.slick.Color;import java.util.Random; public class Slick0200 extends BasicGame{//Store references to Sprite01 objects here.Sprite01[] sprites = new Sprite01[1000];//Populate this with a ladybug image later. Image image = null;//Populate these variables with the background// image along with the width and height of the // image later.Image background = null; float backgroundWidth;float backgroundHeight;//This object produces random float values for a // variety of purposes.Random random = new Random();//Frame rate we would like to see and maximum frame // rate we will allow.int targetFPS = 60; //----------------------------------------------------//public Slick0200(){//constructor //Set the titlesuper("Slick0200, baldwin"); }//end constructor//----------------------------------------------------// public static void main(String[]args) throws SlickException{AppGameContainer app = new AppGameContainer( new Slick0200(),414,307,false);app.start(); }//end main//----------------------------------------------------// @Overridepublic void init(GameContainer gc) throws SlickException {//Create and save the background image object. Also // compute and save the width and height of the image.background = new Image("background.jpg"); backgroundWidth = background.getWidth();backgroundHeight = background.getHeight(); //Create and save an Image object of a ladybug. The// sprites will wear this image image = new Image("ladybug.png");//Populate the array with references to objects of // the Sprite01 class.for(int cnt = 0;cnt<sprites.length;cnt++){ sprites[cnt]= new Sprite01( image,//ladybug imagebackgroundWidth/2.0f,//initial position backgroundHeight/2.0f,//initial position(random.nextFloat()>0.5) ? 1f : -1f,//direction (random.nextFloat()>0.5) ? 1f : -1f,//direction 0.1f+random.nextFloat()*2.0f,//step size0.1f+random.nextFloat()*2.0f,//step size random.nextFloat()*0.15f,//scalenew Color(random.nextFloat(),//color filter random.nextFloat(),random.nextFloat())); }//end for loopgc.setTargetFrameRate(targetFPS);//set frame rate }//end init//----------------------------------------------------// @Overridepublic void update(GameContainer gc, int delta) throws SlickException{//Do the following for every sprite in the array for(int cnt = 0;cnt<sprites.length;cnt++){ //Ask each sprite to move.sprites[cnt].move();//Ask each sprite to bounce off the edge if // necessary.sprites[cnt].edgeBounce(backgroundWidth,backgroundHeight); }//end for loop}//end update //----------------------------------------------------//public void render(GameContainer gc, Graphics g) throws SlickException{//set the drawing mode to honor transparent pixels g.setDrawMode(g.MODE_NORMAL);//Draw the background to erase the previous picture. background.draw(0,0);//Draw every sprite in the array. for(int cnt = 0;cnt<sprites.length;cnt++){ //Ask the sprite to draw itself.sprites[cnt].draw();}//end for loop }//end render}//end class Slick0200 //======================================================//

Questions & Answers

How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
How can I make nanorobot?
Lily
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
how can I make nanorobot?
Lily
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Anatomy of a game engine. OpenStax CNX. Feb 07, 2013 Download for free at https://legacy.cnx.org/content/col11489/1.13
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Anatomy of a game engine' conversation and receive update notifications?

Ask