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   
  Show Posts
Pages: [1] 2
1  Game Development / Game Play & Game Design / How to simplify existing Inventory System? on: 2016-09-24 22:48:04
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?
2  Game Development / Networking & Multiplayer / Re: Why Threads for the Client on the Server? on: 2016-09-20 18:28:05
Nope, already got NotregisteredException and figured all of them out.

Adding the Log Level it does not change.

btw, should I make an own Thread for this?..
3  Game Development / Networking & Multiplayer / Re: Why Threads for the Client on the Server? on: 2016-09-20 15:52:30
Yeah... then shall it be still used?

Is there an Condition to send packets over TCP per Kryonet?
always when I try to send one Packet (Class with three Stings) the Client disconnects from the Server.
If I don´t use that Method it says logged into the Server.
I do not get any errors, just a DC.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
 @Test
    public void connectToServerTest() {
        LoginServer server = LoginServer.getInstance();
        MyClient client = MyClient.getInstance();

        while (!client.client.isConnected()) {

        }
        client.tryToLogin("test","test");

      while(client.client.isConnected()){
          System.out.println("still connectde");
          try {
              Thread.sleep(400);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
    }

 public void tryToLogin(String name, String password) {
        Logger.getInstance().log(this, "sending LoginPacket....");
        client.sendTCP(new LoginPacket(name, password, generatedSalt));
    }


If I call tryToLogin() it jumps directly to disconnected() and the connection is null, if I remove that Line it will stay online.
4  Game Development / Networking & Multiplayer / Re: Why Threads for the Client on the Server? on: 2016-09-19 00:40:09
Well this question was more theoretical. For productive Code I would of course use some well etablied library.
But I like to go from "low " level to learn some things.

And yes, I knew that it is needed to Thread those CLients that other tasks don´t block.
But I am just curious.
When I am looking at some (very simple) Codes they do also use a single Thread for one CLient.
Like.. just Chat Handlers or Game Server where you don´t get any complicated Commands.
If a bunch of CLients send to an Server some Texts, what exactly would slow down the Server here? The Server just listens, adds the Texts to an que and send them and the same iteration to the other Clients.

Or when the Server gets an Position packet, "want to attack Monster XYZ". Server takes those commands and delegates them to (often) non-threaded Systems/Handlers. and this is where the work happens.

So... why do I see so many examples where the Clients are threaded and that´s it?

I only have seen some total beginner examples and Repository Code and in every? single one it was done like that.

btw: Is there an other Version of kryonet? the exotericsoftware/kryonet was been updated three years ago.
5  Game Development / Networking & Multiplayer / Re: Why Threads for the Client on the Server? on: 2016-09-12 22:13:29
Okay thanks.

What would you now suggest how to implement it on the Serverside? Assuming <100 Clients.
Just one Thread per Client or something else? Better use a CachedThreadpool for that?
6  Game Development / Networking & Multiplayer / Why Threads for the Client on the Server? on: 2016-09-09 22:51:30
Hey, I am just playing around a little bit, so no Code here. But I am interested in how to do this.
I knew there are libs like Kryonet, but I would like to knew how to do it.

When I am checking some Online Game Sources I nearly always see that the Server is listening for CLients and for each(sic!) one it makes an own Thread.... Why?

Afaik, if I have a lot of Threads ~double the amount of my Cores the PC´s Power goes down extremely. So why do some people do that? Wouldn´t it be better to make some Systems eg.: Movement, Battle, Chat System a own Thread? Although, I could think that with that the sync between Movement and Battle could be a little bit annoying :/
 Or instead for every Client an Thread I could "batch" some Client´s together and do the work on those. But for a lot of CLient´s I will get again the same Problem.

Why not just accept the incoming login and add this Client into a list and iterate over it? I doubt that it would be an recognizable time difference, especially at RPG´s with <100 current Players. On the other Hand for Strategy Games that could be too slow.

Anyone can clarify/sort my thoughts?
7  Java Game APIs & Engines / Engines, Libraries and Tools / Re: libGDX with Gradle -> how to install? on: 2015-07-21 17:28:42
Ehh, what do I have to do now if I want to use Gradle?
8  Java Game APIs & Engines / Engines, Libraries and Tools / libGDX with Gradle -> how to install? on: 2015-07-20 22:16:16
Okay, I used libGDX always with the complete Source, now I try it with Gradle and I failed terribly.

I am using IntelliJ.

I generated an new Project with the libGDX Project Setup and I need Gradle to resolve the libGDX dependencies.
And well, ... it´s not working.

I tried to import the Project directly with the build.gradle.
I settet in the Project Settings the Module Dependencies to Gradle Wrapper.
I created an 2nd Project.
I run and created the build.gradle
It has the same project tree like described at the libGDX Homepage.

But IntelliJ is not resolving the libGDX Libs.

What else do I have to do?
9  Game Development / Artificial Intelligence / Re: Decision Making in Strategy Game on: 2015-07-20 22:07:29
Okay, one last question, then I am going back to the world  persecutioncomplex

You say that it doesn´t have to knew any kind of the game.
Does that mean the Client=the Game is generating the possible Moves?

So your MCTS offers an Interface and your Client is in charge to generate the accoring tree and saves it, and the same thing for the valuing of the moves?
10  Game Development / Artificial Intelligence / Re: Decision Making in Strategy Game on: 2015-07-16 19:09:19
Quote
Quick side note: I would avoid calling behavior trees 'b-trees' because that usually refers to something different.

Hehe thought the same thing Wink

So, well I checked out some different techniques and AI Books, but I still haven´t found anything practical.
But after some tree drawing I came up with an idea, which seems - at least in theory- nice. It´s totally unperformant but in terms of decision making it should do the job, will check it out.

Quote
....MCTS...
I suppose you mean Monte Carlo Tree Search.

Could anyone explain me that? I have only found a few pages, which are mostly theoretical.
What I got is that it first produces an tree regarding the game state and then has a heuristic function to value every possibility and after that node was choosen it makes n-Random moves?
So, the difference to Alpha Beta Search is that it doesn´t have to generate all child nodes?
And how does that then apply to Strategy games? If I only choose one Node I would only choose one unit although I am able to move ~50 per turn.
11  Game Development / Artificial Intelligence / Re: Decision Making in Strategy Game on: 2015-07-08 22:13:59
Thanks, but didn´t helped that much.

Now I knew that I will need Influence Maps - gonna check out how to develop nice ones.

The most Stuff in the Links I have already known.
I just don´t get how to Score the importance of events properly and build the behaviour Tree.
Especially when I want to put everything in one tree it will get really big and too complex. And not that easy to cennect the Logic for ~50 turns and one turn.

But I found an other approach.
They divided it into some different Systems.
- One for the turn, one for logistics, one which takes car for the next few rounds and one for the goal of the whole game.
, although I don´t understand the last two.


My idea was now:
For every Unit find out what it is able todo.
If that possibility is helping me to get to an wanted goal -> consider it
In an 2nd Step check out what I need (Military, Tech, Buildings) [how todo that? how do I find out what I need? With an influence map I can tell where I have to sent my Units and maybe if the distribution is uneven that I need to produce some., But so far I have no idea how to program it so that it doesn´t produce the whole time military only.]
Or I could use Alpha/Beta too look forward for ~5 turns and check. But still no idea how to connect everything...
12  Game Development / Artificial Intelligence / Decision Making in Strategy Game on: 2015-07-05 20:27:46
Heya,
So, well after dozens of failed projects I went back to the roots and finally there is an little Plaything which seems fine so far.

It is a turn based Strategy 2D Game, at the moment completly tile oriented.

Now I want an Computer AI.
And would need to know how to make decisions, especially in an bigger context and not only depending on the turn.
So, how to tell the AI to produce Units /which ones, or produce Technology, to attack etc...
And this, since it´s an Strategy Game, with many Units in one turn.

Of course I came to Behavioural Trees, but they doesn´t seem to fit, or I don´t understand them correctly.
Like, how can I say there: "Okay I have enough Pawns, now produce a Technology".
 
When to attack and how to place my Units too...
And all of my Units have different Stats, another thing to care about.

Could you please give me some ideas /Examples how todo that?
13  Discussions / General Discussions / Re: Interpolationsearch unknown Bug on: 2015-04-26 21:24:54
I edited my above post^^

Well, as I already wrote, it´s working but only for "little" numbers.
So I have to use BigDec. - which has an strange beaviour :O
Now everything is in BigDecimal and it works.
I first had the feeling that it´s again an linear search, but it´s not.

When I am using an array with <15 it becomes nearly linear and when I am using ~100 values it needs approx <5 steps to find the searched value.

Thanks for your help!
14  Discussions / General Discussions / Re: Interpolationsearch unknown Bug on: 2015-04-26 20:55:45
Okay, I gues i got it, but I have no clue how to solve it...

When you are dividing its very probable that your value is >0 and <1 so, an int will make an 0.
So I make every partcalculation extra and use double.

Edit:
So,... changed the stuff completly to double.
It seems that it´s work correctly.

But I still have the problem that I get too high numbers, if the numbers are higher than 10 signs.
So, I used BigInt and BigDecimal , but the funny thing is.
When I am using that it´s cutting the Values like an Integer. So, the 0.14 becomes an 0 and with that I get an wrong pivot....
15  Discussions / General Discussions / Re: Interpolationsearch unknown Bug on: 2015-04-26 20:16:43
That´s strange...
It is the same code, why is it working in this order?....

But i´ts still not working correctly.
I am always getting an linear search....
16  Discussions / General Discussions / Re: Interpolationsearch unknown Bug on: 2015-04-26 16:57:09
Yes, it is.
Sorry,
Before i call the Algorithm I use Arrays.sort() on the Arrays.
17  Discussions / General Discussions / Interpolationsearch unknown Bug on: 2015-04-26 13:02:53
Hello,
well nothing directly about Game dev, but hopefully someone can help me.
I tried to implement Interpolationsearch, but it´s not working properly and even after Debugging I have no clue where my fault is.

1  
2  
3  
4  
5  
6  
7  
8  
9  
 private int interpolationSearch(int[] data, int toSearch, int left, int right) {
        int pivot = left + ((toSearch - data[left]) / (data[right] - data[left])) * (right - left);
        if (pivot < 0 || pivot >= data.length) return -1;
        if (data[pivot] == toSearch) return pivot;
        if (data[pivot] < toSearch) {
            return interpolationSearch(data, toSearch, pivot + 1, right);
        } else if (data[pivot] > toSearch) return interpolationSearch(data, toSearch, left, pivot - 1);
        return -1;
    }


My Problem is that with special Numbers i get negative pivots.
I thought it´s about JAVAs int size but even after I used BigInteger or double I get wrong ones.

Second, if I have "normal" numbers. It´s not working as Interpolationsearch, but as "linear search" - so my pivot begins from 0 and goes to array length.

{5, 3, 5, 228, 14, 69, 18, 27, 109, 85}; becomes an linear search and
{-2074115388, -1899117555, -1339377864, -1242732811, -957055745, 209856485, 632141739, 826711003, 1894825342, 1968537296}, return an negative pivot

Anyone can please help me?
18  Game Development / Newbie & Debugging Questions / Re: Looking for Source Code Ressources on: 2015-04-22 14:48:41
Thanks guys.
Of course I am not taking anything from the Code, it´s more about the Software Design.

I misspelled something. I also would like to see some examples of offline RPG/Strategy Games.
I just said MMO because it´s.... well interesting.
19  Game Development / Newbie & Debugging Questions / Looking for Source Code Ressources on: 2015-04-18 21:12:13
Hello,
I found a ~year ago nice Game Code but can´t remember where it was.
And since I also, don´t remember much of it´s content,... I am looking for:

Open Source Games on Github,Bitbucket,...
At best RPG/strategy as MMO or Browser based.
In Java or an Java like language (C#...)

I don´t want to make 1:1 copies, but for me such things are great to learn new techniques.
20  Discussions / Miscellaneous Topics / Looking for nice RPGs to check out (online/offline) on: 2014-12-23 18:08:14
Heya.
I am looking for some games with:
RPG, standalone or "MMO"
Nice arts
big open World (killable npcs, buying objects and ablte todo what i want,..)
if online: many pvp features
important economy system

Not like Minecraft, it´s too "open" and there is no real goal.

indie, but please not in the alpha

So, nothing special what I am looking for, but I can´t find it.
An example would be Vampires Dawn 1&2 from 2005....
21  Game Development / Game Mechanics / Re: Game Movement Howto? on: 2014-12-22 20:36:25
Quote
All of that needs to be dealt with in the pathfinder, and is probably a headache. You'd need to send the pathfinder things like the Sprites width/height, so it can say: Ok this guy is 64 in height (2 tiles high lets say) so all tiles he can stand on MUST have an empty tile above it, or w/e.
I already was afraid that I have todo that like that....

let´s say on my tile can be objects, which are not visitable. How should I calculate this?
Because at the moment I only look at the tiles, if they are visitable or not.
how should I do it when an Tile is lets say to 50% visitable.
-Then I would need to check every tile for objects, but how should I store this in my Path?
Should I then store pixel values to go?
22  Game Development / Game Mechanics / Game Movement Howto? on: 2014-12-21 22:52:32
Hello,
I am after an time again in game dev and I have an question about the movement of entities.

The game is orthogonal and with tiles.

I have implemented A* which searches an valid path to an mouse click. And i am operationg on nodes=tiles. Where I don´t knew if it´s very intelligent. So I have an path object.
I don´t knew how to move then.
Normal keyboard input is working.
I am just multiplying the world.delta with the velocity and add it to position.

1.) Movement from tile to tile
lets say i am only going from Tile to Tile. How should I do this if I don´t want that an step happens after one tick?

2.) pixel movement
When in my Path are only "the tiles to go" stored, how should i move pixelish?
Sure, I knew the tileSize.
But I don´t knew how I should go automatically.

The only idea I had was:
get the Node
calc it´s pixel value
set the velocity to the max speed
and then go to the next position
check if outside the node
begin again util list empty
if node.pixel != current.pos -> go util click.pos

But I have the feeling that there is something missing and that it´s not an very nice way todo so.
And how sould I go if one tile is partly solid?
Let´s say my spirte is 32x64 pixels and my tiles 32x32.
A* calulated an valid path, but if I go there my sprite will collide with an object, because it´s above the valid Tile.

I hope it´s understandable what I wrote...

23  Discussions / Miscellaneous Topics / Looking for an Repo & Tutorials on: 2014-07-03 23:48:46
Hello,
I had have found an (Java)? Game Project on an Code Hosting Site and found it very useful, but I am not able to find it anymore.
It was an bigger one and I believe a clone of Dwarf Fortress. It followed mainly the ECS Model. Would be great if someone knews it.

And furthermore I am looking for more games which are implemented as an Component System.
24  Game Development / Newbie & Debugging Questions / Re: Colission Detection + ECS on: 2013-10-08 17:02:31
Okay, thx.
Updated the first post, hope somebody can now imagine what I am doing. But I basiclly guess that my Player has such a bad behaviour, due to the Input of more than one Key.
25  Game Development / Newbie & Debugging Questions / Re: Colission Detection + ECS on: 2013-10-07 18:41:32
Well, has nobody an clue whats wrong?
26  Game Development / Newbie & Debugging Questions / Colission Detection + ECS on: 2013-10-05 20:53:14
Hey I wrote a while back a Colission Detection which works more or less.
The problem is that if i am pressing up and left or right and above me is a colission Tile my Sprite goes the whole way right/left to the last colission Tile and I dont get why.

And how can I make it more intuitive? Because I want to be able to rotate Sprite, so they are not just looking in one of the four directions.

atm, I am doing it so:
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  
TiledMapTileLayer colissionLayer = (TiledMapTileLayer) gameMap.getLayers().get("colission");

        Vector3 colissionTile = null;
        if (colissionLayer != null || colissionOn) {
            if (pseudoPlayer == null) this.pseudoPlayer = new Player(player.getPostition(), player.getImage());
            pseudoPlayer.setFacing(player.getFacing());
            pseudoPlayer.setX(player.getX());
            pseudoPlayer.setY(player.getY());
            pseudoPlayer.update(elpasedTime);
            colissionTile = Collision.getTileColission(pseudoPlayer, colissionLayer, "blocked");
        }
        if (colissionTile == null) {
            player.update(elpasedTime);
        } else {
            switch (player.getFacing()) {
                case RIGHT:
                    player.setX(colissionTile.x - player.getWidth() - 1);
                    break;
                case LEFT:
                    player.setX(colissionTile.x + getTileSize() + 1);
                    break;
                case UP:
                    player.setY(colissionTile.y - player.getHeight() - 1);
                    break;
                case DOWN:
                    player.setY(colissionTile.y + getTileSize() + 1);
                    break;
            }
        }

    public static Vector3 getTileColission(IEntiy entity, TiledMapTileLayer layer, String term) {
        float y = entity.getY(), x = entity.getX();
        float TILE_SIZE = layer.getTileWidth();

        int tileX = (int) (x / TILE_SIZE);
        int tileY = (int) (y / TILE_SIZE);

        Vector3 tileA = new Vector3(x, y, 0);
        Vector3 ereg = new Vector3(0, 0, 0);
        int width = (int) entity.getWidth();
        int height = (int) entity.getHeight();

        tileA.x = tileX * TILE_SIZE;
        tileA.y = tileY * TILE_SIZE;
        if (intersects(entity, tileA, 32, 32) && !tileisFree(tileX, tileY, layer, term)) {


            return ereg.set(World.tilesToPixels(tileX, (int) TILE_SIZE), World.tilesToPixels(tileY, (int) TILE_SIZE), 0);
        }

        x += width;
        tileX = (int) (x / TILE_SIZE);
        if (intersects(entity, tileA, 32, 32) && !tileisFree(tileX, tileY, layer, term)) {
            return ereg.set(World.tilesToPixels(tileX, (int) TILE_SIZE), World.tilesToPixels(tileY, (int) TILE_SIZE), 0);
        }

        x -= width;
        y += height;
        tileY = (int) (y / TILE_SIZE);
        tileX = (int) (x / TILE_SIZE);
        if (intersects(entity, tileA, 32, 32) && !tileisFree(tileX, tileY, layer, term)) {
            return ereg.set(World.tilesToPixels(tileX, (int) TILE_SIZE), World.tilesToPixels(tileY, (int) TILE_SIZE), 0);
        }

        x += width;
        tileX = (int) (x / TILE_SIZE);
        if (intersects(entity, tileA, 32, 32) && !tileisFree(tileX, tileY, layer, term)) {
            return ereg.set(World.tilesToPixels(tileX, (int) TILE_SIZE), World.tilesToPixels(tileY, (int) TILE_SIZE), 0);
        }

        return null;
    }

So, how can I avoid that?


I recently discovered Entity Systems and like the concept so far.
How should I make an Colission System? And how to communicate between the Systems?
I thought about just processing the Movement System and then a collide System. If in the collide System a colission is detected it would set the sprite to the next safe place.
How to make an InputComponent? I thought about making just an COmponent with a List<Input.keys, Gameaction> this is then rendered by an System which checks if and key of the COmponent is pressend and then takes the GameAction and performs and Action depending on the GameAction.


Edit PseudoCode:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
method1(){
if(checkifColissionLayer){
    generate pseudoPlayer; set values to values of Player
    update pseudoPlayer;
    Vector3 clollTile= checkColission(pseudoPlayer)   //collTile is bottom left pixel of Tile
}
if(colltile==null) player.update;  //no colission
else
adjust player position depending on Direction he moved last
so, if the player last pressed up and there is an colission -> above me is an colissionTile -> calculate nearest pixel to the colissionTile
}

Vector3 checkColission(Player p,Layer l, String term){ //l... The layer where colissionTiles are exppected;  term... the property of a Tile if is colidable
tileX,TileY = The Tile, the player is standing on

calculate for all four corners the pixel Position and then change it back to the x,y coordinate of the Tile
if the player intersects with this Tile and the Tile is not free -> return bottom left Vector of the Tile the colission happened.

}

I already read many articles about Colission Detection, but didnt undersand them. So developed this one for my own. Although I knew that its not very sophisticated.
27  Game Development / Newbie & Debugging Questions / Re: libGdx HUD/ UI + PathFinding on: 2013-09-06 17:46:25
Ahh slider, right.
But how to add there the "HP"? So draw the background/borders and then how do i fill it? I see that there is an setter for that, but how to draw em? Maybe something with the draw() and then make the batch red?
BTW, is there an Bug? If I set disabled true, I am still able to change the value.


Yeah the Algorithms is not the Problem, more libgdx.
It makes Cells into TiledMapLayers and TiledTiles into Cells and Layers int MapLayers. So, what should I take to create an easy Map for the Pathfinder? It also seems taht the TileLayers dont have the same size as the created Map, at least if the TileLayer is not so big as the map.
So, from which class can i get the stuff?

Yeah i hardcoded some sizes, but they didnt aplly. Either on the texture or on the Widget.
28  Games Center / Featured Games / Re: Blue Saga on: 2013-09-05 19:53:48
yeah, I don´t knew wif u knew it already, but there seems to be a bug with the new login.

I used "forgot password" and generated a new one, but the client always told me, that the Account has to be activated.
And now I am even not able to send a mail, I am always getting an:
Quote
Message could not be sent.Mailer Error: Could not instantiate mail function.
Error.

Would be great if someone could report it to the Admin.
29  Game Development / Newbie & Debugging Questions / Re: libGdx HUD/ UI + PathFinding on: 2013-09-05 18:04:28
Thanks, but i still dont get it.

So, i should make an Image with the full HP/MP and instantiiate it as an Image, okay.
But how then i set the pixxels inside the Bar? The only thing i can think about is taking something like a Progressbar, but yeah that wouldnt be very handy...

And is there maybe an easy way to get to the informations of an TiledMap?
Only to get to the Tilesize I do :
1  
2  
TiledMapTileLayer layer= (TiledMapTileLayer)gameMap.getLayers().get(0);
       return layer.getTileWidth();

Especially; If there is an way how to get the Tile I am standing or clicking? Currently I am just divididing the position tru the Tile Size, but its not very sophisticated...
30  Game Development / Newbie & Debugging Questions / libGdx HUD/ UI + PathFinding on: 2013-09-02 20:45:13
Hello, I would like to know how it is possible to make an Interface in libgdx? I knew the Channel from dermetfan and some Tutorials, but I don´t get it to 100%.

Is it possible to set a screen ontop of another Screen or do I have to use Stage for the UI?

Lets say I want to make an hp/mp bar what would I have todo to draw this? Currently I am doing it just like this
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
    Table playerInfo = new Table();
        //playerInfo.top().left();
        playerInfo.defaults().space(3f);
        playerInfo.pad(10f, 10f, 0, 0);
        playerInfo.debug();
        playerInfo.setPosition(0, Gdx.graphics.getHeight());
        playerInfo.size(200f, -100f);
        playerInfo.add(new Label("HP: ", skin)).size(25f, 20f);
        playerInfo.add(new Label("", skin)).size(75f, 20f).row();
        playerInfo.add(new Label("MP: ", skin)).size(25f, 20f);
        playerInfo.add(new Label("", skin)).size(75f, 20f).row();


In order to use an normal Image like in every common Game how todo? Especially I dont get how to draw the pixel, when the bar is not full. So, would it be correct to draw the bar surronding and load it then per LabelStyle? So the Background? Or just an different Class? How then i draw the red pixels according to the health?

How do i do it that it looks like an Window? ....Ah I can make an Window Class and then add to it an Table, great.
How can I make the positions better? When u look at the above example, its very annoying with the fixed sizes, is there somekind of Layout possible?

Well for Pathfinding Algorithms I need the Map data, so should i read everytime from the Tiledmap from libgdx or make an own Map Class and then fill it with an 2d Array just if the Tile is blocked or free?
Pages: [1] 2
 
Wave Propagation (180 views)
2016-09-20 13:29:55

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

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

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

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

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

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

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

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

roseslayer (1289 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!