Pickups, Powerups and Triggers

From IrrWizard

Jump to: navigation, search

Introduction

This tutorial will outline one approach to implementing Powerups, Pickups and Triggers into a game.


Powerups, Pickups and Triggers

The following classes of interest are created when you choose the 'Full Framework' option while running IrrWizard

  • CGameItemManager
  • CGameItem

Also please note that minor modifications to previous classes may have been made for integration/improvement purposes. ie IGameEntity for the Trigger implementation.

The first step is to create the power-ups in the CGamePlayState01::Init(CGameManager pManager) function. A new class, CGameItem has been created for this purpose, and can be added as follows:

// create a HEATH powerup
CGameItem* health = new CGameItem(GAME_ITEM_HEALTH);
health->setTriggerRegion(50);
pManager->getItemManager->AddItem(health);
...
           

The TriggerRegion is the radius in which the item will be triggered if the player enters, 50 is a very small area, which is roughly the same size as the health model. An invisible game item with a larger radius can be put in the middle of a room, then when the player enters the room, a trigger will activated. This can be anything from a sound, a goal, opening a door etc..

The CGameEnemy also has a TriggerRegion, this should be set to a higher value and will act as it's 'aggro range'.

Different types of trigger can be created, this is generally reflected by the GAME_ITEM_TYPE, in this case a GAME_ITEM_HEALTH. The CGameItemManager has a separate function with logic for each of the trigger types.

(nb seperate Trigger classes similar to the EntityStates would be better if the game has a lot of them. This has been avoided for demonstration purposes as to not created too many unnecessary classes.)

The CGameItemManager is called every game cycle by the CGamePlayState's Update() function. The CGameItemManager then calls the Try() function of each of the CGameItems that have been added to the manager, this in effect tests each of their trigger regions for a hit.

This may seem like a big overhead, although in reality isn't as each trigger region is tested very quickly. Although it's always the responsibility of the game designer to construct efficient game levels at all times.

Personal tools