Skip to content

Commit

Permalink
refactor Get_Pixel_Angle()
Browse files Browse the repository at this point in the history
Get_Pixel_Angle() renamed and refactored, Get_Angle() now calls it instead of having its own calcuation
  • Loading branch information
Doubleumc committed Dec 14, 2023
1 parent c40919a commit b74d754
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
var/atom/movable/big_subject = subject
. += (big_subject.bound_height - world.icon_size) / 2

/// Calculate the angle between two atoms. Uses north-clockwise convention: NORTH = 0, EAST = 90, etc.
/proc/Get_Angle(atom/start, atom/end)//For beams.
if(!start || !end)
return 0
Expand All @@ -112,14 +113,14 @@
return 0 //Atoms are not on turfs.
var/dy = get_pixel_position_y(end) - get_pixel_position_y(start)
var/dx = get_pixel_position_x(end) - get_pixel_position_x(start)
. = arctan(dy, dx)
return delta_to_angle(dx, dy)

/// Calculate the angle produced by a pair of x and y deltas. Uses north-clockwise convention: NORTH = 0, EAST = 90, etc.
/proc/delta_to_angle(dx, dy)
. = arctan(dy, dx) //y-then-x results in north-clockwise convention: https://en.wikipedia.org/wiki/Atan2#East-counterclockwise,_north-clockwise_and_south-clockwise_conventions,_etc.
if(. < 0)
. += 360

/proc/Get_Pixel_Angle(dx, dy)//for getting the angle when animating something's pixel_x and pixel_y
var/da = arctan(dy, dx) //y-then-x results in north-clockwise convention: https://en.wikipedia.org/wiki/Atan2#East-counterclockwise,_north-clockwise_and_south-clockwise_conventions,_etc.
return (da >= 0 ? da : da + 360)

/proc/angle_to_dir(angle)
switch(angle) //diagonal directions get priority over straight directions in edge cases
if (22.5 to 67.5)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/projectiles/projectile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@

var/dx = p_x + aim_turf.x * 32 - source_turf.x * 32 // todo account for firer offsets
var/dy = p_y + aim_turf.y * 32 - source_turf.y * 32
angle = Get_Pixel_Angle(dx, dy)
angle = delta_to_angle(dx, dy)

/obj/projectile/process(delta_time)
. = PROC_RETURN_SLEEP
Expand Down Expand Up @@ -287,7 +287,7 @@

//Change the bullet angle to its visual path

var/vis_angle = Get_Pixel_Angle(pixel_x_target - pixel_x_source, pixel_y_target - pixel_y_source)
var/vis_angle = delta_to_angle(pixel_x_target - pixel_x_source, pixel_y_target - pixel_y_source)
var/matrix/rotate = matrix()
rotate.Turn(vis_angle)
apply_transform(rotate)
Expand Down

0 comments on commit b74d754

Please sign in to comment.