ID:296998
 
Sidescroller by Forum_account
This library gives you the basic movement system of a platformer. You can make an action/platform game in minutes!
51 fans · Created Nov 3 2010
I just posted an overdue update. I used to update the library once or twice a month but it's been just over two months.

The biggest change is to the can_bump() proc. Previously, the default behavior made you only able to bump dense turfs - you'd walk right through mobs. While this may frequently be the desired behavior, it's not consistent with BYOND's default density behavior and caused some confusion. The can_bump proc now behaves more like you might expect.

There are still some exceptions. Non-dense mobs can walk through dense mobs, but they still bump into dense turfs. If they didn't, you'd fall through the floor and off the map - that's probably not what you want to happen. Also, atoms with scaffold = 1 are treated as non-dense. You can walk in front of them or stand on top of them. If you want them to be dense so you can't move over them at all, set density = 1 and scaffold = 0.

I also added a new demo (called v4.2-demo) which shows a new feature for ladders. The mob now has an on_ladder() proc which determines if they're standing over a ladder. This proc is called to check if the mob can climb a ladder. By default it returns 1 if the turf the mob overlaps most is a ladder and 0 otherwise. The demo shows how to change this so you can climb a ladder only if you're completely inside the turf horizontally. The demo also shows how to make the top ladder turf be a scaffold so you can stand on top of it (like ladders in Mega Man).
Neat update.

One potential issue: I have ladders set up as scaffolds but when I add the following to the down action it's a little buggy:
<code> var/turf/t = locate(x, y - 1, z) if(t.ladder && t.scaffold && on_ground) drop()</code>
Mainly when climbing to the top, the player will fall through after they have stood at the top and gone down.
In response to Jmurph (#1)
var/turf/t = locate(x, y - 1, z) if(t.ladder && t.scaffold && on_ground) drop()
In response to Jmurph (#1)
Jmurph wrote:
Neat update.

One potential issue: I have ladders set up as scaffolds but when I add the following to the down action it's a little buggy:
<code> > var/turf/t = locate(x, y - 1, z) > if(t.ladder && t.scaffold && on_ground) > drop()</code>
Mainly when climbing to the top, the player will fall through after they have stood at the top and gone down.

Calling drop() sets the dropped var to 1. dropped is only set to zero when you release the jump key (since, by default, the only way it's set is when you hold down and press jump). You can probably do something like this:

mob
action()
..()

// if you're hanging on a ladder, clear the dropped flag
if(on_ladder) dropped = 0
I used your library on my sidescroller game since I started, and I have a question:

Is it possible to stop a mob from running to a place with density? When it's vel_x is too high, it can break in and get in a place with density, I have a system which auto-checks if he's "stuck", but it's pretty annoying because it'd be really sweet if it could be totally fixed, or remove the chances of getting in dense objects, any idea? :( Thank you so much for creating the library, really useful.
If the mob's velocity is too high you can split their move in half:

mob
pixel_move(dpx, dpy)

if(abs(dpx) > 32)
dpx /= 2
dpy /= 2

..(dpx, dpy)
..(dpx, dpy)
else
..()

Big moves can have problems, so splitting it into two smaller moves should avoid this.
Not sure if this goes here or under the keyboard lib, but is there a way to distinguish between tapped keys and held keys? Say for a short jump instead of a long jump.
In response to Jmurph (#6)
The library provides a key_repeat proc that works like key_down.

However, I always disable that feature and check client.keys in a loop proc like action().

As for where your post belongs, I'd say definitely not in library comments. Make a new topic in the library's forum.

I think there's a demo that has variable jump height based on duration.
Kaiochao wrote:
The library provides a key_repeat proc that works like key_down.
However, I always disable that feature and check client.keys in a loop proc like action().

sidescroller.dme has #define NO_KEY_REPEAT before the keyboard library include, so it's only getting the key up and down events.

I think there's a demo that has variable jump height based on duration.

Yes, it's in v2.5\demo.dm:

mob
// this shows how to create variable-height jumps
var
boost = 0

jump()
vel_y = 6
boost = 8

// After you jump, if you continue to hold the jump key
// you'll continue to accelerate upwards. The boost var
// is the number of ticks it'll check for. In this case,
// you'll continue to accelerate upwards for 6 ticks if
// you keep holding the jump key.

action()
// after you jump, for the next 6 ticks you'll
// be able to continue accelerating upwards (to
// jump higher) if you keep the jump key held.
if(boost > 0)
boost -= 1
if(client.keys[controls.jump])
vel_y += 1
else
boost = 0
..()

bump(atom/a, d)
..()

// If you jumped and hit the ceiling, you can't continue
// to accelerate upwards
if(d == UP)
boost = 0