i making somekind of roguegame or something i dunno... and im having problems with the moving... refreshrate is like **** and i have no idea how to make it better
ofcourse general tips are also wellcome
heres my code >> plus the file u need is attached
Code:
#include <stdio.h>
#include <conio.h>
char map;
int x=1,xl,yl;
int def,grass,wall,character,door;
int quit,input;
int line=1;
int draw(FILE *mapf)
{
clrscr();
rewind(mapf);
while(feof(mapf)==0)
{
map=fgetc(mapf);
switch(map)
{
case '#':
textcolor(wall);
break;
case '\n':
while(x!=0)
{
printf("\b");
x--;
}
line++;
break;
case '.':
if(line==yl && x==xl-1)
{
textcolor(character);
printf("\b");
cprintf("@");
textcolor(def);
}
textcolor(grass);
break;
case '/':
textcolor(door);
break;
default:
textcolor(def);
break;
}
cprintf("%c",map);
x++;
}
line=0;
x=0;
}
int setup(FILE *ini)
{
fscanf(ini,"DEFAULT=%d\n",&def);
fscanf(ini,"X LOCATION=%d\n",&xl);
fscanf(ini,"Y LOCATION=%d\n",&yl);
fscanf(ini,"GRASS=%d\n",&grass);
fscanf(ini,"WALL=%d\n",&wall);
fscanf(ini,"CHAR=%d\n",&character);
fscanf(ini,"DOOR=%d\n",&door);
}
int main()
{
clrscr();
FILE *ini, *mapf;
mapf=fopen("map.m", "r");
ini=fopen("map.ini","r");
if(!mapf||!ini) return 1;
while(quit!=-1)
{
setup(ini);
draw(mapf);
input=getch();
switch(input)
{
case 32:
quit=-1;
textcolor(LIGHTGRAY);
textbackground(BLACK);
break;
case 56: // up
yl--;
draw(mapf);
printf("up");
break;
case 50: // down
yl++;
draw(mapf);
printf("down");
break;
case 52: // left
xl--;
draw(mapf);
printf("left");
break;
case 54: // right
xl++;
draw(mapf);
printf("right");
break;
default:
draw(mapf);
break;
}
}
fclose(ini);
fclose(mapf);
return 0;
}