2.1 The lg_scene class
As you may already know, this is the most important class in the Intrepid library. With this class, you may define the environments of your game, and store its objects, defined by the lg_objects class.
When we, the authors idealized this class, we thought about how a traditional RPG game works. We noticed how we had different scenes within a single game, like, for an example, you may have things like:
-> A main menu
-> The status menu
-> The field
-> The world map
-> The battle scene...
Do you get it??? We noticed that a game is made up of a set of scenes, so we generalized the idea of a scene with the lg_scene class...
lg_scene Class Definition
class lg_scene
{
protected:
//whoa, this is some secret stuff...
//look at the source code for the protected listing....
public:
lg_scene();
~lg_scene();
void set(lg_scene_param *p);
void set_cam_pos(int x, int y);
void get_cam_pos(int *x, int *y);
void add_object(void *v);
void render();
void get_pos(int *x, int *y);
void get_scene_size(int *w, int *h);
void get_canvas_size(int *w, int *h);
lg_object* get_obj_bypos (int posx, int posy);
};
Please keep in mind that when we refer to objects, we're actually talking about the objects that were added to the scene with the add_object method.
Methods
lg_scene();
Well, this is the constructor for the class, and it sets up default values to its members. Well, ya know, just maintenance stuff..
~lg_scene();
This is the destructor for the class.. You know, to clean it up...
void set(lg_scene_param *p);
This function is used to set up the scene. Just fill up the lg_scene_param structure, that we will set it up. Here's the definition of lg_scene_param:
struct stc_lg_scene_param {
int canvas_w, canvas_h;
int scene_w, scene_h;
int start_x, start_y;
int bits;
char *fname;
};
typedef struct stc_lg_scene_param lg_scene_param;
int canvas_w, canvas_h: size of the scene's viewport.
int scene_w, scene_h: sets the size of the scene. If fname is given, you don't have to set these variables. They are automatically read from fname.
int start_x, start_y: Position of the scene's upper left corner in relation to the current OpenGL coordinate system. Usually, using the OpenGL coortinates (0,0). If you're not sure on how to set this up, leave it alone or check the sample programs.
int bits: bit-depth of the background image.
char *fname: if this is set to NULL, the scene won't have a background image. Otherwise, this should be the path to the background image file. Please keep in mind this must be in the BMP format.
void set_cam_pos(int x, int y);
Sets the camera position. x must be between 0 and scene_w, and y must be between 0 and scene_h. See the set method.
void get_cam_pos(int *x, int *y);
Gets the camera current position and stores it in *x and *y.
void add_object(void *v);
This adds an object to the scene. Please note that *v should be a lg_object* or another object derived from lg_object. The void pointer is the solution we found to make add_object compatible with objects derived from lg_object.
void render();
Renders the current scene. It prints the background first, and then the objects, in the order they were added with add_object. For an example, the last object added will be printed in front of all other objects.
void get_pos(int *x, int *y);
Stores start_x and start_y parameters in *x and *y. See the set method.
void get_scene_size(int *w, int *h);
Stores scene_w and scene_h parameters in *w and *h. See the set method.
void get_canvas_size(int *w, int *h);
Stores canvas_w and canvas_h parameters in *w and *h. See the set method.
lg_object* get_obj_bypos (int posx, int posy);
Returns the pointer to the top-most object located in (posx,posy). Returns NULL if none.
Back to Home