Advertisement
Guest User

vvvvvv.py

a guest
Oct 2nd, 2013
2,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.72 KB | None | 0 0
  1. """Python Script to complete VVVVVV Veni Vidi Vici puzzle"""
  2. """Written by Grassman7z7"""
  3. """You can find the win32* libraries as part of pywin32, found here:"""
  4. """ http://sourceforge.net/projects/pywin32/ """
  5.  
  6. """HOW TO USE:"""
  7. """It's simple. On a Windows Machine (Since I'm using the pywin library) launch VVVVVV"""
  8. """You'll need to navigate to the bottom of VeniVidiVici. Stand at the checkpoint located on there"""
  9. """In a cmd window, launch the script with 'py vvvvvv.py'"""
  10. """Don't touch anything, and watch him go!"""
  11.  
  12.  
  13. """Imports"""
  14. import win32api
  15. import win32con
  16. import win32com.client
  17. import time
  18. import copy
  19.  
  20. ######################################################
  21. """Variables you'll wanna edit. If this is the first time, the trinket will screw up the reset."""
  22. """Also you can set it to repeat..."""
  23. """0 count = infinity"""
  24. """Repeat is not currently working due to Python timer inaccuracies. Maybe you can fix it!"""
  25. reset = True
  26. repeat = False
  27. repeatCount = 0
  28. ######################################################
  29.  
  30. """The keyboard byte codes"""
  31. """I'm using ASD for LJR"""
  32. keyRight = 0x44
  33. keyLeft = 0x41
  34. keyJump = 0x53
  35.  
  36. """The 'commands' we will be using"""
  37. commandRight = 'r'
  38. commandLeft = 'l'
  39. commandJump = 'j'
  40. commandWait = 'w'
  41.  
  42. """Each screen in the puzzle"""
  43. n6 = ['j', 'w', 0.55]
  44. n5 = ['r', 0.5, 'w', 0.3]
  45. n4 = ['l', 0.6]
  46. n3 = ['w', 1]
  47. n2 = ['w', 0.5, 'r', 0.2]
  48. n1 = ['w', 0.4, 'r', 0.2]
  49. top = ['w', 0.4, 'l', 0.2, 'w', 0.2, 'j', 'r', 0.3, 'w', 0.2]
  50. p1 = ['l', 0.2, 'w', 0.55]
  51. p2 = ['l', 0.2, 'w', 0.4]
  52. p3 = ['w', 1]
  53. p4 = ['r', 0.7, 'w', 0.2]
  54. p5 = ['l', 0.45]
  55. p6 = ['w', 1, 'r', 0.5]
  56. rs = ['w', 0.5, 'l', 0.2, 'j', 'l', 0.9, 'w', 0.2, 'r', 0.2, 'j']
  57.  
  58. """The main array for the puzzle. Contains every screen"""
  59. veniVidiVici = [n6, n5, n4, n3, n2, n1, top, p1, p2, p3, p4, p5, p6]
  60.  
  61. def MoveRight(duration):
  62.     """This will begin moving right for a time (in seconds), then stop."""
  63.     win32api.keybd_event(keyRight, 0, win32con.KEYEVENTF_EXTENDEDKEY, 0)
  64.     time.sleep(duration)
  65.     win32api.keybd_event(keyRight, 0, win32con.KEYEVENTF_KEYUP, 0)
  66.     return
  67.  
  68. def MoveLeft(duration):
  69.     """This will begin moving left for a time (in seconds), then stop."""
  70.     win32api.keybd_event(keyLeft, 0, win32con.KEYEVENTF_EXTENDEDKEY, 0)
  71.     time.sleep(duration)
  72.     win32api.keybd_event(keyLeft, 0, win32con.KEYEVENTF_KEYUP, 0)
  73.     return
  74.  
  75. def Jump():
  76.     """This will 'jump'"""
  77.     win32api.keybd_event(keyJump, 0, win32con.KEYEVENTF_EXTENDEDKEY, 0)
  78.     time.sleep(0.1)
  79.     win32api.keybd_event(keyJump, 0, win32con.KEYEVENTF_KEYUP, 0)
  80.     return
  81.    
  82. def Wait(duration):
  83.     """Simply do nothing!"""
  84.     time.sleep(duration)
  85.     return
  86.  
  87. def ActivateGame():
  88.     """Activates the game for us. Make sure you are in the correct spot!"""
  89.     win32com.client.Dispatch("WScript.Shell").AppActivate("VVVVVV")
  90.     return
  91.    
  92. def VeniVidiViciComplete():
  93.     """Since we defined everything in arrays, we just do them in a loop!"""
  94.     veniVidiViciCopy = copy.deepcopy(veniVidiVici)
  95.     for array in veniVidiViciCopy:
  96.         """We will start popping elements off the array"""
  97.         """Since we've defined them as queues, we'll use pop(0)"""
  98.         print(array)
  99.         while len(array) > 0:
  100.             """Get a command"""
  101.             command = array.pop(0)
  102.             if (command == commandRight):
  103.                 """We're going right. Get the duration and go!"""
  104.                 duration = array.pop(0)
  105.                 MoveRight(duration)
  106.             elif(command == commandLeft):
  107.                 """We're going left. Get the duration and go!"""
  108.                 duration = array.pop(0)
  109.                 MoveLeft(duration)
  110.             elif(command == commandWait):
  111.                 """We're waiting, just relax!"""
  112.                 duration = array.pop(0)
  113.                 Wait(duration)
  114.             elif(command == commandJump):
  115.                 """Jump! No need to get a duration"""
  116.                 Jump()
  117.             else:
  118.                 print("NOT A COMMAND, YOU DUMBSTUFF")
  119.                
  120.     """At this point we're out of arrays. Hopefully we got the trinket!"""
  121.     return
  122.    
  123. def ResetToCheckpoint():
  124.     """This will take us from the end of the puzzle to the checkpoint, allowing us to do it over"""
  125.     rsCopy = copy.deepcopy(rs)
  126.     while len(rsCopy) > 0:
  127.         """Get a command"""
  128.         command = rsCopy.pop(0)
  129.         if (command == commandRight):
  130.             """We're going right. Get the duration and go!"""
  131.             duration = rsCopy.pop(0)
  132.             MoveRight(duration)
  133.         elif(command == commandLeft):
  134.             """We're going left. Get the duration and go!"""
  135.             duration = rsCopy.pop(0)
  136.             MoveLeft(duration)
  137.         elif(command == commandWait):
  138.             """We're waiting, just relax!"""
  139.             duration = rsCopy.pop(0)
  140.             Wait(duration)
  141.         elif(command == commandJump):
  142.             """Jump! No need to get a duration"""
  143.             Jump()
  144.         else:
  145.             print("NOT A COMMAND, YOU DUMBSTUFF")
  146.     """Aaaaand we're back!"""
  147.     return
  148.  
  149. ######################################################
  150. #Start of the code
  151. ######################################################
  152. """Assuming you have the VVVVVV game running, and you are at the checkpoint of the puzzle..."""
  153. """Nab the game..."""
  154. ActivateGame()
  155.  
  156. """How many times you wanna do it?"""
  157. if (repeat == False):
  158.     """Move to the right to make sure we are in position."""
  159.     MoveRight(1)
  160.  
  161.     """Now we begin to do it! Veni Vidi Vici!"""
  162.     VeniVidiViciComplete()
  163.    
  164.     """Potentially go and do it again here..."""
  165.     if reset:
  166.         ResetToCheckpoint()
  167.  
  168. else:
  169.     """I guess you wanna watch it more than once..."""
  170.     count = 0
  171.     while repeat:
  172.         """Move to the right to make sure we are in position."""
  173.         MoveRight(1)
  174.    
  175.         """Now we begin to do it! Veni Vidi Vici!"""
  176.         VeniVidiViciComplete()
  177.    
  178.         """Reset"""
  179.         ResetToCheckpoint()
  180.        
  181.         """Have we had enough?"""
  182.         count = count + 1
  183.         print("Venispin! You've Venispun " + str(count) + " times!")
  184.         if(repeatCount != 0 and count == repeatCount):
  185.             repeat = False;
  186.            
  187.         Wait(1)
  188.  
  189. ######################################################
  190. #EOF
  191. ######################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement