-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObstacle.java
More file actions
111 lines (83 loc) · 2.91 KB
/
Copy pathObstacle.java
File metadata and controls
111 lines (83 loc) · 2.91 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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 abstract class Obstacle implements drawable{
//Variables ================================================================================================
public int xPosition;
public int yPosition;
public int velocity;
public int length;
public ImageObserver observer;
public int leftOrRight;//0 drives to the right
//Parent's Constructor ================================================
public Obstacle(int x, int y){
xPosition=x;
yPosition = y;
velocity = 1;
}
public void update(){
xPosition -= velocity;
}//update
public abstract void draw(Graphics g, String biome);
}//Obstacle
//Truck ================================================================================================
class Truck extends Obstacle{
public static BufferedImage truck;
public static BufferedImage flippedTruck;
public Truck(int x, int y, int a){
super(x, y);
this.length = 75;
if (a==0)//Because of its usage in external classes, a will always be 1 or 0. This is just a way of determining which directions the vehicle drives
velocity*=-1;
leftOrRight=a;
}
public void draw(Graphics g, String biome){
if (leftOrRight==1)
g.drawImage(truck, xPosition, yPosition, observer);
else
g.drawImage(flippedTruck, xPosition, yPosition, observer);
}
public static void readImage(){//Reads in the images of the Truck. This is called early in the main method of Frogger
try{
truck=ImageIO.read(new File("Truck.png"));
}catch (IOException e){}
try{
flippedTruck=ImageIO.read(new File("flippedTruck.png"));
}catch (IOException e){}
}
}
class Sedan extends Obstacle{//This class will not be commented because it is essentially the same as Truck (found above). The only difference is its length and the specific images it imports
public static BufferedImage car;
public static BufferedImage flippedCar;
public Sedan(int x, int y, int a){
super(x, y);
this.length = 50;
if (a==0)
velocity*=-1;
leftOrRight=a;
}
public void draw(Graphics g, String biome){
if (leftOrRight==1)
g.drawImage(car, xPosition, yPosition, observer);
else
g.drawImage(flippedCar,xPosition,yPosition,observer);
}
public static void readImage(){
try{
car=ImageIO.read(new File("Car.png"));
}catch (IOException e){}
try{
flippedCar=ImageIO.read(new File("flippedCar.png"));
}catch (IOException e){}
}
}