Looping Rooms

Started by DontTreadOnMe, Sun 10/04/2005 11:28:00

Previous topic - Next topic

DontTreadOnMe

Hey, first post in the tech forum, im pretty sure it should be here, and i have searched for it but cant find anything covering the topic. The only documentation i can find on looping rooms is the explanation of how its done that was used in the demo quest.

Has anyone actually used this in a game, because im trying to, but im having a few problems. For the most part the script used in the demo quest works fine, but at one end of the room if you're standing a certain distance from the end and click on the other side of the boundry between one end and the other the room shifts fine but then the player runs all the way to the other end of the room again. And i cant figure out why, heres the snippet of script tat controlls the walking in that room. Its the same as the one used in demo quest but with the distances changed.

Code: ags
function walk(int mx, int my, int ox) {
  if (mx+ox <= 160) character[DUKE].x = character[DUKE].x + 960;
  if (mx+ox >= 1280) character[DUKE].x = character[DUKE].x - 960;
  MoveCharacter(DUKE,mx+GetViewportX(),my);
}


The room is 1440 long and the origional was 960 before adding the first 480 pixels on again.

If you have any idea why its doing this then help wuld really be appreciated

Thanks - Rich
Seeing as I really shouldn't have to get up at such an ungodly hour as 7am, ill put my watch forward by 5 hours to make me feel better...

stuh505

I'm having diffculty understanding what you want...you want the character to go back to the left side of the screen when they try to walk off the right side, and vice versa?  If so...try this

Code: ags

//global var
int EDGE = 10; 

//in repeatedly execute
cycle(5);

//in global script
function cycle(int room) {
  if (character[player.ID].room == room)
    {
    if (character[player.ID].x > game.room_width - EDGE){
      character[player.ID].x = EDGE*2;
    } else if (character[player.ID].x < EDGE) {
      character[player.ID].x = game.room_width - 2*EDGE;
    }
  }
}

DontTreadOnMe

Not exactly, ive already got a looping room working like the one in the demo quest, ive followed all the documentation by System Error (the guy that scripted the origional room in demo quest) what the script does is when the player clicks in the end 160 pixels of the room it shifts them to the other end (there is a copy of the first 480 pixels of the room at the oposite end) the player doesnt notice the shift and the script tells the character to move where the player clicked on the old screen pluss the viewport offset so as far as the player can tell they havent gone anywhere and cant tell where the seam is.

My explanation is pretty bad, but basicly i did exactly what the demo quest document said (in the docs folder of the demo quest file) and it appears to work, theres just a slight glitch when occasionally instead of moving to the position on the shifted screen he will move to the position on the old screen right at the otehr end of the room, effectively running a lap of the room

My explanation sucks (and i cant blame not being so great at the language) but thats the best i can do at explainin the problem. But the only stuff i can find on looping rooms is whats in the demo files and ive followed that to the word and it doesnt seem to eb working so great

Thanks-rich
Seeing as I really shouldn't have to get up at such an ungodly hour as 7am, ill put my watch forward by 5 hours to make me feel better...

strazer

I did it like this:

Code: ags

// room script file

#define BUFFERAREA_LENGTH 240 // relative width of room background buffer area (480 pixels)

function PauseMoving (int charid) {
// Stops the supplied character but keeps its last frame
// For seamlessly changing walking speed, for example

  char prevview = character[charid].view+1;
  char prevloop = character[charid].loop;
  char prevframe = character[charid].frame;
  int wasmoving = character[charid].walking;
  StopMoving(charid);
  if (wasmoving) SetCharacterFrame(charid, prevview, prevloop, prevframe);
    // since we're using his current view, the lock will be released automatically once the character is moved again
}


function WaitHidden(int gameloops) {
  int prevmode = GetCursorMode; // store the current cursor mode
  SetCursorMode(MODE_WAIT); // change to wait cursor mode
  SetMouseCursor(prevmode); // change appearance to look like previous cursor mode
  Wait(gameloops);
  SetDefaultCursor(); // revert wait cursor to the default sprite
  SetCursormode(prevmode); // revert to previous cursor mode
}


function on_mouse_click(MouseButton button) {

  if (IsGamePaused()) return; // if game is paused, quit function

  if (button == LEFT) { // if left mouse click
    if (GetCursorMode() == MODE_WALK) { // if mouse is in walk mode
      if (GetViewportX() + mouse.x >= game.room_width - (system.viewport_width / 2)) { // if clicked on right end of room
        PauseMoving(GetPlayerCharacter()); // see above
        character[GetPlayerCharacter()].x = character[GetPlayerCharacter()].x - (game.room_width - BUFFERAREA_LENGTH); // put character at left end of room
        WaitHidden(1); // see above; let screen update before running global on_mouse_click
      }
      else if (GetViewportX() + mouse.x <= (system.viewport_width / 2)) { // if clicked on left end of room
        PauseMoving(GetPlayerCharacter()); // see above
        character[GetPlayerCharacter()].x = character[GetPlayerCharacter()].x + (game.room_width - BUFFERAREA_LENGTH); // put character at right end of room
        WaitHidden(1); // see above; let screen update before running global on_mouse_click
      }
    }
  }

  // global on_mouse_click will be called afterwards -> character starts walking

}

SMF spam blocked by CleanTalk