Tumbleweed Doors function and animation

Started by Jackpumpkinhead, Fri 14/02/2025 01:18:50

Previous topic - Next topic

Jackpumpkinhead

I am currently using the Tumbleweed template and just started using the doors function. I am wanting to add and animation of my player reaching out to open the door, and then the door object will be visible. But I don't know how to make those things happen in that sequence. Is there a way to add that option to the function or is there another way?

Kara Jo Kalinowski

Here's what I've got.

It could be done more elegantly i.e. defined in a function but adding this code to your door's AnyClick function also works instead of the one line you were using. Just replace animation_view, animation_loop, and animation_delay to values that meet your needs. It's not the most elegant, and could be defined in a function instead of this, but it works

Code: ags
function hDoor_AnyClick()
{
  bool continue_clicking = true; //Will be set to false if the player walks away before reaching the door
  int animation_view = VROGER_TALK; //Just using this to test, replace with the view that has your animation
  int animation_loop = eDirectionRight; //which is loop 2,  you could also just put a number here. Again,  only using this specific value to test.
  int animation_delay = 4; //Number of frames delay per animation frame displayed
  
  if (Verbs.UsedAction(eGA_Close) || Verbs.UsedAction(eGA_Open) || Verbs.UsedAction(eGA_UseInv)) 
  {
    if (Verbs.AnyClickMove(313, 165, eDirectionUp)) 
    {
      player.LockView(animation_view);
      player.Animate(animation_loop, animation_delay, eOnce, eBlock);
      player.UnlockView();
    }
    else { //means walk was not completed
      continue_clicking = false;
    }
  }
  if (continue_clicking) {
      if ( Doors.AnyClickSpecial(10, oDoor.ID, 313, 165, eDirectionUp, 1, 210, 145, eDirectionUp, null, null, 3, 0) == 0 ) Verbs.Unhandled();
  }
}


Khris

#2
I'd create a universal extender function called Reach or something and call that at the appropriate time:

Code: ags
void Reach(this Character*, HeightType height) {
  this.LockView(PLAYER_REACH);
  this.Animate(loop, ..., eBlock); // loop calculated from player.Loop and height
  this.UnlockView();
}

In your door hotspot handling:
Code: ags
  player.Reach(eHeightMid);
  if (Doors.AnyClickSpecial(...)) ...

In general, avoid duplicate code at all costs and separate concerns whenever possible. (i.e. absolutely never put multiple lines of identical reach animation code into every single door hotspot function and think about whether the player reaching for something will only happen when they're opening a door [probably not])

Kara Jo Kalinowski

Yeah something like that is probably better, but it requires editing tumbleweed itself as the Doors.AnyClickSpecial does both the movement and the stuff that happens afterwards. And I wasn't sure if he wanted the same animation for every door. (I did say that my solution was inelegant and should probably be functioized)


 provides
Quote from: Khris on Fri 14/02/2025 15:39:52I'd create a universal extender function called Reach or something and call that at the appropriate time:

Code: ags
void Reach(this Character*, HeightType height) {
  this.LockView(PLAYER_REACH);
  this.Animate(loop, ..., eBlock); // loop calculated from player.Loop and height
  this.UnlockView();
}

In your door hotspot handling:
Code: ags
  player.Reach(eHeightMid);
  if (Doors.AnyClickSpecial(...)) ...

In general, avoid duplicate code at all costs and separate concerns whenever possible. (i.e. absolutely never put multiple lines of identical reach animation code into every single door hotspot function and think about whether the player reaching for something will only happen when they're opening a door [probably not])

Kara Jo Kalinowski

@Khris your extender function won't work (the way I'm understanding it) because AnyClickSpecial also handles what happens as a result of the click on the door, and you want the animation to play after walking, but before handling the click, so the modifications have to be done to Tumbleweed itself, really.

I've done some work to integrate this into Tumbleweed

https://pastebin.com/nYHCb8tn

Follow those steps to add stuff to the Tumbleweed script

Explanations:

You need to call the function Doors.SetAnimation(bool animate_on,  int view_id,  int animation_speed,  int delay_after); once (at the start of game load, for example) to set the values that you want. You can re-call this function if the values ever need to change.

animate_on should be set to true if you want it to animate, false to disable it.
view_id is which view contains the animation. It should have 4 loops depending on the direction you're facing.
animation_speed is the number of frames delay between each animation frame.
delay_after is the number of frames to wait before continuing with the rest of the script.

I've editted the AnyClickSpecial function to call this animation every time you try to open a closed door, try to close an open door, or try to use an inventory item on a door. You could try and finetune this if you want slightly different behavior. If so, it needs to be in the if block which starts with if (Verbs.AnyClickMove (x, y, dir)) because that's the script Tumbleweed uses to determine whether walking to the point was successful.

Khris

@Kara Jo Kalinowski
True, I forgot that the function completely takes over the hotspot handling :-[

SMF spam blocked by CleanTalk