Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##What you do to create a demo is this:
- ##1) Decide what you want the ninja to do in each frame.
- ##2) Convert that into hexadecimal using this code:
- ##nothing=0
- ##left=1
- ##right=2
- ##left and right=3
- ##hold=4
- ##hold and left=5
- ##hold and right=6
- ##hold and left and right=7
- ##jump=C
- ##jump and left=D
- ##jump and right=E
- ##jump and left and right=F
- ##3) String together all your characters to make one long hexadecimal number.
- ##4) Split this number into groups of 7.
- ##5) Reverse each group.
- ##6) Put the groups back together again, separated by | symbols.
- ##7) Convert the numbers back into base 10.
- def demoMaker2():
- frames, commands = makeCommandList()
- for i in range(len(commands)):
- print commands[i],
- print
- demoMaker(frames)
- def demoMaker(framesLS):
- validDemo = True
- for i in range(len(framesLS)):
- framesLS[i] = str(framesLS[i])
- if commandToHex(framesLS[i],i+1) == 'Invalid':
- validDemo = False
- break
- else:
- framesLS[i] = commandToHex(framesLS[i],i+1)
- if validDemo == True:
- hexToDemo(framesLS)
- demo = hexToDemo(framesLS)
- print 'Your demo data is:',demo[:-1]
- def commandToHex(command, frame):
- # This function converts each command into the correct hexadecimal code
- # above, and if the input is an invalid command, stops the program and
- # tells you what frame is wrong.
- command.lower()
- if command == 'n':
- return hex(0)
- elif command == 'l':
- return hex(1)
- elif command == 'r':
- return hex(2)
- elif command == 'lr' or command == 'rl':
- return hex(3)
- elif command == 'h':
- return hex(4)
- elif command == 'hl' or command == 'lh':
- return hex(5)
- elif command == 'hr' or command == 'rh':
- return hex(6)
- elif command == 'hlr' or command == 'hrl' or command == 'lrh' or command == 'lhr' or command == 'rhl' or command == 'rlh':
- return hex(7)
- elif command == 'j':
- return hex(12)
- elif command == 'jl' or command == 'lj':
- return hex(13)
- elif command == 'rj' or command == 'jr':
- return hex(14)
- elif command == 'jlr' or command == 'jrl' or command == 'lrj' or command == 'ljr' or command == 'rjl' or command == 'rlj':
- return hex(15)
- else:
- print 'Invalid entry for frame', frame
- return 'Invalid'
- def hexToDemo(frames):
- # This function takes the commands that have been converted into hexadecimal
- # codes and returns the final demo data for the original input commands.
- # Creates the beginning of demo data with frame count and colon.
- demoLength = len(frames)
- totalDemo = str(demoLength)
- totalDemo = totalDemo + ':'
- # Goes through demo 7 frames at a time.
- for i in range(0,len(frames),7):
- # Placeholder for eventual order reversal, keeping as hexadecimal code
- # in the computer.
- hexDemoFrag = '0x'
- # Takes 7 command/frame chunks of the input commands that were changed
- # to hexadecimal. This varaible will be reused and reset each time the
- # program moves to the next set of 7 commands/frames.
- demoFrag0 = frames[i:i+7]
- # This loop reverses the order of the commands.
- for j in range(len(demoFrag0)-1,-1,-1):
- hexDemoFrag = hexDemoFrag + demoFrag0[j][-1]
- # Converting reversed hexadecimal code back into base-10 numbers, which
- # is the final form of the demo data.
- demoFrag = eval(hexDemoFrag)
- # Formatting base-10 number into useable form for the program, and
- #adding the "|" character that separates each section of 7 frames
- # in the demo data.
- demoFrag = str(demoFrag)
- demoFrag = demoFrag + '|'
- # Adding the 7-frame chunk of demo data to the entire demo.
- totalDemo = totalDemo + demoFrag
- # Allowing the computer to display the final demo data as an output.
- return totalDemo
- def makeCommandList():
- frameList, commandList, frameCount, done, starting = [], [], 0, False, True
- command = raw_input("Enter your list of commands and frames, in form of command, 'x', number of frames, and each new command separated by a space. (e.g. 'Rx4 Lx4') Use N -> nothing, J -> jump, H -> hold jump, R -> move right, L -> move left, and any combination of these commands (e.g. JR -> jump right). Warning: Only use J when starting a jump for one frame, and use H for all other frames that you would normally be holding the jump button. ")
- command = str(command).split()
- for i in range(len(command)):
- commandList.append(str(command[i].split('x')[0].upper() + ' x ' + str(command[i].split('x')[1]) + ' frames'))
- for j in range(int(command[i].split('x')[1])):
- frameCount =+ 1
- frameList.append(command[i].split('x')[0])
- print
- return frameList, commandList
Advertisement
Add Comment
Please, Sign In to add comment