Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (690)
Games in Android Showcase (200)
games submitted by our members
Games in WIP (764)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2 3 ... 10
 1 
 on: 2016-09-25 00:02:29 
Started by xTheGamerPlayz - Last post by FabulousFellini
The camera kind of zooms in and out depending on how far you hit the enemy off the screen.  I love MK, it's one of my all time favorites.  I really liked breaking the boards/stone/ruby, etc. No idea why they got rid of that in the other installments.

This is great if you've never seen it:
<a href="http://www.youtube.com/v/8vmW8FMIxYo?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/8vmW8FMIxYo?version=3&amp;hl=en_US&amp;start=</a>

 2 
 on: 2016-09-24 23:57:31 
Started by xTheGamerPlayz - Last post by xTheGamerPlayz
Well I've never played Smash Bro's so I don't know what you mean by camera, but the explosions are a give =). I was thinking more along the lines of Mortal Kombat type though.

 3 
 on: 2016-09-24 23:46:11 
Started by xTheGamerPlayz - Last post by FabulousFellini
Maybe you could implement cool explosions/effects/camera stuff like in smash bros.  lots of cool stuff going on in that while still a fighting game.

 4 
 on: 2016-09-24 23:41:57 
Started by xTheGamerPlayz - Last post by xTheGamerPlayz
Hm... A fighting game would be cool. It feels like it would be pretty basic. Creating each limb and giving it certain indivisual animations. That way you can jump and punch without creating a whole new animation. These could be fun actually. Thanks.
Also if you are reading this I am still wanting ideas for a later date  Grin

 5 
 on: 2016-09-24 23:18:54 
Started by xTheGamerPlayz - Last post by FabulousFellini
As a 2d game? I can't see how a racing game would be much different than a game of Pong except for more movement, but thanks for the suggestion!

Oh sorry, the racing game was a suggestion for 3d lol.  For 2d, what about a 2 player fighting game?  You would have to implement multiple body parts all working together, might be fun.

 6 
 on: 2016-09-24 23:09:47 
Started by xTheGamerPlayz - Last post by xTheGamerPlayz
As a 2d game? I can't see how a racing game would be much different than a game of Pong except for more movement, but thanks for the suggestion!

 7 
 on: 2016-09-24 23:07:35 
Started by xTheGamerPlayz - Last post by FabulousFellini
Try to make a racing game around a course.  i think that would be fun, but that's just my opinion  Smiley

 8 
 on: 2016-09-24 23:05:56 
Started by FabulousFellini - Last post by FabulousFellini
Sorry to ask this, but I can't really find a solid answer.  For simple 2d games like mine using JavaSound, should I have the sound playing on it's own thread?  Meaning, should I start the sound on it's own thread in the AudioHandler class?  right now I just have a method in the AudioHandler class called handleAudio(), which is called in the main game loop.  It works fine, but I don't know if that's the correct way to do it.

 9 
 on: 2016-09-24 23:03:43 
Started by xTheGamerPlayz - Last post by xTheGamerPlayz
I have been practicing quite a bit with 2d games, and I thought that I would be able to keep doing this for a while. But recently I've noticed that they were getting too simple and repetitive. I used to take a while to create 2d games, but I can now make them all within an hour or so. They are all about the same minus the names of the classes, so I'm here to ask some people for ideas for a bit more complicated 2d games and maybe a simple 3d game as I've been experimenting with those, but have never had any good game ideas. I am no professional or maybe not even moderate , but the fact is that I'm bored and a bit scared that without a new challenge I'll stop and forget most of what I know.

 10 
 on: 2016-09-24 22:48:04 
Started by theOne - Last post by theOne
Yeah I try to rewrite my Inventory  Cranky
So far it´s working and passing all Unittests but the more Testcases I find the more I have to rewrite, not the logic part, but the overall Dependencies.

I have an Item class and one Itemstack, which holds one item and it´s amount.
The Inventory is an List of InventorySlot and this InventorySlot holds an Item or an ItemStack.
Especially that InventorySlot can hold both seems to be problematic. Or that now Item needs to have an currentAmount Method only to be able to have it for the ItemStack.
Or ItemStack now has an isEquippable Method etc...

Furthermore I don´t knew yet if I will distinguish different Materials with an enum, with interface or even with ECS Components.

Any idea how to redo my class dependencies?


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  
public interface IItem {
    String getName();
    ItemType getType();
    boolean isStackable();
    int maxStackCount();
    String getDescription();
    boolean isEquipable();
    void use();
    boolean equals(Object obj);
    long getItemId();
    int getCurrentStackCount();
    void removeAmount(int count);
}

