Hi !
Sorry for big
example , but I don't know how to explain it better than with working sample (4 parts in RAR ~1.5Mb).
This sample covers:
-using pointers (especially material and function one) for creating levels on the fly;
-execute() command for creating user defined level file (yes, for published game), look at Orange Brat's awesome camera code. With that camera and this example you can provide level editor even with A6 comm
-trick with execute() to provide user redefinable actions (yes, for published game).In archive:
File LEVEL01.LVL is a plain text file, that describe user game level (game 'Skeleton Inc.' from AUM). You can modify it.
File USERPROC.TXT is a plain text file but with C-script syntax
. It's a user actions for objects defined in level file. You can modify it.
For code and comments look at SKINC.WDL
That's all.
EDIT:
Sorry for very short description, but I coded that at night (4am)
Idea is simple:
to build 'loading engine' for our level file. We can produce WMP format (it's isn't complicated), but our customers can't compile them. So we define our plain text format for game map. Each line is a name_of_prefab, X_coord, Y_coord, name_of_action. I separate these fields by '|' (I want to use comma in comments
). Prefab may be .WMB or .MDL. In my game proj I'm using more types, just rewrite function load_level_ent(fhandle,fsection):
Code:
...
//prepare model file name
str_cat(temp_model, ".wmb");
if (!file_exists(temp_model)) {
str_trunc(temp_model,4);
str_cat(temp_model, ".mdl");
if (!file_exists(temp_model)){
return(-1); //return ERROR if can't find prefab
}
}
...
X and Y coords is an 'imagine' coords (like in 'sea war' game, that i played in school many years ago)
Name_of_action is a real name of function or action, defined in your script.
I divide level file in sections just for clarity, you haven't to do this...
Functions load_my_level(name_of_level) and load_level_ent(fhandle,fsection) does all work (look at their sources, I placed comments a little):
-read level file line by line;
-create entitiy at needed position and assign action to it;
-fill arrays with handles to our entities (you can use these arrays for group operations over entities, look at function purge_level);
-assign some skills to entities (I place index in array into skill MY_INDEX, sorry but forget to define it with define MY_INDEX, skill10; in define.wdl.
This can be used, when you kill entity, you have to place 0 at entity's place in array, to avoid crashes in function purge_level);
In sources you can find 10-20 bugs, I hope. But this doesn't matter. I coded it to show general idea.
And for last, to provide user editable actions I'm using trick (showed by me in thread about 'User resources in ZIP'):
Code:
execute("return;} include <userproc.txt>;");
I know that is a trick, so it have to be tested more deeply. Anyway it's working. Try it.
Any comments ?
P.S.
As usually, sorry for my English