Pixel Movement

by Forum_account
Pixel Movement
A pixel movement library for isometric and top-down maps.
ID:919760
 
mob/Move(var/turf/NewLoc,NewDir)
if(src.Sprinting && !src.density && NewLoc.Enter(src))
src.AddAura("Fly")
ShowEffect(src.loc,"[src.GetAuraType()]Trail",0,0,NewDir,1)
if(NewDir==9) ShowEffect(src.loc,"[src.GetAuraType()]Trail",16,-16,NewDir,1,0)
if(NewDir==5) ShowEffect(src.loc,"[src.GetAuraType()]Trail",-16,-16,NewDir,1,0)
if(NewDir==10) ShowEffect(src.loc,"[src.GetAuraType()]Trail",16,16,NewDir,1,0)
if(NewDir==6) ShowEffect(src.loc,"[src.GetAuraType()]Trail",-16,16,NewDir,1,0)
return ..()

^that code is to show trail when player fly but only on tiled based when i convert it to pixel movement like this one
mob/Move(var/turf/NewLoc,NewDir)
if(src.Sprinting && !src.density && NewLoc.Enter(src))
src.AddAura("Fly")
ShowEffect(src.loc,"[src.GetAuraType()]Trail",step_x,step_y,NewDir,1)
if(NewDir==9) ShowEffect(src.loc,"[src.GetAuraType()]Trail",px+16,py-16,NewDir,1,0)
if(NewDir==5) ShowEffect(src.loc,"[src.GetAuraType()]Trail",px-16,py-16,NewDir,1,0)
if(NewDir==10) ShowEffect(src.loc,"[src.GetAuraType()]Trail",px+16,py+16,NewDir,1,0)
if(NewDir==6) ShowEffect(src.loc,"[src.GetAuraType()]Trail",px-16,py+16,NewDir,1,0)
return ..()

it just makes those trail appear 2wice between 2 tiles, i just want to know how can i get this fixed?
#1 src.density, src.blah blah, src.etc. If the variable pertains to src, leave out "src." since "src." is automatically assumed by default.

#2In order to make trails you should really attatch it onto movement() or even better, set_state() since you're displaying something. Move() is still only called when entering a new turf, which explains the since tile issue.

If anything, you may want to switch it with move(), which is the P_M equivalent of Move() and is called for every tick that you're holding down the movement keys, which would make much better trails.

Also, best way to make a trail is to create a mob() that has no density and does nothing for the movement. Then, when you create it, go ahead and adjust its position to match the players mob with set_pos(px,py). Also, when you create that mob, you will want to use mob/path/new(loc) so that it's created at your current position, this saves some headaches I've run into before where the mob gets created at (0,0,0) and then set_pos() does nothing.
as you have mentioned to mob to 'mob/path/new(loc)' the show effect does that automattically
mob/movement(t)
var/NewDir=src.dir
var/turf/NewLoc=get_step(src,src.dir)
if(src.Sprinting && !src.density && NewLoc.Enter(src))
src.AddAura("Fly")
ShowEffect(src.loc,"[src.GetAuraType()]Trail",px,py,NewDir,1)
if(NewDir==9) ShowEffect(src.loc,"[src.GetAuraType()]Trail",px+16,py-16,NewDir,1,0)
if(NewDir==5) ShowEffect(src.loc,"[src.GetAuraType()]Trail",px-16,py-16,NewDir,1,0)
if(NewDir==10) ShowEffect(src.loc,"[src.GetAuraType()]Trail",px+16,py+16,NewDir,1,0)
if(NewDir==6) ShowEffect(src.loc,"[src.GetAuraType()]Trail",px-16,py+16,NewDir,1,0)
return ..()

it is still giving the same problem as as far as it is for the Show effect proc its here.
proc/PopulateEffects()
for(var/i=1;i<=500,i++) EffectObjs+=new/obj/Effect
obj/Effect
layer=7
icon_state=""
icon='Effects.dmi'
proc/ShowEffect(var/atom/Loc,var/Effect,var/OffX=0,var/OffY=0,var/Dir,var/Repeat=0,var/RandomOffset=1)
var/obj/O=EffectObjs[1]
EffectObjs-=O;EffectObjs+=O
if(Dir) O.dir=Dir
else O.dir=SOUTH
O.loc=locate(Loc.x,Loc.y,Loc.z)
if(RandomOffset) {O.pixel_x=rand(-OffX,OffX);O.pixel_y=rand(-OffY,OffY)}
else {O.pixel_x=OffX;O.pixel_y=OffY}
O.icon_state=""
if(Repeat) O.icon_state="[Effect]"
else flick("[Effect]",O)
O.name="[initial(O.name)]: [Effect]"
spawn(10) O.loc=null
Hmm... perhaps I should show you how I do it because it really only requires about 10-15 lines of code max, you've got about 30 here.

Give me a bit to get together an example, but, just to be sure you're looking for a trail effect like this?

http://www.youtube.com/ watch?v=RQn0rlA1xAQ&feature=player_detailpage#t=29s
yes it is something like that
Okay, great, here's what you need to do:

mob
trail
density=0
movement()
icon='trail.dmi'
var/life=5
New(loc, mob/owner)
..()
set_pos(owner.px,owner.py)
flick("animation",src)
spawn(life) del(src)


This is essentially all you need.

In order to create it just use mob/trail/new(loc,src) and it'll automatically position itself and delete itself. "life" is used to determine how long it's displayed, and flick("animation",src) is just an example that you can have them display an animation as well.

To make multiple ones, to make an effect like in the video, just call it with set_state(), or action() or any of the other P_M procs that relate directly to your mob.

you may also have to adjust pixel_x and pixel_y. If you want it to face a certain dir, just add that to the New()

If you have any other problems with it just let me know.