diff options
| author | Amir Rajan <[email protected]> | 2020-09-11 02:02:01 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-09-11 02:02:57 -0500 |
| commit | 33ec37b141e896b47ed642923fd33b0c658ae9fb (patch) | |
| tree | a40d3e5d41beeb06508200078f6f26b0ee57d6a4 /samples/09_sprite_animation_using_tile_sheet/app/main.rb | |
| parent | 958cf43779d2bf528869e80511c4c4f2a433b2db (diff) | |
| download | dragonruby-game-toolkit-contrib-33ec37b141e896b47ed642923fd33b0c658ae9fb.tar.gz dragonruby-game-toolkit-contrib-33ec37b141e896b47ed642923fd33b0c658ae9fb.zip | |
synced samples
Diffstat (limited to 'samples/09_sprite_animation_using_tile_sheet/app/main.rb')
| -rw-r--r-- | samples/09_sprite_animation_using_tile_sheet/app/main.rb | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/samples/09_sprite_animation_using_tile_sheet/app/main.rb b/samples/09_sprite_animation_using_tile_sheet/app/main.rb deleted file mode 100644 index 17bfd49..0000000 --- a/samples/09_sprite_animation_using_tile_sheet/app/main.rb +++ /dev/null @@ -1,98 +0,0 @@ -def tick args - args.state.player.x ||= 100 - args.state.player.y ||= 100 - args.state.player.w ||= 64 - args.state.player.h ||= 64 - args.state.player.direction ||= 1 - - args.state.player.is_moving = false - - # get the keyboard input and set player properties - if args.inputs.keyboard.right - args.state.player.x += 3 - args.state.player.direction = 1 - args.state.player.started_running_at ||= args.state.tick_count - elsif args.inputs.keyboard.left - args.state.player.x -= 3 - args.state.player.direction = -1 - args.state.player.started_running_at ||= args.state.tick_count - end - - if args.inputs.keyboard.up - args.state.player.y += 1 - args.state.player.started_running_at ||= args.state.tick_count - elsif args.inputs.keyboard.down - args.state.player.y -= 1 - args.state.player.started_running_at ||= args.state.tick_count - end - - # if no arrow keys are being pressed, set the player as not moving - if !args.inputs.keyboard.directional_vector - args.state.player.started_running_at = nil - end - - # wrap player around the stage - if args.state.player.x > 1280 - args.state.player.x = -64 - args.state.player.started_running_at ||= args.state.tick_count - elsif args.state.player.x < -64 - args.state.player.x = 1280 - args.state.player.started_running_at ||= args.state.tick_count - end - - if args.state.player.y > 720 - args.state.player.y = -64 - args.state.player.started_running_at ||= args.state.tick_count - elsif args.state.player.y < -64 - args.state.player.y = 720 - args.state.player.started_running_at ||= args.state.tick_count - end - - # render player as standing or running - if args.state.player.started_running_at - args.outputs.sprites << running_sprite(args) - else - args.outputs.sprites << standing_sprite(args) - end - args.outputs.labels << [30, 700, "Use arrow keys to move around."] -end - -def standing_sprite args - { - x: args.state.player.x, - y: args.state.player.y, - w: args.state.player.w, - h: args.state.player.h, - path: "sprites/horizontal-stand.png", - flip_horizontally: args.state.player.direction > 0 - } -end - -def running_sprite args - if !args.state.player.started_running_at - tile_index = 0 - else - how_many_frames_in_sprite_sheet = 6 - how_many_ticks_to_hold_each_frame = 3 - should_the_index_repeat = true - tile_index = args.state - .player - .started_running_at - .frame_index(how_many_frames_in_sprite_sheet, - how_many_ticks_to_hold_each_frame, - should_the_index_repeat) - end - - { - x: args.state.player.x, - y: args.state.player.y, - w: args.state.player.w, - h: args.state.player.h, - path: 'sprites/horizontal-run.png', - tile_x: 0 + (tile_index * args.state.player.w), - tile_y: 0, - tile_w: args.state.player.w, - tile_h: args.state.player.h, - flip_horizontally: args.state.player.direction > 0, - } -end |
