changing the level once my character reaches a certain posiiton

Posted By: Cactus

changing the level once my character reaches a certain posiiton - 11/02/08 17:12

K I want my level to change once my character reaches a certain position, or when my player touches a certain object. How should I go about this. I am using the A5 templates.
Sorry for being a noob, but help would be great.
Posted By: Xarthor

Re: changing the level once my character reaches a certain posiiton - 11/02/08 20:18

Code:

action LevelChanger_act
{
  while(!player) { wait(1); }

  my.passable = on;

  while(me)
  {
    if(vec_dist(my.x,player.x) < 50)
    {
      level_load("level02.wmb");
    }
    wait(1);
  }
}


Other approach using a touch event:
Code:
function LevelChanger_event()
{
  if(event_type == event_entity || event_type == event_impact)
  {
    if(you == player)
    {
      level_load("level2.wmb");
    }
  }
}

action LevelChanger_act
{
  my.enable_entity = on;
  my.enable_impact = on;
  my.event = LevelChanger_event;
}


Of course you can alter it for using it with multiple levels.
Like, define a skill which works as id for the level that is loaded, have a string array (text object) holding all level name strings, and load it using the id as index:
Code:
text level_files
{
  string = "level1.wmb","level2.wmb"....
}
...
define level_id, skill2;
...
level_load(level_files.string[my.level_id]);
...


hope this helps you a bit
Posted By: Quad

Re: changing the level once my character reaches a certain posiiton - 11/02/08 20:56

Xarthor's 2nd approach is good imo, but you should remove the levelchanger entity right after the impact event called because if you dont remove it, impact event wil get called everyframe, means it will call level_load in everyframe of impact which causes engine to freeze.
Posted By: Xarthor

Re: changing the level once my character reaches a certain posiiton - 11/02/08 21:17

Removing is not necessary, just add the following lines in the event function:
my.enable_entity = off;
my.enable_impact = off;

Thanks for the hint Quadraxas!
Posted By: Cactus

Re: changing the level once my character reaches a certain posiiton - 11/02/08 22:29

Thank You so much, but now when I load the next level all of the panels I made in my main script for for level 2 dont show up. Is it still using the same main script from the last level?
if so how do I load the main script for level two?
Posted By: DJBMASTER

Re: changing the level once my character reaches a certain posiiton - 11/02/08 22:33

you can't use 2 different scripts for 2 different levels. You have to use one master script throughout the game.
Posted By: Cactus

Re: changing the level once my character reaches a certain posiiton - 11/02/08 23:20

k figured somthing out.
Posted By: Cactus

Re: changing the level once my character reaches a certain posiiton - 11/03/08 19:38

Ok I used the seconed aproach and it worked, but now when the player shoots at the level change object the level changer turns off. Still using A5 templates.
Posted By: Xarthor

Re: changing the level once my character reaches a certain posiiton - 11/03/08 21:26

Code:
function LevelChanger_event()
{
  if(event_type == event_entity || event_type == event_impact)
  {
    if(you == player)
    {
      my.enable_entity = null;
      my.enable_impact = null;
      level_load("level2.wmb");
    }
  }
}

This makes sure that events are only turned off if the player hits the entity.
Hope this works.
Posted By: Cactus

Re: changing the level once my character reaches a certain posiiton - 11/04/08 00:09

no that did'nt work, but thanks anyway. I guess I'll just figure it out.
Posted By: Alessandro

Re: changing the level once my character reaches a certain posiiton - 11/04/08 07:07

Generally speaking, put an initialization code in a separated function, and call it just after every level is loaded. In this way you can quickly restore/setup any object for any loaded level (you can use a "switch" statement to apply changes):

(I didn't test the following code, use it only as a guideline):

Code:
#define LEVEL_1   1
#define LEVEL_2   2
#define LEVEL_3   3

function initGame(int argNewLevel) {
  switch( argNewLevel ) 
  {
    case LEVEL_1:
        // WRITE CODE TO INITIALIZE LEVEL 1;
        break;
    case LEVEL_2:
        // WRITE CODE TO INITIALIZE LEVEL 2;
        break;
    case LEVEL_3:
        // WRITE CODE TO INITIALIZE LEVEL 3;
        break;
  }
}

Posted By: Cactus

Re: changing the level once my character reaches a certain posiiton - 11/04/08 16:23

thanks, and xarthar nvm the code did work I just messed up,thaks alot.
© 2024 lite-C Forums