I know that the usual c++ commands i use and like to use where being a bit weird until i changed the mtd to mt. My Streams dont seem to work at all though. i am trying to write a level generator and i cant save any levels i write because of my problem. (There is a way of doing it using DB but it feels a little too unprofessional, especially since the data wont come out the way i want it to). My code compiles and runs. When it gets to:
it dies.
and this even happens when i changed the code to:
is there a solution to this??
here is the full code just in case you need it:
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include <DarkGDK.h>
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
int fileout=0;
int x=0;
int y=0;
ofstream file;
int data[20][15];
//make data empty
for(int i=0;i<20;i++)
{
for(int k=0;k<16;k++)
{
data[i][k]=300;
}
}
int set=1;
dbLoadImage("tileset.png",1);
// our main loop
while ( LoopGDK ( ) )
{
if(fileout==0)
{
LPSTR input;
dbPrint("Type 'new' to ceate new file or type 'open' to open a file");
input=dbInput();
string name=input;
if(name=="new")
{
dbPrint("Enter name");
input=dbInput();
name=input;
name=name+".txt";
file.open(name.c_str());
if(file.is_open())
{
dbSyncOn();
dbSyncRate(20);
fileout=1;
dbCreateAnimatedSprite(1,"tileset.png",20,15,1);
dbSetSpriteFrame(1,set);
}
}
}
else if(fileout==1)
{
dbCLS();
float print=x;
float print2=y;
dbPrint(print);
dbPrint(print2);
for(int i=0;i<20;i++)
{
for(int k=0;k<16;k++)
{
dbCreateAnimatedSprite((i*16)+k+2,"tileset.png",20,15,1);
dbSprite((i*16)+k+2,i*32,k*32,1);
dbSetSpriteFrame((i*16)+k+2,data[i][k]);
}
}
dbSetSpriteFrame(1,set);
x=dbMouseX()-(dbMouseX()%32);
y=dbMouseY()-(dbMouseY()%32);
dbSprite(1,x,y,1);
//special Functions
if(dbKeyState(41)==1)
{
dbWait(10);
dbWaitKey();
//save
if(dbKeyState(31)==1)
{
dbSyncOff();
dbPrint("Saving Data Please Wait");
for(int i=0;i<20;i++)
{
for(int k=0;k<16;k++)
{
if(file.is_open())
{
file<<data[i][k];
file<<" ";
}
}
file<<endl;
}
//save
dbSyncOn();
}
//spercial functions
}
if(dbUpKey()==1)
{
set=set-20;
}
if(dbDownKey()==1)
{
set=set+20;
}
if(dbLeftKey()==1)
{
set--;
}
if(dbRightKey()==1)
{
set++;
}
if(set<1)
{
set=300;
}
if(set>300)
{
set=1;
}
if(dbMouseClick()==1)
{
data[x/32][y/32]=set;
}
}
// update the screen
dbSync();
}
// return back to windows
return;
}
or here is just the save code:
//save
if(dbKeyState(31)==1)
{
dbSyncOff();
dbPrint("Saving Data Please Wait");
for(int i=0;i<20;i++)
{
for(int k=0;k<16;k++)
{
if(file.is_open())
{
file<<data[i][k];
file<<" ";
}
}
file<<endl;
}
//save
dbSyncOn();