Back to Evolution Project page
00001 #ifndef SPRITE 00002 #define SPRITE 00003 00004 #include <stdio.h> 00005 #include <stdlib.h> 00006 #include <glib.h> 00007 00008 #ifdef __cplusplus 00009 extern "C" { 00010 #endif /* __cplusplus */ 00011 00012 00013 #define SPRITE_TYPE_SPRITE 1 00014 #define SPRITE_TYPE_GROUND 2 00015 #define SPRITE_TYPE_NONE 0 00016 #define SPRITE_TYPE_SPRITE_STRING "sprite" 00017 #define SPRITE_TYPE_GROUND_STRING "ground" 00018 00019 #define UNIT_WIDTH 20 00020 #define UNIT_HEIGHT 20 00021 00022 00023 #define CURRENT_FILE_MAJORVERSION 1 00024 #define CURRENT_FILE_MINORVERSION 0 00025 00026 //Format of header of the file that store the map of level on disk 00027 //The size of this structure should be 1024 00028 typedef struct file_header { 00029 long int major_version, minor_version; //version of file format 00030 long int level_width, level_height; //width and height of map 00031 long int num_sprites_on_screen; //number of sprites on screen 00032 long int num_grounds_on_screen; //number of grounds on screen 00033 00034 char reserved[1000]; //Bytes remaining to complete 1024 00035 } file_header; 00036 00037 //sprite structure 00038 typedef struct sprite { 00039 int id; 00040 char name[300]; 00041 char filename[1000]; 00042 char filename_tga[1000]; 00043 char description[1000]; 00044 int sizex, sizey; 00045 int width_pixels, height_pixels; 00046 int type; //Type of the sprite 00047 void *pixmap; //GdkPixmap or CL_Surface 00048 void *mask; //GdkBitmap 00049 } sprite; 00050 00051 00052 typedef struct sprite_unit { 00053 int unitx, unity; 00054 int sprite_id; 00055 struct sprite *sprite; 00056 } sprite_unit; 00057 00058 typedef struct unit { 00059 int sprite_id; 00060 int draw_here; //boolean - indicate if the sprite should be drawed in this unit. 00061 sprite_unit *sp_unit; 00062 } unit; 00063 00064 typedef struct rect { 00065 int x, y, sx, sy; 00066 } rect; 00067 00068 #define CONFIG_FILENAME "/etc/evolution.config" 00069 #define LEVELEDITORFILE "sprite_list.rc" 00070 00071 gchar sprites_dir[1000]; 00072 gchar sprites_dir_home[1000]; 00073 GList* sprite_list; //List of "ground" sprites 00074 GList* sprite_list_sp; //List of "sprite" sprites 00075 00076 GList *sp_unit_list; //List of ground on the screen 00077 GList *sp_unit_list_sp; //List of sprites on the screen 00078 00079 unit *level; //Array of ground units 00080 unit *levelsp; //Array of sprite units 00081 int level_width, level_height; //Width and height in units 00082 00083 void read_sprite_from_file(FILE* f, sprite* sp, gchar *sp_dir); 00084 void read_all_sprites(char* filename, gchar *sp_dir); 00085 void print_sprite_info(sprite* sp); 00086 int get_unit_from_pixelx(int pixels); 00087 int get_unit_from_pixely(int pixels); 00088 sprite *get_sprite_from_id(GList *splist, int id); 00089 sprite_unit *sprite_unit_add(GList **unit_list, sprite *sp, int x, int y); 00090 int can_place_sprite_on_unit(sprite *sp, int x, int y); 00091 void delete_sprite_unit(sprite_unit *sp_unit); 00092 00093 //returns the rect to be updated 00094 rect add_sprite_on_unit(sprite *sp, int x, int y); 00095 rect delete_sprite_on_unit(unit *unitmap, int x, int y); 00096 00097 //Function to open and save the files... 00098 int save_level_to_file(FILE *f); 00099 int open_level_from_file(FILE *f); 00100 00101 void resize_array_of_units(void); //(Re)initialize array of units... 00102 void update_list_of_units(void); //Updates values in list of sprites and ground on screen, to save a file. 00103 int file_exists(gchar *fn); //Returns 1 if the current file exists... 00104 00105 void read_config(void); 00106 void init_variables(void); 00107 00108 #ifdef __cplusplus 00109 } 00110 #endif /* __cplusplus */ 00111 00112 00113 00114 #endif //SPRITE