Game Development Reference
In-Depth Information
Chapter 3. Expandable Item Classes
Items in video games are very important. They can be tools, weapons, healing items,
traps, clothing, armor, ammo, keys, and so on. Items are what the player will interact
with the most in your game. Since the items are so often used, it is a good practice to
create item classes that can be expanded and used in all possible situations without
having to rewrite the class.
In this chapter, we will cover the following topics:
• Creating customizable classes for items
• Learning how GameObjects can interact with each other through sending
messages
• Creating an Item class that affects the player
• Creating a Melee item class that will affect environments and enemies
• Creating a Projectile item class that can be used for items that travel dis-
tances
• Utilizing a classification system for all objects to decide what they do
• Using trigger-based collisions for the Melee and Projectile item classes
• Using two types of movement for projectile items
The self item class
The first item class we'll create is for an item that affects the player upon usage. Items
that players use typically affects their various stats either by adding or removing them
or buffing/debuffing them for a certain amount of time. Now let's start scripting; create
a new script and name it itemSelf .
Adding our variables
Our first set of variables will actually be added outside of our class as they are enum
variables:
public enum SelfAction {BuffDebuff, ChangeHP,
ChangeArmor, None};
public enum SelfType {Armor, Potion, None};
Search WWH ::




Custom Search