0 registered members (),
1,209
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Aum 54, Dungeon creator
#295373
10/24/09 20:59
10/24/09 20:59
|
Joined: Mar 2009
Posts: 42 Dominican Republic
keilyn3d
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 42
Dominican Republic
|
what I need to change for make the dugeon creator work? this don't work with the A7.7 or 7.8. (I don't mean convert it to Lite-c). this is the code from aum 54 but it not work (the level is not created): //////////////////////////////////////////////////////////////////////////////////////// // "#" = wall // " " = floor // "p" = player // "s" = spider // "f" = finish ////////////////////////////////////////////////////////////////////////////////////////
var video_mode = 8; // 1024x768 var video_depth = 32; // 32 bit mode var video_screen = 2; // start in full screen mode
var level_handle; // handle for the level data file var level_size_x; var level_size_y; var lines_index; var all_placed = 0; // will be set to 1 as soon as the entire level is created var starting_position; var char_index; var floor_coords; var players_health = 100; var player_spotted = 0; // will alarm all the spiders as soon as the first spider sees the player
////////////////////////////////////////////////////////////////////////////////////////
sound beep_sound = <beep.wav>;
////////////////////////////////////////////////////////////////////////////////////////
string bigroom_wmb = <bigroom.wmb>; string wall_wmb = <wall.wmb>; string floor_wmb = <floor.wmb>; string player_mdl = <player.mdl>; string spider_mdl = <spider.mdl>; string finish_mdl = <finish.mdl>;
string level_chars[900]; // stores the characters, the level can have up to 30 x 30 = 900 blocks string line_characters[30]; // a level must have a maximum number of 30 blocks on x and y string temp_string[30]; string empty_space = " "; // 30 empty spaces string current_character = " "; // empty space
////////////////////////////////////////////////////////////////////////////////////////
function read_level_data(); function make_static(); function finish_action(); function players_action(); function spider_action(); function spider_event();
////////////////////////////////////////////////////////////////////////////////////////
function main() { randomize(); // initialize the random number generator all_placed = 0; // the level elements aren't placed at this point level_load(bigroom_wmb); // load the level wait (3); // wait until the level is loaded read_level_data(); // read the level elements while (player == null) {wait (1);} // wait until the player model is created while (1) { camera.x = player.x - 300; // place the camera 300 quants below the player on the x axis camera.y = player.y; camera.z = 1000; // and 1000 quants above the player on the z axis camera.tilt = -60; // look down at the player if (mouse_left == on) {camera.arc -= 2 * time;} // zoom in or out using the left / right mouse buttons if (mouse_right == on) {camera.arc += 2 * time;} if (mouse_middle == on) {camera.arc = 60;} // press the middle mouse button to restore the default zoom factor camera.arc = min (max (camera.arc, 40), 100); // limit camera.arc to 40..100 wait (1); } }
function read_level_data() { vec_set (starting_position, nullvector); level_handle = file_open_read("level01.dat"); // open the level file level_size_x = file_var_read(level_handle); // read the level size on x level_size_y = file_var_read(level_handle); // and on y starting_position.x -= (30 - level_size_x) * 64 / 2; // a floor piece has 64 quants starting_position.y -= (30 - level_size_y) * 64 / 2; // a floor piece has 64 quants lines_index = 0; while (lines_index < level_size_y) { file_str_read(level_handle, line_characters); // here we get the lines that create the level (horizontally) str_cat(level_chars, line_characters); if (str_len(line_characters) < level_size_x) // if this line is shorter than level_size_x { str_cpy(temp_string, empty_space); // we copy some spaces in temp_string str_trunc(temp_string, (30 - level_size_x)); // first we cut this line to the standard level_size_x str_trunc(temp_string, (level_size_x - str_len(line_characters))); // now we've got some space to add to the end of the line str_cat(level_chars, temp_string); // and we do that in order to keep the same length for all the lines in the level } lines_index += 1; } file_close(level_handle); // close the file // here I've got all the elements stored in level_chars; if a level has 3 lines and 3 rows (for example) the string stores the elements this way // "## . @### " -> it puts all the level elements that are useful at the beginning of the string // all the lines have the same length (I have added spaces at the end of the shorter lines) // now we have to split them in lines / rows again and read / create them in the "real" world // so we will read only the first level_size_x * level_size_y characters in the string char_index = 0; vec_set (floor_coords, starting_position); // we want to change floor_coords without altering starting_position floor_coords.z = 0; while (char_index < (level_size_x * level_size_y)) { str_cpy(current_character, level_chars); if (str_cmp(current_character, " ") == 1) // floor? { starting_position.z = 0; ent_create(floor_wmb, starting_position, make_static); } if (str_cmp(current_character, "#") == 1) // wall? { starting_position.z = 54; ent_create(wall_wmb, starting_position, make_static); } if (str_cmp(current_character, "p") == 1) // player? (we create the player and the floor below it) { starting_position.z = 0; ent_create(floor_wmb, starting_position, make_static); starting_position.z += 64; player = ent_create(player_mdl, starting_position, players_action); } if (str_cmp(current_character, "s") == 1) // spider? (we create the spider and the floor below it) { starting_position.z = 0; ent_create(floor_wmb, starting_position, make_static); starting_position.z += 64; ent_create(spider_mdl, starting_position, spider_action); } if (str_cmp(current_character, "f") == 1) // finish? (we create the flag and the floor below it) { starting_position.z = 0; ent_create(floor_wmb, starting_position, make_static); starting_position.z += 64; ent_create(finish_mdl, starting_position, finish_action); } char_index += 1; str_clip(level_chars, 1); // remove the 1st character from level_chars and so on starting_position.x += 64; // offset on x if ((char_index % (level_size_x)) == 0) // line finished? draw another line { starting_position.x -= 64 * level_size_x; starting_position.y -= 64; } } // all the level blocks are placed here all_placed = 1; // all the level elements are placed here }
function make_static() { my.dynamic = off; // increases the frame rate, especially if we've got a bigger level }
function finish_action() { while (vec_dist (player.x, my.x) > 50) {wait (1);} // wait until the player comes close to the flag exit; // you should load the 2nd level here }
function players_action() { var anim_percentage; // animation percentage var movement_speed; // player's movement speed while (players_health == 100) // as long as the player is alive { my.pan += 6 * (key_cul - key_cur) * time; // rotate the player using the cursor left and cursor right keys vec_set (temp.x, my.x); // copy player's position to temp movement_speed.x = 5 * (key_cuu - key_cud) * time; // move the player the using cursor up and cursor down keys movement_speed.y = 0; // don't move sideways movement_speed.z = 0; // nor vertically c_move (my, movement_speed.x, nullvector, glide); // move the player if ((key_cuu == off) && (key_cud == off)) // if the player isn't moving { ent_animate(my, "stand", anim_percentage, anm_cycle); // play its "stand" animation } else // the player is moving? { ent_animate(my, "walk", anim_percentage, anm_cycle); // then play its "walk" animation } anim_percentage += 5 * time; // 5 = animation speed wait (1); } while (players_health > 0) // animate the player for its "death" animation { ent_animate(my, "death", 100 - players_health, anm_cycle); // play the "death" animation wait (1); } my.passable = on; }
function spider_action() { var anim_percentage; // animation percentage var movement_speed; // movement speed var spider_antenna; // detects the environment type in front of the spider var distance_covered = 0; // stores the distance covered by the spider in the last frame my.skill10 = my.z; // store the initial height of the spider in skill10 my.scale_x = 0.7; // make the spider a bit smaller, play with this value my.scale_y = my.scale_x; my.scale_z = my.scale_x; my.enable_entity = on; // the spider is sensitive to impact with other entities and level blocks my.enable_impact = on; my.enable_block = on; my.event = spider_event; // this is the event function for the spider while (player_spotted == 0) // stand still until you see the player { c_trace (my.x, player.x, ignore_me + use_box); // trace from the spider to the player if (you == player) // the player is visible { player_spotted = 1; // get out of this while loop; alert all the other spiders } ent_animate(my, "stand", anim_percentage, anm_cycle); // play the "stand" animation until you see the player anim_percentage += 15 * time; // 15 = animation speed sleep (0.1); } movement_speed.x = 3 * time; movement_speed.y = 0; // don't move sideways movement_speed.z = 0; // nor vertically while (1) { spider_antenna.x = my.x + 15 * cos(my.pan); // the spider_antenna variable detects the environment and spider_antenna.y = my.y + 15 * sin(my.pan); // it is placed 15 quants in front of the spider spider_antenna.z = my.z; if (content(spider_antenna) == content_solid) // a wall is in front of the spider { my.skill40 = my.pan; my.skill41 = 88 + random(4); if (random(1) > 0.5) { while (my.pan < my.skill40 + my.skill41) // then rotate for 88...92 degrees to get out of there { my.pan += 3 * time; wait (1); } } else { while (my.pan > my.skill40 - my.skill41) // then rotate for -88...-92 degrees to get out of there { my.pan -= 3 * time; wait (1); } } } else // the road is clear { ent_animate(my, "run", my.skill20, anm_cycle); // play the "run" animation my.skill20 += 10 * time; distance_covered = c_move (my, movement_speed.x, nullvector, ignore_passable | glide); // move the spider if (distance_covered < 0.1) // got stuck or moving too slow? (0.1 = experimental value, prevents the spiders from moving too slow) { movement_speed.x *= -1; // reverse the movement direction movement_speed.x *= 0.5; // halve the movement speed when walking backwards my.skill40 = my.pan; my.skill41 = 88 + random(4); if (random(1) > 0.5) { while (my.pan < my.skill40 + my.skill41) // rotate 88...92 degrees { my.pan += 5 * time; ent_animate(my, "run", my.skill20, anm_cycle); // play the "run" animation my.skill20 -= 10 * time; c_move (my, movement_speed.x, nullvector, ignore_passable | glide); // move the spider wait (1); } } else { while (my.pan > my.skill40 - my.skill41) // rotate -88...-92 degrees { my.pan -= 5 * time; ent_animate(my, "run", my.skill20, anm_cycle); // play the "run" animation my.skill20 -= 10 * time; c_move (my, movement_speed.x, nullvector, ignore_passable | glide); // move the spider wait (1); } } movement_speed.x = 3 * time; // restore the initial movement_speed } } my.z = my.skill10; // restore the initial height wait (1); } }
function spider_event() { if ((event_type == event_entity) && (you == player)) // collided with the player? { my.event = null; // don't trigger the same event several times - the player will die anyway while (players_health > 10) // play with this value until you are happy with the "death" animation { players_health -= 2 * time; // the player dies, "2" controls the "death" animation speed wait (1); } } }
|
|
|
Re: Aum 54, Dungeon creator
[Re: Nowherebrain]
#295804
10/27/09 18:45
10/27/09 18:45
|
Joined: Mar 2009
Posts: 146 USA
paracharlie
Member
|
Member
Joined: Mar 2009
Posts: 146
USA
|
Here is my attempt to convert this to lite-c. I have invalid arguments error in read_level_data. If someone wants to help figure out what the problem is.
////////////////////////////////////////////////////////////////////////////////////////
// "#" = wall
// " " = floor
// "p" = player
// "s" = spider
// "f" = finish
////////////////////////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
var level_handle; // handle for the level data file
var level_size_x;
var level_size_y;
var lines_index;
var all_placed = 0; // will be set to 1 as soon as the entire level is created
VECTOR starting_position;
var char_index;
VECTOR floor_coords;
var players_health = 100;
var player_spotted = 0; // will alarm all the spiders as soon as the first spider sees the player
////////////////////////////////////////////////////////////////////////////////////////
SOUND* beep_sound = "beep.wav";
////////////////////////////////////////////////////////////////////////////////////////
STRING* bigroom_wmb = "bigroom.wmb";
STRING* wall_wmb = "wall.wmb";
STRING* floor_wmb = "floor.wmb";
STRING* player_mdl = "player.mdl";
STRING* spider_mdl = "spider.mdl";
STRING* finish_mdl = "finish.mdl";
STRING* level_chars[900]; // stores the characters, the level can have up to 30 x 30 = 900 blocks
STRING* line_characters[30]; // a level must have a maximum number of 30 blocks on x and y
STRING* temp_string[30];
STRING* empty_space = "#30"; // 30 empty spaces
STRING* current_character = " "; // empty space
////////////////////////////////////////////////////////////////////////////////////////
function read_level_data();
function make_static();
function finish_action();
function players_action();
function spider_action();
function spider_event();
////////////////////////////////////////////////////////////////////////////////////////
function main()
{
video_mode = 8; // 1024x768
video_depth = 32; // 32 bit mode
video_screen = 1; // start in full screen mode
random_seed(0); // initialize the random number generator
all_placed = 0; // the level elements aren't placed at this point
level_load(bigroom_wmb); // load the level
wait (3); // wait until the level is loaded
read_level_data(); // read the level elements
while (player == NULL) {wait (1);} // wait until the player model is created
while (1)
{
camera.x = player.x - 300; // place the camera 300 quants below the player on the x axis
camera.y = player.y;
camera.z = 1000; // and 1000 quants above the player on the z axis
camera.tilt = -60; // look down at the player
if (mouse_left == 1) {camera.arc -= 2 * time_step;} // zoom in or out using the left / right mouse buttons
if (mouse_right == 1) {camera.arc += 2 * time_step;}
if (mouse_middle == 1) {camera.arc = 60;} // press the middle mouse button to restore the default zoom factor
camera.arc = minv (maxv (camera.arc, 40), 100); // limit camera.arc to 40..100
wait (1);
}
}
function read_level_data()
{
vec_set (starting_position, nullvector);
level_handle = file_open_read("level01.dat"); // open the level file
level_size_x = file_var_read(level_handle); // read the level size on x
level_size_y = file_var_read(level_handle); // and on y
starting_position.x -= (30 - level_size_x) * 64 / 2; // a floor piece has 64 quants
starting_position.y -= (30 - level_size_y) * 64 / 2; // a floor piece has 64 quants
lines_index = 0;
while (lines_index < level_size_y)
{
file_str_read(level_handle, line_characters); // here we get the lines that create the level (horizontally)
str_cat(level_chars, line_characters);
if (str_len(line_characters) < level_size_x) // if this line is shorter than level_size_x
{
str_cpy(temp_string, empty_space); // we copy some spaces in temp_string
str_trunc(temp_string, (30 - level_size_x)); // first we cut this line to the standard level_size_x
str_trunc(temp_string, (level_size_x - str_len(line_characters))); // now we've got some space to add to the end of the line
str_cat(level_chars, temp_string); // and we do that in order to keep the same length for all the lines in the level
}
lines_index += 1;
wait(1);
}
file_close(level_handle); // close the file
// here I've got all the elements stored in level_chars; if a level has 3 lines and 3 rows (for example) the STRING* stores the elements this way
// "## . @### " -> it puts all the level elements that are useful at the beginning of the STRING*
// all the lines have the same length (I have added spaces at the end of the shorter lines)
// now we have to split them in lines / rows again and read / create them in the "real" world
// so we will read only the first level_size_x * level_size_y characters in the STRING*
char_index = 0;
vec_set (floor_coords, starting_position); // we want to change floor_coords without altering starting_position
floor_coords.z = 0;
while (char_index < level_size_x * level_size_y)
{
str_cpy(current_character, level_chars);
if (str_cmp(current_character, " ") == 1) // floor?
{
starting_position.z = 0;
ent_create(floor_wmb, starting_position, make_static);
}
if (str_cmp(current_character, "#") == 1) // wall?
{
starting_position.z = 54;
ent_create(wall_wmb, starting_position, make_static);
}
if (str_cmp(current_character, "p") == 1) // player? (we create the player and the floor below it)
{
starting_position.z = 0;
ent_create(floor_wmb, starting_position, make_static);
starting_position.z += 64;
player = ent_create(player_mdl, starting_position, players_action);
}
if (str_cmp(current_character, "s") == 1) // spider? (we create the spider and the floor below it)
{
starting_position.z = 0;
ent_create(floor_wmb, starting_position, make_static);
starting_position.z += 64;
ent_create(spider_mdl, starting_position, spider_action);
}
if (str_cmp(current_character, "f") == 1) // finish? (we create the flag and the floor below it)
{
starting_position.z = 0;
ent_create(floor_wmb, starting_position, make_static);
starting_position.z += 64;
ent_create(finish_mdl, starting_position, finish_action);
}
char_index += 1;
str_clip(level_chars, 1); // remove the 1st character from level_chars and so on
starting_position.x += 64; // offset on x
if ((char_index % (level_size_x)) == 0) // line finished? draw another line
{
starting_position.x -= 64 * level_size_x;
starting_position.y -= 64;
}
wait(1);
}
// all the level blocks are placed here
all_placed = 1; // all the level elements are placed here
}
function make_static()
{
my.emask &= ~DYNAMIC; // increases the frame rate, especially if we've got a bigger level
}
function finish_action()
{
while (vec_dist (player.x, my.x) > 50) {wait (1);} // wait until the player comes close to the flag
sys_exit("bye...bye"); // you should load the 2nd level here
}
function players_action()
{
VECTOR temp[3];
VECTOR movement_speed[3];
var anim_percentage; // animation percentage
while (players_health <= 0) // as long as the player is alive
{
my.pan += 6 * (key_cul - key_cur) * time_step; // rotate the player using the cursor left and cursor right keys
vec_set (temp.x, my.x); // copy player's position to temp
movement_speed.x = 5 * (key_cuu - key_cud) * time_step; // move the player the using cursor up and cursor down keys
movement_speed.y = 0; // don't move sideways
movement_speed.z = 0; // nor vertically
c_move (my, movement_speed, nullvector, GLIDE); // move the player
if ((key_cuu == 0) && (key_cud == 0)) // if the player isn't moving
{
ent_animate(my, "stand", anim_percentage, ANM_CYCLE); // play its "stand" animation
}
else // the player is moving?
{
ent_animate(my, "walk", anim_percentage, ANM_CYCLE); // then play its "walk" animation
}
anim_percentage += 5 * time_step; // 5 = animation speed
wait (1);
}
while (players_health > 0) // animate the player for its "death" animation
{
ent_animate(my, "death", 100 - players_health, ANM_CYCLE); // play the "death" animation
wait (1);
}
set(my, PASSABLE);
}
function spider_action()
{
var anim_percentage; // animation percentage
VECTOR movement_speed[3]; // movement speed
VECTOR spider_antenna[3]; // detects the environment type in front of the spider
var distance_covered = 0; // stores the distance covered by the spider in the last frame
my.skill10 = my.z; // store the initial height of the spider in skill10
my.scale_x = 0.7; // make the spider a bit smaller, play with this value
my.scale_y = my.scale_x;
my.scale_z = my.scale_x;
my.emask |= ENABLE_ENTITY | ENABLE_IMPACT | ENABLE_BLOCK; // the spider is sensitive to impact with other entities and level blocks
//my.enable_impact = on;
//my.enable_block = on;
my.event = spider_event; // this is the event function for the spider
while (player_spotted == 0) // stand still until you see the player
{
c_trace (my.x, player.x, IGNORE_ME + USE_BOX); // trace from the spider to the player
if (you == player) // the player is visible
{
player_spotted = 1; // get out of this while loop; alert all the other spiders
}
ent_animate(my, "stand", anim_percentage, ANM_CYCLE); // play the "stand" animation until you see the player
anim_percentage += 15 * time_step; // 15 = animation speed
wait (-0.1);
}
movement_speed.x = 3 * time_step;
movement_speed.y = 0; // don't move sideways
movement_speed.z = 0; // nor vertically
while (1)
{
spider_antenna.x = my.x + 15 * cos(my.pan); // the spider_antenna variable detects the environment and
spider_antenna.y = my.y + 15 * sin(my.pan); // it is placed 15 quants in front of the spider
spider_antenna.z = my.z;
if (content(spider_antenna) == 1) // a wall is in front of the spider
{
my.skill40 = my.pan;
my.skill41 = 88 + random(4);
if (random(1) > 0.5)
{
while (my.pan < my.skill40 + my.skill41) // then rotate for 88...92 degrees to get out of there
{
my.pan += 3 * time_step;
wait (1);
}
}
else
{
while (my.pan > my.skill40 - my.skill41) // then rotate for -88...-92 degrees to get out of there
{
my.pan -= 3 * time_step;
wait (1);
}
}
}
else // the road is clear
{
ent_animate(my, "run", my.skill20, ANM_CYCLE); // play the "run" animation
my.skill20 += 10 * time_step;
distance_covered = c_move (my, movement_speed.x, nullvector, IGNORE_PASSABLE | GLIDE); // move the spider
if (distance_covered < 0.1) // got stuck or moving too slow? (0.1 = experimental value, prevents the spiders from moving too slow)
{
movement_speed.x *= -1; // reverse the movement direction
movement_speed.x *= 0.5; // halve the movement speed when walking backwards
my.skill40 = my.pan;
my.skill41 = 88 + random(4);
if (random(1) > 0.5)
{
while (my.pan < my.skill40 + my.skill41) // rotate 88...92 degrees
{
my.pan += 5 * time_step;
ent_animate(my, "run", my.skill20, ANM_CYCLE); // play the "run" animation
my.skill20 -= 10 * time_step;
c_move (my, movement_speed.x, nullvector, IGNORE_PASSABLE | GLIDE); // move the spider
wait (1);
}
}
else
{
while (my.pan > my.skill40 - my.skill41) // rotate -88...-92 degrees
{
my.pan -= 5 * time_step;
ent_animate(my, "run", my.skill20, ANM_CYCLE); // play the "run" animation
my.skill20 -= 10 * time_step;
c_move (my, movement_speed.x, nullvector, IGNORE_PASSABLE | GLIDE); // move the spider
wait (1);
}
}
movement_speed.x = 3 * time_step; // restore the initial movement_speed
}
}
my.z = my.skill10; // restore the initial height
wait (1);
}
}
function spider_event()
{
if ((event_type == EVENT_ENTITY) && (you == player)) // collided with the player?
{
my.event = NULL; // don't trigger the same event several times - the player will die anyway
while (players_health > 10) // play with this value until you are happy with the "death" animation
{
players_health -= 2 * time_step; // the player dies, "2" controls the "death" animation speed
wait (1);
}
}
}
Last edited by paracharlie; 10/27/09 20:38. Reason: Fixed Vectors
A8 Commercial
|
|
|
|