ID:168964
 
I need to make the icon of a bullet go STRAIGHT to a target, not using the 32x32 squares. Sort of like the Missile() proc, but I just need to do that with an actual thing, not just a graphical effect... And i'm not using S_Missile.
Use while(), get_dist(), step_to() and bump().
In response to N1ghtW1ng
Did you read what I said?
In response to Hiddeknight
Apparently not (>_>)'.
In response to Hiddeknight
You're going to need to use a custom movment system, which is pretty labor intesive in DM. Here's an example off the top of my head... sorry if it's wrong, but I'm very sleepy. Note that this will only detect a collision when the projectile moves into another object. If another object moves into this projectile, nothing will happen. I have no idea if this is the same method used in S-missile, or if this is worse, but it is close to the method I use for pixelized movment (the redraw and collision check both work on the same concept at least).
projectile{
//parent_type = /datum
var{
obj/reference
xcoor
ycoor
z
// Footnote 4
width = 32
height = 32
xvel
yvel
speed = 2
// Footnote 7
icon = 'file.dmi'
icon_state = "text"
}
New(var/xposition as number, var/yposition as number, var/zloc as number, var/run as number, var/rise as number){
// Footnote 1
.=..()
reference = new /obj()
reference.loc = locate(1,1,1)
// Footnote 2
reference.icon = icon
reference.icon_state = icon_state
xcoor = xposition
ycoor = yposition
z = zloc
}
proc{
redraw(){
// Footnote 3
reference.x = ((xcoor-(xcoor%32))/32)+1
reference.pixel_x = xcoor%32
reference.y = ((ycoor-(ycoor%32))/32)+1
reference.pixel_y = ycoor%32
reference.z = z
}
move(){
for(var/atom/A in range(1,reference)){
if(isarea(A)){continue}
if(A.denisty){
if(abs(((xcoor+xvel)+(width/2))-(A.x*32-16))<((width/2)+16)){
if(abs(((ycoor+yvel)+(height/2))-(A.y*32-16))<((height/2)+16)){
// Footnote 5
collide()
return
// Footnote 6
}
}
}
}
xcoor = xcoor+xvel
ycoor = ycoor+yvel
redraw()
iterations--
spawn(speed){
move()
// Footnote 8
}
}
}
}

Footnote 1: xposition and yposition are the number of pixels from locate(1,1,zloc), where 8x8 would be the center of that turf. This number can be obtained by taking the initiating atom and multiplying it's x or y variable by 32, and then adding a small pixel offset such that the projectile appears to come out of a specific part of the icon, such as a gun or hands.

Footnote 2: The locate() statement is included to avoid a location initializing problem. You can change (1,1,1) to any unused location. DS doesn't seem to obey me when I try to set an x, y, or z value while the loc is null.

Footnote 3: This is the real meat of any movment system. The modulo operator is your friend.

Footnote 4: Non 32px based dimensions are fun, yes no?

Footnote 5: Here I use an imaginary proc 'collide()'. This is basically saying, if both of these conditions are met, then a collision has taken place. That's where you put the code that you want to happen when things collide.

Footnote 6: This return statement prevents 'persistant' projectiles, or projectiles that keep going after they hit something. Remove this if you want persistant objects, or add an extra variable and a check to to see if the projectile is persistant.

Footnote 7: These three variables are named very poorely... a result of my remembering I left something out. 'speed' is the time in between iterations of the 'move()' function, the 'xvel' and 'yvel' translate into the angle at which the projectile will travel, such that 'xvel=1;yvel=2' is the same as 'xvel=5;yvel=10'. Larger values in xvel and yvel, especially values approaching 32, may cause the projectile to miss some objects as it travels, so small values in all three of these variables is prefered. Also, xvel and yvel should not be set in the projectile definition, but should be provided in the call to New().

Footnote 8: Please note that this move() proc does not take into account such problems a travel off the map or infinite recursion, both of which can return runtime errors. A range variable is also suggested, as is a durration variable to make it disappear after a set time. Above all, a check should be made if the projectile tries to move into a turf that doesn't exist (ie, off the map).

Enjoy Hidde :)