Sign in to follow this  

Mission Objectives

This topic is 2344 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For the past few days, I've been contemplating how to implement mission objectives in my shmup. It's going to be a fairly simple system, only one objective is active at a time and objectives will only consist of killing x number of baddies, stay alive for x amount of minutes, and other similar objectives.

Staying alive for x amount of minutes is a simple objective to create because it's a timer. However, objectives that need to keep track of how many baddies were killed or how many items were collected by the player I just can't nail down.

Basically, my idea was when the foe factory generates an enemy that is the goal of the objective, it would assign an event listener to that foe object. When that foe was "killed" it would send a message to the listener saying that it was killed, and the objective counter would increase. The only problem with this is I need to figure out if there is a way to design the factory to differentiate between the different enemy objects so it knows which ones to keep track of. I was hoping to figure out an elegant solution, but I think I might have to resort to assigning a string in the foe objects stating which kind enemy it is, which will allow me to check it against the objective. Is there a better way to do this?

The way my game is setup currently is I have a "Ship" class, and the enemies inherit from this class allowing me to add special functionality. I'm writing this in C++

Share this post


Link to post
Share on other sites
[source lang="cpp"]class Objective
{
// Constructors etc. omitted

public:
template<typename T>
bool WantsToKill(const T&) const
{
return false;
}

template<>
bool WantsToKill(const SpecificShip&) const
{
return WantsToKillSpecificShip;
}

public:
void IncreaseKillCounter()
{
++KillCounter;

if(KillCounter >= TargetKillCount)
GameObjectives.CompleteObjective(*this);
}

private:
unsigned KillCounter;
unsigned TargetKillCount;

bool WantsToKillSpecificShip;
};



class Ship
{
public:
virtual void CheckObjectiveWhenKilled(Objective&) const { }
};

class SpecificShip
{
public:
virtual void CheckObjectiveWhenKilled(Objective& objective) const
{
if(objective.WantsToKill(*this))
objective.IncreaseKillCounter();
}
};[/source]

Share this post


Link to post
Share on other sites

This topic is 2344 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this