-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSafeArea.java
More file actions
89 lines (71 loc) · 2.37 KB
/
Copy pathSafeArea.java
File metadata and controls
89 lines (71 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Dimension;
import java.util.Random;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.awt.Image.*;
import java.io.*;
import javax.imageio.*;
import java.awt.image.ImageObserver;
public class SafeArea extends Segment{
//Variables ================================================
public static BufferedImage cactus;
public static BufferedImage snowman;
public static ImageObserver observer;
public int[] decorLocations;
//==========================================================
//Constructor ================================================
public SafeArea(int yCoordinateTop){
super();
this.yCoordinateTop=yCoordinateTop;
decorLocations = new int[3];
Random random=new Random();
int j= random.nextInt(350);
int space=0;
for(int i=0; i<3; ++i){
decorLocations[i]=random.nextInt(250)+space;
space+=300;
}
}
//================================================
//Methods================================================
public void update(){//This allows it to implement drawable and be held in an ObjectHolder
}
public void draw(Graphics g, String biome){
Color grass = new Color (0, 50, 20);
g.setColor(grass);
if (biome.equals("Desert")){
Color sand = new Color (223, 193, 99);
g.setColor(sand);
}
if (biome.equals("Tundra")){
Color tundra = new Color (216, 229, 242);
g.setColor(tundra);
}
g.fillRect(0, yCoordinateTop, Frogger.WIDTH, 50);
g.setColor(Color.BLACK);
for (int i=5; i<Frogger.WIDTH; i+=5)//This gives the area some texture
for (int j=yCoordinateTop; j<yCoordinateTop+50; j+=5)
g.drawRect(i, j, 0, 0);
//below here is where decor (cacti and snowmen) are drawn
if (biome.equals("Desert")){
for(int i=0; i<decorLocations.length; ++i){
g.drawImage(cactus, decorLocations[i], yCoordinateTop, observer);
}
}
if (biome.equals("Tundra")){
for(int i=0; i<decorLocations.length; ++i)
g.drawImage(snowman, decorLocations[i], yCoordinateTop, observer);
}
}//draw
public static void readImage(){
try{
snowman=ImageIO.read(new File("Snowman.png"));
cactus=ImageIO.read(new File("Cactus.png"));
}catch (IOException e){}
} //read image
}