SlideShare a Scribd company logo
I wanted to change the clouds/rectangles into an actuall image it doesnt matter the image.
import javax.swing.*;
import java.awt.*;
/**
* Created by Thomas on 11/27/2016.
*/
public class Renderer extends JPanel{
//private static final long serialVersionUID = 1L;
protected void paintComponent(Graphics g) {
Main.main.repaint(g);
}
public static int clamp(int greenValue, int i, int j) {
// TODO Auto-generated method stub
return 0;
}
}
OTHER PART:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;
/**
* Created by Thomas on 11/27/2016.
*/
public class Main implements ActionListener, KeyListener{
public static Main main;
public final int WIDTH = 1400;
public final int HEIGHT = 600;
public HUD Hud;
public Renderer renderer;
public Rectangle character;
public ArrayList cloud;
public Random rand;
public boolean start = false, gameover = false;
public int tick;
public Main() {
JFrame jFrame = new JFrame();
Timer timer = new Timer(20, this);
renderer = new Renderer();
rand = new Random();
jFrame.setTitle("Example");
jFrame.add(renderer);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setSize(WIDTH, HEIGHT);
jFrame.addKeyListener(this);
jFrame.setVisible(true);
cloud = new ArrayList();
character = new Rectangle(200, 220, 20, 20);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
timer.start();
}
public void repaint(Graphics g) {
g.setColor(Color.black);
g.fillRect(0,0, WIDTH, HEIGHT);
g.setColor(Color.blue);
g.fillRect(0, HEIGHT - 100, WIDTH, 100);
g.setColor(Color.green);
g.fillRect(character.x, character.y, character.width, character.height);
if (character.y >= HEIGHT - 100 || character.y < 0) {
gameover = true;
}
for (Rectangle rect : cloud) {
g.setColor(Color.white);
g.fillRect(rect.x, rect.y, rect.width, rect.height);
}
g.setColor(Color.WHITE);
g.setFont(new Font("Times New Roman", 1 ,100));
if (!start) {
g.drawString("Press to start!", 450, HEIGHT / 2);
}
else if (gameover) {
g.drawString("Game Over!", 450, HEIGHT / 2);
}
}
public void addCloud(boolean start) {
int width = 400;
int height = 200;
if (start) {
cloud.add(new Rectangle(WIDTH + width + cloud.size() * 300, rand.nextInt(HEIGHT-120),
80, 100));
}
else {
cloud.add(new Rectangle(cloud.get(cloud.size() - 1).x + 300, rand.nextInt(HEIGHT-120), 80,
100));
}
}
public void flap() {
if (gameover) {
character = new Rectangle(300, 400, 40, 40);
cloud.clear();
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
addCloud(true);
gameover = false;
}
if (!start) {
start = true;
}
else if (!gameover) {
character.y -= 70;
tick = 0;
}
}
@Override
public void actionPerformed(ActionEvent e) {
int speed = 15;
//System.out.println("Space");
if (start) {
for (int i = 0; i < cloud.size(); i++) {
Rectangle rect = cloud.get(i);
rect.x -= speed;
}
for (int i = 0; i < cloud.size(); i++) {
Rectangle rect = cloud.get(i);
if (rect.x + rect.width < 0) {
cloud.remove(rect);
addCloud(false);
}
}
for (Rectangle rect : cloud) {
if (rect.intersects(character)) {
gameover = true;
character.x -= speed;
}
}
tick ++;
if (tick %2 == 0 && character.y < HEIGHT-100)
character.y += tick;
if (gameover && character.y >= HEIGHT - 100) {
character.x -= speed;
}
}
renderer.repaint();
}
public static void main(String args[]) {
main = new Main();
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
flap();
}
}
}
Solution
import java.awt.*; import java.awt.event.*; import java.util.*; public class Animate01
extends Frame implements Runnable { private Image offScreenImage; private
Image backGroundImage; private Image[] gifImages = new Image[6];
//offscreen graphics context private Graphics offScreenGraphicsCtx; private
Thread animationThread; private MediaTracker mediaTracker; private SpriteManager
spriteManager; //Animation display rate, 12fps private int animationDelay = 83; private
Random rand = new Random(System. currentTimeMillis()); public
static void main( String[] args){ new Animate01(); }//end main //--------
-------------------------// Animate01() {//constructor // Load and track the images
mediaTracker = new MediaTracker(this); //Get and track the background //
image backGroundImage = Toolkit.getDefaultToolkit().
getImage("background02.gif"); mediaTracker.addImage( backGroundImage,
0); //Get and track 6 images to use // for sprites gifImages[0] =
Toolkit.getDefaultToolkit(). getImage("redball.gif"); mediaTracker.addImage(
gifImages[0], 0); gifImages[1] = Toolkit.getDefaultToolkit().
getImage("greenball.gif"); mediaTracker.addImage( gifImages[1], 0);
gifImages[2] = Toolkit.getDefaultToolkit(). getImage("blueball.gif");
mediaTracker.addImage( gifImages[2], 0); gifImages[3] =
Toolkit.getDefaultToolkit(). getImage("yellowball.gif"); mediaTracker.addImage(
gifImages[3], 0); gifImages[4] = Toolkit.getDefaultToolkit().
getImage("purpleball.gif"); mediaTracker.addImage( gifImages[4], 0);
gifImages[5] = Toolkit.getDefaultToolkit(). getImage("orangeball.gif");
mediaTracker.addImage( gifImages[5], 0); //Block and wait for all images
to // be loaded try { mediaTracker.waitForID(0); }catch (InterruptedException
e) { System.out.println(e); }//end catch //Base the Frame size on the size //
of the background image. //These getter methods return -1 if // the size is not yet known.
//Insets will be used later to // limit the graphics area to the // client area of the Frame.
int width = backGroundImage.getWidth(this); int height =
backGroundImage.getHeight(this); //While not likely, it may be // possible that the
size isn't // known yet. Do the following // just in case. //Wait until size is known
while(width == -1 || height == -1){ System.out.println( "Waiting for image");
width = backGroundImage. getWidth(this); height = backGroundImage.
getHeight(this); }//end while loop //Display the frame
setSize(width,height); setVisible(true); setTitle( "Copyright 2001, R.G.Baldwin");
//Create and start animation thread animationThread = new Thread(this);
animationThread.start(); //Anonymous inner class window // listener to terminate the
// program. this.addWindowListener( new WindowAdapter(){ public
void windowClosing( WindowEvent e){ System.exit(0);}}); }//end
constructor //---------------------------------// public void run() { //Create and add
sprites to the // sprite manager spriteManager = new SpriteManager( new
BackgroundImage( this, backGroundImage)); //Create 15 sprites from 6 gif //
files. for (int cnt = 0; cnt < 15; cnt++){ Point position = spriteManager.
getEmptyPosition(new Dimension( gifImages[0].getWidth(this), gifImages[0].
getHeight(this))); spriteManager.addSprite( makeSprite(position, cnt %
6)); }//end for loop //Loop, sleep, and update sprite // positions once each 83
// milliseconds long time = System.currentTimeMillis(); while (true) {//infinite
loop spriteManager.update(); repaint(); try { time += animationDelay;
Thread.sleep(Math.max(0,time - System.currentTimeMillis())); }catch
(InterruptedException e) { System.out.println(e); }//end catch }//end while loop
}//end run method //---------------------------------// private Sprite makeSprite( Point
position, int imageIndex) { return new Sprite( this, gifImages[imageIndex],
position, new Point(rand.nextInt() % 5, rand.nextInt() % 5)); }//end
makeSprite() //---------------------------------// //Overridden graphics update method //
on the Frame public void update(Graphics g) { //Create the offscreen graphics //
context if (offScreenGraphicsCtx == null) { offScreenImage =
createImage(getSize().width, getSize().height); offScreenGraphicsCtx =
offScreenImage.getGraphics(); }//end if // Draw the sprites offscreen
spriteManager.drawScene( offScreenGraphicsCtx); // Draw the scene onto the
screen if(offScreenImage != null){ g.drawImage( offScreenImage, 0, 0, this);
}//end if }//end overridden update method //---------------------------------//
//Overridden paint method on the // Frame public void paint(Graphics g) { //Nothing
required here. All // drawing is done in the update // method above. }//end overridden
paint method }//end class Animate01 //===================================//
class BackgroundImage{ private Image image; private Component component;
private Dimension size; public BackgroundImage( Component component,
Image image) { this.component = component; size = component.getSize();
this.image = image; }//end construtor public Dimension getSize(){ return size;
}//end getSize() public Image getImage(){ return image; }//end getImage()
public void setImage(Image image){ this.image = image; }//end setImage() public
void drawBackgroundImage( Graphics g) { g.drawImage( image,
0, 0, component); }//end drawBackgroundImage() }//end class BackgroundImage
//=========================== class SpriteManager extends Vector { private
BackgroundImage backgroundImage; public SpriteManager(
BackgroundImage backgroundImage) { this.backgroundImage =
backgroundImage; }//end constructor //---------------------------------// public Point
getEmptyPosition( Dimension spriteSize){ Rectangle trialSpaceOccupied =
new Rectangle(0, 0, spriteSize.width, spriteSize.height);
Random rand = new Random( System.currentTimeMillis()); boolean empty =
false; int numTries = 0; // Search for an empty position while (!empty &&
numTries++ < 100){ // Get a trial position trialSpaceOccupied.x =
Math.abs(rand.nextInt() % backgroundImage. getSize().width);
trialSpaceOccupied.y = Math.abs(rand.nextInt() % backgroundImage.
getSize().height); // Iterate through existing // sprites, checking if position
// is empty boolean collision = false; for(int cnt = 0;cnt < size();
cnt++){ Rectangle testSpaceOccupied = ((Sprite)elementAt(cnt)).
getSpaceOccupied(); if (trialSpaceOccupied. intersects(
testSpaceOccupied)){ collision = true; }//end if }//end for loop empty =
!collision; }//end while loop return new Point( trialSpaceOccupied.x,
trialSpaceOccupied.y); }//end getEmptyPosition() //---------------------------------//
public void update() { Sprite sprite; //Iterate through sprite list for (int cnt = 0;cnt
< size(); cnt++){ sprite = (Sprite)elementAt(cnt); //Update a
sprite's position sprite.updatePosition(); //Test for collision. Positive // result
indicates a collision int hitIndex = testForCollision(sprite); if (hitIndex >=
0){ //a collision has occurred bounceOffSprite(cnt,hitIndex); }//end if
}//end for loop }//end update

More Related Content

Similar to I wanted to change the cloudsrectangles into an actuall image it do.pdf

Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
Jussi Pohjolainen
 
Task Write a Java program to implement a simple graphics editor tha.pdf
Task Write a Java program to implement a simple graphics editor tha.pdfTask Write a Java program to implement a simple graphics editor tha.pdf
Task Write a Java program to implement a simple graphics editor tha.pdf
cronkwurphyb44502
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
Ankara JUG
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
GCS2013
 
Matching Game In Java
Matching Game In JavaMatching Game In Java
Matching Game In Java
cmkandemir
 
The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]
Nilhcem
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScriptersgerbille
 
Following are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdfFollowing are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdf
anithareadymade
 
The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]
Nilhcem
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Java awt
Java awtJava awt
Reloj en java
Reloj en javaReloj en java
Reloj en java
cathe26
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
Jenchoke Tachagomain
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
arcotstarsports
 

Similar to I wanted to change the cloudsrectangles into an actuall image it do.pdf (20)

Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Task Write a Java program to implement a simple graphics editor tha.pdf
Task Write a Java program to implement a simple graphics editor tha.pdfTask Write a Java program to implement a simple graphics editor tha.pdf
Task Write a Java program to implement a simple graphics editor tha.pdf
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
 
A More Flash Like Web?
A More Flash Like Web?A More Flash Like Web?
A More Flash Like Web?
 
Matching Game In Java
Matching Game In JavaMatching Game In Java
Matching Game In Java
 
The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
662305 LAB13
662305 LAB13662305 LAB13
662305 LAB13
 
Following are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdfFollowing are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdf
 
Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Java awt
Java awtJava awt
Java awt
 
Sbaw091117
Sbaw091117Sbaw091117
Sbaw091117
 
Reloj en java
Reloj en javaReloj en java
Reloj en java
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
 

More from feelinggifts

Chapter 22. Problem 3BCP0 Bookmark Show all steps ON Problem Eminent.pdf
Chapter 22. Problem 3BCP0 Bookmark Show all steps ON Problem Eminent.pdfChapter 22. Problem 3BCP0 Bookmark Show all steps ON Problem Eminent.pdf
Chapter 22. Problem 3BCP0 Bookmark Show all steps ON Problem Eminent.pdf
feelinggifts
 
