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

Main.cpp lvl1.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         lvl.waterSurfaceSpeed = 0.5f;
00080 
00081         lvl.gravity = 9.82f;
00082         lvl.friction = 1.0f;
00083         //lvl.ambientLight = Vec4(0.1f, 0.1f, 0.2f, 1.0f);
00084         lvl.music = 1;
00085         lvl.sky = 1;
00086         lvl.numLights = 4;
00087                 lvl.lights[0].ambient = Vec4(0.3f, 0.3f, 0.3f, 1.0f);
00088                 lvl.lights[0].color = Vec4(0.5f, 0.5f, 0.5f, 1.0f);
00089                 //lvl.lights[0].ambient = Vec4(0.5f, 0.5f, 0.5f, 1.0f);
00090                 //lvl.lights[0].color = Vec4(0.5f, 0.5f, 0.5f, 1.0f);
00091                 lvl.lights[0].pos = Vec3(2.0f, 6.0f, 23.0f);
00092                 lvl.lights[0].attenuation = Vec3(1.0f, 0.0f, 0.0f);
00093                 lvl.lights[0].pulse = 0.0f;
00094                 lvl.lights[0].radius = 0.0f;
00095 
00096                 lvl.lights[1].ambient = Vec4(0.3f, 0.1f, 0.1f, 1.0f);
00097                 lvl.lights[1].color = Vec4(0.8f, 0.1f, 0.1f, 1.0f);
00098                 lvl.lights[1].pos = Vec3(28.0f, 1.0f, 15.0f);
00099                 lvl.lights[1].attenuation = Vec3(0.5f, 0.1f, 0.02f);
00100                 lvl.lights[1].pulse = 0.5f;
00101                 lvl.lights[1].radius = 5.0f;
00102 
00103                 lvl.lights[2].ambient = Vec4(0.1f, 0.1f, 0.3f, 1.0f);
00104                 lvl.lights[2].color = Vec4(0.1f, 0.1f, 0.8f, 1.0f);
00105                 lvl.lights[2].pos = Vec3(21.0f, 1.0f, 27.0f);
00106                 lvl.lights[2].attenuation = Vec3(0.5f, 0.1f, 0.02f);
00107                 lvl.lights[2].pulse = 0.0f;
00108                 lvl.lights[2].radius = 5.0f;
00109 
00110                 lvl.lights[3].ambient = Vec4(0.1f, 0.3f, 0.1f, 1.0f);
00111                 lvl.lights[3].color = Vec4(0.1f, 0.8f, 0.1f, 1.0f);
00112                 lvl.lights[3].pos = Vec3(9.0f, 1.0f, 9.0f);
00113                 lvl.lights[3].attenuation = Vec3(0.5f, 0.1f, 0.02f);
00114                 lvl.lights[3].pulse = 0.0f;
00115                 lvl.lights[3].radius = 5.0f;
00116 
00117         Image *image = new Image();
00118         if (!image->loadImage("..\\DeFacto\\data\\lvls\\working\\lvl1.bmp"))
00119                 return -1;
00120 
00121         //lvl.width = 64;
00122         //lvl.height = 64;
00123 
00124         //lvl.data = (unsigned char *)malloc(sizeof(unsigned char)*lvl.width*lvl.height);
00125         //memset(lvl.data, '\0', sizeof(unsigned char)*lvl.width*lvl.height);
00126 
00127         lvl.width = image->width;
00128         lvl.height = image->height;
00129         lvl.data = image->data;
00130 
00131         FILE *file = fopen(filename, "wb");
00132         if (file == NULL) return false;
00133 
00134         memcpy(buf, &lvl, sizeof(LevelInfo));
00135 
00136         fwrite(&buf, sizeof(LevelInfo), 1, file);
00137         fwrite(lvl.data, sizeof(unsigned char)*lvl.width*lvl.height*3, 1, file);
00138 
00139         fclose(file);
00140 
00141         for (int i=0; i<lvl.width*lvl.height*3; i+=3) {
00142                 if (i % lvl.width*3 == 0)
00143                         printf("\n");
00144                 if (lvl.data[i] == 255)
00145                         printf("9");
00146                 else if (lvl.data[i] == 15)
00147                         printf("8");
00148                 else if (lvl.data[i] == 240)
00149                         printf("7");
00150                 else
00151                         printf("%i", lvl.data[i]);
00152         }
00153 
00154         delete [] lvl.data;
00155 
00156         return 0;
00157 }

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