Action RPG Framework

by Forum_account
Action RPG Framework
A framework for developing action RPGs.
ID:809339
 
In mob.action I have the following:
action()
if(!client) return
if(steering)
var/a = 0
if(client.keys[controls.left]) a += 5
if(client.keys[controls.right]) a -= 5

// if you're pressing up you go forwards
if(client.keys[controls.up])
if(steering.velocity < steering.move_speed)
steering.velocity += steering.acceleration

// if you're pressing down you go backwards
else if(client.keys[controls.down])
/*
if(steering.speed > -steering.move_speed / 2)
steering.speed -= steering.acceleration
*/

if(steering.velocity > 0)
steering.velocity -= steering.acceleration
else
steering.velocity = 0

// otherwise you slow down
else
if(steering.velocity > steering.acceleration)
steering.velocity -= steering.acceleration/4
else if(steering.velocity < -steering.acceleration)
steering.velocity += steering.acceleration
else
steering.velocity = 0

angle += a

// generate a rotated icon to represent the angle that you're facing.
var/icon/I = icon(initial(steering.icon), steering.icon_state)
I.Turn(-angle)
steering.icon = I

if(steering.velocity != 0)
var/dx = round(cos(angle) * steering.velocity + 0.5)
var/dy = round(sin(angle) * steering.velocity + 0.5)
steering.pixel_move(dx, dy)
else ..()


In the vehicle mob's interact():
interact(mob/m)
m.loc=src
m.client.eye=src
m.steering = src


Prior to the update, it had the desired behavior- when the mob interacts with the vehicle, they "hop in" and start steering. Now, they "hop in" but the movement keys do nothing.

What am I doing wrong?
Make sure you have the latest version of the Pixel Movement library. I don't think this would cause the problem but we might as well be sure.

The only thing that'd stop the action() proc from being called is if the mob was deactivated. You can put some debug statements in, but I'm pretty sure this code is being executed.

The code works fine for me. The only problem is that I get a black screen when entering the vehicle. I had to call the mob's watch() proc instead of setting client.eye directly (ex: m.watch(src)). All of the movement code works. I would guess this means either:

1. I've made a change to the library since posting it that fixes whatever is causing this problem (seems unlikely, I haven't changed much).

2. You have other code in your project that is causing this to not work (seems less likely, considering this was working for you before the last update).
Yeah, I have the latest Pixel Movement. It appears that action() is not getting called after the mob interacts with the vehicle. Have to do some digging....
Try taking out the line where you change the mob's loc. There might be something in the pixel movement library that prevents action() from being called if you're not on the map.
That was it! Hmm, I guess I can just move the mob to a holder map.
I looked at the Pixel Movement library and I'm not entirely sure why this is happening. Clearly you wouldn't want the pixel_move() proc to be called while you're inside another mob, but it does make sense to call action() since it can be used to handle other things you'd still want to happen regardless of the mob's loc (ex: you'd still want AI routines to run for enemies that get in vehicles).

This might be a bug with the library but for now, setting the mob's loc to some out of the way turf is probably the easiest way around it.

Edit: Turns out this is a small fix in the PM library. This change will be in the next update to that, but that might not be for a while. You can either use this workaround or make the change to the Pixel Movement library yourself.

You have to change the check_loc() proc which starts at line 167 in movement.dm:

        check_loc()
if(x != last_x || y != last_y || z != last_z)

// if you're not on a turf, do nothing
if(!istype(loc, /turf))
return

// rest of the proc...

You just have to add the "if(!istype(loc, /turf)) return" part.
Thank you very much! Piloting vehicles is a core concept of this project, so it's nice to have sorted :-)