D Question 11 1 pts A fundamental feature of money that BitCoin fulfi.pdf
D Question 11 1 pts A fundamental feature of money that BitCoin fulfi.pdfD Question 11 1 pts A fundamental feature of money that BitCoin fulfi.pdf
D Question 11 1 pts A fundamental feature of money that BitCoin fulfi.pdf
feelinggifts
 
connect instructions I helg dule 7 Connect seve & Exit ..pdf
connect instructions I helg dule 7 Connect seve & Exit ..pdfconnect instructions I helg dule 7 Connect seve & Exit ..pdf
connect instructions I helg dule 7 Connect seve & Exit ..pdf
feelinggifts
 
COMPUTER ETHICSDiscuss the local and global impact of malware and .pdf
COMPUTER ETHICSDiscuss the local and global impact of malware and .pdfCOMPUTER ETHICSDiscuss the local and global impact of malware and .pdf
COMPUTER ETHICSDiscuss the local and global impact of malware and .pdf
feelinggifts
 
You’re helping a group of ethnographers analyze some oral history da.pdf
You’re helping a group of ethnographers analyze some oral history da.pdfYou’re helping a group of ethnographers analyze some oral history da.pdf
You’re helping a group of ethnographers analyze some oral history da.pdf
feelinggifts
 
A man with type B blood type claims to be biological father of a typ.pdf
A man with type B blood type claims to be biological father of a typ.pdfA man with type B blood type claims to be biological father of a typ.pdf
A man with type B blood type claims to be biological father of a typ.pdf
feelinggifts
 
