Skip to content

Commit 60033d6

Browse files
authored
Update Item.java
1 parent 696c2fb commit 60033d6

1 file changed

Lines changed: 28 additions & 19 deletions

File tree

src/Item.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Class: Item
22
// Written by: Cat Attack Developers
3-
// Date: May 19, 2024
3+
// Date: April 2, 2024
44
// Description: This class implements an Item. This Item will be drawn onto a graphics panel.
55

66
import java.awt.Component;
@@ -11,18 +11,18 @@
1111
import javax.swing.ImageIcon;
1212

1313
public class Item{
14-
14+
1515
// movement variables
1616
protected int x_coordinate; // These ints will be used for drawing the png on the graphics panel.
1717
protected int y_coordinate; // When the Item's move method is called you should update one or both
18-
// of these instance variables. (0,0) is the top left hand corner of the
19-
// panel. x increases as you move to the right, y increases as you move down.
18+
// of these instance variables. (0,0) is the top left hand corner of the
19+
// panel. x increases as you move to the right, y increases as you move down.
2020

2121
protected int x_direction; // -2 walking left, -1 idle facing left
22-
// 1 idle facing right, 2 walking right
22+
// 1 idle facing right, 2 walking right
2323

2424
protected int y_direction; // 0 : not moving, - 1 : up, 1 : down
25-
25+
2626
protected ImageIcon image; // The ImageIcon is what is actually drawn on the Panel
2727

2828
// method: Default constructor - see packed constructors comments for a description of parameters.
@@ -40,7 +40,7 @@ public Item(){
4040
public Item(int x_coordinate, int y_coordinate, String imageString){
4141
this(x_coordinate, y_coordinate, imageString, 2);
4242
}
43-
43+
4444
// method: Item constructor
4545
// description: Initialize a new Item object.
4646
// parameters: x_coordinate - the initial x-coordinate for Character.
@@ -57,32 +57,32 @@ public Item(int x_coordinate, int y_coordinate, String imageString, int imageSca
5757

5858
x_direction = -2;
5959
y_direction = 0;
60-
60+
6161
ClassLoader cldr = this.getClass().getClassLoader(); // These lines of code load the picture.
6262
String imagePath = imageString;
6363
URL imageURL = cldr.getResource(imagePath);
64-
64+
6565
image = new ImageIcon(imageURL);
66-
66+
6767
Image scaled = image.getImage().getScaledInstance(image.getIconWidth() / imageScale,
6868
image.getIconHeight() / imageScale, Image.SCALE_SMOOTH);
69-
69+
7070
image = new ImageIcon(scaled);
7171
}
72-
72+
7373
// method: collision
7474
// description: This method will return true if the Item collides with the parameter Item.
7575
// return: boolean - true if the two items intersect or collide with each other, otherwise false.
7676
public void changeScale(int imageScale) {
77-
77+
7878
if(image.getIconWidth() > imageScale && image.getIconHeight() > imageScale) {
7979
Image scaled = image.getImage().getScaledInstance(image.getIconWidth() / imageScale,
80-
image.getIconHeight() / imageScale, Image.SCALE_SMOOTH);
81-
80+
image.getIconHeight() / imageScale, Image.SCALE_SMOOTH);
81+
8282
image = new ImageIcon(scaled);
8383
}
8484
}
85-
85+
8686
// method: getBounds
8787
// description: This method will return the coordinates of a rectangle that would be drawn around the
8888
// Item's png. This rectangle can be used to check to see if the Item bumps into
@@ -100,7 +100,7 @@ public Rectangle getBounds(){
100100
public boolean collision(Item otherItem) {
101101
return getBounds().intersects(otherItem.getBounds());
102102
}
103-
103+
104104
// method: getX
105105
// description: This method will return the x-coordinate of the top left hand corner of the the image.
106106
// return: int - the x-coordinate of the top left hand corner of the the image.
@@ -115,7 +115,7 @@ public int getY(){
115115
return y_coordinate;
116116
}
117117

118-
118+
119119
// method: move
120120
// description: This method will modify the Item's x or y (or perhaps both) coordinates. When the
121121
// graphics panel is repainted the Item will then be drawn in it's new location.
@@ -152,7 +152,7 @@ public void stop_Vertical() {
152152
public void moveUp() {
153153
y_direction = -1;
154154
}
155-
155+
156156
public void moveDown() {
157157
y_direction = 1;
158158
}
@@ -171,4 +171,13 @@ public void draw(Graphics g, Component c) {
171171

172172
}
173173

174+
//method: containsPoint
175+
//description: this method is used to identify the bounds of the x and y coordinates of the button in the Graphics Panel.
176+
//parameters: int x and int y
177+
178+
public boolean containsPoint(int x, int y) {
179+
// TODO Auto-generated method stub
180+
return getBounds().contains(x,y);
181+
}
182+
174183
}

0 commit comments

Comments
 (0)