|
Aum 10 Steroidz code (one small problem)
#10858
11/04/02 16:41
11/04/02 16:41
|
Joined: Aug 2002
Posts: 572 Toronto
MadMark
OP
User
|
OP
User
Joined: Aug 2002
Posts: 572
Toronto
|
Has anyone messed around with the Steroidz code? It's an asteroids type game, in 3D. I'm using that as a base for testing, and I have gotten fairly well along in one night. (Actually steroidz and several other scripts combined.) I ran into a problem with the "action sky_follows_player" and "action Space_Sphere" part. I used the models that come with it, have gone through the tutorial on rolling your own, flipping the normals and what-not, but I cannot seem to make these two models (both spheres that are created in code) PASSABLE! The asteroids are created, and then run into the outer walls of the passable models! If I flip the normals on a sphere, isn't it passable in both directions? I've commented out the creation lines and added the models manually, setting them to passable in WED. Same effect. If I delete the inner most model, then all is great, until I move around and get an invalid pointer error because the sky_map's position relative to the ship can't be updated. I apologize for the long post, but would appreciate any help with this. code:
//////////////////////////////////////////////////////////////////////////Paths, here... // Variables start here VAR SHIP_ANGS[3]; VAR ENGINE_WORK_SPEED[3];
var video_mode = 7; var video_depth = 16; var camera_distance[3] = -100, 0, 10; // distance on x, y, z var camera_angle[3]; var rocket_speed; var ship_speed; var asteroid_pos; var asteroid_angle; var shipsound_handle; var score; var particles_left; var particles_right; VAR THRUST_HANDLE = 0; VAR ENGINE_HANDLE = 0; var rocket_fired = 0;
///////////////////////////////////////////////////////////////////////////
font score_font = <score.pcx>, 34, 38; bmap particle_map = <particle.pcx>;
//////////////////////////////////////////////////////////////////////////
SOUND MAIN_ENGINES,<ENGINE.WAV>; SOUND THRUSTERS,<THRUSTER.WAV>; sound firerocket_snd = <firerock.wav>; sound explo_snd = <explode.wav>; sound ship_snd = <shiploop.wav>;
//////////////////////////////////////////////////////////////////////////
// string steroidz_wmb = <steroidz.wmb>;
string rocket_mdl = <rocket.mdl>; string asteroid_mdl = <asteroid.mdl>; string explo13_pcx = <explo+13.pcx>;
/////////////////////////////////////////////////////////////////////////
function ship_rocket(); function remove_me(); function player_dies(); function asteroid_generator(); function move_asteroid(); function destroy_asteroid(); function ship_particles(); function fade_particle();
// Synonyms: SYNONYM PLAYERS_SHIP {TYPE ENTITY;} SYNONYM STAR_SPHERE {TYPE ENTITY;}
////////////////////// DEFINES ///////////////////////////////////////////////////
DEFINE ACCEL_VECTOR,SKILL1; DEFINE ENGINE_THRUST,SKILL1; DEFINE DRIFT_VECTOR,SKILL4; DEFINE DRIFT_VECTOR_X,SKILL4; DEFINE DRIFT_VECTOR_Y,SKILL5; DEFINE DRIFT_VECTOR_Z,SKILL6; DEFINE SHIP_ANGLES,SKILL7; DEFINE PAN_SPEED,SKILL7; DEFINE TILT_SPEED,SKILL8; DEFINE ROLL_SPEED,SKILL9; DEFINE SPIN_RATE,SKILL10; DEFINE DECEL_RATE,SKILL11; DEFINE MAX_SPIN_SPEED,SKILL12; DEFINE MAX_SHIP_SPEED,SKILL13; DEFINE DEAD,SKILL20; DEFINE particle_rate,skill14;
function particle_thrustrun() { my_size -= 0.05*my_size*time; if(my_size < 10) { my_action = null; } }
var my_blend[3]; // for older engines
function main() { fps_max = 60; fps_min = 40; LOAD_LEVEL <steroidz.wmb>; // dummy level wait (2); score = 0; // reset score asteroid_generator(); }
function explode_me() // used to destroy every entity { play_sound explo_snd, 100; if (you.skill2 == 1) {score += 10 + random(10);} // give score if you hit the bad guys (or if they shoot themselves :) my.oriented = on; my.flare = on; my.bright = on; my.ambient = 100; while (my.frame < 14) { if (my.scale_x < 3) { my.scale_x += 0.5 * time; my.scale_y = my.scale_x; } my.frame += 1 * time;
vec_set (temp.x, player.x); vec_sub (temp.x, my.x); vec_to_angle (my.pan, temp); // turn towards the player to make sure that the explosion looks great
wait (1); } remove (me); }
}
ACTION SPACE_SPHERE { STAR_SPHERE = ME; my.passable=on;
WHILE (1) // Constantly keep the player at the center of the universe { VEC_SET(MY.POS,players_ship.POS); WAIT 1; } }
function particle_thrust() { // place at random positions behind the engine mY_pos.x -= random(1)*players_ship.drift_vector_x*time; mY_pos.y -= random(1)*players_ship.drift_vector_y*time; mY_pos.z -= random(1)*players_ship.drift_vector_z*time;
// generate a backthrust my_speed.x = -engine_work_speed.x + random(0.5)-0.25; // -0.25 to +0.25 my_speed.y = -engine_work_speed.y + random(0.5)-0.25; my_speed.z = -engine_work_speed.x + random(0.5)-0.25; my_size = random(100)+50; // 100 to 150 in size
//my_map = spark_map; my_flare = on; my_blend = on;
my_color.red = 245; my_color.green = 100; my_color.blue = 50;
my_action = particle_thrustrun; }
panel score_panel { pos_x = 0; pos_y = 0; digits 600, 20, 5, score_font, 1, score; // score can have up to 5 digits flags = refresh, visible; // always visible }
function ship_rocket() { wait (1); my.ambient = -50; my.skill30 = 0; my.enable_entity = on; my.enable_block = on; my.event = remove_me; my.narrow=on; my.passable = off; my.pan = player.pan; my.tilt = player.tilt; my.skill12 = 100 * time; my.skill13 = 0; my.skill14 = 0; my.frame=1; //start frame while (my != null) // as long as the rocket hasn't exploded { my.frame = my.frame + 1; my.skill12 = 100 * time; my.skill30 += 0.1 * time; wait(1); //slow down animation if (vec_dist (my.x, player.x) < 10) // don't collide with the player { my.passable = on; my.trigger_range = 2; } else { my.passable = off; }
if (my.skill30 < 100) { ent_move (my.skill12, nullvector); } else // remove the rocket even if it hasn't hit anything after a certain period of time { // ent_remove (me); } wait (1); } }
FUNCTION STOP_ROTATION() { // **** If you are still rotating, apply a rotation in the opposite direction to slow down // IF (players_ship.PAN_SPEED == 0) { GOTO CHECKTILT; } ELSE { IF ((KEY_CUL == 0) && (KEY_CUR == 0)) { IF (players_ship.PAN_SPEED > 0) { players_ship.PAN_SPEED -= players_ship.SPIN_RATE * TIME; } ELSE { players_ship.PAN_SPEED += players_ship.SPIN_RATE * TIME; } } IF (ABS(players_ship.PAN_SPEED) < .02) { players_ship.PAN_SPEED = 0; } }
CHECKTILT:
IF (players_ship.TILT_SPEED == 0) { RETURN; } ELSE { IF ((KEY_CUU == 0) && (KEY_CUD == 0)) { IF (players_ship.TILT_SPEED > 0) { players_ship.TILT_SPEED -= players_ship.SPIN_RATE * TIME; } ELSE { players_ship.TILT_SPEED += players_ship.SPIN_RATE * TIME; } } IF (ABS(players_ship.TILT_SPEED) < .02) { players_ship.TILT_SPEED = 0; } } } //}
DEFINE STAR_SKY,<STARS.MDL>; // SPHERE MODEL WITH STARFIELD
//*** Define Flags for space ship flight characteristics DEFINE AUTO_SPIN_STOP,FLAG1; // These flags should all be off for DEFINE AUTO_DECEL,FLAG2; // maximum realism, but can be DEFINE LIMIT_TURN_SPEED,FLAG3; // useful to make a ship "Handle" DEFINE LIMIT_TOP_SPEED,FLAG4; // better.
action player_ship { // Set Synonym for future use and Zero out all ship speeds PLAYERS_SHIP = ME; MY.NARROW = ON; // Use a smaller collision hull VEC_SET(MY.ACCEL_VECTOR,NULLVECTOR); // No starting speed VEC_SET(MY.DRIFT_VECTOR,NULLVECTOR); // No starting momentum CREATE STAR_SKY,MY.POS,SPACE_SPHERE; // Initialize background stars
//********************************************************* // Turn all special flight characteristics on to start. Set them to 0 to turn them off. MY.AUTO_SPIN_STOP = 1; // Let the ship stop spinning by itself MY.AUTO_DECEL = 1; // Let the ship slow down by using MY.DECEL_RATE MY.LIMIT_TURN_SPEED = 1; // Limit how fast you spin based on MY.MAX_SPIN_SPEED // MY.LIMIT_TOP_SPEED = 1; // Ship "speedlimit" based on MY.MAX_SHIP_SPEED
// Starting flight Characteristics for ship: MY.ENGINE_THRUST = 1.5; // Strength of the main engines MY.SPIN_RATE = .15; // Strength of the steering thrusters MY.DECEL_RATE = .04; // "Drift" deceleration rate MY.MAX_SPIN_SPEED = 5; // Top speed for changes in ships orientation MY.MAX_SHIP_SPEED = 10; // Top speed the ship can go //*********************************************************
WHILE (1) { player = me; // I'm the player my.enable_entity = on; // collides with entities my.enable_push = on; my.enable_impact = on; my.event = explode_me; // here's what happens on collision if (key_ctrl == 1) // press ctrl to fire { if (my.skill35 == 0) { my.skill35 = 1; // disable autofire ent_create (rocket_mdl, player.pos, ship_rocket); snd_play (firerocket_snd, 80, 0); } } else { my.skill35 = 0; // enable fire again } wait (1);
# *****Turning thruster logic here: # # If you fire a thruster and you are using LIMIT_TURN_SPEEDS then check # to make sure you are still under the speed limit.
IF (KEY_CUL == 1) {IF ((MY.LIMIT_TURN_SPEED == 0) || (MY.LIMIT_TURN_SPEED == 1) && (MY.PAN_SPEED < MY.MAX_SPIN_SPEED)) {MY.PAN_SPEED += MY.SPIN_RATE * TIME; IF (THRUST_HANDLE == 0) // no sound playing {PLAY_LOOP THRUSTERS,15; THRUST_HANDLE = RESULT;}}}
IF (KEY_CUR == 1) {IF ((MY.LIMIT_TURN_SPEED == 0) || (MY.LIMIT_TURN_SPEED == 1) && (MY.PAN_SPEED > -MY.MAX_SPIN_SPEED)) {MY.PAN_SPEED -= MY.SPIN_RATE * TIME; IF (THRUST_HANDLE == 0) // no sound playing {PLAY_LOOP THRUSTERS,15; THRUST_HANDLE = RESULT;}}}
IF (KEY_CUU == 1) {IF ((MY.LIMIT_TURN_SPEED == 0) || (MY.LIMIT_TURN_SPEED == 1) && (MY.TILT_SPEED < MY.MAX_SPIN_SPEED)) {MY.TILT_SPEED += MY.SPIN_RATE * TIME; IF (THRUST_HANDLE == 0) // no sound playing {PLAY_LOOP THRUSTERS,15; THRUST_HANDLE = RESULT;}}}
IF (KEY_CUD == 1) {IF ((MY.LIMIT_TURN_SPEED == 0) || (MY.LIMIT_TURN_SPEED == 1) && (MY.TILT_SPEED > -MY.MAX_SPIN_SPEED)) {MY.TILT_SPEED -= MY.SPIN_RATE * TIME; IF (THRUST_HANDLE == 0) // no sound playing {PLAY_LOOP THRUSTERS,15; THRUST_HANDLE = RESULT;}}}
IF ((THRUST_HANDLE != 0) && // If sound is playing... (KEY_CUU == 0) && (KEY_CUD == 0) && // ...and... (KEY_CUL == 0) && (KEY_CUR == 0)) // No arrow keys were pressed {STOP_SOUND THRUST_HANDLE ;// stop the sound THRUST_HANDLE = 0;}
//******* If using Auto_Spin_Stop, Stop spinning when not actively stearing.
IF (MY.AUTO_SPIN_STOP == 1) {STOP_ROTATION();}
//********Main Engine firing is here:
IF (KEY_SPACE == 1) // if the space bar is pressed { IF (ENGINE_HANDLE == 0) // If no sound playing, then play { PLAY_LOOP MAIN_ENGINES,25; ENGINE_HANDLE = RESULT; }
// 1) Set ENGINE_WORK_SPEED to the current thrust // 2) Vec_rotate will convert the thrust relative to the ship's orientation // (which is only the x axis) and convert it into the // X,Y,& Z components relative to the world's orientation.
VEC_SET(ENGINE_WORK_SPEED,MY.ENGINE_THRUST); VEC_ROTATE(ENGINE_WORK_SPEED,MY.PAN);
// If there is no speed limit, then apply the thrust, If there is a // speed limit, apply only the components of thrust that have not maxed out IF (MY.LIMIT_TOP_SPEED == 0) {VEC_ADD(MY.DRIFT_VECTOR,ENGINE_WORK_SPEED);} ELSE {IF (ABS(ENGINE_WORK_SPEED.X + MY.DRIFT_VECTOR_X) < MY.MAX_SHIP_SPEED) {MY.DRIFT_VECTOR_X += ENGINE_WORK_SPEED.X;}
IF (ABS(ENGINE_WORK_SPEED.Y + MY.DRIFT_VECTOR_Y) < MY.MAX_SHIP_SPEED) {MY.DRIFT_VECTOR_Y += ENGINE_WORK_SPEED.Y;}
IF (ABS(ENGINE_WORK_SPEED.Z + MY.DRIFT_VECTOR_Z) < MY.MAX_SHIP_SPEED) {MY.DRIFT_VECTOR_Z += ENGINE_WORK_SPEED.Z;} }
// Ignite engines - send a speed corrected number of particles my.particle_rate += time * vec_length(my.drift_vector_x); while (my.particle_rate > 1) // 1 particle per quant { ent_vertex(temp,354); // first engine vertex emit(1,temp,particle_thrust); ent_vertex(temp,368); // second engine vertex emit(1,temp,particle_thrust); my.particle_rate -= 1; } } ELSE { STOP_SOUND ENGINE_HANDLE ;// stop playing sound ENGINE_HANDLE = 0; }
//**** Set it all in motion MY.ROLL_SPEED = 0; // We don't use ROLL as an active control ROTATE ME,MY.SHIP_ANGLES,NULLVECTOR; // Rotate the ship based on our pan and tilt rates
// If you are not actively firing the engines, and Auto_decel is active, slow down the ship IF ((KEY_SPACE != 1) && (MY.AUTO_DECEL == 1)) {CALL DECEL_SHIP;}
// calculate a distance by multiplying the speed with the time vec_set(temp,MY.DRIFT_VECTOR); vec_scale(temp,time); MOVE ME,NULLVECTOR,temp; // Then move the ship according to distance
//////// POINT_CAMERA(); // Adjust the camera ADDED CODE INSTEAD OF CALLING FUNCTION! CAMERA.GENIUS = PLAYER_SHIP; // Camera won't see parts the ship VEC_SET(CAMERA.X,players_ship.X); // Camera is where the ship is VEC_SET(CAMERA.PAN,players_ship.PAN); // Camera looks in the same direction as ship
wait(1); }
}
ACTION DECEL_SHIP { # *** If you have momentum: # 1) Set ENGINE_WORK_SPEED to have the decel rate as it's "X" component of thrust # (It's negative because we are counter-thrusting to slow down, # not thrusting to speed up) # 2) Figure out the pan and tilt angles that correspond to the existing drift # vector using Vec_to_angle. # 3) Use Vec_Rotate to convert the thrust from the Ship's perspective to the real # world's perspective. # 4) Use the Vec_Scale command to time correct these speeds based on frame rate # 5) Add this new Deceleration Vector to the existing Drift Vector to slow down
IF (VEC_LENGTH(players_ship.DRIFT_VECTOR) != 0) // If I have momentum {VEC_SET(ENGINE_WORK_SPEED,NULLVECTOR); ENGINE_WORK_SPEED.X = -players_ship.DECEL_RATE; VEC_TO_ANGLE(SHIP_ANGS.PAN,players_ship.DRIFT_VECTOR); VEC_ROTATE(ENGINE_WORK_SPEED,SHIP_ANGS.PAN); VEC_SCALE(ENGINE_WORK_SPEED,TIME); VEC_ADD(players_ship.DRIFT_VECTOR,ENGINE_WORK_SPEED);} ELSE {RETURN;}
# *** If DRIFT_VECTOR is close enough to zero, make it zero
IF (VEC_LENGTH(players_ship.DRIFT_VECTOR) < .02) {VEC_SET(players_ship.DRIFT_VECTOR,NULLVECTOR);} }
action sky_follows_player { my.passable = on; // asteroids can pass through the sky sphere while (player == null) {wait (1);} while (1) { vec_set (my.pos, player.pos); wait (1); } }
function remove_me() { wait (1); //score += 1; ent_remove (me); }
function player_dies() { wait (1); player.skill22 += 1; if (player.skill22 > 4) // hit by 5 asteroids so it has to die { player.dead = 1; } }
function asteroid_generator() { while (1) { if (random(1) > 0.97) { asteroid_angle = player.pan + 30 - random(60); // -30...+30 degrees asteroid_pos.x = player.x + (5000 + random(5000)) * cos (asteroid_angle); asteroid_pos.y = player.y + (5000 + random(5000)) * sin (asteroid_angle); asteroid_pos.z = player.z + 300 - random(600); ent_create (asteroid_mdl, asteroid_pos, move_asteroid); } waitt (3); } }
function move_asteroid() { my.ambient = 50; my.metal = on; my.enable_entity = on; my.trigger_range = 2; my.event = destroy_asteroid; my.fat=on; asteroid_old_pos = Asteroid_pos; vec_set (temp.x, player.x); vec_sub (temp.x, my.x); vec_to_angle (my.pan, temp); // turn towards the player my.pan += 3 - random(6); // miss the player from time to time my.tilt += 1 - random(2); while (my != null) { my.roll += 5 * time; my.skill3 = 20 * time; my.skill4 = 0; my.skill5 = 0; my.passable=off; ent_move(my.skill3, nullvector); wait (1); if(event_type == event_impact) { remove_me(); return; }
} }
function destroy_asteroid() { my.ambient = 100; // my.passable = on; my.transparent = on; ent_create (explo13_pcx, my.pos, explode_me); waitt (2); ent_remove (me); snd_play (explo_snd, 70, 0); score += 1; }
function fade_particle() { my.alpha -= 20 * time; if (my.alpha < 0) {my.lifespan = 0;} }
function ship_particles() { temp.x = random(2) - 1; temp.y = random(10) + 2; temp.z = random(2) - 1; vec_add (my.vel_x, temp); my.alpha = 30 + random(50); my.bmap = particle_map; my.size = 7 + random(4); my.flare = on; my.bright = on; my.lifespan = 20; my.function = fade_particle; }
on_r main; // R = restart }
People who live in glass houses shouldn't vacuum naked.
|
|
|
Re: Aum 10 Steroidz code (one small problem)
#10859
11/07/02 08:37
11/07/02 08:37
|
Anonymous
Unregistered
|
Anonymous
Unregistered
|
Use move_mode = ignore_passable for all your entities that are moving; place the line before ent_move.
|
|
|
Re: Aum 10 Steroidz code (one small problem)
#10861
11/09/02 07:29
11/09/02 07:29
|
Joined: Jul 2002
Posts: 1,529 Sudbury, Ontario, Canada
Shummy
Expert
|
Expert
Joined: Jul 2002
Posts: 1,529
Sudbury, Ontario, Canada
|
Yo mad mark you live in toronto so icked i live in sudbury its not often you find people using 3dgs thats are only hours away about 3 at that !! d u have msn!
~Shummy
Level Designer/Scripts
º_º€Lkº_ºBð¥º_Šøƒ†_º
[url=http://www.elkboysoftware.cjb.net]www.elkboysoftware.cjb.net[/url]
skater_boy29@hotmail.com
|
|
|
Re: Aum 10 Steroidz code (one small problem)
#10862
11/09/02 09:21
11/09/02 09:21
|
Joined: Aug 2002
Posts: 572 Toronto
MadMark
OP
User
|
OP
User
Joined: Aug 2002
Posts: 572
Toronto
|
Howdy Transplants. Betcha it's colder up there than down here. The summer snow is melting in Toronto, but the winter snow is on it's way. What do you give a frozen Canadian with hypothermia? Another beer. I'm very pleased with 3DGS so far, considering my eval is technically over. I formatted my hard drive and re-installed, though. Too much crap on the HD to do a fair eval. I've actually got most of this Steroidz game working now. Just tweaking the collision detection... Yes, I've got MSN. Wanna chat, shoot me your info in a Private Message. That first one is a WHACK site. Love that intro. Nice screenies on the second. How far along have you gotten with SOULex? MultiPlayer yet? Mark
People who live in glass houses shouldn't vacuum naked.
|
|
|
|