why should filtrate be used to transfer the residue when the desired.pdf
why should filtrate be used to transfer the residue when the desired.pdfwhy should filtrate be used to transfer the residue when the desired.pdf
why should filtrate be used to transfer the residue when the desired.pdf
feelinggifts
 
Winch of the following is NOT one of the reasons an IO Exception is t.pdf
Winch of the following is NOT one of the reasons an IO Exception is t.pdfWinch of the following is NOT one of the reasons an IO Exception is t.pdf
Winch of the following is NOT one of the reasons an IO Exception is t.pdf
feelinggifts
 
Why is attending to the full scope of drivers critical in implementi.pdf
Why is attending to the full scope of drivers critical in implementi.pdfWhy is attending to the full scope of drivers critical in implementi.pdf
Why is attending to the full scope of drivers critical in implementi.pdf
feelinggifts
 
Which of the following is not a function of interest groups A. to i.pdf
Which of the following is not a function of interest groups A. to i.pdfWhich of the following is not a function of interest groups A. to i.pdf
Which of the following is not a function of interest groups A. to i.pdf
feelinggifts
 
When explaining civil law one would say that it is concemed with disp.pdf
When explaining civil law one would say that it is concemed with disp.pdfWhen explaining civil law one would say that it is concemed with disp.pdf
When explaining civil law one would say that it is concemed with disp.pdf
feelinggifts
 
What is the difference between a short and long branchSolution.pdf
What is the difference between a short and long branchSolution.pdfWhat is the difference between a short and long branchSolution.pdf
What is the difference between a short and long branchSolution.pdf
feelinggifts
 
What is the maximum file size in a FAT32 systemSolutionFirst .pdf
What is the maximum file size in a FAT32 systemSolutionFirst .pdfWhat is the maximum file size in a FAT32 systemSolutionFirst .pdf
What is the maximum file size in a FAT32 systemSolutionFirst .pdf
feelinggifts
 
View transaction list Journal entry worksheet The company paid $510 c.pdf
View transaction list Journal entry worksheet The company paid $510 c.pdfView transaction list Journal entry worksheet The company paid $510 c.pdf
View transaction list Journal entry worksheet The company paid $510 c.pdf
feelinggifts
 
The numeric data types in C++ can be broken into two general categori.pdf
The numeric data types in C++ can be broken into two general categori.pdfThe numeric data types in C++ can be broken into two general categori.pdf
The numeric data types in C++ can be broken into two general categori.pdf
feelinggifts
 
The capillaries at the alveoli Form a respiratory membrane Are spe.pdf
The capillaries at the alveoli  Form a respiratory membrane  Are spe.pdfThe capillaries at the alveoli  Form a respiratory membrane  Are spe.pdf
The capillaries at the alveoli Form a respiratory membrane Are spe.pdf
feelinggifts
 
