Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrapnel smooth movement [WIP] #6821

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions code/modules/projectiles/projectile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,14 @@

//Change the bullet angle to its visual path

var/mutable_appearance/new_appearance = new(appearance)
new_appearance.invisibility = invisibility
new_appearance.plane = plane

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)
new_appearance.transform = rotate

//Determine apparent position along visual path, then lerp between start and end positions

Expand All @@ -326,25 +330,22 @@

//Set pixel offset as from current loc to old position, so it appears to start in the old position

pixel_x = (start_turf.x - current_turf.x) * world.icon_size + start_pixel_x
pixel_y = (start_turf.y - current_turf.y) * world.icon_size + start_pixel_y

//Determine apparent distance travelled, then lerp for projectile fade-in

var/dist_current = distance_travelled + speed * (time_carry * 0.1) //speed * (time_carry * 0.1) for remainder time fade-in
var/alpha_interpolant = dist_current - 1 //-1 so it transitions from transparent to opaque between dist 1-2
var/alpha_new = LERP(0, 255, alpha_interpolant)
new_appearance.pixel_x = (start_turf.x - current_turf.x) * world.icon_size + start_pixel_x
new_appearance.pixel_y = (start_turf.y - current_turf.y) * world.icon_size + start_pixel_y

//Animate the visuals from starting position to new position

if(projectile_flags & PROJECTILE_SHRAPNEL) //there can be a LOT of shrapnel especially from a cluster OB, not important enough for the expense of an animate()
alpha = alpha_new
pixel_x = pixel_x_rel_new
pixel_y = pixel_y_rel_new
return
appearance = new_appearance

var/anim_time = delta_time * 0.1
animate(src, pixel_x = pixel_x_rel_new, pixel_y = pixel_y_rel_new, alpha = alpha_new, time = anim_time, flags = ANIMATION_END_NOW)
if(alpha < 255) //Determine apparent distance travelled, then lerp for projectile fade-in
var/dist_current = distance_travelled + speed * (time_carry * 0.1) //speed * (time_carry * 0.1) for remainder time fade-in
var/alpha_interpolant = dist_current - 1 //-1 so it transitions from transparent to opaque between dist 1-2
var/alpha_new = LERP(0, 255, alpha_interpolant)

animate(src, pixel_x = pixel_x_rel_new, pixel_y = pixel_y_rel_new, alpha = alpha_new, time = anim_time, flags = ANIMATION_END_NOW)
else
animate(src, pixel_x = pixel_x_rel_new, pixel_y = pixel_y_rel_new, time = anim_time, flags = ANIMATION_END_NOW)

/// Flies the projectile forward one single turf
/obj/projectile/proc/fly()
Expand Down
Loading