Created
February 8, 2026 23:17
-
-
Save amirrajan/fe97af910a09bcc272216d4ad0bffc29 to your computer and use it in GitHub Desktop.
DragonRuby Game Toolkit - Easing.spline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def tick args | |
| zig_zag_spline = [ | |
| [0, 0.33, 0.66, 1], | |
| [1, 0.66, 0.33, 0], | |
| [0, 0.33, 0.66, 1], | |
| [1, 0.66, 0.33, 0] | |
| ] | |
| linear_down_spline = [ | |
| [1, 0.66, 0.33, 0] | |
| ] | |
| linear_up_spline = [ | |
| [0, 0.33, 0.66, 1.0] | |
| ] | |
| args.state.start_at ||= 0 | |
| args.state.duration ||= 10 * 60 | |
| args.state.player ||= { | |
| x: 0, | |
| y: 720, | |
| w: 32, | |
| h: 32, | |
| x_spline: zig_zag_spline, | |
| y_spline: linear_down_spline, | |
| path: :solid, | |
| r: 0, | |
| g: 80, | |
| b: 80, | |
| anchor_x: 0.5, | |
| anchor_y: 0.5 | |
| } | |
| perc_x = Easing.spline(args.state.start_at, | |
| Kernel.tick_count, | |
| args.state.duration, | |
| args.state.player.x_spline) | |
| perc_y = Easing.spline(args.state.start_at, | |
| Kernel.tick_count, | |
| args.state.duration, | |
| args.state.player.y_spline) | |
| args.state.player.x = Grid.w * perc_x | |
| args.state.player.y = Grid.h * perc_y | |
| if args.state.start_at.elapsed_time == args.state.duration | |
| args.state.start_at = Kernel.tick_count | |
| if args.state.player.y == 0 | |
| args.state.player.y_spline = linear_up_spline | |
| else | |
| args.state.player.y_spline = linear_down_spline | |
| end | |
| end | |
| args.outputs.sprites << args.state.player | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment