diff --git a/code/modules/mob/mob_helpers.dm b/code/modules/mob/mob_helpers.dm index 7fe2d7a587a..a2b6b08770d 100644 --- a/code/modules/mob/mob_helpers.dm +++ b/code/modules/mob/mob_helpers.dm @@ -479,23 +479,48 @@ GLOBAL_LIST_INIT(organ_rel_size, list( p=p+n_mod return sanitize(t) -#define TICKS_PER_RECOIL_ANIM 2 -#define PIXELS_PER_STRENGTH_VAL 16 +#define TILES_PER_SECOND 0.7 +/// Shake the camera of the person viewing the mob SO REAL! +/// Takes the mob to shake, the time span to shake for, and the amount of tiles we're allowed to shake by in tiles +/// Duration isn't taken as a strict limit, since we don't trust our coders to not make things feel shitty. So it's more like a soft cap. +/proc/shake_camera(mob/M, duration, strength=1) + if(!M || !M.client || duration < 1) + return + var/client/C = M.client + var/oldx = C.pixel_x + var/oldy = C.pixel_y + var/max_x = strength*ICON_SIZE_X + var/max_y = strength*ICON_SIZE_Y + var/min_x = -(strength*ICON_SIZE_X) + var/min_y = -(strength*ICON_SIZE_Y) -/proc/shake_camera(mob/M, duration, strength = 1) - var/current_time = world.time - if(!M || !M.client || (M.shakecamera > current_time)|| M.stat || isEye(M) || isAI(M)) - return - if(((M.client.view != world.view) || (M.client.pixel_x != 0) || (M.client.pixel_y != 0))) //to prevent it while zooming, because zoom does not play well with this code - return - M.shakecamera = current_time + max(TICKS_PER_RECOIL_ANIM, duration) - strength = abs(strength)*PIXELS_PER_STRENGTH_VAL - var/steps = min(1, FLOOR(duration/TICKS_PER_RECOIL_ANIM, 1))-1 - animate(M.client, pixel_x = rand(-(strength), strength), pixel_y = rand(-(strength), strength), time = TICKS_PER_RECOIL_ANIM, easing = JUMP_EASING|EASE_IN) - if(steps) - for(var/i = 1 to steps) - animate(pixel_x = 0 + rand(-(strength), strength), pixel_y = 0 + rand(-(strength), strength), time = TICKS_PER_RECOIL_ANIM, easing = JUMP_EASING|EASE_IN) - animate(pixel_x = 0, pixel_y = 0, time = TICKS_PER_RECOIL_ANIM) + //How much time to allot for each pixel moved + var/time_scalar = (1 / ICON_SIZE_ALL) * TILES_PER_SECOND + var/last_x = oldx + var/last_y = oldy + + var/time_spent = 0 + while(time_spent < duration) + //Get a random pos in our box + var/x_pos = rand(min_x, max_x) + oldx + var/y_pos = rand(min_y, max_y) + oldy + + //We take the smaller of our two distances so things still have the propencity to feel somewhat jerky + var/time = round(max(min(abs(last_x - x_pos), abs(last_y - y_pos)) * time_scalar, 1)) + + if (time_spent == 0) + animate(C, pixel_x=x_pos, pixel_y=y_pos, time=time) + else + animate(pixel_x=x_pos, pixel_y=y_pos, time=time) + + last_x = x_pos + last_y = y_pos + //We go based on time spent, so there is a chance we'll overshoot our duration. Don't care + time_spent += time + + animate(pixel_x=oldx, pixel_y=oldy, time=3) + +#undef TILES_PER_SECOND /proc/findname(msg) for(var/mob/M in GLOB.mob_list) diff --git a/html/changelogs/Bat-ScreenShake.yml b/html/changelogs/Bat-ScreenShake.yml new file mode 100644 index 00000000000..3ebd3a977e3 --- /dev/null +++ b/html/changelogs/Bat-ScreenShake.yml @@ -0,0 +1,58 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# - (fixes bugs) +# wip +# - (work in progress) +# qol +# - (quality of life) +# soundadd +# - (adds a sound) +# sounddel +# - (removes a sound) +# rscadd +# - (adds a feature) +# rscdel +# - (removes a feature) +# imageadd +# - (adds an image or sprite) +# imagedel +# - (removes an image or sprite) +# spellcheck +# - (fixes spelling or grammar) +# experiment +# - (experimental change) +# balance +# - (balance changes) +# code_imp +# - (misc internal code change) +# refactor +# - (refactors code) +# config +# - (makes a change to the config files) +# admin +# - (makes changes to administrator tools) +# server +# - (miscellaneous changes to server) +################################# + +# Your name. +author: Batrachophrenoboocosmomachia + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - refactor: "Ports smooth shake_camera proc from /tg/station."