Select the word or phrase which best matches the description of it..pdf
Select the word or phrase which best matches the description of it..pdfSelect the word or phrase which best matches the description of it..pdf
Select the word or phrase which best matches the description of it..pdf
feelinggifts
 
Robin Hood has hired you as his new Strategic Consultant to help him.pdf
Robin Hood has hired you as his new Strategic Consultant to help him.pdfRobin Hood has hired you as his new Strategic Consultant to help him.pdf
Robin Hood has hired you as his new Strategic Consultant to help him.pdf
feelinggifts
 
Research indicates that online news seekers tend to access topics of.pdf
Research indicates that online news seekers tend to access topics of.pdfResearch indicates that online news seekers tend to access topics of.pdf
Research indicates that online news seekers tend to access topics of.pdf
feelinggifts
 
Read Case Study Room 406 and answer the following questions in 2.pdf
Read Case Study Room 406 and answer the following questions in 2.pdfRead Case Study Room 406 and answer the following questions in 2.pdf
Read Case Study Room 406 and answer the following questions in 2.pdf
feelinggifts
 

More from feelinggifts (20)

Chapter 22. Problem 3BCP0 Bookmark Show all steps ON Problem Eminent.pdf
Chapter 22. Problem 3BCP0 Bookmark Show all steps ON Problem Eminent.pdfChapter 22. Problem 3BCP0 Bookmark Show all steps ON Problem Eminent.pdf
Chapter 22. Problem 3BCP0 Bookmark Show all steps ON Problem Eminent.pdf
 
D Question 11 1 pts A fundamental feature of money that BitCoin fulfi.pdf
D Question 11 1 pts A fundamental feature of money that BitCoin fulfi.pdfD Question 11 1 pts A fundamental feature of money that BitCoin fulfi.pdf
D Question 11 1 pts A fundamental feature of money that BitCoin fulfi.pdf
 
connect instructions I helg dule 7 Connect seve & Exit ..pdf
connect instructions I helg dule 7 Connect seve & Exit ..pdfconnect instructions I helg dule 7 Connect seve & Exit ..pdf
connect instructions I helg dule 7 Connect seve & Exit ..pdf
 
COMPUTER ETHICSDiscuss the local and global impact of malware and .pdf
COMPUTER ETHICSDiscuss the local and global impact of malware and .pdfCOMPUTER ETHICSDiscuss the local and global impact of malware and .pdf
COMPUTER ETHICSDiscuss the local and global impact of malware and .pdf
 
You’re helping a group of ethnographers analyze some oral history da.pdf
You’re helping a group of ethnographers analyze some oral history da.pdfYou’re helping a group of ethnographers analyze some oral history da.pdf
You’re helping a group of ethnographers analyze some oral history da.pdf
 
A man with type B blood type claims to be biological father of a typ.pdf
A man with type B blood type claims to be biological father of a typ.pdfA man with type B blood type claims to be biological father of a typ.pdf
A man with type B blood type claims to be biological father of a typ.pdf
 
why should filtrate be used to transfer the residue when the desired.pdf
why should filtrate be used to transfer the residue when the desired.pdfwhy should filtrate be used to transfer the residue when the desired.pdf
why should filtrate be used to transfer the residue when the desired.pdf
 
Winch of the following is NOT one of the reasons an IO Exception is t.pdf
Winch of the following is NOT one of the reasons an IO Exception is t.pdfWinch of the following is NOT one of the reasons an IO Exception is t.pdf
Winch of the following is NOT one of the reasons an IO Exception is t.pdf
 
Why is attending to the full scope of drivers critical in implementi.pdf
Why is attending to the full scope of drivers critical in implementi.pdfWhy is attending to the full scope of drivers critical in implementi.pdf
Why is attending to the full scope of drivers critical in implementi.pdf
 
Which of the following is not a function of interest groups A. to i.pdf
Which of the following is not a function of interest groups A. to i.pdfWhich of the following is not a function of interest groups A. to i.pdf
Which of the following is not a function of interest groups A. to i.pdf
 
When explaining civil law one would say that it is concemed with disp.pdf
When explaining civil law one would say that it is concemed with disp.pdfWhen explaining civil law one would say that it is concemed with disp.pdf
When explaining civil law one would say that it is concemed with disp.pdf
 
What is the difference between a short and long branchSolution.pdf
What is the difference between a short and long branchSolution.pdfWhat is the difference between a short and long branchSolution.pdf
What is the difference between a short and long branchSolution.pdf
 
