JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Achievement Struct Reference

Represents one unlockable Achievement (aka Trophy) More...

#include <jngl/Achievement.hpp>

Public Member Functions

 Achievement (std::string id, std::string name, std::string description, std::string icon, int initialValue=0, int maxValue=1)
 The id must match the ID you set in Steamworks (if you use Steam, otherwise it's unused).
 
int getValue () const
 
void increaseValue (int by)
 

Public Attributes

std::string id
 API Name.
 
std::string name
 
std::string description
 
std::string icon
 filename for achievement icon, will be loaded when the achievement is displayed
 
int maxValue
 
std::function< int(int)> customDisplayValue
 

Detailed Description

Represents one unlockable Achievement (aka Trophy)

This struct holds all the necessary information about a specific achievement and provides integration to the Steam SDK (if available). One way to handle achievements is to create a Singleton class which holds all achievements as member variables:

struct Achievements : public jngl::Singleton<Achievements> {
jngl::Achievement finishLevel5{"FINISH_LEVEL_5", "Finish Level 5",
"Finish level 5", "finish_level_5"};
jngl::Achievement collect100Coins{"COLLECT_100_COINS", "Collect 100 Coins",
"Collect 100 coins", "collect_100_coins",
0, 100};
};
Contains jngl::Achievement class.
Contains jngl::Singleton base class.
Inherit from this class to create a singleton that will be destroyed when your games exits.
Definition Singleton.hpp:23
Represents one unlockable Achievement (aka Trophy)

Then you can unlock the achievements like this:

void onNextLevel() {
if (currentLevel >= 5 && Achievements::handle().finishLevel5.getValue() == 0) {
Achievements::handle().finishLevel5.increaseValue(1);
}
}
void onCollectCoin() {
Achievements::handle().collect100Coins.increaseValue(1);
}

Definition at line 43 of file Achievement.hpp.

Collaboration diagram for Achievement:
[legend]

Member Data Documentation

◆ id

API Name.

Definition at line 49 of file Achievement.hpp.

◆ name

Definition at line 51 of file Achievement.hpp.

◆ description

std::string description

Definition at line 52 of file Achievement.hpp.

◆ icon

filename for achievement icon, will be loaded when the achievement is displayed

Definition at line 55 of file Achievement.hpp.

◆ maxValue

int maxValue

Definition at line 57 of file Achievement.hpp.

◆ customDisplayValue

std::function<int(int)> customDisplayValue

Definition at line 63 of file Achievement.hpp.


The documentation for this struct was generated from the following file: