1 registered members (7th_zorro),
1,390
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
[SOLVED] changing levels [yes another one of these]
#430151
09/24/13 19:08
09/24/13 19:08
|
Joined: Nov 2006
Posts: 497 Ohio
xbox
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2006
Posts: 497
Ohio
|
Thanks to 3run, it was discovered that the problem somewhere lied in using multiple main files. After combining them both to make one, large file, everything seems to work just fine. Sorry for yet another thread about changing levels. I feel like they pop up all of the time. I have 4 separate levels for my game, and 2 main scripts. 1 is the main file where "main" is run but also contains an action for an entity to assist with the player changing levels. The 2nd the player code. The player code deals with the player physics and camera stuff. First issue is when I select the level from the menu panel i create in "main", If I select the 3rd level or 4th level initially, then the entities placed from WED load properly and the physics on the player work properly. However, when I initially choose level 1 or 2, and change levels to 3 or 4, the only entity that loads is the one to assist in level change, all other entities are not loaded. Second issue is, I can load any level initially and have everything (entities, and physics) work perfectly, but once I change levels, the physics get screwed up and my player slides all over the place. Here is the code for the main script,
#include <acknex.h>
#include <default.c>
#include <ackphysx.h>
#include "ballPlayer.c"
ENTITY* skycube =
{
type = "sky_fu_256+6.tga";
flags2 = SKY| CUBE | SHOW;
}
var current_level = 0;
STRING* level = "";
BMAP* button_1 = "button_1.bmp";
BMAP* button_2 = "button_2.bmp";
BMAP* button_3 = "button_3.bmp";
BMAP* button_4 = "button_4.bmp";
function load1();
function load2();
function load3();
function load4();
var soundhandle;
function main()
{
mouse_mode = 4;
PANEL* menuPan = pan_create(NULL, 1);
FONT* standard_font = font_create("Calibri#20");
pan_setbutton(menuPan, 0, 0, 250, 100, button_1, button_1, button_1, button_1, load1, NULL, NULL);
pan_setbutton(menuPan, 0, 0, 250, 150, button_2, button_2, button_2, button_2, load2, NULL, NULL);
pan_setbutton(menuPan, 0, 0, 250, 200, button_3, button_3, button_3, button_3, load3, NULL, NULL);
pan_setbutton(menuPan, 0, 0, 250, 250, button_4, button_4, button_4, button_4, load4, NULL, NULL);
set(menuPan, SHOW);
while(current_level == 0){wait(1);}
reset(menuPan, SHOW);
physX_open();
level_load(level);
wait(2);
ballInit();
//doors_init(level);
//soundhandle = media_loop("Prince Yeti - Coco.mp3", NULL, 50);
}
function load1()
{
current_level = 1;
level = "ttest.wmb";
return;
}
function load2()
{
current_level = 2;
level = "level2.wmb";
return;
}
function load3()
{
current_level = 3;
level = "level3.wmb";
return;
}
function load4()
{
current_level = 4;
level = "level4.wmb";
return;
}
action end()
{
while(ball == NULL){wait(1);}
while(vec_dist(my.x, ball.x) > 50){wait(1);}
if(current_level == 4)
sys_exit("111");
else
{
ent_remove(me);
ent_remove(ball);
current_level = 0;
main();
}
}
...and the second file...
///////////////////////////////////////////////////////////////
//#include <acknex.h>
//#include <default.c>
//#include <ackphysx.h>
///////////////////////////////////////////////////////////////
VECTOR ball_force;
var frict = 100;
ENTITY* ball;
ENTITY* bball;
STRING* triggerString = "Hit the trigger to open the door!";
//function outlin();
VECTOR camPos;
// movement vector:
VECTOR dist;
// camera angle:
ANGLE camInput; // input from the mouse
ANGLE camAngle; // accelerated input angles
// camera parameters:
var camFocus = 0;
var camDist = 250; // default distance to the ball
var camDistMin = 150; // min distance to the ball
var camDistMax = 350; // max distance to the ball
var camMouseSpeed = 0.2; // mouse movement speed
var camAngFric = 0.99; // angular friction (should be between 0.1 and 0.99)
var camResult = 0; // result given by the camera trace
// function to attach simple 3rd person camera:
void attachCamera(){
// get input:
camInput.pan -= camMouseSpeed * mickey.x;
camInput.tilt -= camMouseSpeed * mickey.y;
// limit tilt:
camInput.tilt = clamp(camInput.tilt, -65, 20);
// no ROLL rotation:
camInput.roll = 0;
// accelerate angles:
vec_accelerate(camAngle.pan, camAngle.pan, camInput.pan, camAngFric);
// limit tilt:
camAngle.tilt = clamp(camAngle.tilt, -65, 65);
// rotate camera itself:
camera.pan = camAngle.pan;
camera.tilt = camAngle.tilt;
camera.roll = camAngle.roll;
// zoom in and out:
camDist -= 0.3 * mickey.z;
// limit the distance:
camDist = clamp(camDist, camDistMin, camDistMax);
// get the focus:
camFocus = fcos(camera.tilt, -camDist);
// define the offset vector, by the focus var:
camPos.x = ball.x + fcos((camera.pan), camFocus);
camPos.y = ball.y + fsin((camera.pan), camFocus);
camPos.z = ball.z + fsin(camera.tilt, -camDist);
// define 'trace_mode':
trace_mode = IGNORE_MODELS | IGNORE_PASSABLE | IGNORE_PASSENTS | IGNORE_SPRITES | IGNORE_ME |
IGNORE_YOU | IGNORE_FLAG2 | IGNORE_MAPS | IGNORE_CONTENT;
// detect walls (level blocks):
camResult = c_trace(ball.x, camPos.x, trace_mode);
// if we hit something:
if(camResult > 0){
// scale the normal we get from the hit surface:
vec_scale(normal.x, 5);
// add it to the hit position:
vec_add(target.x, normal.x);
// set camera to that position:
vec_set(camera.x, target.x);
}
else{
// if we didn't hit anything, set camera directly:
vec_set(camera.x, camPos.x);
}
}
function ballInit()
{
ball = ent_create ("cartoonball.mdl", vector(0, 0, 100), NULL); // create the ball
//bball = ent_create("bball.mdl", vector(ball.x, ball.y, ball.z), outlin);
set(ball, SHADOW);
pXent_settype (ball, PH_RIGID, PH_SPHERE); // set the physics entity type
pXent_setfriction (ball,frict); // set the friction on the ground
pXent_setdamping (ball,10,10); // set the damping
pXent_setelasticity (ball,50); // set the elasticity
while (ball)
{
ball_force.x = (key_d-key_a)*10*time_step; // rotate the ball about the global x axis
ball_force.y = (key_w-key_s)*10*time_step; // rotate the ball about the global y axis
ball_force.z = 0; // no need to rotate about the vertical axis
vec_rotate(ball_force, vector(camera.pan, 0, 0));
pXent_addtorqueglobal (ball, ball_force); // add a torque (an angular force) to the ball
attachCamera();
/*if(key_pressed(57))
{
while(key_pressed(57)){wait(1);}
pXent_addforcelocal(ball, vector(0,0,200), nullvector);
pXent_addforcelocal(ball, nullvector, nullvector);
}*/
wait(1);
}
}
ENTITY* trap;
ENTITY* door_;
STRING* triggerString = "Hit the trigger to open the door!";
var triggered = 0;
action trigger()
{
my.alpha = 50;
my.red = 255;
my.lightrange = 100;
while(ball == NULL){wait(1);}
while(vec_dist(my.x, ball.x) > 50){wait(1);}
triggered = 1;
ent_remove(me);
}
action door()
{
while(ball == NULL){wait(1);}
while(door_ == NULL){wait(1);}
PANEL* temp = pan_create(NULL, 1);
FONT* standard_font = font_create("Calibri#30");
pan_setstring(temp, 0, 250, 500, standard_font, triggerString);
while(triggered == 0)
{
if(vec_dist(door_.x, ball.x) < 200)
{
set(temp, OUTLINE);
set(temp, SHOW);
}
else
reset(temp, SHOW);
wait(1);
}
triggered = 0;
ent_remove(me);
}
Last edited by xbox; 09/24/13 20:21.
|
|
|
|