Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by peepli

Hello everyone,

I am trying to create a simple achievements system for our upcoming game. But I need help from the community regarding the design

The system is pretty simple. We have a core mechanic in our game where we throw questions to the players and they have to answer them. Each player has to first register at the start of the game. In the back end, we have a database that dynamically creates players ID on registration. In our players database there is a separate data structure called questionsSolved for each player with their specific ID which again dynamically stores all the questions that specific player solves each time.

So we are building an achievement system around this mechanic of questions solved. For now we have not really decided what kind of achievements we want to implement but some examples would be "An achievement for first three questions solved", "An achievement to solve the hardest question", "An achievement to solve question no 4,7 and 15" assuming we have around 40-50 questions in our entire game but hopefully you get the picture of where we are heading.

So my question would be how do I go about an implement a system which tracks all the different kinds of achievements.

For now I have created an Entity called Achievements. I am not sure if I should use a normal class or an Entity for now. Maybe it should be a class as its not visible or interactive in any way in our game. It just runs all the time and checks if certain achievements were met and if an achievement gets met it just throws a pop up telling "achievement 1 is unlocked" or " Ach 2 is unlocked " or watever. For now let's just say I have an Achievements Entity. So in the initial stage we want to be able to check at least 2 achievements for play test.

I think I need two functions -> checkAchievements() which runs on every update to check if a certain achievement is met. From inside this function if a certain achievement is met, I call triggerAchievements(achID) which has a switch case and spawns a specific achievement pop up for that achID.

The issue I feel is the optimization. Here are a few problems I feel I need to address but I don't know how!

1. Calling and checking the database on every update for the problems solved by a player is a big overhead I feel. This is done inside the checkAchievements() function on every update.

2. Also for every achievement, the conditions would be different for that achievement to be met. If I have say 100 achievements in my game, how do I go about and implement the different checks for each achievement. For now in my checkAchievements() function, I call various other functions that check for specific achievements. Meaning if I have 100 achievements in my game I have to write down 100 different functions in my checkAchievements() function which is a lot!

How do I address the above two problems? Is there a better design structure?

I would be really really grateful if anyone with experience in this domain could provide me some help as I am relatively new to this type of class design or could throw a simple skeleton code of how I can structure my Achievements class.

Thank you!

1 decade ago by peepli

I feel I should show you guys my skeleton code for now as it provides a clear picture of my current design.

  EntityAchievements = ig.Entity.extend(
            probsSolved:null,
             init: function(x,y,settings){
                 this.parent(x, y, settings);
             },

             update:function(){
                 this.parent();
             },

             draw:function(){
                 this.parent();
             },

             checkAchievements:function(){
            // gets all the problems solved by a player from database. not relevant.  just assume that it works!
                probsSolved = this.getTeamProbSolved(); 

                     if(firstAch())
                           triggerAchievements(1);
                    else if(secondAch())
                          triggerAchievements(2);
               },

             firstAch:function(){
              // check for first achievement
             },
             secondAch:function(){
              // check for second achievement
             },
             triggerAchievements:function(achID){
                 switch(achID){
                     case 1:
                    // first ach pop up
                     break;
                    case 2:
                    //second ach pop up
                    break;
                 }
              },

1 decade ago by FragOnly

Hello,

You might want to consider putting each achievement in its own class. Once they are all on their own class you can add all of the achievements into an array in the Achievements class and just iterate through them for the checks, etc. This would keep your Achievements class a little more management, imagine it with hundreds of if statements.

1 decade ago by Joncom

You may want to make your achievement class extend ig.Class instead of ig.Entity, because you don't really need an entity, do you? After all, you won't be drawing this class, needing physics, or any of that...

10 years ago by bustedkrutch

I'm currently at the exact same point in my game and was hoping that PEEPLI would be able to share what was learned ?
Page 1 of 1
« first « previous next › last »