-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTube.java
More file actions
112 lines (101 loc) · 3.15 KB
/
Tube.java
File metadata and controls
112 lines (101 loc) · 3.15 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
112
//----------------------------------------------------------------------
// Author: Micheal Oyenekan
// Date : 10/23/2020 (Completed)
// File : Tube.java
// Description: The Tube class simply determines the attributes of a tube
// object and what methods act on a single tube.
//-----------------------------------------------------------------------
// NOTE: The information in tubetest.json is still in the file, so when
// the program is run, a print statement appears saying "You've loaded
// a tube at (300, 306)".
//-----------------------------------------------------------------------
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Comparator;
import javax.imageio.ImageIO;
import java.awt.Graphics;
class Tube extends Sprite
{
static BufferedImage image;
Model model;
//-----------------------------------------------------------------------
// Constructor with the x and y positions as parameters. This initializes
// the x and y coordinates of the tube.
//-----------------------------------------------------------------------
public Tube(int pos_x, int pos_y, Model m)
{
this.x = pos_x;
this.y = pos_y;
w = 55;
h = 400;
model = m;
loadTubeImage();
}
@Override
boolean isTube()
{
return true;
}
//-----------------------------------------------------------------------
//
//-----------------------------------------------------------------------
static void loadTubeImage()
{
if (image == null)
{
image = View.loadImage("tube.png");
}
}
//-----------------------------------------------------------------------
//
//-----------------------------------------------------------------------
void draw(Graphics g)
{
g.drawImage(image, x - model.mario.x + model.mario.marioOffset, y, null);
}
//-----------------------------------------------------------------------
//
//-----------------------------------------------------------------------
void update()
{
}
//-----------------------------------------------------------------------
// Method for storing tube attributes to a Json file
//-----------------------------------------------------------------------
Json marshal()
{
Json ob = Json.newObject();
ob.add("x", x);
ob.add("y", y);
return ob;
}
//-----------------------------------------------------------------------
// Method for loading tube attributes from a Json file.
//-----------------------------------------------------------------------
public Tube(Json ob, Model m)
{
x = (int)ob.getLong("x");
y = (int)ob.getLong("y");
w = 55;
h = 400;
model = m;
if (image == null)
loadTubeImage();
System.out.println("You've loaded a tube at (" + x + ", " + y + ")");
}
//-----------------------------------------------------------------------
// Method that determines whether or not a tube has been clicked.
//-----------------------------------------------------------------------
public boolean tubeClicked(int mouse_x, int mouse_y)
{
if (mouse_x < x)
return false;
if (mouse_x > (x + w))
return false;
if (mouse_y < y)
return false;
if (mouse_y > (y + h))
return false;
return true;
}
}