How I add weapons to Dead Pixels.

I’ve realised that I don’t go into many details about the backend of Dead Pixels, which is a shame because I like to read about that kind of thing with other peoples games.

So in this blog post I’m going to show start to finish how I add a new gun to the game.  In this case it’s going to be a sniper rifle.

So first I add the items name to the code in an enum called itemNames.

I called it simply sniperRifle1.  This is just a simple name for for the back end of the game.

Next I add it to the item database. There are 11 fields I must fill out for it here.

  • Name: This is the simple name I used before.
  • Clean Name: This is the name I want to be shown in game.
  • Description: This is the item description used in game. (weapons do not have a description)
  • Weight: This is the items weight.
  • Buy Price: The items default buy price
  • Sell price: Default sell price (It’s easy isn’t it?)
  • Type: This is the item type. In this case it’s weapon.
  • Chance of being in a building: This is a number that represents how common the item is. The higher the better.
  • Chance of being in a store: Same as above but for stores.
  • Max amount: This is the maximum amount of the item you will find when raiding a house. This stops you from finding 4 of the same shotguns in a house.
  • Level: The level represents what street the item should start appearing in stores and items.  There is still a chance of it appearing before then but it is very slim.

Once the sniper rifle is in the items database I add it to the weapons data base as well.  There are 19 fields in the weapons database.

  • Name: Again this is the name we put in the code. (sniperRifle1)
  • Damage: This is the default damage of the weapon.
  • Shots per second: This is how fast the gun fires.
  • Range: This is the horizontal range of the gunfire.
  • Width: This is the vertical range of the gunfire. for example the rifles have a very low width where as the sawn-off shotguns have a very high one.
  • Penetration:  This is the percentage of damage left as the shot goes through each zombie.
  • Ammo: This is the type of ammo the gun uses.
  • Stun Time: This is how much time a zombie is stunned when they are hit by a shot from the weapon.
  • Melee stun time: This is how long a zombie will be stunned if you melee them with the weapon.
  • Vol: This is how load the gun it.  Load guns will alert nearby zombies to your presence.
  • Gun Sprite height: This is where the gun is on the player sprite sheet.
  • Flare sprite: This is a number which represents which muzzle flare is to be used when the gun fires.
  • Gib: This is if the weapon “gibs” the zombie when they die or not.
  • Sound: This is the sound the weapon makes when it’s used.
  • Reload Sound: This is the sound the weapons makes between shots.
  • Ammo used: This is how much ammo is used with each shot.
  • Fire: This is if the weapon sets zombies on fire or not.
  • Shock: This is if the weapon gives zombies and electric shock or not.
  • Freeze: This is if the weapon freezes zombies or not.

Now it’s time to do the sprite work.

I separate out the legs, head and body to make things easier.  Each new kind of weapon needs it’s own set of body frames containing 6 frames.

  • The 1st is the normal idle frame.
  • 2nd is the melee frame. (This frame is twice the width)
  • 3rd is reloading.
  • 4th and 5th is for throwing grenades.
  • And 6th is for the gun firing.

Of course this is just the frames for one character. Currently there are 10 in the game so sprites for all of them must be done. So each new type of weapon needs 60 frames, but if it’s a similar weapon to something else i can use the same set of sprites for multiple wepons.

Finally I test it and make changes as necessary.

And that’s how it’s done.