introduction/Approach to parsing/Game development

Hey, Just joined the forum! hope to find much knowledge!

Anyway, Im writing a c++ game using the SDL graphics library.

Ive got gravity, a character, a map loaded (from a textfile), etc. But I need to animate the character and i think its inefficient to put all the info of the x's, y's, w's and h's of all the characters movements in the code itself. I decided to put it all in a text file and 'parse' it, and this is where im having trouble, just cant get it to read the characters properly.

Am i taking the right approach, and if i am, how would i 'parse' the text file, ive tried many times myself.

many thanks, SuperStinger
In what way is it inefficient to put this data into the code?
closed account (1yR4jE8b)
Nobody is going to be able to help you unless you post some code that you've already written, and what you are trying to do with it.
Ye ok, i thought i had to, im using C's FILE to open and read a file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
void animateEntity(int animation, int entityNum , vector<liveEntity> entityInfo)
{
	//Temp variable for storage

	int type = 0;

	//Different Stages

	int stage = 0;

	//used for EOF

	int c;

	//For loops and other things

	int i = 0;

	//load some vars

	entityInfo.at(entityNum).animState = animation;

	entityInfo.at(entityNum).subAnimState++;

	//load the file

	FILE *animFile;

	animFile = fopen("animations.txt", "r");

	while((c = fgetc(animFile)) != EOF)
	{
		i++;
	}

	fclose(animFile);

	//create string/char based on i

	char animString[i];
	i = 0; //Reset i for reuse

	//put the chars into the array

	animFile = fopen("animations.txt", "r");

	while((c = fgetc(animFile)) != EOF)
	{
		animString[i] = c;
	}

	fclose(animFile);

	for (i = 0; i < sizeof(animString); i++)
	{
		if (stage == 0)
		{
			if (animString[i] == 't' && animString[i + 1] == 'y' && animString[i + 2] == 'p' && animString[i + 3] == 'e' && animString[i + 4] == ':') //Trying to read the word 'type:'
			{
				if (entityInfo.at(entityNum).type == animString[i + 5] - '0')
				{
					type = entityInfo.at(entityNum).type;
					stage = 1;
				}
			}
		}
		else if (stage == 1)
		{
			if (animString[i] == '{')
			{
				stage = 2;
			}
		}
		else if (stage == 2)
		{
			if (animString[i] == 'a' && animString[i + 1] == 'n' && animString[i + 2] == 'i' && animString[i + 3] == 'm' && animString[i + 4] == ':')
			{
				entityInfo.at(entityNum).subAnimState = animString[i + 5] - '0';
			}
		}
	}
}


this is my own attempt at reading code by creating this function(did not work :( ),

and for mik,
what i mean by putting directly in code, is create a large array (however many dimensions) and store all the x's, y's, widths and heights of all my character movements on my character sheet (bitmap) in that array, because everytime the bitmap would change, i would have to recompile,etc. Instead I thought i could read from a text file.

EDIT: sorry, this is the file im trying to read. This just represents a differents spirtes in a bitmap spreadsheet.

type:1
{
anim:1
{
subanim:1
{
x:63
y:8
w:30
h:40
}
subanim:2
{
x:95
y:11
w:33
h:37
}
delay:500
}
}
Last edited on
Topic archived. No new replies allowed.