Posts mit dem Label gamedev werden angezeigt. Alle Posts anzeigen
Posts mit dem Label gamedev werden angezeigt. Alle Posts anzeigen

Sonntag, 18. September 2016

6 Tipps Boosting Your Productivity With HackNPlan

The tool Hack 'N' Plan is a very sophisticated project managing tool made by gamedevs for gamedevs. I have been working with it for about 5 months and my productivity sparked ever since. I am more focused and notice when my game is suffering from the infamous scope creep syndrome.

In the following I want to present you 5 tipps how to work with this piece of software. These may work without making use of Hack 'N' Plan, too!


  1. Plan out the most important features first. Focus on those.

  2. Avoid spontaneously added tasks as much as possible.Bugs and improvements of existing code/assets are an exception. This serves mainly the purpose to prevent a scope creep. I know it's tempting to add one idea after the other, but like this you will never get your game done. Ever.

  3. Use the game model feature to set a design direction(e.g. game mechanics you want to have). This will be your focus. Do not add tasks that do not support your game model (except bug fixing)! Push them down the abyss of the forgotten mercilessly if you find any.



    Or just dump sidetracking tasks into a "unimportant brainfarts" milestone if you're not a ruthless task-murderer like me.



    In fact, I'm still trying to find a most effective way on how to use this.

  4. Make many milestones with small scope.Keep it 10 tasks and below, add a max of 5 tasks spontaneously (thus a maximum of 15 tasks in total). You need ruthless focus and this will help you establish it.

  5. Cut tasks into the smallest chunks.You don't have to (and shouldn't) plan out every detail of your project, but if you notice you need more tasks, make them small.

  6. Group together tasks that cover a similar topic.Not doing so has a chance of making you feel scatter-headed because you are jumping from one section in your code to the other. This is ok when you fix bugs, but not when you need focus to do progress.

    Do not make a clutter like this:



    ...but keep it more like this.



    Those are all UI-tasks I got done very quickly because I grouped them ruthlessly. Kept the scope of these tasks small, too.

I hope this helped with your gamedev endeavours. Keep on rocking, keep on coding!

Freitag, 26. August 2016

Life is like Gamedev

It happens to me when I code all the time: Create something just to later discard it and start new from scratch. You make two steps forward just to make one step back again. It's frustrating sometimes.

Come to think of it, it's just like real life. Sometimes you're trying to make a change in your life, trying to adapt some habits, like trying to stick to your marketing schedule or diet plan. Then there's times when things happen, you slack and fall back to your old habits.

It's a bit like marble in a funnel that's slowly rolling towards the hole in the center. You're trying to roll towards the center, but sometimes you go too fast and bounce back to the outer edge. You do this until you finally achieve your final breakthrough: when your good habits finally stick and your code finally works (well... mostly ;) ).

Just like in gamedev.

So when you practice going through this with gamedev, it will likely spread over other parts of your life.

Code away, never stop creating and keep making awesome games!


Mittwoch, 6. Juli 2016

Creating a Mission System in Java


So... how do you create a Mission System?

I asked myself this question twice so far and recently I came up with the following approach. This system is relatively simple but you can do most of basic missions with it. It consists of a tree with depth 3: Mission, Objectives. Conditions. Each of the components has a mission state, consisting of PENDING, SUCCESS and FAILURE.

First, I will describe the classes needed, which is then followed by their java code at the end of this article.


The general structure is as follows:






Mission:
  • A Mission has a title, a debrief description and a short description. 
  • A Mission has multiple objectives.
  • As general rule, a mission is deemed a success if all its child objectives are deemed successful.

Objective:
  • An Objective has numerous conditions.
  • Objectives have a different behavior per type, described below:

    Default: All objectives must be set to success for a mission to return success.
    Failure: If this objective is failed, the entire mission fails.
    Optional: The objective is effectively ignored by the mission, but can be used to, say, determine a score.
     
  • By default, they are not being updated once a condition was met or failed, but you can change them to run permanent updates.
 
Conditions
  • All conditions must be met for an Objective to be successful. Behavior types (default, failure, optional) do not apply here to keep it simple. To make up for that, I've added the possibility to invert them.
  • Conditions are implemented by you via an interface and an abstract helper class. 
  • For GUI purposes, there's also methods to display the condition as string for the end user.

To use it, you setup your Mission, Objectives and Conditions and call Mission.update() each time you update your game.

Here's the code:



Mission


/**
 *
 * @author B5cully
 */
public class Mission {
  
    public String title;
    public String debrief;
    public String summary;   
    public LinkedList<Objective> objectives = new LinkedList();
    Objective.State state = Objective.State.PENDING;

    public Mission() {
    }
   
    public Mission(String title) {
        this.title = title;
    }

   
    public Objective.State getState() {
        return state;
    }
   
    public void addObjective(Objective obj) {
        objectives.add(obj);
    }
   
    public void start() {
        for( Objective objective : objectives ) {
            objective.start();
        }
    }
   
    public void stop() {
        for( Objective objective : objectives ) {
            objective.stop();
        }
    }

    /**
     * Updates this mission's state
     * @return
     */
    public void update() {
        int i=0;
        boolean success = true;
        boolean failure = false;
        for( Objective objective : objectives ) {
            switch (objective.state) {
                case SUCCESS:
                    if( objective.constant_check ) objective.checkState();
                    break;
                case FAILURE:
                    if( objective.constant_check ) objective.checkState();
                    break;
                case PENDING:
                    objective.checkState();
                    break;
            }
            switch( objective.type ) {
                case NORMAL: {
                    success = i == 0 ? objective.state.equals(Objective.State.SUCCESS) :
                                   success && objective.state.equals(Objective.State.SUCCESS);               
                } break;
                case OPTIONAL: {
                    //ignore the objective
                } break;
                case FAIL: {
                    //only consider fail state
                    failure = failure || objective.state.equals(Objective.State.FAILURE);                       
                } break;
                   
            }
            i++;
        }
        if( success ) {
            state = Objective.State.SUCCESS;
        }
        if( failure ) {
            state = Objective.State.FAILURE;
        }
    }





Objective

/**
 *
 * @author B5cully
 */
public class Objective {
  
    public enum Type{
        /**
         * The objective contributes to success of the mission.
         */
        NORMAL,
        /**
         * The objective counts as fail condition of the mission.+
         * If one objective of this type closes with failure,
         * the entire mission fails. The pending state of
         * FAIL objectives are ignored in the total outcome.
         */
        FAIL,
        /**
         * The objective is optional, it has no effect
         * on the total outcome.
         */
        OPTIONAL;
    }
    public enum State{
        PENDING, SUCCESS, FAILURE;
    }
  
    public String title;
    /**if this is true, the objective is constantly validated. If false,
       the objective is validated once and succeeds permanently once triggered.*/
    public boolean constant_check;
    /***/
    public Type type = Type.NORMAL;
    State state = State.PENDING;
    /**
     * All conditions must be met in order for na objective to
     * succeed.
     */
    LinkedList<ConditionImpl> conditions = new LinkedList<ConditionImpl>();

    public Objective() {
    }
  
    public Objective(String title) {
        this.title = title;
    }
  
    public void addCondition(ConditionImpl condition) {
        conditions.add(condition);
    }
  
    public void start() {
        for( ConditionImpl condition : conditions ) {
            condition.start();
        }
    }
  
    public void stop() {
        for( ConditionImpl condition : conditions ) {
            condition.stop();
        }
    }
  

    @Override
    public String toString() {
        String s = "";
        int i =0;
        for( ConditionImpl condition : conditions ) {
            s += condition.getName() + ": " + condition.getDisplayedText();
            if( i > 0 && i < conditions.size()) s += "\n";
            i++;
        }
        return s;
    }

    public State getState() {
        return state;
    }
  
    public void checkState() {
        boolean success = false;
        int i =0;

        //check the conditions
        for( ConditionImpl condition : conditions ) {
          
            state = condition.getState();
          
            if( !state.equals(State.PENDING) && constant_check) {
                //still update the condition if constant check enabled
                condition.checkState();
            } else
            if( state.equals(State.PENDING) ) {
                //pending: simply update. No updates if failed or succeeded.
                condition.checkState();
            }
            success = i == 0 ? state.equals(Objective.State.SUCCESS) :
                               success && state.equals(Objective.State.SUCCESS);
            switch( state ) {
                case FAILURE: {
                    this.state = State.FAILURE;
                    return;
                }
                default: break;
            }
            i++;
        }
        if( success) this.state = State.SUCCESS;
        else this.state = State.PENDING;
    }
}



Condition 


/**
 *
 * @author B5cully
 */
public interface ConditionImpl {
  

    /**
     * Invoked on condition start.
     */
    public void start();
   
    /**
     * Gets the name of this condition
     * @return
     */
    public String getName();
    /**
     * A Localized, properly formatted display
     * text for this condition.
     * @return
     */
    public String getDisplayedText();
   
    /**
     * @return the state of the condition
     */
    public Objective.State getState();
   
    /**
     * Evaluates the state of this condition. This normally involves
     * calculations.
     */
    public void checkState();
   
    /**
     * Invoked on condition stop (e.g. when
     * it has failed or is being reset)
     */
    public void stop();

}

Here's the helper class for Condition, followed by an example implementation. 


/**
 *
 * @author B5cully
 */
public abstract class Condition implements ConditionImpl {
  
    protected Objective.State state = Objective.State.PENDING;
    protected boolean inverted = false;
    /**
     * The name of this condition.
     */
    protected String name;
    /**
     * A format string to display the condition.
     */
    protected String format_string;
    /**
     * The string returned for display. This is usually
     * name + String.format(format_string, args), where
     * args is relevant info about the condition.
     */
    protected String displayed_text;

    public Condition(String name, String format_string) {
        this.name = name;
        this.format_string = format_string;
    }
   
    @Override
    public String getName() {
        return name;
    }
   
    /**
     * Inverts the result. E.g. Instead of delivering
     * SUCCESS by default, FAILED is being returned.
     * @param inverted
     */
    public void setInverted(boolean inverted) {
        this.inverted = inverted;
    }
   
    @Override
    public void start() {
    }

    @Override
    public Objective.State getState() {
        return state;
    }

    @Override
    public void stop() {
    }
}


/**
 *
 * @author B5cully
 */
public class ConditionKilledEnemies extends Condition{

    LinkedList<Entity> enemies = new LinkedList<Entity>();
    LinkedList<ListenerEntityImpl> listeners = new LinkedList<ListenerEntityImpl>();
    int size = 0;
   
    String current_displayed_text = "";
   
    {
        format_string = "%d/%d";
    }

    public ConditionKilledEnemies() {
        super("Killed", "%d/%d");
    }
   
    public void registerEnemy(Entity enemy) {
        //add enemy to list
        //add a entity listener that tracks the enemy death
        //and adds to the counter here
        ListenerEntityImpl listener = getListener(enemy);
        enemy.addEntityListener( listener);
        enemies.add(enemy);
        listeners.add(listener);
        size++;
        current_displayed_text = String.format(format_string, enemies.size(), size);
    }
   
    public ListenerEntityImpl getListener(Entity enemy) {
        return new ListenerEntityImpl() {

            @Override
            public void onDeath(EntityMobile object) {
                super.onDeath(object);
                int index = enemies.indexOf(object);
                if( index >= 0 ) {
                    enemies.remove(index);
                    listeners.remove(index);
                    current_displayed_text = String.format(format_string, enemies.size(), size);
                }
            }
        };
    }
   
    @Override
    public String getDisplayedText() {
        return current_displayed_text;
    }

    @Override
    public void checkState() {
        //success if the list is empty
        if( enemies.isEmpty() ) state = Objective.State.SUCCESS;
        else state = Objective.State.PENDING;
    }
   

Donnerstag, 23. Juni 2016

How to Make Leaving Your Comfort Zone a Habit

In an earlier article, I talked about how important it is to get out of your comfort zone. But how do you actually get out of it?

Before I start, it's important to keep in mind the following:
  1. If you want to achieve goals, you must acquire habits that help you accomplish them. 
  2. Nothing will change if you don't stop making excuses. If the time to make a change isn't now, then when?


These two things are essential in understanding what I'm about to tell you next.

"Getting out of your comfort zone" may be one goal in a larger chain of goals you have in mind.Once you achieve it, all other goals can be accomplished with greater ease. So how could a habit look like that helps you get off your lazy bumcheeks?


Find something...
  • that doesn't require a huge effort to start doing (highly accessible)
  • that pushes you to the limit, at your own discretion 
  • lets you explore and expand said limits.

Let me show you two of these habits I acquired:

  • Taking cold showers. Cold showers expand your blood vessels, thus giving your metabolism a rush of energy. They may help if you are struggling with making physical exercise a habit, too. The fact you are forcing yourself to cold water exposure is a perfect way to teach yourself to get out of your comfort zone (and defeat the "innere Schweinehund" - the "inner lazy skunk" - as we Germans say). If you shower everyday make it a habit! That being said, you don't have to jump right into cold water. What I do is to wash myself normally, then proceed with cold shower, gradually making the water colder - and remain in the shower for a maximum of two minutes. Next time I'd shower I will try to make it even colder, trying to push my own limits. Keep in mind that if you notice you start shivering or feel your limbs are getting numb, you should stop with the shower and get yourself warm as soon as possible. Push your limits, but never drive it too far!

  • Physical exercise. Similarly to taking cold showers, it fires up your metabolism. Besides it keeps you fit and healthy. To make exercise a habit, I started doing situps before going to shower in the evening. For me personally I choose a familiar environment for exercise (the bed in my room), which meant less effort for me to start doing it. You can do whatever exercise you feel most comfortable with, like stretch lessons, situps, yoga - simply chose the lesser evil ;). Just keep in mind that workout - if done wrong - can be damaging to your health (like kickboxing with limb weights on). So if in doubt, I highly recommend seeking professional advice.

With these two habits I am fostering I basically got used to getting out of my comfort zone. Slowly I am expanding this to other parts of my life. I must say it helped me getting to know the unknown called "discipline".


But beware: Do not ever think about slipping on any of these habits. If you don't have time for them now, you're not going to have time for them later - because you are more inclined to find an excuse for not doing them at all. Try to remember this: If you're not investing in good habits now, then when? 


What will remain if you lost everything you have? You. So invest in yourself. Because you are the most valuable asset you have.

Samstag, 18. Juni 2016

How to avoid bad Color Schemes

Notice: you may want to get Krita in order to follow the steps described below.

I've adviced a few indie programmers with their games already. And all of them had a common issue: color choice. Good old infamous programmer art. How do you get better at it?!


Now I could bombard you guys with dry color theory in this post. But eventually this is all just "theory" and not necessarily helpful for you in practice (especially if you lack the understanding for it).

So let's start off with applied color theory. I'll show you some pics while explaining the basic concepts, adapted to gamedev.



Contrast



Every picture can be minimized to black and white, right? You have hotspots here and there that attract your attention. You have dark areas that create contrast and can be used to create multiple effects in the audience (like emotion or tension).



In the above picture, there seems to be a dark blue cloud luring over what appears to be a yellow valley. Notice the white areas on the right and left top corners of the picture that surround the darker areas. The contrast of the cloud is rather prominent, creating a tense scenery. The tilted angle adds to the dramatic display.


Now the interesting thing about this is, that a lot of this can be applied to games. You want your enemies to stand out, peaceful items also needs to be highlighted (the white areas) and obstacles that cannot be passed (dark blue cloud). And then you have your environment, that balances out those two elements (yellow/purple valley).



You do not want to have a very similar contrast for your background and your walls, for example. Or all your backgrounds, obstacles and player in the same brightness of color. It will look mushy and they won't stand out, making your game look worse and harder to play.


Look at this picture here:


This looks like a ornamented floor, right? Let me show you what happens when I make the green tiles darker.



Now these tiles actually look more like walls that encase a tiny room. Darker. Impassable. Something you probably should not even bother messing around with!

Contrast is an important tool to set apart different elements in your game. If you have moving entities, they must be distinguishable from the rest of the environment.

Let's take a look at this screenshot of Sonic The Hedgehog (Genesis).



The overall environment is relatively bright, happy even. Yet the enemies are still easily to spot and distinguishable from the rest because they have a very strong color (red) that does not appear in the rest of the environment. Sonic himself has a different hue than the water, too.



Color


So much for contrast. How to choose the correct color?


You can choose colors using color wheels or similar provided by graphics programs. If you keep moving the color wheel towards cyan in Krita and pick one color every now and then, it's a very good starting point to figure out rough colors that fit.



Like this, I've chosen this color palette. Let's imagine I want these colors in my game. These aren't perfect, but definitely usable.

The color picture looks like this:



So let's apply the contrast lesson here. I put the color picture layer over the contrast the black and white contrast layer. Then I applied blend mode "Darken" in Krita on the color picture layer. You can download this file here, by the way!




So the result looks like this:


...which is a pretty solid color scheme to use for your game. To modify it, you can use the HSV tool of Krita to make further adjustments. Keep in mind you will have to readjust colors to the correct contrast if you do that. The second color of "player, enemies" is too similar to the first color of "backgrounds" and may make problems in a final game!




Getting Color Schemes


You don't have to do this process all the time. There are numerous websites and tools that help you chose a fitting color palette. One of these tools is paletton:



Another website that is very useful is www.colourlovers.com. It provides very handy, user-created palettes. The palettes displayed below are actually very interesting colors to use in a game already.





Choosing the right Color Scheme for your game


So how do you choose the correct coloring scheme for your game? 

It always depends what kind of game you are making and what kind of atmosphere, experience and emotion you want to create. Colors can be a very powerful tool to help achieve this, as they have a strong subconscious effect.

If you make a post-apocalyptic game, you should probably use pastel colors (colors without high saturation) - as long as it looks rotten and pale, you're good to go!
When making a horror game, you may want to do the same. Or you maybe want to use dark colors only, with red being the only brighter color.

But not only the colors themselves are important, but also the context they are perceived. If the gameplay makes it clear there is danger near, I will perceive a red-black color scheme differently than say, a blue-black. The cold, blue colors may even create a sense of despair!

In the picture below, I created a few color combinations and listed the words that came to my mind when looking at them.


You can do the same experiment by looking at other games, movies or art and asking yourself how what you see make you feel. That also helps you figuring out a good color mood for your own game.


I hope this article helped you figure out more about colors and color schemes! What are your favorite games in terms of colors and atmosphere?



Samstag, 11. Juni 2016

CamoTactics: Where will it go?





CamoTactics is a top down shooter set in a futuristic and turbulent future, where mankind has ventured into the depths of space and crashed into a planet with strange and bizarre alien life. Despite the hostility of this world, mankind finally has managed to get over its blood-thirsty past that exploited its environment - Until events turned around and tensions between two countries, Rubia, known as the cradle of mankind, and Panta rose again. Someone has gotten hold of ancient war technology and is trying to stumble the entire planet into chaos. Can you identify and stop the evil forces trying to disrupt the fragile peace?






Read more about its gameplay concepts below. This article applies to CamoTactics 7.1.


Environment, Stealth & Camouflage:

What's already in: Enemies won't see you if you are well camouflaged or behind them. How well you are camouflaged depends on how well your current camouflage color matches the terrain color. It also depends on the distance from the target. A sensor system makes sure that even if you cannot be seen, you still can be heard. The soon to be released demo version 7.1 features day and night cycles and lighting effects.

What's to come: hiding in bushes and being in the shadow will make you harder to spot. Appropriate sound design, weather conditions like fog, rain, thunder, snow, many strange and bizarre plants and animals that you may encounter (who may eat you alive while you sleep) are planned. The game plays on a alien planet and as such I want to display an adequate atmosphere and make the impression of a whole new world for you to explore. I want this game not only be fun, but also an unique experience for YOU.


Detailed Combat:

What's already in: Weapons have attachments like scopes and magazines that can be edited. They affect overall weapon performance. I want players to discover and collect new guns and mods. This mechanic is very similar to weapon modding in Fallout 4. Weapons overheat and break as you use them, too. To shield you from different types of projectiles you can equip armor. It's possible to use health kits and repair kits as well. If you're not boarding and driving them, vehicles explode if you destroy them.

What's to come: The possibility to freely assemble your own guns is subject of future versions. Earlier versions included rocket launchers and shotguns, which will definitely come back. That will include close combat weapons.


World and Character Depth

What's to come:
The game gives the player a whole new world to explore. It's a futuristic society that sometime 2000 years ago crashed on an alien and hostile planet (that happened to be home planet of an ancient precursor alien race). That also means: spaceships! Well, ancient wrecks for you to explore, that is! With notes, dialog, and speech bubbles the player can explore the characters, animals, plants, locations, technology, history and structure of society humanity has adapted in this strange world.

The story is written out for the most part and was as described as "inspirational" and "giving a different perspective" by some proofreaders. It will be delivered via missions and presentation-style cut scenes.



Inspiration

CamoTactics started out as simple prototype that has grown a lot in two years. Many games inspired me to make it what it is today. Let me list the most prominent ones:

  • ARMA II
  • Thing Thing Arena
  • Metro 2033
  • Metal Gear Solid 3
  • Fallout 3

During those two years developing this game, I've readjusted it quite a few times. There was a huge setback, too, considering I switched frameworks halfway through which delayed its release. But it's back, being better than ever.



Sonntag, 29. Mai 2016

Game Localization using Java Bundles


I toyed around with two ways how to implement Localization in Java. Let me present you the two ways I've implemented and which are better for you to use. I am assuming you know how to use Java Resource Bundles. If not, the check oracle the tutorial here or check this video I made here. In my examples, I will be using LibGDX, however, the code is almost the same.


The methods have both up and downsides which I'll discuss later.


Using Object Reflection

This method I worked out runs over all fields of one class and translates String types of fields (including fields in superclasses). The value of that field is being used as localization variable. Fields to be translated are marked with an annotation. This is helpful when you don't want to translate every single String in a class, and say, use untranslated Strings for object IDs.

You have a localization annotation like this:

/**
 * Marks a field to be localized.
 * The content of the field is being used to localize it.
 * @author B5cully
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Localized {
   
}


A very simple class. It's just a marker, after all.

The object is being localized like this:

  
    private static I18NBundle translations= ... // init the the bundle. This is libgdx specific, 
                                             // but works the same with a java resource bundle
                                             // the call may look a bit different
    /**
     * Localizes an object.
     * @param o
     */
    public static void localize(Object o) {
        Class current = o.getClass();
        do{
            try {             
                Field[] fields = current.getDeclaredFields();
                for( Field field : fields ) {

                    //the following is a hack to make the field temporarily accessible
                    boolean accessible = field.isAccessible();
                    field.setAccessible(true);
                    //check if the annotation exist
                    Localized annotation = field.getAnnotation(Localized.class);
                    if( annotation != null ) {

                        //localize the content of the field here
                        String localized = translations.get((String) field.get(o));
                        field.set(o, localized);
                    }
                    field.setAccessible(accessible);
                }
            } catch (SecurityException ex) {
                ex.printStackTrace();
            } catch (IllegalArgumentException ex) {
                Logger.getLogger(Localization.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(Localization.class.getName()).log(Level.SEVERE, null, ex);
            }
            current = current.getSuperclass();
        } while( current != null );       
    }


An object I want to translate may look like this:

public class CTWindow {

    @Localized
    public String title = "loc_window";

    public String id = "Window001";
}

Using this code, only the title will be translated by the localize() method. However, this may not work as elegantly for switching languages in a live system.



Using Field Names as identifiers

The other method is to use canonical names in your properties file. For example, your property file has an entry like this: com.neutronio.Infantry.hitpoints = Hitpoints. When you translate the field of an object, all you have to do is to get its class and field to obtain the localization.

What sounds nice in theory, isn't as easy in practice. We need multiple methods to achieve this.

    private static I18NBundle translations= ... // init the the bundle. This is libgdx specific, 
                                             // but works the same with a java resource bundle
                                             // the call may look a bit different
    /**
     * Gets the standard file path for a locale. This is required to

     * to turn a path of a properties file into desired format using its tag.
     * @param locale
     * @return
     */
    public static String convertPath( Locale locale) {
        String tag = locale.toLanguageTag().replace('-', '_');
        return tag;              
    }
  
    /**
     * Obtains a localized variable by
     * a simple field name and class.
     * @param field
     * @return
     */
    public static String localizedVar(Field field) {
        if( field == null) return "";
        return field.getDeclaringClass()

                    .getCanonicalName()+"."+field.getName();    
    }
  
    /**
     * Gets a field by name and class. Null if none was found.

     * This method works recursively in all superclasses.
     * @param name
     * @return
     */
    public static Field getField(Class clazz, String name) {
        Exception exception1 = null;
        Exception exception2 = null;
        Class current = clazz;
        Field result = null;
        do{
            try {              
                Field[] fields = current.getDeclaredFields();
                for( Field field : fields ) {
                    boolean accessible = field.isAccessible();
                    field.setAccessible(true);
                    if( Objects.equals(field.getName(), name) ) {
                        result = field;
                        break;
                    }
                    field.setAccessible(accessible);
                }
            } catch (SecurityException ex) {
                ex.printStackTrace();
                exception2 = ex;
                Logger.getLogger(Localization.class.getName()).log(Level.SEVERE,
                        "No acess to Field " + name + " in " +           

                         clazz.getCanonicalName() + ".", ex);
            }
            current = current.getSuperclass();
            if( result != null) break;
        } while( current != null );
        return result;
    }
  
    /**
     * This is the method that ultimately translates the field.

     * Obtains a statically defined localized string.
     */
    public static String getLocale(Class clazz, String name) {
        Field field = getField(clazz, name);
        if( field == null) return name;
        return translations.get(localizedVar(field));
    }


While this sounds like a handy approach there is one huge downside to it: Say my CTWindow class is extended with a MainMenuScreen. So what happens? Due to the nature of this algorithm, I can't define anything like MainMenuScreen.title = Main Menu instead of CTWindow.title= Some Title in my properties file. That means the String in the CTWindow.title local variable is stuck and cannot be redefined by subclasses. That is because of the field.getDeclaringClass() part in localizedVar(). You can work around this if you change the methods by providing the class of the object instead class where the field is being declared, like so:

    /**
     * Obtains a localized variable by
     * a simple field name and class.
     * @param field
     * @return
     */
    public static String localizedVar(Class declaring, Field field) {
         if( field == null) return "";

         if( declaring == null) return "";
         return declaring.getCanonicalName()+"."+field.getName(); 
    }

I haven't tried this out yet, so I cannot say for sure if this works! Let me know if it does. ;)

You also can still use the localize() method ontop of this, as described further above, so both of these methods can be combined together. If combined, they may actually offer the possibility to change language in a live system, as the field names are used directly for translation.

But how do you treat lists or collections of Strings?!

That's a topic for another article!


I hope I brought you closer to the topic of localization. Thanks for reading! I hope you enjoyed it.

Samstag, 28. Mai 2016

7 Ways to Boost Your Productivity

We've all been there once, wasting our time then wondering where it went. So how do you actually boost your productivity?

I collected a few helpful tips here:


  1. Get rid of all distractions. Get your focus right! Log out to all your social network accounts. Turn of your phone. Turn off internet, too, if it's not crucial. Spend a few hours doing what you planned without any distractions. DO IT!


    https://i.ytimg.com/vi/Z6gG3tKDBlk/maxresdefault.jpg

  2. Find a way to organize yourself. Keep a to-do list. If you're an indiedev, you can use HackNPlan. Don't lose track of what you're doing - which leads me to the third point.

  3. Review how far you've come and ask yourself if it helps achieving your goals. You HAVE to do this no matter what you're trying to achieve (no matter if you want to become better as a person, live a better life, or fulfill your biggest dreams). Dream big and make it happen!

  4. Make sure your work environment is well-lit. Bright light encourages your brain to focus more. Too less and you get in sleepy mode!

  5. Make sure your work environment is tidy if you work on tasks requiring a lot of brain juice. For creative tasks, a bit of a chaos may actually help finding ideas.

  6. Make sure you don't work with a full belly. That's when all your blood is in your intestines instead of your brain. The best time for mental work is with empty stomach after a walk, workout, or cold shower, when your metabolism is all fired up, feeding your brain with valuable oxygen. Breathing exercises in fresh air may help, too.

  7. A cup of blueberries and other fruit can help boosting your mental capabilities.

    https://upload.wikimedia.org/wikipedia/commons/0/0b/Blueberries-In-Pack.jpg


How do you keep your productivity high? How do you keep it? Let me know in the comments!

Montag, 16. Mai 2016

6 Things that make Your Box2D world freeze

Ever encountered problems with your Box2D setup freezing or locking up and you don't know why?


Yes?

Then read on!

There are quite a few things you can do wrong with Box2D. I have collected a few common mistakes here. These mistakes include...


1) ... Changing the position of a body manually!
Generally, it's a bad idea to modify any body information directly, e.g. by using Body.setTransform() or changing position with Body.getPosition().set(x,y). This makes all contacts currently processed by the simulation invalid and ocreates unpredictable behavior.

Solution: Applying changes to velocity or position (including setting transformation) should always happen after the world has stepped. To do this, you can create a list of operations that is then processed after the world step. This can look a bit like this:
      
   world.step(...);
   if (!operations.isEmpty() )
   {
     operations.perform();
   }

See stackoverflow for more of this issue. You can also try copying the vector to avoid modifying it when using vector math.


2) ... Destroying physic bodies during a callback!
Raycasts and Queues are solved during a timestep. Modifying bodies during that process will cause Box2D to crash. Do not ever do this!

Solution: The code setup in 1) can help you out here. Send your destroy operations to a list containing bodies to be destroyed, where it is processed after the world has stepped. I do this in my game and it works perfectly fine.


3) ... Vectors getting NaN as values!
This happens if you apply an enormous amount of angular or linear impulses to your physic bodies, to the point they get catapulted to nowhere, because they adopt infinite velocity (and thus position).

Solution: Check your formulas and make sure the values are usable! It's a good idea to include a check on whether your values are valid when doing calculations; and throwing an error in case they don't.


4) ... References to destroyed physic bodies!
Once you have destroyed a body, it should not be referenced anywhere again.

Solution: Once destroyed, a body reference should always be set to null!


5) ... Creating physic bodies when the world is in the middle of a time step!
Because if you do, granted, you will get a freeze! This has caused me a lot of headaches personally.

Solution: You can use a similar solution as in 1): creating your objects after the world has stepped by putting them in your operations queue. 


6) ... Creating physic bodies that are created inside other physic bodies!
This causes your created physic bodies to be slung away like a bowl of peanuts gone crazy - if it doesn't crash first! In my experience, this happens when you have shooting mechanics, but the spawned projectiles touch the entity they were shot from.

Solution: There are numerous ways to solve this. You can either make sure your bodies are small enough and far away enough from a defined projectile spawning point - or if collision behavior doesn't matter too much, you can use collision groups and masking to avoid them touching each other.



I hope this helped you with any issues you had! If you still have problems, let me know - I'll be happy to help you out.

5 Reasons Why Your Game Should have Achievements


A while back I was asking my twitter followers about achievements and their significance in a game.
The general sentiment was that achievements were an important feature that you should consider adding. Let me present you the results and explain why.

Achievements...


1. ...Make Players Stick to your Game
Gamers want challenges. So by providing them achievements they can complete you are also giving them a sense of accomplishment once they finished them. They will want to complete as many achievements as possible and play your game longer, too. Even better if you're also giving them rewards while doing so!


2. ...Make Players explore Your Game
When a player sees a certain achievement, they will spend time trying to do things that may help them get it. This gives them a very good reason to explore your game and scoop out all possibilities.


3. ...Add Replayability & Variety
In case your game has mechanics that allow usage of different strategies or play styles, achievements are the best way to let many gamers experience as many aspects of the game as possible. If you want to promote creativity, reward players for doing things differently. Having your hands on the knob called variety is, in my opinion, a very crucial tool of game design. I think Team Fortress 2 does this very well - even though in practice it doesn't always turn out so well!

http://65.media.tumblr.com/35534564b0c069dc16e53688db64aeb9/tumblr_mhrbwedGhv1qmp4f4o1_500.jpg

4. ...Provide Guidance
Achievements can give important information to the player, such as how the game is being played or what else can be done in your game. Players will know what gameplay, items etc. to look after just by checking the list of achievements - if you are providing them with one.


5. ...Encourage Competition 
Especially in online gaming communities, achievements are often worn as a badge of honor and proudly shown off to others. Paired with a leaderboard, that also increases the chance someone plays your game longer.

http://www.mememaker.net/static/images/memes/4342839.jpg

I remember playing too much agar.io trying to get on the leaderboard in the first place...


Summary
Achievements are a great way to enhance your game, even if it is a small one. They increase variety, add more challenges and makes players explore your game more. All of which that, if done right, eventually results in more fun and time spent playing.

For further reading, you can check this video on which types of achievements are the best ones (Youtube). Thanks for Mr. Aqua for showing me this, you know who you are!

Thanks for reading!

Dienstag, 10. Mai 2016

What really makes a game fun and worth playing?




What makes a game fun?

That seems like a so simple question. The more I contemplate it, the more multilayered it becomes.

What is fun? 
 
What triggers a fun experience?

How to create something that is fun?


Fun is all about:
  • challenge
  • reward
  • taking risks
  • exploration
  • the rush of the unknown
  • taking opportunities
  • collecting things
  • messing around and testing out limits
  • answering the question, "what would happen, if...?"
...all in a playful way. It's how nature makes all life learns its lessons. Fun can also be something that brings back childish wonder and curiosity and allows us to reconnect to this deepest part of ourselves many of us learned to "grow away" from. Maybe that's why games are generally liked by many people - whether it be tabletop games, video games, or also the games you played on the playground, or later the "mind games" adults play (games that sometimes turn into not so funny ones..).


How does fun in games look like? 

I can think of a couple of things. Generally spoken, flashy-ness and the right aesthetic can make a HUGE difference in making a game fun.

If your explosions look amazing, the player will have endless fun making things blow up. For a while, they'll try to cause explosions whenever they can (exploration & testing out your limits).

If your GUI features detailed LED displays that lighten up, players may act similarly. Good sign: when you're coding something like this and notice you end up playing with it instead of just testing it!

If the sound design is exceptional, like in Don't Starve, only the act of opening up the build menu already contributes to the user having fun.


But it's not only aesthetics that make a game fun.

Rewarding the player for interacting with the environment, like loot drops from enemies or treasure chests, is also a good way to make a game more enjoyable.

To a degree, randomized outcomes (loot) gives uncertainty and make the player strive for more (rush of the unknown). Even if procedural generated content potentially becomes repetitive after a while, it can still give variety and spice up a game considerably. This is very well demonstrated in the game DoomRL or Phantasmal: House of the Shunned Ones, where each run will be different due to the fact the maps are generated and you find different equipment and enemies each time. Then, if you're lucky and good enough, you might even get to the end!

Let's take a look at Minecraft. The sheer amount of possibilities to play the game and build whatever is on your mind is probably the most important reason why it has gotten so popular. Players would create new challenges for themselves and take on them as they build whatever is on their minds.

In Fallout 4, I had a lot of fun just by collecting all weapon mods and using the best mods for my guns, because I am little perfectionist gun nut! Collecting things generally is a good idea, no matter what you collect: achievements, items, coins, badges, titles, obligatory notes that - as a whole - tell a story... or just screenshots of Fallout teddy bears!
 https://pbs.twimg.com/media/CWIptp3XIAADnF8.jpg
In games like the Fallout series, it was also fun to test out your limits in dialogue with the characters and see how they react - without suffering from potential backlash, as would happen real life. This can be a valuable social learning tool.

Things that can spoil fun a game:

A reliance on too much luck can potentially spoil a game if the outcome becomes too unpredictable. It's important to mix in an adequate amount of player skill required if the player wants to advance in a level.

Game mechanics that don't go too well and are in conflict with each other are another aspect that can spoil much of the fun.

For example, take a look at Don't Starve: it's a survival game taking place in a procedural generated world, but exploration is actually discouraged by the fact time is very limited and you die in the dark. Damn Charlie stealing your soul at night! This also puts the player under a lot of pressure. Of course, this can be fun for certain players, but after a while patience runs low and most just prefer to quit the game instead. Something you, as someone who makes games, should avoid!


I hope my insights gave you an interesting perspective on the topic "fun". Thanks to @TheSnee for giving me some ideas for this article!

If you want to check some more game development related articles, you may be interested in how to store your data in a Java game or check these 5 useful tools to start out gamedev.

Donnerstag, 5. Mai 2016

5 Free, Must-have Tools to Start Out Gamedev

Ever wanted to get into game development?

Yes?

Then read on!

You probably have wondered how to start out making your first game. Maybe you tinkered around with scripts or mods but never made something all by yourself. Fear not, for this article will give you an insight how to start out your development without much hassle.

Out of incredible amount of tools that exist to create games, I now present you 5 tools you should use starting out your first 2D game.


  1. Editor: Unity 3D

    Unity is a cross-platform, user-friendly 3D engine that allows you to quickly get a game and some gameplay running without worrying too much about the technical side of things. It features a huge asset store and many tutorials that help you kickstart your game development. The engine can also be used for 2D games.
  2.  Graphics Program: Krita

    To create all the game art you need, you will need a graphics program. A good choice here is Krita, which is a powerful tool to create your assets. I've used many graphics programs in my life, from Photoshop to PhotoImpact and Paint Tool SAI - and Krita has an astounding amount of features for a program that is open source.



  3. Map Editor: Tiled

    If you want to make a game, you will also need create a world for it. The map editor Tiled comes very handy here. It allows you to create terrain brushes, add images and objects to the world and define properties for each. All in all it's a great editor that is free for you to use. To load Tiled maps into Unit3D, you can get this plugin to add TMX support to your project.



  4. Music Editor: Bfxr

    What's a game without sound? With the free-to-use program Bfxr, you can create your own sounds from scratch - without worrying about permission or copyright.
  5. Organizer: Trello

    If you do your daily dose of development, you also need something to help you keep track of your tasks and bugs! (Believe me, there will be many...) Trello helps you to do just that and get organized. You can create to-do lists and spreadsheets very easily. It's also available as mobile app. (Thank you @PeculiarCarrot for pointing out there is also Hack 'n' Plan for this purpose!)

If you want to check out a larger choice of tools, I recommend you to check the resource page.

Happy coding! If this inspired you, make sure to show me what you've made!