Skip to content

Custom Weapons Walkthrough

cxong edited this page Nov 5, 2014 · 10 revisions

This page will walk through the process of creating a custom weapon.

Start with a campaign

Let's start with a blank campaign. This one is very basic and will simply let us try the weapon out. There are a few scattered map objects that we can blow up.

The campaign itself will be a folder, inside there are these three files:

Add guns.json and bullets.json

Custom weapons start with guns, defined in a guns.json file. Go ahead and add this, with the following contents:

{
  "Version": 1,
  "Guns": [
    {
      "Name": "My Gun",
      "Bullet": "my_bullet"
    }
  ]
}

And create a bullets.json file too, with the following contents:

{
  "Version": 1,
  "Bullets": [
    {
      "Name": "my_bullet"
    }
  ]
}

You can see what's going on here: the gun we've made will shoot the bullet we've made, by referring to it by the same name. The bullet name doesn't show up anywhere else so it doesn't really matter what we name it, as long as it's unique.

If you open the campaign up in the editor, you should see that this gun already shows up in the "Available weapons" section:

At this point we can actually load this campaign up in game, and try out our new weapon...

... and it does nothing except make a lot of noise. We need to fill out those gun and bullet attributes now.

Add basic attributes

There's a big list of gun and bullet attributes here. No matter what weapon you make however, you'll probably want to change these:

For the guns (guns.json):

  • Cost: how much score each shot costs
  • Lock: how much time between shots, in terms of game ticks. This controls rate of fire.
  • Sound: the sound that this gun makes. Different guns should make different sounds!

For the bullets (bullets.json):

  • Pic: probably the most important, what the bullet will look like. There's actually several different types of structures you can use here, from basic images to animations. The most common types would be "Normal" and "Directional".
  • Speed
  • Range: how much time, in terms of game ticks, this bullet stays alive for.
  • Power: a.k.a. damage

Let's add some of those attributes now:

guns.json

{
  "Version": 1,
  "Guns": [
    {
      "Name": "My Gun",
      "Bullet": "my_bullet",
      "Cost": 6,
      "Lock": 100,
      "Sound": "launch"
    }
  ]
}

bullets.json

{
  "Version": 1,
  "Bullets": [
    {
      "Name": "my_bullet",
      "Pic": {
        "Type": "Normal",
        "Pic": "molotov"
      },
      "Speed": 400,
      "Range": 60,
      "Power": 0
    }
  ]
}

We're getting somewhere now.

More attributes

Let's give the gun some more character. We want to make a gun that shoots a bouncing projectile that deploys into a booby trap. Let's work on the first part: getting the bouncing projectile. Here are the attributes we'll need:

guns.json

  • ReloadLead, ReloadSound: since the gun takes a long time to reload, it'll be nice to add a sound that plays just before the gun is ready to fire again.
  • Recoil: this adds a bit of random inaccuracy to the gun, which makes it feel more like it's launching a heavy, nonaerodynamic projectile.
  • Elevation: this tells the gun to shoot upwards (or downwards).

bullets.json

  • ShadowSize: as the bullet will be falling, it's nice to show this with a shadow. This attribute both enables the shadow and specifies a size, which should match the size of the bullet.
  • Size: this affects the collision size of the bullet.
  • Spark: this is a short-lived sprite that shows whenever the bullet hits something - walls, objects, players - but since this bullet will act like a bouncing grenade, we don't want any sparks.
  • HitSounds: the sounds that will play when this bullet hits something. We'll want sounds that sound like bouncing here.
  • WallBounces: the bullet should bounce off walls
  • HitsObjects: the bullet should ignore objects and simply go through them
  • Falling: this describes whether the bullet will fall with gravity and how. We just want regular gravity so we'll want a GravityFactor of 1, Bounces so that the bullet bounces off the ground instead of getting destroyed.

Let's put those values in and see what we get:

guns.json

{
  "Version": 1,
  "Guns": [
    {
      "Name": "My Gun",
      "Bullet": "my_bullet",
      "Cost": 6,
      "Lock": 100,
      "Sound": "launch",
      "ReloadSound": "package_r",
      "ReloadLead": 15,
      "Recoil": 0.4,
      "Elevation": 20
    }
  ]
}

bullets.json

{
  "Version": 1,
  "Bullets": [
    {
      "Name": "my_bullet",
      "Pic": {
        "Type": "Normal",
        "Pic": "molotov"
      },
      "Speed": 400,
      "Range": 60,
      "Power": 0,
      "ShadowSize": [4, 3],
      "Size": [4, 4],
      "Spark": "",
      "HitSounds": {
        "Object": "",
        "Flesh": "",
        "Wall": "bounce"
      },
      "WallBounces": true,
      "HitsObjects": false,
      "Falling": {
        "GravityFactor": 1,
        "Bounces": true
      }
    }
  ]
}