diff options
Diffstat (limited to 'samples/99_genre_mario/01_jumping')
| -rw-r--r-- | samples/99_genre_mario/01_jumping/app/main.rb | 78 | ||||
| -rw-r--r-- | samples/99_genre_mario/01_jumping/replay.txt | 52 | ||||
| -rw-r--r-- | samples/99_genre_mario/01_jumping/sprites/square/red.png | bin | 0 -> 335 bytes |
3 files changed, 130 insertions, 0 deletions
diff --git a/samples/99_genre_mario/01_jumping/app/main.rb b/samples/99_genre_mario/01_jumping/app/main.rb new file mode 100644 index 0000000..2d12a22 --- /dev/null +++ b/samples/99_genre_mario/01_jumping/app/main.rb @@ -0,0 +1,78 @@ +def tick args + defaults args + render args + input args + calc args +end + +def defaults args + args.state.player.x ||= args.grid.w.half + args.state.player.y ||= 0 + args.state.player.size ||= 100 + args.state.player.dy ||= 0 + args.state.player.action ||= :jumping + args.state.jump.power = 20 + args.state.jump.increase_frames = 10 + args.state.jump.increase_power = 1 + args.state.gravity = -1 +end + +def render args + args.outputs.sprites << { + x: args.state.player.x - + args.state.player.size.half, + y: args.state.player.y, + w: args.state.player.size, + h: args.state.player.size, + path: 'sprites/square/red.png' + } +end + +def input args + if args.inputs.keyboard.key_down.space + if args.state.player.action == :standing + args.state.player.action = :jumping + args.state.player.dy = args.state.jump.power + + # record when the action took place + current_frame = args.state.tick_count + args.state.player.action_at = current_frame + end + end + + # if the space bar is being held + if args.inputs.keyboard.key_held.space + # is the player jumping + is_jumping = args.state.player.action == :jumping + + # when was the jump performed + time_of_jump = args.state.player.action_at + + # how much time has passed since the jump + jump_elapsed_time = time_of_jump.elapsed_time + + # how much time is allowed for increasing power + time_allowed = args.state.jump.increase_frames + + # if the player is jumping + # and the elapsed time is less than + # the allowed time + if is_jumping && jump_elapsed_time < time_allowed + # increase the dy by the increase power + power_to_add = args.state.jump.increase_power + args.state.player.dy += power_to_add + end + end +end + +def calc args + if args.state.player.action == :jumping + args.state.player.y += args.state.player.dy + args.state.player.dy += args.state.gravity + end + + if args.state.player.y < 0 + args.state.player.y = 0 + args.state.player.action = :standing + end +end diff --git a/samples/99_genre_mario/01_jumping/replay.txt b/samples/99_genre_mario/01_jumping/replay.txt new file mode 100644 index 0000000..d56d585 --- /dev/null +++ b/samples/99_genre_mario/01_jumping/replay.txt @@ -0,0 +1,52 @@ +replay_version 2.0 +stopped_at 574 +seed 100 +recorded_at 2021-11-20 16:44:37 -0600 +[:mouse_button_up, 1, 0, 1, 1, 3] +[:key_down_raw, 32, 0, 2, 2, 89] +[:key_up_raw, 32, 0, 2, 3, 92] +[:key_down_raw, 32, 0, 2, 4, 193] +[:key_up_raw, 32, 0, 2, 5, 195] +[:key_down_raw, 32, 0, 2, 6, 258] +[:key_down_raw, 32, 0, 2, 7, 273] +[:key_down_raw, 32, 0, 2, 8, 275] +[:key_down_raw, 32, 0, 2, 9, 277] +[:key_down_raw, 32, 0, 2, 10, 279] +[:key_down_raw, 32, 0, 2, 11, 281] +[:key_down_raw, 32, 0, 2, 12, 283] +[:key_down_raw, 32, 0, 2, 13, 285] +[:key_down_raw, 32, 0, 2, 14, 287] +[:key_down_raw, 32, 0, 2, 15, 289] +[:key_down_raw, 32, 0, 2, 16, 291] +[:key_down_raw, 32, 0, 2, 17, 293] +[:key_down_raw, 32, 0, 2, 18, 295] +[:key_down_raw, 32, 0, 2, 19, 297] +[:key_down_raw, 32, 0, 2, 20, 299] +[:key_down_raw, 32, 0, 2, 21, 301] +[:key_down_raw, 32, 0, 2, 22, 303] +[:key_down_raw, 32, 0, 2, 23, 305] +[:key_down_raw, 32, 0, 2, 24, 307] +[:key_up_raw, 32, 0, 2, 25, 307] +[:key_down_raw, 32, 0, 2, 26, 336] +[:key_up_raw, 32, 0, 2, 27, 339] +[:key_down_raw, 32, 0, 2, 28, 389] +[:key_up_raw, 32, 0, 2, 29, 392] +[:key_down_raw, 32, 0, 2, 30, 444] +[:key_down_raw, 32, 0, 2, 31, 459] +[:key_down_raw, 32, 0, 2, 32, 461] +[:key_down_raw, 32, 0, 2, 33, 463] +[:key_down_raw, 32, 0, 2, 34, 465] +[:key_down_raw, 32, 0, 2, 35, 467] +[:key_down_raw, 32, 0, 2, 36, 469] +[:key_down_raw, 32, 0, 2, 37, 471] +[:key_down_raw, 32, 0, 2, 38, 473] +[:key_down_raw, 32, 0, 2, 39, 475] +[:key_down_raw, 32, 0, 2, 40, 477] +[:key_down_raw, 32, 0, 2, 41, 479] +[:key_down_raw, 32, 0, 2, 42, 481] +[:key_down_raw, 32, 0, 2, 43, 483] +[:key_down_raw, 32, 0, 2, 44, 485] +[:key_up_raw, 32, 0, 2, 45, 485] +[:key_down_raw, 96, 0, 2, 46, 509] +[:key_up_raw, 96, 0, 2, 47, 512] +[:key_down_raw, 13, 0, 2, 48, 574] diff --git a/samples/99_genre_mario/01_jumping/sprites/square/red.png b/samples/99_genre_mario/01_jumping/sprites/square/red.png Binary files differnew file mode 100644 index 0000000..a59443e --- /dev/null +++ b/samples/99_genre_mario/01_jumping/sprites/square/red.png |