What is the maximum file size in a FAT32 systemSolutionFirst .pdf
What is the maximum file size in a FAT32 systemSolutionFirst .pdfWhat is the maximum file size in a FAT32 systemSolutionFirst .pdf
What is the maximum file size in a FAT32 systemSolutionFirst .pdf
 
View transaction list Journal entry worksheet The company paid $510 c.pdf
View transaction list Journal entry worksheet The company paid $510 c.pdfView transaction list Journal entry worksheet The company paid $510 c.pdf
View transaction list Journal entry worksheet The company paid $510 c.pdf
 
The numeric data types in C++ can be broken into two general categori.pdf
The numeric data types in C++ can be broken into two general categori.pdfThe numeric data types in C++ can be broken into two general categori.pdf
The numeric data types in C++ can be broken into two general categori.pdf
 
The capillaries at the alveoli Form a respiratory membrane Are spe.pdf
The capillaries at the alveoli  Form a respiratory membrane  Are spe.pdfThe capillaries at the alveoli  Form a respiratory membrane  Are spe.pdf
The capillaries at the alveoli Form a respiratory membrane Are spe.pdf
 
Select the word or phrase which best matches the description of it..pdf
Select the word or phrase which best matches the description of it..pdfSelect the word or phrase which best matches the description of it..pdf
Select the word or phrase which best matches the description of it..pdf
 
Robin Hood has hired you as his new Strategic Consultant to help him.pdf
Robin Hood has hired you as his new Strategic Consultant to help him.pdfRobin Hood has hired you as his new Strategic Consultant to help him.pdf
Robin Hood has hired you as his new Strategic Consultant to help him.pdf
 
Research indicates that online news seekers tend to access topics of.pdf
Research indicates that online news seekers tend to access topics of.pdfResearch indicates that online news seekers tend to access topics of.pdf
Research indicates that online news seekers tend to access topics of.pdf
 
Read Case Study Room 406 and answer the following questions in 2.pdf
Read Case Study Room 406 and answer the following questions in 2.pdfRead Case Study Room 406 and answer the following questions in 2.pdf
Read Case Study Room 406 and answer the following questions in 2.pdf
 

Recently uploaded

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 

Recently uploaded (20)

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 

