So since ive havent got a reply to my post about my game ive started work on a map editor. But im having two issues. 1.)I have a enumerated variable holding the current brush being used. Issue is that, when i click on a tile to edit, it is somehow reset to a blank brush, i only have one place in the code that says curren=nothing and i commented that out and it still does it. Second whenever i go to save my map, it creates the file properly but there is nothing in it despite what i write or how i write it (dbWriteWord, dbWriteFloat or whatever) it doesnt matter if i write by variable, or direct input it refuses to write. I know im doing something wrong but heres my source:
#include "DarkGDK.h"
//mouse variables
int mouseX=0;
int mouseY=0;
int mouse_click=0;
//system variables
enum selection {nothing, block, scroll, warp};
selection current;
int current_tile=0;
char* filename="00000.txt";
//wrapper classes
class sprite
{
public:
sprite(int id, char* fileName, int storeIMG);
~sprite(){};
int id;
char* fileName;
int storeIMG;
int x;
int y;
int solid;
int imageID;
int alpha;
int draw(int xT, int yT, int alphaT);
};
//functions
void refresh_mouse();
void check_mouse_menu(sprite pixel);
int getTile(sprite pixel);
void check_for_name();
void save();
//create gamegrid
int grid[15][20];
int x=0;
int y=0;
int sid=6;
void make_map()
{
dbMakeMemblock(1,300);
while(sid!=307)
{
grid[y][x]=0;
dbWriteMemblockFloat(1,sid-5,0);
dbCreateAnimatedSprite(sid,"Media\\tile.PNG",1,1,sid);
dbSprite(sid,x*16+100,y*16+20,sid);
x++;
if(x==20)
{
y++;
x=0;
}
sid++;
if(y==15)
{
sid=307;
}
}
}
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
//text settings
dbSetTextOpaque();
//create nessesary system sprites
sprite blockI(2,"Media\\block.PNG",2);
sprite scrollI(3,"Media\\scroll.PNG",3);
sprite warpI(4,"Media\\teloport.PNG",4);
sprite pix(5,"Media\\pixel.PNG",5);
make_map();
sprite nameB(308,"Media\\name.PNG",308);
sprite saveB(309,"Media\\save.PNG",309);
//draw the system
blockI.draw(20,20,255);
scrollI.draw(60,20,255);
warpI.draw(20,60,255);
pix.draw(mouseX,mouseY,0);
nameB.draw(320,275,255);
saveB.draw(320,295,255);
// our main loop
while ( LoopGDK ( ) )
{
dbText(1,1,"FPS:");
dbText(20,1,dbStr(dbScreenFPS()));
check_mouse_menu(pix);
pix.draw(mouseX,mouseY,pix.alpha);
//check for the currently highlighted tile
current_tile=getTile(pix);
if(current_tile!=0)
{
dbSetWindowTitle(dbStr(current_tile));
}
// update the screen
check_for_name();
save();
refresh_mouse();
dbSync ( );
}
// return back to windows
return;
}
//function definitions
//refreshes the mouse positions and click info
void refresh_mouse()
{
mouseX=dbMouseX();
mouseY=dbMouseY();
mouse_click=dbMouseClick();
}
//sprite setup
sprite::sprite(int idT ,char* fileNameT ,int storeIMGT)
{
sprite::id=idT;
sprite::fileName=fileNameT;
sprite::storeIMG=storeIMGT;
sprite::imageID=id+10000;
dbLoadImage(sprite::fileName , sprite::id+10000);
dbCreateAnimatedSprite(sprite::id,sprite::fileName,1,1,sprite::storeIMG);
}
//this one draws the sprite on the screen
int sprite::draw(int xT , int yT , int alphaT)
{
if(dbSpriteExist(sprite::id))
{
sprite::x=xT;
sprite::y=yT;
sprite::alpha=alphaT;
dbSetSpriteAlpha(sprite::id,sprite::alpha);
dbSprite(sprite::id , sprite::x , sprite::y , sprite::imageID);
return 1;
}
else
{
return 0;
}
}
//this checks if the mouse is hilighting a menu option
void check_mouse_menu(sprite pixel)
{
if(mouseX>=20 && mouseX<=52 && mouseY>=20 && mouseY<=52)
{
if(mouse_click==1)
{
current=block;
dbSetWindowTitle("Current Tool: Block");
}
else
{
if(mouse_click==0 && current==nothing)
{
dbSetWindowTitle("block");
}
}
}
else
{
if(mouseX>=60 && mouseX<=92 && mouseY>=20 && mouseY<=52)
{
if(mouse_click==1)
{
current=block;
dbSetWindowTitle("Current Tool: Scroll");
}
else
{
if(mouse_click==0 && current==nothing)
{
dbSetWindowTitle("scroll");
}
}
}
else
{
if(mouseX>=20 && mouseX<=52 && mouseY>=60 && mouseY<=92)
{
if(mouse_click==1)
{
current=block;
dbSetWindowTitle("Current Tool: Teloport");
}
else
{
if(mouse_click==0 && current==nothing)
{
dbSetWindowTitle("teloport");
}
}
}
else
{
//put more menu choices here
if(mouse_click==1 && getTile(pixel)==0)
{
//current=nothing;
dbSetWindowTitle("");
}
else
{
if(current==nothing)
{
dbSetWindowTitle("");
}
}
}
}
}
}
int getTile(sprite pixel)
{
int hit;
hit=dbSpriteCollision(pixel.id,0);
if(hit>5 && hit <307)
{
if(mouse_click)
{
int m=hit;
int x=0;
int y=0;
while(m!=6)
{
m--;
x++;
if(x==20)
{
x=0;
y++;
}
}
grid[y][x]=current;
}
return hit;
}
else
{
return 0;
}
}
//this function checks to see if you are within the name box
//and if so and u click waits for input for the filename 320x275
void check_for_name()
{
if(mouseX>319 && mouseX<389 && mouseY>274 && mouseY<296 && mouse_click==1)
{
filename=dbInput();
}
dbText(390,280,filename);
}
void save()
{
if(mouseX>319 && mouseX<389 && mouseY>274+20 && mouseY<296+20 && mouse_click==1)
{//first we create a memblock from our data
if(dbFileExist(filename))
{
dbDeleteFile(filename);
}
dbOpenToWrite(1,filename);
int f=dbFileOpen(1);
int sid=6;
x=0;
y=0;
while(sid!=307)
{
dbWriteFile(1,grid[y][x]);
x++;
if(x==20)
{
y++;
x=0;
}
sid++;
if(y==15)
{
sid=307;
}
}
dbMakeFileFromMemblock(1,1);
dbCloseFile(1);
}
}
Show me your combat algorithms(programmers read this NOT in a programming state of mind)