"""Python Script to complete VVVVVV Veni Vidi Vici puzzle"""

"""Written by Grassman7z7"""

"""You can find the win32* libraries as part of pywin32, found here:"""

""" http://sourceforge.net/projects/pywin32/ """

"""HOW TO USE:"""

"""It's simple. On a Windows Machine (Since I'm using the pywin library) launch VVVVVV"""

"""You'll need to navigate to the bottom of VeniVidiVici. Stand at the checkpoint located on there"""

"""In a cmd window, launch the script with 'py vvvvvv.py'"""

"""Don't touch anything, and watch him go!"""

"""Imports"""

import win32api

import win32con

import win32com. client

import time

import copy

######################################################

"""Variables you'll wanna edit. If this is the first time, the trinket will screw up the reset."""

"""Also you can set it to repeat..."""

"""0 count = infinity"""

"""Repeat is not currently working due to Python timer inaccuracies. Maybe you can fix it!"""

reset = True

repeat = False

repeatCount = 0

######################################################

"""The keyboard byte codes"""

"""I'm using ASD for LJR"""

keyRight = 0x44

keyLeft = 0x41

keyJump = 0x53

"""The 'commands' we will be using"""

commandRight = 'r'

commandLeft = 'l'

commandJump = 'j'

commandWait = 'w'

"""Each screen in the puzzle"""

n6 = [ 'j' , 'w' , 0.55 ]

n5 = [ 'r' , 0.5 , 'w' , 0.3 ]

n4 = [ 'l' , 0.6 ]

n3 = [ 'w' , 1 ]

n2 = [ 'w' , 0.5 , 'r' , 0.2 ]

n1 = [ 'w' , 0.4 , 'r' , 0.2 ]

top = [ 'w' , 0.4 , 'l' , 0.2 , 'w' , 0.2 , 'j' , 'r' , 0.3 , 'w' , 0.2 ]

p1 = [ 'l' , 0.2 , 'w' , 0.55 ]

p2 = [ 'l' , 0.2 , 'w' , 0.4 ]

p3 = [ 'w' , 1 ]

p4 = [ 'r' , 0.7 , 'w' , 0.2 ]

p5 = [ 'l' , 0.45 ]

p6 = [ 'w' , 1 , 'r' , 0.5 ]

rs = [ 'w' , 0.5 , 'l' , 0.2 , 'j' , 'l' , 0.9 , 'w' , 0.2 , 'r' , 0.2 , 'j' ]

"""The main array for the puzzle. Contains every screen"""

veniVidiVici = [ n6 , n5 , n4 , n3 , n2 , n1 , top , p1 , p2 , p3 , p4 , p5 , p6 ]

def MoveRight ( duration ) :

"""This will begin moving right for a time (in seconds), then stop."""

win32api. keybd_event ( keyRight , 0 , win32con. KEYEVENTF_EXTENDEDKEY , 0 )

time . sleep ( duration )

win32api. keybd_event ( keyRight , 0 , win32con. KEYEVENTF_KEYUP , 0 )

return

def MoveLeft ( duration ) :

"""This will begin moving left for a time (in seconds), then stop."""

win32api. keybd_event ( keyLeft , 0 , win32con. KEYEVENTF_EXTENDEDKEY , 0 )

time . sleep ( duration )

win32api. keybd_event ( keyLeft , 0 , win32con. KEYEVENTF_KEYUP , 0 )

return

def Jump ( ) :

"""This will 'jump'"""

win32api. keybd_event ( keyJump , 0 , win32con. KEYEVENTF_EXTENDEDKEY , 0 )

time . sleep ( 0.1 )

win32api. keybd_event ( keyJump , 0 , win32con. KEYEVENTF_KEYUP , 0 )

return

def Wait ( duration ) :

"""Simply do nothing!"""

time . sleep ( duration )

return

def ActivateGame ( ) :

"""Activates the game for us. Make sure you are in the correct spot!"""

win32com. client . Dispatch ( "WScript.Shell" ) . AppActivate ( "VVVVVV" )

return

def VeniVidiViciComplete ( ) :

"""Since we defined everything in arrays, we just do them in a loop!"""

veniVidiViciCopy = copy . deepcopy ( veniVidiVici )

for array in veniVidiViciCopy:

"""We will start popping elements off the array"""

"""Since we've defined them as queues, we'll use pop(0)"""

print ( array )

while len ( array ) > 0 :

"""Get a command"""

command = array . pop ( 0 )

if ( command == commandRight ) :

"""We're going right. Get the duration and go!"""

duration = array . pop ( 0 )

MoveRight ( duration )

elif ( command == commandLeft ) :

"""We're going left. Get the duration and go!"""

duration = array . pop ( 0 )

MoveLeft ( duration )

elif ( command == commandWait ) :

"""We're waiting, just relax!"""

duration = array . pop ( 0 )

Wait ( duration )

elif ( command == commandJump ) :

"""Jump! No need to get a duration"""

Jump ( )

else :

print ( "NOT A COMMAND, YOU DUMBSTUFF" )

"""At this point we're out of arrays. Hopefully we got the trinket!"""

return

def ResetToCheckpoint ( ) :

"""This will take us from the end of the puzzle to the checkpoint, allowing us to do it over"""

rsCopy = copy . deepcopy ( rs )

while len ( rsCopy ) > 0 :

"""Get a command"""

command = rsCopy. pop ( 0 )

if ( command == commandRight ) :

"""We're going right. Get the duration and go!"""

duration = rsCopy. pop ( 0 )

MoveRight ( duration )

elif ( command == commandLeft ) :

"""We're going left. Get the duration and go!"""

duration = rsCopy. pop ( 0 )

MoveLeft ( duration )

elif ( command == commandWait ) :

"""We're waiting, just relax!"""

duration = rsCopy. pop ( 0 )

Wait ( duration )

elif ( command == commandJump ) :

"""Jump! No need to get a duration"""

Jump ( )

else :

print ( "NOT A COMMAND, YOU DUMBSTUFF" )

"""Aaaaand we're back!"""

return

######################################################

#Start of the code

######################################################

"""Assuming you have the VVVVVV game running, and you are at the checkpoint of the puzzle..."""

"""Nab the game..."""

ActivateGame ( )

"""How many times you wanna do it?"""

if ( repeat == False ) :

"""Move to the right to make sure we are in position."""

MoveRight ( 1 )

"""Now we begin to do it! Veni Vidi Vici!"""

VeniVidiViciComplete ( )

"""Potentially go and do it again here..."""

if reset:

ResetToCheckpoint ( )

else :

"""I guess you wanna watch it more than once..."""

count = 0

while repeat:

"""Move to the right to make sure we are in position."""

MoveRight ( 1 )

"""Now we begin to do it! Veni Vidi Vici!"""

VeniVidiViciComplete ( )

"""Reset"""

ResetToCheckpoint ( )

"""Have we had enough?"""

count = count + 1

print ( "Venispin! You've Venispun " + str ( count ) + " times!" )

if ( repeatCount != 0 and count == repeatCount ) :

repeat = False ;

Wait ( 1 )

######################################################

#EOF