0
\$\begingroup\$

I am using Java and the Slick2D library.

I've been testing around with ways to develop a Player Graphical User Interface (GUI) (to show armour, items picked up, weapons equipped, etc). The one problem I am facing however is how to actually make such a system work.

I do not know if Slick2D has a system for creating a Player GUI. I have tried looking up resources on the internet with limited success.

Currently I am thinking of having a BasicGameState named StatePlayerInventory which is the Player Inventory for the player to interact with and I have another BasicGameState named GameState which is the Over-world map and whatever items the player gets from the over-world map, it will render in the Player Inventory GUI. I already have a functionable inventory class and an item class but it isn't able to be rendered because of I have no GUI for the Player currently.

My question is is what does if this kind of system I have is efficient/workable. If there are better ways of creating the Player Gui, I am open to suggestions. Also, if there are online resources on Player Inventories, it would be nice to have access to them.

\$\endgroup\$
2
  • \$\begingroup\$ Do you mean your question in terms of code structure, interactivity, or the graphical look of an in-game UI system? It sounds like an entire book could be written on this as it stands. \$\endgroup\$
    – Anko
    Apr 28, 2016 at 22:01
  • \$\begingroup\$ I would say in terms of code structure and interactivity. \$\endgroup\$
    – BlueJet
    Apr 29, 2016 at 1:03

1 Answer 1

1
\$\begingroup\$

I've stumbled on an answer for creating a decent and easy GUI system from playing around with my game. Currently it draws the images of items onto the GUI screen, but more can be done in the future.

This is essentially how I have it setup:

Over-World State: EntityPlayer {picks up} --> Item (i.e. ItemPotion) --> {goes to} Player Inventory

The Player walks over the item, which picks the item up and then the item goes into the Player's Inventory, which is handled by a List. Here's a code snippet:

    private List<Item> itemList = new LinkedList<Item>();

This handles all the items the Player picks up and stores the items into the Player inventory.

A method that will come into play is the getItemSprite() method:

    public Image getItemSprite (List<Item> itemList) {
    for (int i=0;i<itemList.size();i++) {
        item = itemList.get(i);
        return item.getSprite();
    }
    return null;
}

PlayerInventory State: in the PlayerInvState, I have a method called drawItemsToInventory(Graphics graphics) {} which grabs all the items in the Player Inventory, specifically the sprites of the items, and displays those images onto the gui screen. Here's a code snippet:

public void drawItemsToInventory (Graphics graphics) {
    for (int x=0; x < StateGame.getPlayer().inventory.getItems().size(); x++) {
        if (StateGame.getPlayer().inventory.checkIfEmpty() == true) { //Checks to see if inventory has an item, if not, it won't draw an empty image which could crash the game
            return;
        }
        graphics.drawImage(StateGame.getPlayer().inventory.getItemSprite(StateGame.getPlayer().inventory.getItems()), 8 +((64) * x), 356);
    }
}

This way, whatever items the Player picks up goes to the inventory, and then the PlayerInvState renders those items found in the list, onto the screen. Here's an example of it in action: enter image description here

In this instance, the Player picks up the item in stores it into the inventory.

enter image description here

And in this instance the item sprite is being read and written onto the GUI.

I've just managed to get this to work, it's far from being finished however. But, at least it can be beneficial to those who are struggling to create their own kind of GUI System.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .