Are idle games easy to code?

6    29 Jun 2015 01:47 by u/with-or-without

12 comments

7

Yeah. Well, I've only poked around in it a bit. If you know how to write functional JavaScript it's easy. The hard part is balance and coming up with a fun formula. From my limited experience with them, I know you need:

  • The click function
    This is the first and only available action the player can take, initially (in most cases). Click to collect some kind of resource. Write a function like this:

    var points = 0; // Track total points here
    var bonus = 0; // If you use modifiers for higher points per click, use this
    var theClick = function(n) {
        if ( n > 1 ) {
            points = points + ( n * (1 + bonus));
        } else {
            points = points + (1 + bonus);
        }
    }  
    

    Then just apply that function to a button in your interface. The n argument is explained below in the repeated function.

  • Resource(s)
    In my example above, points are your primary resource. You'll earn it from your theClick() function. You can get creative and come up with multiple resources (with multiple functions) to add more depth to your game. This is good if you want to add a rarer resource later in the game.

  • The repeating function
    Next you need to write a function that repeats every X seconds. This is used if you have "clickers" in your game. Any kind of upgrade that does the clicking for you. In the above example, I've included an argument to your function. Use this argument with the number of clickers the player currently has. Example:

     var clickers = 3;
     setInterval(
         theClick(clickers), 1000;
     )  
    

    This will fire your function every 1000ms (1 second). It passes the number of clickers as the argument, which multiplies the effect of the function. In the above example, it will add 3 to your points every 1 second.

  • Upgrades
    Upgrades add depth and interest to your game. This could be something like a percentage bonus to clicks, or doubling the effectiveness of your clickers.

Those are the core building blocks of any idle clicker game. The funnest games have many more layers to them, adding hundreds of upgrades, new resource types, animations, etc. It's a good exercise for someone who is an intermediate at JavaScript coding to build one of these kinds of games.

Edit: Fixed the click function.

1

Wow, that was great! Thanks for taking the time. Would building a simple idle game be outside the scope of a beginner?

Also, could I use this comment in my subverse /v/idlegaming ? I'm trying to construct a definition for idle games and think your post is relevant and insightful!

1

Oh yeah sure feel free to use it. As far as being outside of the scope of a beginner probably not. If you understand functions, arguments, variables, etc. you should be fine. If you have questions I can try to answer them as well. I'll subscribe to that sub too. I love idle games and I want to build a really engaging one but I'm limited on time for the most part.

0

Awesome, thanks! I may just take you up on the offer.

0

Could you do me a favor and post this to the Idle game definition thread in /v/idlegaming? Id do it myself but im not sure if the layout would be compromised with a simple copy/paste.

0

Thanks, that's pretty interesting.

I was wondering, how do you handle really big values (like billions of billions) ? Do you cut your value into several int (i.e. var value1 = 999, var value 2 = 0, when value1>999; value2 ++ )?

1

I haven't really spent much time dealing with large numbers in my projects. The typical way I've seen is go up to 999 then convert to 1.00K, then 1.00M, 1.00B, 1.00T, 1.00Qa, 1.00Qi, 1.00Sx, 1.00Sp, 1.00O, 1.00N, and so on. That way the most digits you display would be five (999.99K). You can use a simple if statement to determine if the value should be displayed as K, M, etc. The back end value would remain the same. 980520001 would simply display as 980.52M for instance.

1

What do you mean by "idle games"? Turn based? Casual games?

3

idle games are a growing genre of games where, some degree of progress is made without player intervention. A game where you gain 1 dollar per second, with the only requirement be that the game is open, you then use this currency to buy upgrades, which have an effect on how much money you earn per second....

this is a very simplified example, good idle games (IMO) generally have multiple systems of customization and more then just one currency.

1

check out /v/idlegaming

0

Kongregrate has a whole section for idle games.