Wizard Fu's Cocos2dx Platformer Game Engine v1.0.1


See the file LICENSE for the license governing this code.

#pragma once
#include "Headers.h"

LevelObject > Character > AI

AI represents a specific type of Character object which is controlled by artificial intelligence. This class is not meant to be instantiated. It is further derived into Enemy and NPC which are further derived into specific enemies and NPCs.


Moods determine what thoughts and actions an AI will take. Moods use a timer that counts down. When the timer reaches zero a new mood is chosen.


const float kTimerUp = -9999.0f;


class AI : public Character
		virtual const char* const profileName()=0;
		virtual ~AI();

Set properties.

		virtual void setProperties(Level& level, ValueMap& dict);

Tick / animate.

		virtual void tick(float delta);
		virtual void animate(float delta);

Run the sleep mood.

		virtual void moodSleep(float delta);

Run the seek mood.

		virtual void moodSeek(float delta);

Run the attack mood.

		virtual void moodAttack(float delta);

Run actions when the player’s input becomes locked.

		virtual void onLock();


		virtual void die();

Disable (become dead).

		virtual void disable();

Protected / Private


The current mood of this AI.

		int mood;

A timer used in mood functions.

		float timer;

The amount of time the AI has been awake.

		float awakeDuration, awakeDurationMax;

The amount of time the AI sleeps for.

		float sleepDuration;

The AI’s last position.

		Vec2 lastPos;

Whether the AI is locked.

		bool locked;

Triggers (example: onDeath=open Door0).

		map<string, string> triggers;

Set wake distance.

		virtual void setWakeDistance(float dist);

Set the AI’s mood.

		virtual void setMood(int newMood);

Choose a new mood.

		virtual void chooseMood();

Returns true if the AI can wake up.

		virtual bool canWakeup();

When alerted, AI will wake up if sleeping.

		virtual void alert(LevelObject* obj);

Fade the sprite out.

		void fadeOut(float delay, float duration);

Emit some smoke.

		void emitSmoke(float delay, float duration);

		typedef Character super;
		typedef AI self;
		float wakeDistanceSQ;
		string music;

Class hierarchy