public boolean hasItem(Point p) { if (inventory.size() == 0) return false; System.out.println("Clicked on (" + p.getX() + ", " + p.getY() + ")"); Point topLeft = new Point(IMG_XOFFSET, IMG_YOFFSET); int totalHeight = IMG_YOFFSET + ITEM_HEIGHT * inventory.size(); if (withinBounds(p, topLeft, ITEM_WIDTH, totalHeight)) { return true; } else { return false; } }
/** * Draws a specific inventory item from the inventory list on the panel * * @param g - graphics layer to draw it on * @param y - drawing at y position on the panel */ private void drawInventory(Graphics g) { for (int i = 0; i < inventory.size(); i++) { String itemName = inventory.getItem(i).toString(); int positionFromTopofPanel = FIRST_LINE + (LINE_HEIGHT * (i + 1)); // WORKING V2 g.drawString(itemName, IMG_XOFFSET, positionFromTopofPanel); drawItem(g, i, itemName); /* working v2 if(itemName.equals("RedKey")) { drawKey(g, i, Color.RED); } else if(itemName.equals("BlueKey")) { drawKey(g, i, Color.BLUE); }else { g.drawString(itemName,IMG_XOFFSET, IMG_YOFFSET *(i+1)); } */ } // testing position // drawKey(g, 0, Color.RED); // drawKey(g, 1, Color.BLUE); }