Created
September 4, 2019 02:37
-
-
Save AnanthVivekanand/e1dde5b359fa80331f030dcca07999ab to your computer and use it in GitHub Desktop.
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 | |
| defaults args | |
| render args | |
| calc args | |
| inputs args | |
| end | |
| def defaults args | |
| args.state.arr1 ||= ['Cat1', 'Cat2', 'Cat3', 'Cat4'] | |
| args.state.arr2 ||= ['Dog1', 'Dog2', 'Dog3', 'Dog4'] | |
| args.state.keypress ||= [10000000, :up] | |
| end | |
| def render args | |
| y = 700 | |
| args.outputs.labels << [50, y, 'Words'] | |
| args.outputs.labels << [1170, y, 'List 2'] | |
| args.state.arr1.each { |word| | |
| args.outputs.labels << [50, (y -= 50), word] | |
| } | |
| y = 700 | |
| args.state.arr2.each { |word| | |
| args.outputs.labels << [1170, (y -= 50), word] | |
| } | |
| end | |
| def calc args | |
| if args.state.tick_count != nil | |
| if ((args.state.tick_count - args.state.keypress[0]) < 300) | |
| time_passed = ((args.state.tick_count - args.state.keypress[0]).to_f / 75).floor.to_i | |
| # puts time_passed | |
| if args.state.keypress[1] == :up | |
| outputs = args.state.arr1[(time_passed)] | |
| elsif args.state.keypress[1] == :down | |
| outputs = args.state.arr1[3.to_i - (time_passed)] | |
| elsif args.state.keypress[1] == :right | |
| outputs = "#{args.state.arr1[time_passed]} and #{args.state.arr1[3.to_i - (time_passed)]}" | |
| elsif args.state.keypress[1] == :left | |
| time_passed2 = ((args.state.tick_count - args.state.keypress[0]).to_f / 25).floor.to_i | |
| if time_passed2 % 3 == 1 | |
| outputs = "Assigning Words[#{(time_passed2 / 3).floor}] to List2[#{(time_passed2 / 3).floor}]" | |
| args.state.arr2[(time_passed2 / 3).floor] = args.state.arr1[(time_passed2 / 3).floor] | |
| elsif time_passed2 % 3 == 0 | |
| outputs = "Assigning List2[#{(time_passed2 / 3).floor}] to TempVar" | |
| args.state.tempvar = args.state.arr2[(time_passed2 / 3).floor] | |
| elsif time_passed2 % 3 == 2 | |
| outputs = "Assigning TempVar to Words[#{(time_passed2 / 3).floor}]" | |
| args.state.arr1[(time_passed2 / 3).floor] = args.state.tempvar | |
| end | |
| end | |
| args.outputs.labels << [620, 300, outputs] | |
| end | |
| end | |
| end | |
| def inputs args | |
| keyboard_entry = args.inputs.keyboard.key_held | |
| if keyboard_entry.up | |
| args.state.keypress = [args.state.tick_count, :up] | |
| elsif keyboard_entry.down | |
| args.state.keypress = [args.state.tick_count, :down] | |
| elsif keyboard_entry.right | |
| args.state.keypress = [args.state.tick_count, :right] | |
| elsif keyboard_entry.left | |
| args.state.keypress = [args.state.tick_count, :left] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment