[8edd04e] | 1 | package main;
|
---|
| 2 |
|
---|
| 3 | import java.awt.Graphics;
|
---|
| 4 | import java.awt.image.BufferedImage;
|
---|
| 5 | import javax.imageio.ImageIO;
|
---|
| 6 | import java.io.IOException;
|
---|
| 7 |
|
---|
| 8 | public class Item {
|
---|
| 9 |
|
---|
| 10 | private String name;
|
---|
| 11 | private ItemType type;
|
---|
| 12 | private BufferedImage img;
|
---|
| 13 | private Point loc;
|
---|
| 14 | private String description;
|
---|
| 15 |
|
---|
| 16 | public Item(String name, ItemType type, String strImg) {
|
---|
| 17 | this.name = name;
|
---|
| 18 | this.type = type;
|
---|
| 19 | this.loc = null;
|
---|
| 20 | try {
|
---|
[b2d7893] | 21 | this.img = ImageIO.read(getClass().getResource("/images/" + strImg));
|
---|
| 22 | } catch (IOException | IllegalArgumentException e) {
|
---|
| 23 | System.out.println("Failed to load image: /images/" + strImg);
|
---|
| 24 | e.printStackTrace();
|
---|
[8edd04e] | 25 | }
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public Item(Item copy, Point loc) {
|
---|
| 29 | this.name = copy.name;
|
---|
| 30 | this.type = copy.type;
|
---|
| 31 | this.img = copy.img;
|
---|
| 32 | this.loc = loc;
|
---|
| 33 | this.description = copy.description;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public Item copy(Point loc) {
|
---|
| 37 | return new Item(this, loc);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public BufferedImage getImg() {
|
---|
| 41 | return this.img;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public String getDescription() {
|
---|
| 45 | return this.description;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public void setDescription(String description) {
|
---|
| 49 | this.description = description;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public boolean isRelic() {
|
---|
| 53 | return (this.type == ItemType.Relic);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public void draw(Graphics g, int playerX, int playerY) {
|
---|
| 57 | g.drawImage(this.img, 375 + this.loc.getX() - playerX, 275 + this.loc.getY() - playerY, null);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public void drawStatic(Graphics g, int x, int y) {
|
---|
| 61 | g.drawImage(this.img, x, y, null);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | public String getName() {
|
---|
| 65 | return this.name;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | public ItemType getType() {
|
---|
| 69 | return this.type;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | public Point getLoc() {
|
---|
| 73 | return this.loc;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public void setLoc(Point loc) {
|
---|
| 77 | this.loc = loc;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|