public class MyItem extends AbstractItem {

    public MyItem(String name, int itemId, int maxStackCount) {
        super(name, itemId, maxStackCount);
    }

    public MyItem(String name, int itemId) {
        super(name, itemId);
    }

public class InventorySlot<T extends IItem> {
    public int id;
    private T item;

    public InventorySlot(int id) {
        this.id = id;
    }
    boolean isOccupied() {
        //TODO
        return item != null;
    }
    public void add(T item) {
        this.item = item;
    }
    public T getItem() {
        return this.item;
    }

public abstract class AbstractItem extends AGameObject implements IItem {
    private String name;
    private int itemId,maxStack;
    private boolean isStackable;
   
    AbstractItem(String name, int itemId, int maxStackCount) {
        super();
        this.name = name;
        this.itemId = itemId;
        this.maxStack = maxStackCount;
        if (maxStackCount > 1) this.isStackable = true;
    }

    AbstractItem(String name, int itemId) {
        this(name, itemId, 1);
    }

    //no need for this
    public int getCurrentStackCount() {
        return 1;
    }




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  
public class ItemStack implements IItem {

    long stackId;
    IItem item;
    int currentCount;

    public ItemStack(IItem item) {
        this.item = item;
        this.currentCount = 1;
    }

    @Override
    public void removeAmount(int count) {
        this.remove(count);
    }

    boolean canAdd(IItem item) {
        if (item.equals(item)) {
            return true;
        }
        return false;
    }

    boolean canAdd(ItemStack stack) {
        if (item.equals(stack.item)) {
            return true;
        }
        return false;
    }

    public int getCurrentStackCount() {
        return this.currentCount;
    }

    public boolean add(IItem newItem) {
        //item which wants to be added is not the same as in the stack
        if (!canAdd(item)) return false;

        //this stack is already at maximum Stackvalue
        if (this.currentCount == item.maxStackCount()) return false;
        this.currentCount++;
        return true;
    }

    /**
     * add the itemcount form an stack with the same Item to "this"
     *
     * @param stack the ItemStack  whose count shall be added to this Object
     * @return the updated Itemstack (parameter) or "null" if the to be to be removed count is less than the currentAmount.
     */

    public ItemStack add(ItemStack stack, int transferCount) {
        //item which wants to be added is not the same as in the stack
        if (!canAdd(stack)) return stack;

        //this stack is already at maximum Stackvalue
        if (this.currentCount == item.maxStackCount()) return stack;

        if (stack.currentCount < transferCount) return null;

        //current stack amount + amount, less than maxStack
        //-> add everything from stack to "this"
        if (this.currentCount + transferCount <= item.maxStackCount()) {
            int count = transferCount;
            if (!stack.remove(count)) return null;
            this.currentCount += count;
            //TODO notify that item is null, make  transaction
            return stack;
        } else if (this.currentCount + stack.currentCount > item.maxStackCount()) {
            //"this" is not at maximum amount, but not all of stack can be added
            int count = this.currentCount - transferCount;
            if (!stack.remove(count)) return null;
            this.currentCount += count;
            return stack;
        }
        //Unknown error
        return null;
    }

    public ItemStack add(ItemStack stack) {
        return this.add(stack, stack.currentCount);
    }

    boolean remove(int count) {
        if (this.currentCount - count >= 0) {
            this.currentCount -= count;
            return true;
        } else {
            return false;
        }
        //TODO item less or equal than zero
    }

    public long getId() {
        return stackId;
    }

    boolean isEmpty() {
        if (this.currentCount <= 0) return true;
        return false;
    }
}


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  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
public class Inventory<T extends IItem> {
    Set<InventorySlot> slots = new HashSet<>();
    private int inventoryCols = 1;
    private int inventoryRows = 1;
    private int maxSlots;
    private int maxCols, maxRows;
    private int additionalSpace;

    public Inventory() {
        this(64, 8, 8);
    }

    public Inventory(int rows, int cols) {
        this.inventoryRows = rows;
        this.inventoryCols = cols;
    }

    public Inventory(int size, int maxRows, int maxCols) {
        maxSlots = size;
        this.inventoryCols = Math.max(inventoryCols, maxCols);
        int addRows = (int) Math.ceil(size / inventoryCols);
        this.inventoryRows += addRows;
        this.inventoryRows = Math.min(inventoryRows, maxRows);
        this.maxCols = maxCols;
        this.maxRows = maxRows;
    }

