Combat Items: Master Code Extension Guide - UQdeco2800/2022-studio-2 GitHub Wiki

How can I add a new weapon to the game (from start to finish and including animation)?

Master Step 1: Add the weapon to the Weapons.json config file

  1. Browse to source/core/assets/configs/Weapons.json using your Java IDE of choice.
  2. Add a new weapon configuration to the .json file, for example:
  3. Note that you will be using this name in the next step, so take note of your "newWeapon" name.
  "newWeapon": {
    "damage": 60,
    "coolDown": 1000,
    "weight": 1,
    "materials": {"gold": 1, "steel": 1}
  }
  1. Note what each factor does
  • damage: how much health points of damage the weapon does
  • coolDown: number of milliseconds (ms) of wait time before each attack swing can be made
  • weight: this impacts move speed. the higher the number the heavier the weapon (and the slower the player moves)
  • materials: the materials that are required to craft the weapon within the crafting system

Master Step 2: Add the weapon into the WeaponFactory

  1. Browse to source/core/src/main/com/deco2800/game/entities/factories/WeaponFactory.java using your Java IDE of choice.
  2. Add a new create() following the syntax outlined below:
public static Entity createNewWeapon() {
        Entity newWeapon= createBaseWeapon();
        WeaponConfig config = configs.newWeapon;
        PhysicalWeaponStatsComponent weaponStats = new PhysicalWeaponStatsComponent(config.damage,
                config.coolDown, config.materials, config.weight, "newWeapon");
       newWeapon
                .addComponent(weaponStats)
                .addComponent(new TextureRenderComponent("images/CombatItems/newWeapon.png"));
        newWeapon.getComponent(TextureRenderComponent.class).scaleEntity();
        newWeapon.scaleHeight(1f);
        newWeapon.setEntityType(EntityTypes.MELEE);
        return newWeapon;
}

The different weapon creator methods will call the base weapon creator method to create a base weapon entity and have different component add-ons onto the Weapon Entity.

Please note that you will need to add the TexturePath of the new weapon to core/src/main/com/deco2800/game/areas/ForestGameArea and also to core/src/main/com/deco2800/game/areas/UndergroundGameArea if you plan on using these textures on the map.

Also, you will need to add the weapon into the crafting system so it can be crafted. For this, refer to Team09's explanation of crafting logic. https://github.com/UQdeco2800/2022-studio-2/wiki/Crafting-System-Code-Implementation-Sprint-Two

Now, we have added the new weapon to the WeaponFactory and WeaponConfig, it's time to add its animations!

Master Step 3: How to add a new combat animation to the game

Add your new images

Firstly, you should have generated a new .atlas and .png file containing your new animations. Currently, the primary animation system is built in the combatItemsAnimation.atlas and .png files.

Create the new animation

Go to PlayerFactory.java and find the createCombatAnimator() function. In the section where the animations are listed, add in your animation. Your chosen animation name must match up with the entry within the .atlas file. For example, the below animation:

animator.addAnimation("sword", 0.1f);

Will trigger the "sword" animation within the .atlas file, such as below:

image

There can be multiple images with the same animation name. When this is the case, when the "sword" animation started, it will play all frames in the atlas file named "sword"

Note that for static animations where there is no attack event but there are particle effects we use a LOOP. e.g.

animator.addAnimation("swordSpeedStatic", 0.1f, Animation.PlayMode.LOOP);

Add the event listener

Then, go to PlayerCombatAnimationController and add an event listener for the name of the animation you have just created. For example:

entity.getEvents().addListener("sword", this::animateSword);

Add the start animation function

Scroll down to the section below the listeners where the animate functions are written. Add your animation start event.

void animateSword() {
    animator.startAnimation("sword");
}

Note that you can name the animate function whatever you would like. However, for consistency, we follow the convention of calling the function animateEventName.

Master Step 4: Review and test!

Now, your weapon should be in the game! Open it up and test it for yourself. If not, maybe check out the link below -

To fully understand the Combat Animation System, take a read of https://github.com/UQdeco2800/2022-studio-2/wiki/Combat-Animation-System!