Wizard Fu's Cocos2dx Platformer Game Engine v1.0.1

nat@wizardfu.com

See the file LICENSE for the license governing this code.

LevelObject > Solid > Solids

#pragma once
#include "Headers.h"

Chest

A Chest is a essentially an Item (see NonSolids) which has hitpoints, must be opened via attacking it and plays a neat animation when the item is finally obtained.

class Chest : public Solid
{
	public:
		GETTER(string, item, Item);
		virtual const char* const profileName() {return "Chest";}
		Chest();
		virtual ~Chest();
		virtual void setProperties(Level& level, ValueMap& dict);
		virtual void createFixtures();
		virtual void attackedBy(LevelObject* o);
		virtual void tick(float delta);
		virtual void animate(float delta);
		virtual void open();
		virtual void take();
		virtual void disable();

	private:
		typedef Solid super;
		typedef Chest self;
		
		int hp, maxHP;
		bool isSmall, isOpen;
		SpriteMirrored* triangle, *grad;
		double lastAmbienceTime;
		double lastHitTime;
		
		void setOpenState();
};

JumpPad

Launches the player into the air when the player comes in contact.

class JumpPad : public Solid
{
	private:
		typedef Solid super;
		typedef JumpPad self;
		
		bool open;
		float strength;
		Vec2 vec;

	public:
		virtual const char* const profileName() {return "JumpPad";}
		JumpPad();
		virtual ~JumpPad();
		virtual void setProperties(Level& level, ValueMap& dict);
		virtual void createFixtures();
		virtual void attackedBy(LevelObject* o);
		virtual void setFirstFrame();
};

Platform

A Platform is a solid rectangular object that can move along a path and which the player can land on.

class Platform : public Solid
{
	public:
		virtual const char* const profileName() {return "Platform";}
		Platform();
		virtual ~Platform();
		virtual void setProperties(Level& level, ValueMap& dict);
		virtual void createFixtures();
		virtual void tick(float delta);

	private:
		typedef Solid super;
		typedef Platform self;
		
		Vec2 startPosition;
		Vec2 movement;
		float speed;
		bool repeat, reversed, stopped;
		double reverseTime;
};

DoorProtocol

A protocol for door-like objects. Inheriting from this protocol means an object can be opened with a trigger, like on an enemy’s death.

class DoorProtocol
{
	public:
		virtual void open(LevelObject* opener) = 0;
};

Door

A Door is a solid rectangular object taking it’s x, y, width and height from the tmx object. It can be opened using a trigger or by its hitpoints reaching zero. Upon opening, it immediately becomes a non-solid object. Then it either slides open in a given direction or explodes into many Debris objects.

Trigger example:

class Door : public Solid, public DoorProtocol
{
	public:
		virtual const char* const profileName() {return "Door";}
		Door();
		virtual ~Door();
		virtual void setProperties(Level& level, ValueMap& dict);
		virtual void createFixtures();
		virtual void open(LevelObject* opener);
		virtual void attackedBy(LevelObject* obj);

	private:
		typedef Solid super;
		typedef Door self;
		
		int openDirection;
		string openSound;
		float openDuration;
		float shakeDuration;
		bool explode, activateViaMissile;
		int hp;
};

Debris

A piece of Debris is a solid object which collides with other Debris objects and solid fixtures, but not the Player or any other level objects. The Door class can be set to create a lot of these and sends them flying in the air when a opening. This creates an explosion effect, the Debris objects bouncing off each other and the Level.

class Debris : public Solid
{
	public:
		virtual const char* const profileName() {return "Debris";}
		Debris();
		virtual ~Debris();
		virtual void setProperties(Level& level, ValueMap& dict);
		virtual void createFixtures();
		virtual void tick(float);

	private:
		typedef Solid super;
		typedef Debris self;
		
		int direction;
};

Box

A Box can be moved around, used to jump from and blocks projectiles.

class Box : public Solid
{
	public:
		virtual const char* const profileName() {return "Box";}
		Box();
		virtual ~Box();
		virtual void setProperties(Level& level, ValueMap& dict);
		virtual void createFixtures();

	private:
		typedef Solid super;
		typedef Box self;
};

Fire

A solid object animated with Flicker and particles to resemble fire that damages Characters who come in contact with it. Default damage 1.

class Fire : public Solid
{
	public:
		virtual const char* const profileName() {return "Fire";}
		Fire();
		virtual ~Fire();
		virtual void setProperties(Level& level, ValueMap& dict);
		virtual void createFixtures();
		virtual void tick(float delta);
		virtual void attackedBy(LevelObject* o);

	private:
		typedef Solid super;
		typedef Fire self;
		
		double wavelength;
};

Class hierarchy

 
h