2.2 The lg_object class

The objects are the elements that make up a scene.

Following the example in the section 2.1, objects can be:

-> The buttons in the main menu
-> The characters on the field
-> The messages in the status and battle scene
-> The monsters in the battle scene
-> ...



lg_object Class Definition


 
class lg_object
{
	protected:
		//whoa, this is some secret stuff...
		//look at the source code for the protected listing....

	public:		
		//Functions
		lg_object();
		~lg_object();

		void set(lg_object_param *p, lg_scene *my_scene);
		
		//overload
		void set_pos(int x, int y);
		void set_pos(float x, float y);
		void set_pos(lg_point *p);
		
		//overload
		void get_pos(int *x, int *y);
		void get_pos(float *x, float *y);
		void get_pos(lg_point *p);

		void set_ang (float ang);
		float get_ang();
		
		void get_size(int *w, int *h);
		int get_id();

		void get_video_handler (void *v);
		void set_video_handler (void *v);
		
		void set_scene(lg_scene *scene);
		lg_scene* get_scene();
		
		void render();

		virtual void pos_changed() { }
};


Methods



lg_object();
Well, this is the constructor for the class, and it sets up default values to its members. Well, ya know, just maintenance stuff..

~lg_object();
This is the destructor for the class.. You know, to clean it up...

void set(lg_object_param *p, lg_scene *my_scene);
This function is used to set up the object. Just fill up the lg_object_param structure, that we will set it up. *my_scene should point to the scene that contains this object. Here's the definition of lg_object_param:
struct lg_object_paramstc {
	int id;
	int active;
	int visible;
	float ang;
	float x;
	float y;
};
typedef struct lg_object_paramstc lg_object_param;
int id: this is a unique identifier for an object.

int active: this determines if the object is active on the screen or not. Some of the processing reads this value to make the code more efficient. We advise you to set it to non-zero. In case you should want to deactivate an object, set this to 0.

int visible: this determines if the object is currently supposed to be printed in the render method.

float angle: this determines the angle this object should be rotated. Please note this is in radians and that 180 degrees = PI (3.14159) radians.

float x, y: these hold the position of the object in the scene.

void set_pos(int x, int y);
void set_pos(float x, float y);
void set_pos(lg_point *p);

Sets the object position in the scene.

void get_pos(int *x, int *y);
void get_pos(float *x, float *y);
void get_pos(lg_point *p);

Gets the object position in the scene.

void set_angle(float ang);
Sets the angle this object should be rotated. Please note this is in radians and that 180 degrees = PI (3.14159) radians.

float get_angle();
Gets the angle this object is rotated. Please note this is in radians and that 180 degrees = PI (3.14159) radians.

void get_size(int *w, int *h);
Gets the object size.

int get_id();
Returns the object id.

void get_video_handler (void *v);
Gets the video handler being used by the object. v should be a lg_video_handler object or an object from a class derived from lg_video_handler.

void set_video_handler (void *v);
Sets the video handler. See the 3. Built-in video handlers section to see the built-in video-handlers. v should be a lg_video_handler object or an object from a class derived from lg_video_handler.

void set_scene(lg_scene *scene);
Sets the scene this object is placed in.

lg_scene* get_scene();
Returns the scene this object is placed in.

void render();
Renders the object on the current position.



Functions



int obj_check_coll_pixel (void *v1, void *v2);
Returns non-zero if v1 and v2 are colliding. v1 and v2 should be a lg_object object or an object from a class derived from lg_object.



Back to Home