MODULE: GotThere 0.5

Started by Khris, Wed 03/01/2024 08:46:42

Previous topic - Next topic

Khris

In a basic BASS / Sierra game, start a non-blocking walk toward something when interacting with it that can be canceled by the player at any time.

Download: GotThere.scm

The module provides a single function:

bool WalkFace(int x, int y, CharacterDirection dir)

Use it like this:
Code: ags
function hSomeHotspot_Interact() {
  if (WalkFace(123, 45, eDirectionLeft)) {
    // what happens when the player reaches those coordinates goes in here
  }
}

cat

A few caveats for people who want to use this module:


Monsieur OUXX

Please note: The Tumbleweed template relies on the same mechanics, as Lucasarts games let you change your mind while the character is walking towards the location where you told him/her to perform an action.
In Tumbleweed I nicknamed it "delayed action" when I spotted it, as it waits on the character "getting there" first, like this module does.
However in Tumbleweed the logic for this is mixed together with the logic for the rest of the module, making it hard to spot despite being a critical feature.
I had extracted it once into its own module, but have no clue what I did with that updated script.

I do not know which implementation has the least caveats : Khris' one or Tumbleweed's one. It would be interesting to compare side by side, and maybe Khris can snatch some cool tricks from that other implementation (or the other way around -- again, no idea which one did it best)

Long things short: I think the AGS code base would benefit from this very module (or its sibling from Tumbleweed) to be integrated into the templates, as a standalone module.

PS: It could have been Tumbleweed or one of the other Lucasarts templates : 9-verb, verbcoin ?
 

blaholtzen

#3
Is there is an easy way to combine the features of this module with the ones in this function I'm using for most of the movement in my game? (The gist is I'm doing side-scroller perspective and most things you can interact with can be done from either side, plus an extra thing for auto running, all of which is just comparing x coordinates)


Code: ags
static void DoIt::WalkUpTo(int middle, int distance) {
  
// Walks up to something from either direction to set up for interaction.
  
  if(middle > cTy.x + 120 || middle < cTy.x - 120){ //If far away enough,  switch to running.
    if(!MacIsShirtless && cTy.Moving && cTy.View != 175){
    cTy.StopMoving();
    }
    if(MacIsShirtless && cTy.Moving && cTy.View != 177){
    cTy.StopMoving();
    }
    cTy.SetWalkSpeed(9, 9);
    cTy.AnimationSpeed = 3;
    if(MacIsShirtless){
    cTy.LockView(177);
    }
    else{
    cTy.LockView(175);
    }
  }
  
  if (cTy.x < middle)
  {
  cTy.Walk(middle-distance, cTy.y, eBlock);
  }
  else {
  cTy.Walk(middle+distance, cTy.y, eBlock);
  }
  cTy.FaceLocation(middle, cTy.y, eBlock);  //Makes sure he still ends up facing it if he happened to be standing close to the middle of the thing.
  
  DoIt.ResetMacWalk();  // Makes sure he goes back to walking
}


I assume my stuff would need to get shoved into a second variation of the function in this module since its working off that if statement.
I had a go at that myself but I couldn't figure out how, haha.

Update: I figured it out, just had to do it one bit at a time :)

SMF spam blocked by CleanTalk