I want to change the starting px and py for objs when they are generated on the map. The reason for this is because I've been making a random dungeon generator, and so far it works pretty well, however the issue is that when objs are created (like chests, traps, etc.), they always appear on the bottom left corner as that's how the icon is set up. I have the icon set up that way due to the bounding box mechanics, and the only way I could see to get the bounding box to properly work on the objs is to have their icon on the bottom left of the image. Besides, even if there is a way around this, I would prefer to have their exact px and py randomized because most of these are around 20-30x20-30 pixels, and the icon size I am using is 64x64. It would look stupid to have them in the same exact place on a single tile every time they are created.
For mobs this isn't really an issue, I just have them move slightly when they are generated and as a result they are able to appear truly randomized, HOWEVER...when objs are created I cannot do this. I want them to be able to appear randomized, however whenever one is generated on a corner or edge of a room, they are always an exact distance from said edge, whether it be hugging them or X pixels away. It looks really bad, especially considering they are supposed to be randomly placed anywhere on the map.
So to try and fix this issue, I added the following to my New() for objs:
New()
..()
if(src.randomizePLoc)
var/randomPX = rand(0, (PixelMovement.tile_width-src.pwidth))
var/randomPY = rand(0, (PixelMovement.tile_height-src.pheight))
src.px += randomPX
src.py += randomPY
This does nothing. I'm not exactly sure what I'm missing, because px and py are the parameters used to determine pixel location as far as I can see. I tried using several of the procs provided in the Demos, however since the demos use mobs for these types of movements and these are objs, I've hit a standstill.
I've honestly been able to figure out a lot of issues just by going through the demos and the like and learning the library, as I should, however this really has stumped me. I do not know of any of the movement methods that work with objs, I cannot find any. Making things that are objs mobs just so that I can have them shift a little from their default location sounds stupid to me, so I'd rather not do that.
Any help would be greatly appreciated. If screenshots are needed, I can provide them to show exactly what I mean is the problem.
Se the thing is, objs don't update with the movement() proc, so it needs to be done manually.
What I also noticed is that generated objects don't have a px or py either. When generated they come out as 0 which has caused me to fly off the map when bumping into them on occasion.
When generating an object you'll want to do is first make the adjustment to pixel_x and pixel_y and then use that to determine it's px and py, it's a bit backwards but it saves a step and some math since they don't auto update through movement(). OR you could do it your way and then adjust the pixel position as well..
in your method...
That should fix the visual issue you get with the icon, but I'm not 100% on this as I can't test it myself without writing up a new environment and I'm pretty lazy, haha.
Now if you get an issue where the physical position and the visual position are different then remove the pixel_x and pixel_y portion as it may just be the fact that the px and py were wrong from the get-go
ALSO quit using " src. " you almost never have to use src. when it comes to DM in general as DM automatically assumes that a variable is referring to src. =P