I wanted to change the cloudsrectangles into an actuall image it do.pdf

  • 1. I wanted to change the clouds/rectangles into an actuall image it doesnt matter the image. import javax.swing.*; import java.awt.*; /** * Created by Thomas on 11/27/2016. */ public class Renderer extends JPanel{ //private static final long serialVersionUID = 1L; protected void paintComponent(Graphics g) { Main.main.repaint(g); } public static int clamp(int greenValue, int i, int j) { // TODO Auto-generated method stub return 0; } } OTHER PART: import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.util.ArrayList; import java.util.Random; import javax.swing.*; /** * Created by Thomas on 11/27/2016. */ public class Main implements ActionListener, KeyListener{ public static Main main; public final int WIDTH = 1400; public final int HEIGHT = 600; public HUD Hud; public Renderer renderer;
  • 2. public Rectangle character; public ArrayList cloud; public Random rand; public boolean start = false, gameover = false; public int tick; public Main() { JFrame jFrame = new JFrame(); Timer timer = new Timer(20, this); renderer = new Renderer(); rand = new Random(); jFrame.setTitle("Example"); jFrame.add(renderer); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.setSize(WIDTH, HEIGHT); jFrame.addKeyListener(this); jFrame.setVisible(true); cloud = new ArrayList(); character = new Rectangle(200, 220, 20, 20); addCloud(true); addCloud(true); addCloud(true); addCloud(true); addCloud(true); addCloud(true); addCloud(true); addCloud(true); timer.start(); } public void repaint(Graphics g) { g.setColor(Color.black); g.fillRect(0,0, WIDTH, HEIGHT); g.setColor(Color.blue); g.fillRect(0, HEIGHT - 100, WIDTH, 100); g.setColor(Color.green); g.fillRect(character.x, character.y, character.width, character.height);
  • 3. if (character.y >= HEIGHT - 100 || character.y < 0) { gameover = true; } for (Rectangle rect : cloud) { g.setColor(Color.white); g.fillRect(rect.x, rect.y, rect.width, rect.height); } g.setColor(Color.WHITE); g.setFont(new Font("Times New Roman", 1 ,100)); if (!start) { g.drawString("Press to start!", 450, HEIGHT / 2); } else if (gameover) { g.drawString("Game Over!", 450, HEIGHT / 2); } } public void addCloud(boolean start) { int width = 400; int height = 200; if (start) { cloud.add(new Rectangle(WIDTH + width + cloud.size() * 300, rand.nextInt(HEIGHT-120), 80, 100)); } else { cloud.add(new Rectangle(cloud.get(cloud.size() - 1).x + 300, rand.nextInt(HEIGHT-120), 80, 100)); } } public void flap() { if (gameover) { character = new Rectangle(300, 400, 40, 40); cloud.clear(); addCloud(true); addCloud(true); addCloud(true); addCloud(true);
  • 4. addCloud(true); addCloud(true); addCloud(true); addCloud(true); gameover = false; } if (!start) { start = true; } else if (!gameover) { character.y -= 70; tick = 0; } } @Override public void actionPerformed(ActionEvent e) { int speed = 15; //System.out.println("Space"); if (start) { for (int i = 0; i < cloud.size(); i++) { Rectangle rect = cloud.get(i); rect.x -= speed; } for (int i = 0; i < cloud.size(); i++) { Rectangle rect = cloud.get(i); if (rect.x + rect.width < 0) { cloud.remove(rect); addCloud(false); } } for (Rectangle rect : cloud) { if (rect.intersects(character)) { gameover = true; character.x -= speed; } }
  • 5. tick ++; if (tick %2 == 0 && character.y < HEIGHT-100) character.y += tick; if (gameover && character.y >= HEIGHT - 100) { character.x -= speed; } } renderer.repaint(); } public static void main(String args[]) { main = new Main(); } @Override public void keyTyped(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { flap(); } } } Solution import java.awt.*; import java.awt.event.*; import java.util.*; public class Animate01 extends Frame implements Runnable { private Image offScreenImage; private Image backGroundImage; private Image[] gifImages = new Image[6]; //offscreen graphics context private Graphics offScreenGraphicsCtx; private Thread animationThread; private MediaTracker mediaTracker; private SpriteManager spriteManager; //Animation display rate, 12fps private int animationDelay = 83; private Random rand = new Random(System. currentTimeMillis()); public static void main( String[] args){ new Animate01(); }//end main //--------
  • 6. -------------------------// Animate01() {//constructor // Load and track the images mediaTracker = new MediaTracker(this); //Get and track the background // image backGroundImage = Toolkit.getDefaultToolkit(). getImage("background02.gif"); mediaTracker.addImage( backGroundImage, 0); //Get and track 6 images to use // for sprites gifImages[0] = Toolkit.getDefaultToolkit(). getImage("redball.gif"); mediaTracker.addImage( gifImages[0], 0); gifImages[1] = Toolkit.getDefaultToolkit(). getImage("greenball.gif"); mediaTracker.addImage( gifImages[1], 0); gifImages[2] = Toolkit.getDefaultToolkit(). getImage("blueball.gif"); mediaTracker.addImage( gifImages[2], 0); gifImages[3] = Toolkit.getDefaultToolkit(). getImage("yellowball.gif"); mediaTracker.addImage( gifImages[3], 0); gifImages[4] = Toolkit.getDefaultToolkit(). getImage("purpleball.gif"); mediaTracker.addImage( gifImages[4], 0); gifImages[5] = Toolkit.getDefaultToolkit(). getImage("orangeball.gif"); mediaTracker.addImage( gifImages[5], 0); //Block and wait for all images to // be loaded try { mediaTracker.waitForID(0); }catch (InterruptedException e) { System.out.println(e); }//end catch //Base the Frame size on the size // of the background image. //These getter methods return -1 if // the size is not yet known. //Insets will be used later to // limit the graphics area to the // client area of the Frame. int width = backGroundImage.getWidth(this); int height = backGroundImage.getHeight(this); //While not likely, it may be // possible that the size isn't // known yet. Do the following // just in case. //Wait until size is known while(width == -1 || height == -1){ System.out.println( "Waiting for image"); width = backGroundImage. getWidth(this); height = backGroundImage. getHeight(this); }//end while loop //Display the frame setSize(width,height); setVisible(true); setTitle( "Copyright 2001, R.G.Baldwin"); //Create and start animation thread animationThread = new Thread(this); animationThread.start(); //Anonymous inner class window // listener to terminate the // program. this.addWindowListener( new WindowAdapter(){ public void windowClosing( WindowEvent e){ System.exit(0);}}); }//end constructor //---------------------------------// public void run() { //Create and add sprites to the // sprite manager spriteManager = new SpriteManager( new BackgroundImage( this, backGroundImage)); //Create 15 sprites from 6 gif // files. for (int cnt = 0; cnt < 15; cnt++){ Point position = spriteManager. getEmptyPosition(new Dimension( gifImages[0].getWidth(this), gifImages[0]. getHeight(this))); spriteManager.addSprite( makeSprite(position, cnt %
  • 7. 6)); }//end for loop //Loop, sleep, and update sprite // positions once each 83 // milliseconds long time = System.currentTimeMillis(); while (true) {//infinite loop spriteManager.update(); repaint(); try { time += animationDelay; Thread.sleep(Math.max(0,time - System.currentTimeMillis())); }catch (InterruptedException e) { System.out.println(e); }//end catch }//end while loop }//end run method //---------------------------------// private Sprite makeSprite( Point position, int imageIndex) { return new Sprite( this, gifImages[imageIndex], position, new Point(rand.nextInt() % 5, rand.nextInt() % 5)); }//end makeSprite() //---------------------------------// //Overridden graphics update method // on the Frame public void update(Graphics g) { //Create the offscreen graphics // context if (offScreenGraphicsCtx == null) { offScreenImage = createImage(getSize().width, getSize().height); offScreenGraphicsCtx = offScreenImage.getGraphics(); }//end if // Draw the sprites offscreen spriteManager.drawScene( offScreenGraphicsCtx); // Draw the scene onto the screen if(offScreenImage != null){ g.drawImage( offScreenImage, 0, 0, this); }//end if }//end overridden update method //---------------------------------// //Overridden paint method on the // Frame public void paint(Graphics g) { //Nothing required here. All // drawing is done in the update // method above. }//end overridden paint method }//end class Animate01 //===================================// class BackgroundImage{ private Image image; private Component component; private Dimension size; public BackgroundImage( Component component, Image image) { this.component = component; size = component.getSize(); this.image = image; }//end construtor public Dimension getSize(){ return size; }//end getSize() public Image getImage(){ return image; }//end getImage() public void setImage(Image image){ this.image = image; }//end setImage() public void drawBackgroundImage( Graphics g) { g.drawImage( image, 0, 0, component); }//end drawBackgroundImage() }//end class BackgroundImage //=========================== class SpriteManager extends Vector { private BackgroundImage backgroundImage; public SpriteManager( BackgroundImage backgroundImage) { this.backgroundImage = backgroundImage; }//end constructor //---------------------------------// public Point getEmptyPosition( Dimension spriteSize){ Rectangle trialSpaceOccupied = new Rectangle(0, 0, spriteSize.width, spriteSize.height); Random rand = new Random( System.currentTimeMillis()); boolean empty = false; int numTries = 0; // Search for an empty position while (!empty && numTries++ < 100){ // Get a trial position trialSpaceOccupied.x =
  • 8. Math.abs(rand.nextInt() % backgroundImage. getSize().width); trialSpaceOccupied.y = Math.abs(rand.nextInt() % backgroundImage. getSize().height); // Iterate through existing // sprites, checking if position // is empty boolean collision = false; for(int cnt = 0;cnt < size(); cnt++){ Rectangle testSpaceOccupied = ((Sprite)elementAt(cnt)). getSpaceOccupied(); if (trialSpaceOccupied. intersects( testSpaceOccupied)){ collision = true; }//end if }//end for loop empty = !collision; }//end while loop return new Point( trialSpaceOccupied.x, trialSpaceOccupied.y); }//end getEmptyPosition() //---------------------------------// public void update() { Sprite sprite; //Iterate through sprite list for (int cnt = 0;cnt < size(); cnt++){ sprite = (Sprite)elementAt(cnt); //Update a sprite's position sprite.updatePosition(); //Test for collision. Positive // result indicates a collision int hitIndex = testForCollision(sprite); if (hitIndex >= 0){ //a collision has occurred bounceOffSprite(cnt,hitIndex); }//end if }//end for loop }//end update