    public boolean add(T item) {
        InventorySlot usedSlot = null;
        if (item.isStackable()) {
            usedSlot = this.slots.stream().filter(x -> x.getItem().getItemId() == item.getItemId() && x.getItem().maxStackCount() > x.getItem().getCurrentStackCount()).findAny().orElse(null);
            //we have an Slot and there can be something added
            if (usedSlot != null) {
                if (usedSlot.getItem() instanceof MyItem) {
                    //already an item of the same type in the inventory, -> create an ItemStack
                    //the new item
                    ItemStack stack = new ItemStack(item);

                    //the old item
                    if (stack.add(usedSlot.getItem())) {
                        //add stack to that slot instead of item
                        usedSlot.add(null);
                        usedSlot.add(stack);
                        return true; //could add another item to the stack
                    }
                } else if (usedSlot.getItem() instanceof ItemStack) {
                    //already an stack of the same item in  the inventory, -> check if can add new items
                    if (((ItemStack) usedSlot.getItem()).add(item)) {
                        //could add another item of the same type
                        return true;
                    }
                }
            }
        }
        //item was not stackable or the stack was already full

        InventorySlot freeSlot = findFreeSlot();
        if (freeSlot == null) return false;
        freeSlot.add(item);

        return true;
    }


    /**
     * removes an item ENTIRELY from the Inventory
     *
     * @param item
     */

    public void remove(T item) {
        InventorySlot slot = this.slots.stream().filter(x -> x.getItem().getItemId() == item.getItemId()).findFirst().get();
        slot.add(null);
    }

    /**
     * removes given amount of an item form the Inventory, only works if amount >1
     *
     * @param item
     * @param amount
     */

    public void remove(T item, int amount) {
        InventorySlot slot = this.slots.stream().filter(x -> x.getItem().getItemId() == item.getItemId()).findFirst().orElse(null);
        slot.getItem().removeAmount(amount);
      //  reaarangeSlots();
    }


    /**
     * deletes InventorySlots which have a item count below 0
     */

    private void reaarangeSlots() {
        this.slots.stream().filter(x -> x.getItem().getCurrentStackCount() <= 0).forEach(null);
    }

    public InventorySlot getSlotByItem(IItem item) {
        return this.slots.stream().filter(x -> x.getItem().getItemId() == item.getItemId()).findFirst().orElse(null);
    }

    /**
     * returns the InventorySlot at the given row/col Position.
     * @param col >=1
     * @param row >=1
     * @return
     */

    public InventorySlot getSlotAt(int col, int row) {
        return this.slots.stream().filter(x -> x.id == col * row).findAny().orElse(null);
    }

    public InventorySlot getSlotAt(int place) {
        return this.slots.stream().filter(x -> x.id == place).findAny().orElse(null);
    }

    /**
     * finds the first InventorySlot without Item. If there is non and the list.size is lower than the maximum Slot count a new Slot will be instaniated and added to the Inventory.
     * @return
     */

    private InventorySlot findFreeSlot() {
        InventorySlot freeSlot = this.slots.stream().filter(x -> !x.isOccupied()).findFirst().orElse(null);
        if (freeSlot == null && slots.size() < getMaxInventorySlots()) {
            for (int i = maxSlots; i >= 1; i--) {
                if (getSlotAt(i) == null) {
                    freeSlot = new InventorySlot(i);
                    this.slots.add(freeSlot);
                    break;
                }
            }
        }
        return freeSlot;
    }

    public int getUsedSlots() {
        return (int) this.slots.stream().filter(x -> x.isOccupied()).count();
    }

    public Set<InventorySlot> getItems() {
        return this.slots;
    }


Edit: deleted some unimportant Methods and getter/setter.
btw: Is the Spoiler tag not working?

Pages: [1] 2 3 ... 10
 
Wave Propagation (152 views)
2016-09-20 13:29:55

steveyg90 (269 views)
2016-09-15 20:41:23

steveyg90 (267 views)
2016-09-15 20:13:52

steveyg90 (304 views)
2016-09-14 14:44:42

steveyg90 (331 views)
2016-09-14 14:42:13

theagentd (365 views)
2016-09-12 16:57:14

theagentd (320 views)
2016-09-12 14:18:31

theagentd (252 views)
2016-09-12 14:14:46

Nihilhis (718 views)
2016-09-01 13:36:54

roseslayer (1287 views)
2016-08-06 11:43:29
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!