Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Lewis on Thu 23/05/2013 07:29:54

Title: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Lewis on Thu 23/05/2013 07:29:54
Hello! Is this a beginners' question still? I'm not sure. I never know what sort of level I'm at.

ANYWAY.

We're working on a side-scrolling game. Movement is entirely keyboard-controlled, with the mouse only used for interacting with the world. Movement is bound to A and D - there's no jumping or crouching - and characters move along 1px-thin walkable areas.

Problem is, we'd like to include slopes and stairs in the game, but I can't wrap my head around how to do this. Obviously, when you get to this sort of obstacle, I need the player character to move diagonally up and to the right, even though the player is only pressing the 'move right' key.

Any pointers on how to achieve this would be super-appreciated, as it would be kinda bland to have a side-scrolling game where everything was just on the same plane. Cheers!
Title: Re: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Phemar on Thu 23/05/2013 09:26:06
If there are no double pixels on your slope's walkable area, the character won't be able to walk up it.
Title: Re: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Lewis on Thu 23/05/2013 09:57:31
I've tried it with multiple pixels as well, the problem is that the character gets 'stuck' as the 'move right' button literally does that - moves the player character ++ along the x axis.

What I'm hoping we can do is find a way that, when the player reaches a slope, continuing to press 'move right' moves the character up the slope accordingly.
Title: Re: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Crimson Wizard on Thu 23/05/2013 10:02:02
I think, first you need a way to define stairs e.g. by drawing a region over it and tagging it with certain custom property which marks it as stairs (like "IsStairs" = true) and where it goes (like "Direction" = 1 for rising to left and = 2 for rising to right).

Then check if character is at region with this property. If he/she is, then adjust movement direction when he is told to move.
Title: Re: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Lewis on Thu 23/05/2013 10:04:57
Bingo. I'll try this out later. Thanks!
Title: Re: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Crimson Wizard on Thu 23/05/2013 10:13:54
Oh my, the regions do not have custom properties! Only hotspots do.

What's a shame, it would be better if walkable areas had ones, in which case you won't need extra regions over them... an idea for the next ags version perhaps. ;)


EDIT: Also, you may set up an array in the script, which stores the IDs of walkable areas per room and corresponding properties.
Title: Re: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Calin Leafshade on Thu 23/05/2013 10:24:36
Alternatively you could do it like a platformer whereby you move the player down until it hits a walkable area everytime you move the player forwards so they are always resting on a walkable area.
Title: Re: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Crimson Wizard on Thu 23/05/2013 10:27:25
Quote from: Calin Leafshade on Thu 23/05/2013 10:24:36
Alternatively you could do it like a platformer whereby you move the player down until it hits a walkable area everytime you move the player forwards so they are always resting on a walkable area.
How that will work for rising stairs?
Title: Re: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Khris on Thu 23/05/2013 11:44:15
I'd probably go the vector route.

Say you have this:
________
        ---
           ---
              ---________________

The y position is going to be something like
if (x < 100) y = 130
else if (x < 150) y = x + 20   // slope
else y = 170

Movement changes the x coordinate, the according y is calculated, and the character is positioned and animated by hand.
Title: Re: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Calin Leafshade on Thu 23/05/2013 11:51:08
Quote from: Crimson Wizard on Thu 23/05/2013 10:27:25
How that will work for rising stairs?

If the player is already on a walkable area you move the player up until they are no longer on it and then move them 1 pixel down. Essentially you always make sure that the player is on the top of the walkable area, using them like colliders rather than regions.

@Khris

I think your method is more difficult to generalise than mine.
Title: Re: Slopes/stairs in side-scrolling, keyboard-controlled game
Post by: Khris on Thu 23/05/2013 11:58:08
Yep, I'd maybe actually do it your way, depending on the circumstances.
I just like math :)