|
Entities... Displaying 1-12 of 12 total.
1
rao_dao_zao
|
Here I go again...
I was wondering; is there a way to modify the base entity code, or create a kind of subset entity with extra properties? You see, I might like to add more powerful enemies to my ever-growing battle system, and at the moment it's one-shot-one-kill. But I don't know how to do this, if it's even possible. The thought occured to me that I could use an array of health values for every entity, but this would be lost every time the player left the map; dead entities would come back to life again, or something.
Help, please?
Posted on 2005-12-22 14:16:34
|
CrazyAznGamer
|
Quote: Originally posted by Rao Dao Zao
Here I go again...
I was wondering; is there a way to modify the base entity code, or create a kind of subset entity with extra properties? You see, I might like to add more powerful enemies to my ever-growing battle system, and at the moment it's one-shot-one-kill. But I don't know how to do this, if it's even possible. The thought occured to me that I could use an array of health values for every entity, but this would be lost every time the player left the map; dead entities would come back to life again, or something.
Help, please? Err.. as of right now, I believe not.
HOWEVER, it shouldn't be too hard to code in VC. If you post a little tidbit of your current entity data management code, then maybe there's a chance we might be able to help you upgrade it.
If you use an array of health values for every entity, shouldn't it be easy to keep dead entities from coming back alive? Or are you thinking about putting it in the Map VC?
Posted on 2005-12-22 16:33:10
|
resident
|
It sounds easy enough. You should be able to use an array just as you've said.
You certainly shouldn't need to delve into Verge 3's internal workings in order to get this to work. It was one of the things I had in mind for 100 Zombies and never got around to, but it's difficult to know what you'd need to add without seeing your code.
You could also save the contents of the array to a small file, and load that file every time the map is loaded to restore the contents of the array, if you're really all that bothered about dead enemies staying dead.
edit: Thinking about it a bit more, you need an extra array. Something like
int enemy_health[MAX_ENEMIES];
When the enemy is added, you set this to a figure representing their health, obviously, and every time you hit the enemy by whatever means, you decrement the health variable by an appropriate amount for whatever weapon you're using. If the health drops below zero, then the entity is removed by whatever means you're currently using.
Posted on 2005-12-23 02:58:24 (last edited on 2005-12-23 03:06:07)
|
rao_dao_zao
|
You see, I thought about saving the entity health and stuff to a file, but then I realised I know absolutely nothing about file I/O in VergeC. I can handle it in Visual Basic, but that's a whole other kettle o' fish. Can somebody around here teach me, or point me to a tutorial?
Or shall I just post all my code and let you marvel?
Posted on 2005-12-23 13:48:25
|
CrazyAznGamer
|
Quote: Originally posted by Rao Dao Zao
You see, I thought about saving the entity health and stuff to a file, but then I realised I know absolutely nothing about file I/O in VergeC. I can handle it in Visual Basic, but that's a whole other kettle o' fish. Can somebody around here teach me, or point me to a tutorial?
Or shall I just post all my code and let you marvel? Not too hard to do file IO, though as of right now, there aren't any tutorials and it's considered an "advanced topic"
Straight from the Manual:
Reading from plain text data files
Useful for: Managing in-game data in an easy to access and alter form. Load-once purposes.
FileReadLn() to get a sting of data from the file
GetToken() to extract the information from the string
val() to turn string data into numbers where needed.
As it's easy to make the odd mistake when creating or editing datafiles by hand, be sure to add some error checking in case of mistakes, and preferably allow for extra non-data lines, so the file can be commented/explained where needed.
Also, if you look at the VCs of various games, you'd find some implementation of file reading/writing one way or another. I remember using Geas Tech Demo's File Reading for my own stuff. (I still do, since it suits my purposes and I'm lazy to code my own, heh)
Posted on 2005-12-23 14:48:15
|
rao_dao_zao
|
Hmm. Guess I'll just keep it at one-shot-one-kill for now, I really don't feel confident enough to tackle file I/O during the festive season.
I'll tidy up my stuff and post a demo. Thanks, anyway, and Merry Christmas!
Posted on 2005-12-24 04:12:23
|
rosh.r03
|
sorry to inteupt this thrread but i'd just like to say merry Xmas cus i wont be on for a while i'm spending 3 weeks in florida!
MERRY XMAS EVERY1!!!!
ps be safe this xmas and don't get too plastered!!
Posted on 2005-12-24 17:39:01
|
zonker6666
|
The solution to your problem can be solved in this manner --- it does require file IO but really its not really that difficult.
Some may dissagree - but this would be my way of handling it :
#1 use a dummy layer to hold the entities (not the actual entities layer) ----- when u load the map u look on lets say layer 6 and spawn entities depending on which 'special' tiles u've put there --- for example u may decide that tiles 100 to 120 are your entities --- so (GetTile(X,Y,6)-100) would be your first entity and so on.
#2 you need to write some sort of data file for every map ---- if that data file doesnt exist it means that the player is visiting that map for the first time - and u load the entities by reading that special layer..... otherwise u load the entities based on the list u've saved to file.
You re-write this file every time the player leaves a map --- this could also be used to keep track of doors that have been unlocked or opened - items that were taken by the player and many other things im sure u can see what im getting at.
Now - how do you write a structure to file? The simplest way is as a string .... and here's a little example.
struct NPC
{
int hp;
int xpos;
int ypos;
string name;
}
int fptr; /// a global file pointer
void WriteNPCsToFile()
{
int i;
fptr=OpenFile("mydatafile.txt",FILE_WRITE);
for(i=0;i<NumNPCS;i++)
WriteNPCToFile(i);
FileClose(fptr);
}
void WriteNPCToFile(int NPCID)
{
string savedata;
savedata=str(MyNPCS[NPCID].hp);
savedata=savedata+",";
savedata=savedata+str(MyNPCS[NPCID].xpos);
savedata=savedata+",";
savedata=savedata+str(MyNPCS[NPCID].ypos);
savedata=savedata+",";
savedata=savedata+MyNPCS[NPCID].name;
FileWriteLn(fptr,savedata);
}
hope that helps you out
Posted on 2005-12-28 18:05:59
|
rao_dao_zao
|
Yes, that does seem quite helpful... But how do I get the data back in? Each property of the saved NPC is separated by a comma, yes, but how can I let the loading procedure know about that and extract the necessary sections?
Posted on 2005-12-29 07:18:37
|
Overkill
|
Uhm, here's an easier and faster way to read/write files. Enjoy! It writes in binary though, so if you open up the files it'll look mostly like garbage. Not ideal for when it expects plain-text, but good for when you're only reading and writing only from the program.
#define NPC_MAX_COUNT 20
struct npc_type
{
string name;
int hp;
int x, y;
};
int npc_count;
npc_type npc[NPC_MAX_COUNT];
void SaveNPCs(string filename)
{
int i;
int f = FileOpen(filename, FILE_WRITE);
// FileWriteQuad() works for saving ints.
FileWriteQuad(f, npc_count);
for (i = 0; i < npc_count; i++)
{
// FileWriteString() works for saving strings.
FileWriteString(f, npc[i].name);
FileWriteQuad(f, npc[i].hp);
FileWriteQuad(f, npc[i].x);
FileWriteQuad(f, npc[i].y);
}
FileClose(f);
}
void LoadNPCs(string filename)
{
int i;
int f = FileOpen(filename, FILE_READ);
if (!f)
{
Exit ("LoadNPCs() - " + filename + " not found!");
}
// FileReadQuad() works for loading ints.
npc_count = FileReadQuad(f);
for (i = 0; i < npc_count; i++)
{
// FileReadString() works for loading strings.
npc[i].name = FileReadString(f);
npc[i].hp = FileReadQuad(f);
npc[i].x = FileReadQuad(f);
npc[i].y = FileReadQuad(f);
}
FileClose(f);
}
Posted on 2005-12-29 17:06:57 (last edited on 2005-12-29 22:17:40)
|
zonker6666
|
Oh my - I neglected to put in the reading part of that :) I'll do so for completeness even though Overkills solution is perfectly fine (in fact I would say its even better) but here goes ....
void ReadNPCs(string filename)
{
int fp=OpenFile(filename,FILE_READ);
int NPCIDcount;
string filein;
while(!FileEOF(fp))
{
filein=FileReadLn(fp);
NPCs[NPCIDcount].hp=val(StringToken(filein,",",0));
NPCs[NPCIDcount].atx=val(StringToken(filein,",",1));
NPCs[NPCIDcount].aty=val(StringToken(filein,",",2));
NPCs[NPCIDcount].name=StringToken(filein,",",3);
NPCIDcount++;
}
}
Posted on 2005-12-29 19:14:05
|
rao_dao_zao
|
Very nice, thank you! Although I think I'll stick with the plain text for now, I'm still quite n00by at all this.
Posted on 2005-12-30 12:42:29
|
Displaying 1-12 of 12 total.
1
|
|