Pushing a box [design]

Started by eri0o, Sun 22/10/2017 14:27:50

Previous topic - Next topic

eri0o

Hey,

There's a scene where we wanted our character to push a box, which he will use to climb on top and reach something that's normally out of reach. How would you design such a scene? Our first design idea is that interacting with the box reveals a GUI with forward and backward arrows.

Crimson Wizard

#1
An alternative solution: change cursor to corresponding arrow when you hover mouse around the object, depending on relative cursor/object position.

Pro: no extra gui, so using is faster.
Con: easier for player to make a mistake by misclick. Also may conflict with the chosen UI style (depends on what you are using).

Snarky

Another option: Direct manipulation, where you have to e.g. click-and-drag, or swipe, to move the box. This can often be more engaging than just a clicking an arrow button on a GUI. (Resonance is an example of a game that used this kind of interaction to good effect, with things like sawing a cable and winding a winch done by direct manipulation.)

So you could do a thing where you have to hold down the button to grab the box, and then move the cursor left or right to push/pull it. If if it's heavy you might only be able to move it a little bit at a time, and would have to repeat the drag gesture several times. Just a matter of how involved you want to get about the interaction.

rongel

I'm glad I noticed this, because I have a similiar situation: There is a ladder with wheels in the library next to high bookshelfs. You can push the ladder further so you can climb on the ladder and pick up the book you want. Currently you can only push the ladder to the right. When the ladder reaches the right edge, the push-direction changes to left. It works allright but this would be much nicer option:

Quote from: Crimson Wizard on Sun 22/10/2017 15:49:25
An alternative solution: change cursor to corresponding arrow when you hover mouse around the object, depending on relative cursor/object position.

Only problem is I don't know where to start with this. How can I tell AGS that the mouse is on the left or right side of the ladder? Do I need to split the object in two sides, or is there a better, cleaner way?

Sorry eri0o about hijacking the thread, but didn't want to start a new one!
Dreams in the Witch House on Steam & GOG

Snarky

#4
Use something like:

Code: ags
if(mouse.x + GetViewportX() > oLadder.x + oLadder.Width/2)
{
  // To the right of the ladder, so use push-left cursor
}
else
{
  // To the left of the ladder, so use push-right cursor
}


This checks whether you're to the left or right of the center-line of the object.

Edit: Objects don't have a .Width property, apparently, so follow CW's instructions to get the width.

Crimson Wizard

#5
Quote from: rongel on Mon 23/10/2017 18:41:54
Quote from: Crimson Wizard on Sun 22/10/2017 15:49:25
An alternative solution: change cursor to corresponding arrow when you hover mouse around the object, depending on relative cursor/object position.

Only problem is I don't know where to start with this. How can I tell AGS that the mouse is on the left or right side of the ladder? Do I need to split the object in two sides, or is there a better, cleaner way?

Ah, Snarky already answered while I was typing.

One need to mention though that Object does not have Width and Height properties, but they may be found from its current sprite properties like this:
Code: ags

int obj_width = Game.SpriteWidth[oLadder.Graphics];
int obj_height = Game.SpriteHeight[oLadder.Graphics];


If your object is animated that's a little more complicated. Here are expanded functions of getting current object's width and height.
Code: ags

int GetObjectWidth(Object *o)
{
    if (o.View != 0)
    {
      ViewFrame* vf = Game.GetViewFrame(o.View, o.Loop, o.Frame);
      if (vf != null)
        return Game.SpriteWidth[vf.Graphic];
    }
    return Game.SpriteWidth[o.Graphic];
}

int GetObjectHeight(Object *o)
{
    if (o.View != 0)
    {
      ViewFrame* vf = Game.GetViewFrame(o.View, o.Loop, o.Frame);
      if (vf != null)
        return Game.SpriteHeight[vf.Graphic];
    }
    return Game.SpriteHeight[o.Graphic];
}


rongel

Thanks for the quick answers! I did some quick testing and it looks pretty good. The ladders are luckily only a still image, so didn't need that more advanced code.

This is what I have now when I interact with the ladders:

Code: ags
function oLadder_Interact()
{
  if(mouse.x + GetViewportX() > oLadder.X + Game.SpriteWidth[oLadder.Graphic]/2) {
    Display("right");
  }
  else {
    Display("left");
  }


And this is in rep_exec. I would use this to change the cursor but haven't yet played with that.

Code: ags
if((Object.GetAtScreenXY(mouse.x, mouse.y) ==oLadder) && (mouse.x + GetViewportX() > oLadder.X + Game.SpriteWidth[oLadder.Graphic]/2)) lblActionText.Text = "Ladder Right";
if((Object.GetAtScreenXY(mouse.x, mouse.y) ==oLadder) && (mouse.x + GetViewportX() < oLadder.X + Game.SpriteWidth[oLadder.Graphic]/2)) lblActionText.Text = "Ladder Left";

Dreams in the Witch House on Steam & GOG

eri0o

Thank you all for all the insightful ideas. I like the being able to click on each side and arrow indications on cursor - my box is actually a hospital bed with wheels, so the gesture idea doesn't work as great, but I will have this idea in mind for other things.

One question, I usually have lots of "how to design x" questions when I am making a game, does these type of questions belong here in the technical questions? (this a bit offtopic but I am not sure where to go for these meta questions).

Snarky

Quote from: eri0o on Wed 25/10/2017 23:26:44
One question, I usually have lots of "how to design x" questions when I am making a game, does these type of questions belong here in the technical questions? (this a bit offtopic but I am not sure where to go for these meta questions).

No, they don't really belong here unless the question is how to code it. If you're making a concrete proposal and are asking what people think of your idea, it should go in the Critics' Lounge. If you're discussing it more generally, it probably belongs in Adventure-Related Talk & Chat.

SMF spam blocked by CleanTalk