Experience - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

The user has a value for accumulated experience, certain amounts of experience is needed to level up, which results in user perks. Experience is also assigned to Enemy NPC's and is constant for each instance of that enemy type. When the user defeats an enemy, that experience value is added to the user total experience value. image

Yellow experience bar: represents a visual indicator in games that tracks a player's progress

image

Functionality

The player has a level up system, requiring a certain amount of experience points per level. The number of experience points required per level is specified by the following formula:

$y=71.7125e^{0.191529x}+13.1489$

Where y is the amount of experience needed per level and x is the level, each integer resulting in a level up.

The following is what the function looks like as a curve:

desmos small

Experience required per level:

1 2 3 4 5 6 7 8 9 10
100 118 140 167 200 239 287 345 415 500

The maximum level that the user can be is 10. For each level up, each user attribute is incremented by 3.

For information on how much experience is gained from each enemy, refer to the Enemy NPC Statistic Wiki.

Implementation

Experience is assigned to each enemy in the enemyNPCs.json file under "experience". An excerpt from this file is shown below, with the chicken and frog enemies with experience of 10 and 20 respectively:

{
  "chicken": {
    "spritePath": "images/enemy-chicken.atlas",
    "health": 5,
    "baseAttack": 1,
    "defense": 2,
    "speed": 200,
    "experience": 10,
    "isEnemy": 1
  },
  "frog": {
    "spritePath": "images/enemy-frog.atlas",
    "health": 4,
    "baseAttack": 25,
    "defense": 1,
    "speed": 50,
    "experience": 20,
    "isEnemy": 1
  }

XP Transfer

Example of Usage

When the user defeats the enemy, experience will be transferred to the user. In CombatActions.java under onCombatWin, the following code achieves this:

int enemyExp = enemy.getComponent(CombatStatsComponent.class).getExperience();
manager.getPlayer().getComponent(CombatStatsComponent.class).addExperience(enemyExp);

gets value to display

int experience = entity.getComponent(CombatStatsComponent.class).getExperience();
        CharSequence experienceText = String.format("EXP: %d", experience);
        experienceLabel = new Label(experienceText, skin, "large");

gets value after defeated enemies

    public void returnFromCombat (Screen screen, ServiceContainer container, Entity enemy) {
        setOldScreen(screen, container);
        ((MainGameScreen)screen).getGameArea().spawnConvertedNPCs(enemy);
        List<Entity> enemies = ((MainGameScreen) screen).getGameArea().getEnemies();
        for (Entity e : enemies) {
            if (e.equals(enemy)) {
                enemies.remove(e);
                break;
            }
        }
        AnimationRenderComponent animationRenderComponent = enemy.getComponent(AnimationRenderComponent.class);
        animationRenderComponent.stopAnimation();
        int enemyExp = enemy.getComponent(CombatStatsComponent.getExperience());
        player.getComponent(CombatStatsComponent.addExperience())
        enemy.getComponent(CombatStatsComponent.getExperience());

        enemy.specialDispose();
    }
⚠️ **GitHub.com Fallback** ⚠️