Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In Need of a simple Function.

ghaxaqghaxaq Member Posts: 16
I need a function that when I press X, it will break all other procedures and go to a procedure I will assign in the code. The situation is that I am making a game, and when I press x kickout:=true but because of different levels in the game (e.g rookie) when I press x it jumps to the next level, instead I want it to go to the main screen.
Thx alot.

Comments

  • Phat NatPhat Nat Member Posts: 757
    [b][red]This message was edited by Phat Nat at 2006-1-17 22:34:5[/red][/b][hr]
    : I need a function that when I press X, it will break all other procedures and go to a procedure I will assign in the code. The situation is that I am making a game, and when I press x kickout:=true but because of different levels in the game (e.g rookie) when I press x it jumps to the next level, instead I want it to go to the main screen.
    : Thx alot.
    :

    If you are using the boolean variable KICKOUT, then it all has to do on how you handle it.
    If you want this at any point in the game, you could hook the timer interrupt and have it check the keyboard buffer I suppose. if it sees 'x' it could call your desired procedure. Not positive it would work perfect with the original Pascal Keyboard handler. I have done something like this with my own Keyboard handler.
    Anyways, if you want to try this you will need to hook interrupt $1C (timer interrupt) and check the keyboard (port[$60]) for the 'x' key.

    Phat Nat



  • ghaxaqghaxaq Member Posts: 16
    I wrote this procedure
    [code]
    procedure rookie;
    begin

    laby(maze, col, row); {read 1st maze from text}
    try1(count);
    laby2(maze, col, row);
    try2(count);
    laby3(maze, col, row);
    try3(count);

    end;
    [/code]

    I need to edit the code such that when I press X the procedure would be interrupted.

  • Phat NatPhat Nat Member Posts: 757
    : I wrote this procedure
    : [code]
    : procedure rookie;
    : begin
    :
    : laby(maze, col, row); {read 1st maze from text}
    : try1(count);
    : laby2(maze, col, row);
    : try2(count);
    : laby3(maze, col, row);
    : try3(count);
    :
    : end;
    : [/code]
    :
    : I need to edit the code such that when I press X the procedure would be interrupted.
    :

    I'm going to guess that laby() loads the maze and Try() is the porcedure where the user actually moves through the maze.
    If I'm right, then you should be able to have all three maze levels called from one procedure:

    [code]
    procedure rookie;
    begin
    laby(1,maze, col, row); {read 1st maze from text}
    try(1,count);
    laby(2,maze, col, row);
    try(2,count);
    laby(3,maze, col, row);
    try(3,count);
    end;
    [/code]

    If all your maze procedures are the same, then this should work. And if so, then you can do this:
    [code]
    procedure rookie;
    VAR
    Level : Byte;
    begin
    Level := 0;
    Repeat
    Inc(Level);
    laby(Level,maze, col, row); {read 1st maze from text}
    try(Level,count);
    Until (Level = 3) or (Kickout);
    end;
    [/code]

    Then in between levels it will check for Kickout and inside the Try() procedure when you check for a keypress, you can have it Set Kickout := True and Exit out of the procedure. This would take you right back to the main screen.

    If you don't think you can do it this way, try posting the code for at least 2 levels & I'll help

    Phat Nat

  • ghaxaqghaxaq Member Posts: 16
    : : I wrote this procedure
    : : [code]
    : : procedure rookie;
    : : begin
    : :
    : : laby(maze, col, row); {read 1st maze from text}
    : : try1(count);
    : : laby2(maze, col, row);
    : : try2(count);
    : : laby3(maze, col, row);
    : : try3(count);
    : :
    : : end;
    : : [/code]
    : :
    : : I need to edit the code such that when I press X the procedure would be interrupted.
    : :
    :
    : I'm going to guess that laby() loads the maze and Try() is the porcedure where the user actually moves through the maze.
    : If I'm right, then you should be able to have all three maze levels called from one procedure:
    :
    : [code]
    : procedure rookie;
    : begin
    : laby(1,maze, col, row); {read 1st maze from text}
    : try(1,count);
    : laby(2,maze, col, row);
    : try(2,count);
    : laby(3,maze, col, row);
    : try(3,count);
    : end;
    : [/code]
    :
    : If all your maze procedures are the same, then this should work. And if so, then you can do this:
    : [code]
    : procedure rookie;
    : VAR
    : Level : Byte;
    : begin
    : Level := 0;
    : Repeat
    : Inc(Level);
    : laby(Level,maze, col, row); {read 1st maze from text}
    : try(Level,count);
    : Until (Level = 3) or (Kickout);
    : end;
    : [/code]
    :
    : Then in between levels it will check for Kickout and inside the Try() procedure when you check for a keypress, you can have it Set Kickout := True and Exit out of the procedure. This would take you right back to the main screen.
    :
    : If you don't think you can do it this way, try posting the code for at least 2 levels & I'll help
    :
    : Phat Nat
    :
    :


    This is the main code used in the program that interacts with this feature,currently as is it does not display the maze from the text file as before:

    [code]Procedure laby(var Level:byte; maze: mazear; var col, row: shortint);

    var dfile: text;

    begin
    row:=0;
    assign(dfile, 'L:maze1.txt');
    reset(dfile);
    while not eof(dfile) do
    begin
    row:=row+1;
    col:=0;
    while not eoln(dfile) do
    begin
    col:=col+1;
    read(dfile, maze[row, col]);
    end;{y}
    readln(dfile);
    write(row,col);
    end;{x}
    close(dfile);
    end;{procedure}

    [/code]

    [code]
    {Player Movements' Validtion Begin}
    Procedure Moveman2(var maze: mazear; var row, col, x, y: shortint;
    var movement: char);


    Function checkmove(var movement: char): boolean;
    begin
    checkmove:=false;
    case movement of
    chr(72): checkmove:= true;
    chr(75): checkmove:= true;
    chr(77): checkmove:= true;
    chr(80): checkmove:= true;
    'X': checkmove:= true;

    end;
    end;
    {End Player Movements' Validation}
    [/code]

    [code]
    Function KickOut(var maze: mazear; var x,y: shortint; var movement: char ): boolean;

    begin
    kickout:=false;
    if maze[y-1,x-7]= 'F' then kickout:= true;
    if movement= 'X' then kickout:= true;
    end;
    [/code]

    [code]
    Procedure TRY1 (var Level:byte; count:shortint); {Loading of game rookie level1}

    begin
    clrscr;
    display(maze, col, row); {displays characters from text}
    start(maze,col,row); {where we start the man}
    y:=row;
    x:=col+5;
    count:=0;
    repeat {repeat loop when moving}
    moveman2(maze,row,col, x, y, movement); {how to move man}
    while hit(maze,x,y, movement) do {what happens when you hit a wall}
    begin
    moveman2(maze,row,col, x, y, movement);
    end;
    move(movement, x, y);
    count:=count+1;

    until kickout(maze, x, y, movement) ;

    end;
  • Phat NatPhat Nat Member Posts: 757
    Email me your full code. I think we can clean this up a bit. There are a couple of things that have me puzzled without seeing the rest of the code. For one, I notice these lines:
    [code]
    : y:=row;
    : x:=col+5;

    : if maze[y-1,x-7]= 'F' then kickout:= true;
    [/code]

    Is your maze drawn towards the center of the screen? Anyways, looking back at having one procedure to load all your maps is the best place to start. I figure that one of the main problems that you had with that is that your guy starts & finishes in a different place in each maze. However, this can be easily fixed by adding start and end points to the files or automatically detecting them by the 'F' when the maze is loaded.

    Anyways, if you would like, email me your code (or post it here if it all fits) and I will help you clean it up a little and make it easier to implement the Kickout function.

    Phat Nat

  • ghaxaqghaxaq Member Posts: 16
    : Email me your full code. I think we can clean this up a bit. There are a couple of things that have me puzzled without seeing the rest of the code. For one, I notice these lines:
    : [code]
    : : y:=row;
    : : x:=col+5;
    :
    : : if maze[y-1,x-7]= 'F' then kickout:= true;
    : [/code]
    :
    : Is your maze drawn towards the center of the screen? Anyways, looking back at having one procedure to load all your maps is the best place to start. I figure that one of the main problems that you had with that is that your guy starts & finishes in a different place in each maze. However, this can be easily fixed by adding start and end points to the files or automatically detecting them by the 'F' when the maze is loaded.
    :
    : Anyways, if you would like, email me your code (or post it here if it all fits) and I will help you clean it up a little and make it easier to implement the Kickout function.
    :
    : Phat Nat
    :
    :

    In case you did not receive my e-mail I have uploaded my pascal program along witht the text files to

    [code]http://rapidshare.de/files/11962236/maze_pascal.rar.html [/code]

    I need to add also a save/load game procedure, + a timer in the game.
  • ghaxaqghaxaq Member Posts: 16
    Hi I edited my program to this

    [code]http://rapidshare.de/files/12759487/LASTONE.PAS.html[/code]

    and the problem is that the maze does not show on screen. Could you chekc it out pls .Thx
Sign In or Register to comment.