Thread: Problems with sluggishnesgsd or something :D

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    3

    Problems with sluggishnesgsd or something :D

    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;
    }

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    What's the rewind function do?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Store the map in an array, not a file

    files are like 1000 times slower

    Start with
    char map[25][80];


    Then read your "map.m" file into this array just once at the start

    Then recode your draw() function to use this array

    You also read your ini file every time around the loop as well (or at least you try to)

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Draco
    What's the rewind function do?
    While I don't see rewind used in their program, here's what it does:

    The rewind function sets the file position indicator for
    the stream pointed to by stream to the beginning of the
    file. It is equivalent to:

    (void)fseek(stream, 0L, SEEK_SET)

    except that the error indicator for the stream is also
    cleared (see clearerr(3)).
    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    ah, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM