Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

Copy of Main.cpp

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include "../DeFacto/Math/Vector.h"
00005 #include "../DeFacto/Game/Level.h"
00006 #include "../DeFacto/Graphics/Image.h"
00007 
00008 int save();
00009 int load();
00010 
00011 int main() {
00012         save();
00013         //load();
00014         return 0;
00015 }
00016 
00017 int load() {
00018         char buf[sizeof(LevelInfo)];
00019         char *filename = "file.lvl";
00020 
00021         LevelInfo lvl;
00022         lvl.data = NULL;
00023 
00024         memset(buf, '\0', sizeof(buf));
00025 
00026         FILE *file = fopen(filename, "rb");
00027         if (file == NULL) return false;
00028 
00029         fread(&lvl, sizeof(lvl), 1, file);
00030 
00031         printf("%s\n", lvl.name);
00032         printf("size: %i x %i\n", lvl.width, lvl.height);
00033 
00034         lvl.data = new unsigned char[lvl.width*lvl.height*3]; //(unsigned char *)malloc(sizeof(unsigned char)*lvl.width*lvl.height*3);
00035         //memset(lvl.data, '\0', sizeof(unsigned char)*lvl.width*lvl.height);
00036         fread(lvl.data, sizeof(unsigned char)*lvl.width*lvl.height*3, 1, file);
00037 
00038         fclose(file);
00039 
00040         for (int i=0; i<lvl.width*lvl.height*3; i+=3) {
00041                 if (i % lvl.width*3 == 0)
00042                         printf("\n");
00043                 if (lvl.data[i] == 255)
00044                         printf("9");
00045                 else if (lvl.data[i] == 15)
00046                         printf("8");
00047                 else if (lvl.data[i] == 240)
00048                         printf("7");
00049                 else
00050                         printf("%i", lvl.data[i]);
00051         }
00052 
00053         delete [] lvl.data;
00054 
00055         return 0;
00056 }
00057 
00058 int save() {
00059         char buf[sizeof(LevelInfo)];
00060         char *filename = "lvl1.lvl";
00061 
00062         memset(buf, '\0', sizeof(buf));
00063 
00064         LevelInfo lvl;
00065 
00066         //char name[32] = "Gravity Pump";
00067         //char map[32] = "gp.map";
00068         //char texWater[32] = "lava1.bmp";
00069         //char texWaterSurface[32] = "lava1Surface.bmp";
00070         //char texWall[32] = "stone.bmp";
00071         //char texFloor[32] = "rock.bmp";
00072 
00073         //memcpy(lvl.name, name, sizeof(name));
00074         //memcpy(lvl.texFloor, texFloor, sizeof(texFloor));
00075         //memcpy(lvl.texWall, texWall, sizeof(texWall));
00076         //memcpy(lvl.texWater, texWater, sizeof(texWater));
00077         //memcpy(lvl.texWaterSurface, texWaterSurface, sizeof(texWaterSurface));
00078 
00079         strcpy(lvl.name, "Gravity Pump");
00080 
00081         strcpy(lvl.texWater, "lava1.bmp");                                                                      // textures
00082         strcpy(lvl.texWaterSurface, "lava1Surface.bmp");
00083         strcpy(lvl.texWall, "stone.bmp");
00084         strcpy(lvl.texFloor, "rock.bmp");
00085 
00086         lvl.numModels = 1;                                                                                                      // models
00087         strcpy(lvl.modelsPath, "data//models//");
00088         strcpy(lvl.models[0], "cylinder.txt");
00089 
00090         lvl.waterSurfaceSpeed = 0.7f;                                                                           // constants
00091         lvl.gravity = 9.82f;
00092         lvl.friction = 0.5f;
00093         lvl.music = 1;
00094         lvl.sky = 1;
00095 
00096         lvl.numLights = 4;                                                                                                      // lights
00097                 lvl.lights[0].ambient = Vec4(0.3f, 0.2f, 0.2f, 1.0f);
00098                 lvl.lights[0].color = Vec4(0.5f, 0.2f, 0.2f, 1.0f);
00099                 lvl.lights[0].pos = Vec3(46.0f, 20.0f, 30.0f);
00100                 lvl.lights[0].attenuation = Vec3(1.0f, 0.0f, 0.0f);
00101                 lvl.lights[0].pulse = 0.0f;
00102                 lvl.lights[0].radius = 0.0f;
00103 
00104                 lvl.lights[1].ambient = Vec4(0.3f, 0.1f, 0.1f, 1.0f);
00105                 lvl.lights[1].color = Vec4(0.8f, 0.1f, 0.1f, 1.0f);
00106                 lvl.lights[1].pos = Vec3(27.0f, 1.0f, 23.0f);
00107                 lvl.lights[1].attenuation = Vec3(0.5f, 0.05f, 0.02f);
00108                 lvl.lights[1].pulse = 0.5f;
00109                 lvl.lights[1].radius = 5.0f;
00110 
00111                 lvl.lights[2].ambient = Vec4(0.1f, 0.1f, 0.3f, 1.0f);
00112                 lvl.lights[2].color = Vec4(0.1f, 0.1f, 0.8f, 1.0f);
00113                 lvl.lights[2].pos = Vec3(57.0f, 1.0f, 4.0f);
00114                 lvl.lights[2].attenuation = Vec3(0.5f, 0.01f, 0.02f);
00115                 lvl.lights[2].pulse = 0.0f;
00116                 lvl.lights[2].radius = 5.0f;
00117 
00118                 lvl.lights[3].ambient = Vec4(0.1f, 0.3f, 0.1f, 1.0f);
00119                 lvl.lights[3].color = Vec4(0.1f, 0.8f, 0.1f, 1.0f);
00120                 lvl.lights[3].pos = Vec3(11.0f, 1.0f, 57.0f);
00121                 lvl.lights[3].attenuation = Vec3(0.5f, 0.01f, 0.02f);
00122                 lvl.lights[3].pulse = 0.0f;
00123                 lvl.lights[3].radius = 5.0f;
00124 
00125 
00126         Image *image = new Image();                                                                                                     // map
00127         if (!image->loadImage("..\\DeFacto\\data\\lvls\\working\\lvl1.bmp"))
00128                 return -1;
00129 
00130         lvl.width = image->width;
00131         lvl.height = image->height;
00132         lvl.data = image->data;
00133 
00134 
00135         FILE *file = fopen(filename, "wb");                                                                                     // save
00136         if (file == NULL) return false;
00137 
00138         memcpy(buf, &lvl, sizeof(LevelInfo));
00139 
00140         fwrite(&buf, sizeof(LevelInfo), 1, file);
00141         fwrite(lvl.data, sizeof(unsigned char)*lvl.width*lvl.height*3, 1, file);
00142 
00143         fclose(file);
00144 
00145         for (int i=0; i<lvl.width*lvl.height*3; i+=3) {
00146                 if (i % lvl.width*3 == 0)
00147                         printf("\n");
00148                 if (lvl.data[i] == 255)
00149                         printf("9");
00150                 else if (lvl.data[i] == 15)
00151                         printf("8");
00152                 else if (lvl.data[i] == 240)
00153                         printf("7");
00154                 else
00155                         printf("%i", lvl.data[i]);
00156         }
00157 
00158         delete [] lvl.data;
00159 
00160         return 0;
00161 }

Generated on Sun Jun 5 15:47:03 2005 for Defacto by  doxygen 1.4.3