Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


menyo

Member Since 09 May 2010
Offline Last Active Today, 01:19 AM

Topics I've Started

Adding item modifiers

09 November 2014 - 06:29 AM

I want to implement modifiers for special items. But I cannot figure out a good way to implement this. Let's say I have this item class structure:

public class Item
{
    String name;
    int strengthReq;
    int dexReq;
    int wisdomReq;
}

public class Weapon extends Item
{
    int maxDamage;
    int minDamage;
    int durability;
}

Now i want to add modifiers to this, the best way i can think of besides directly altering the item itself is a modifier class that uses a Enum to tell what has been modified. Adding a modifier object to an item and use statements every time a modifier might have been used and act accordingly. Currently my game uses a simple action system, for instance: when someone attacks source and target get passed to a static method and all the damage will be resolved according to the weapon damage/type.

public class Modifier
{
    enum ModifierType()
    {
         Strength,
         Dexterity,
         Wisdom,
         MaxDamage,
         MinDamage,
         PlayerHealth,
         lifeDrain,
         etc
    }
    ModifierType modifierType;
    int modifierValue;
}

Looking for pointers to make my item system more dynamic and fun with modifiers.


Action system with XML

31 October 2014 - 01:46 PM

Hi,

 

I want all my different character actions to be read in by XML so i can easily balance things out and modify all those actions. I would like some feedback on what I have started. I will have some basic actions like attack, move, cast, etc but most of the skills will be a combination of those (like "Dash" and "Wound" in the example below).

 

Q: I would also like to incorporate some kind of formula. Like a cooldown is based on (X * weapon weight) or damage is based on (skill level * weapon damage) but i am not sure how to implement this.

 

<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <ability>
        <name>Attack</name>
        <info>A regular melee attack with your main weapon.</info>
        <coodown>10</coodown>
        <action>
            <type>damage</type>
            <sort>mainWeapon</sort>
        </action>
    </ability>
    <ability>
        <name>Dash</name>
        <info>Dash forward to a target to hit him with greater impact.</info>
        <coodown>20</coodown>
        <action>
            <type>move</type>
            <location>target</location>
        </action>
        <action>
            <type>damage</type>
            <sort>mainWeapon</sort>
        </action>
    </ability>
    <ability>
        <name>Wound</name>
        <info>Inflicts a wound to your target.</info>
        <action>
            <type>damage</type>
            <sort>mainWeapon</sort>
        </action>
        <action>
            <type>dot</type>
            <element>physical</element>
        </action>
    </ability>
</actions>

I basically check for the type value and read XML accordingly. Q: Later i want to expand on this and i'm wondering if it is ok to to have different elements/nodes below these same types? Can i filter those out with something like:

if (action.GetChildByName("childThatMayOrMayNotExist"))
{
     //Do something if it exists!
}

For those formula's i can think of something hacky like below. But i am really looking for something more flexibel and of course compatible with LibGDX/Android if you recommend a library.

<first>weaponDamage</first>
<operator>*</operator>
<second>skillLevel</second>

Like i said, i would love to have some feedback from people with more experience.

 

Thank you,

 

Do i really need to deep copy this?

27 October 2014 - 03:42 PM

Hey,

 

I come from a C# and i'm trying to get my Astar implementation working on java for Android. Since Java is pass by value I need to make a copy of this Array[][] each time I request a path. This feels awkward for me and perhaps unnecessary.

 

So what i actually do in my Astar method, instead of iterating over a closed and open list many time, or putting new nodes into it in a ordered fashion I am creating a 2D map resembling my map in nodes. These nodes hold a open and closed boolean so all i need to do is check directly on this map if this tile belongs to the open/closed list, see move cost and if it is walkable. Instead of searching for it in a potential huge open list each time. I create this map when a new map is loaded, so with C# this actually got created only once.

 

Anyway, I did the same in Java but when I passed this NodeMap as a parameter it actually alters the base object instead of making a copy to work on. Now my (crude?) solution was to implement a constructor for my Node class so i can deep copy the complete NodeArray[][].

public Node(Node copy)
        {
            this.G = copy.G;
            this.H = copy.H;
            this.position = copy.position;
            this.parent = copy.parent;
            this.closed = copy.closed;
            this.open = copy.open;
            this.walkable = copy.walkable;
        }

And here i copy it, every time i need a path, i pass the actual Array[][] that needs to stay unaltered as nodeMapRef.

Node[][] nodeMap = new Node[nodeMapRef.length][nodeMapRef[0].length];
        for (int y = 0; y < nodeMapRef[0].length;y++)
        {
            for (int x = 0; x < nodeMapRef.length;x++)
            {
                nodeMap[x][y] = new Node(nodeMapRef[x][y]);
            }
       }

It really loses it's charm this way but i cannot think of a good way to handle this. And i can imagine if my map size grows and need much more paths this might slow things down significantly.


Understanding the input processor.

19 October 2014 - 06:58 AM

I am somewhat lost as to how the LibGDX input processor works and how to implement it for what i want. I simple want to detect if a touch was made or released in a specific class. Something as simple as "if (touchUp) { //do stuff }".

 

But the input processor works differently, it just runs the code there when a touch is released. The only way i can think of doing what i want feels hacky: create globals in my class and set these to true from the InputProcessor and at the end of the update cycle in my class I put them false again.

//MyInputProcessor

@Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        MyClass.touched = true;
        return false;
    }


    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) {
        MyClass.released = true;
        return false;
    }


//MyClass


public static touched = false;
public static released = false;


@Override
public void render(float delta) {
if (touched)
  //do stuff
if (released)
  //do stuff


//end of update
touched = false;
released = false;
}

It just doesn't feel right to do it this way. If i want to do all the touchup/touchdown code inside the InputProcessor class i have to make tons of fields in MyClass global. Am i missing something? I just need something like "if (getInputProcessor().getTouchDown) { //Do stuff }".

 

Also, if i want to have multiple pointers for fingers (Which is highly unlikely) the above example does not work.


Post your desktop (2014)

05 October 2014 - 01:36 AM

Moderator note: This topic was split off from the 2004 topic by the same title so that the older topic could be left to rest.

 

 

Because my desktop makes me a very happy person I hereby revive this ancient topic!

 

IQ0pFgb.jpg

 

I showed mine, now show me yours!


PARTNERS