Beispiel #1
0
def left():
    # print(straight_frame_diff)
    ReleaseKey(D)
    PressKey(A)
    #ReleaseKey(W)
    if AUTO_STRAIGHT and straight_frame_diff >= 5:
        PressKey(W)
        time.sleep(t_time)
        ReleaseKey(A)
    time.sleep(t_time)
    ReleaseKey(A)
def left():
    global AUTO_STRAIGHT
    # print(straight_frame_diff)
    ReleaseKey(D)
    PressKey(A)
    if AUTO_STRAIGHT:
        PressKey(W)

    time.sleep(t_time)

    ReleaseKey(A)
    ReleaseKey(W)
def right():
    global AUTO_STRAIGHT
    # PressKey(W)
    ReleaseKey(A)
    PressKey(D)
    if AUTO_STRAIGHT:
        PressKey(W)

    time.sleep(t_time)

    ReleaseKey(W)
    ReleaseKey(D)
Beispiel #4
0
def right(AUTO_STRAIGHT, straight_frame_diff):
    # PressKey(W)
    ReleaseKey(A)
    PressKey(D)
    if AUTO_STRAIGHT and straight_frame_diff >= 5:
        print("going forward")
        PressKey(W)
        time.sleep(t_time)
        ReleaseKey(W)
    #ReleaseKey(W)
    #ReleaseKey(D)
    time.sleep(t_time)
    ReleaseKey(D)
Beispiel #5
0
def PlayCurveFever(statusRefImg, color):
    # Settings

    colors = {
        'red': np.array((69, 69, 255)),
        'pink': np.array((186, 164, 255)),
        'yellow': np.array((43, 233, 255)),
        'green': np.array((48, 255, 106)),
        'aqua': np.array((192, 209, 2)),
        'blue': np.array((255, 68, 68)),
        'orange': np.array((52, 136, 255))
    }
    full = {"top": 10, "left": 1320, "width": 2535 - 1320, "height": 1023 - 10}
    sct = mss.mss()
    PlayerColor = colors[color]  # red
    colMin = PlayerColor - 20
    colMax = PlayerColor + 20
    states = []
    pyauto.click(x=1900, y=500)
    while 'Play':
        last_time = time.time()
        state1, status = cfb.GrabScreen(statusRefImg, sct, full, colMin,
                                        colMax)

        if status == 'Play':
            states.append(state1)
            if (len(states) == 3):
                p1, p2 = cfb.proccesTwoStates(states[0], states[1], states[2])
                fit, params, dists = cfb.getParameters(p1, p2)
                # imgView = cv2.line(state2,
                #                   (int(p2[0]), int(p2[1])),
                #                   (int(params['collisionPoint'][0]), int(params['collisionPoint'][1])),
                #                   (255, 255, 255),
                #                   2)

                # dodac odelglosc punkt przeciecia dla sladu
                print(cfb.checkPathCollsion(states[2], fit, params, p2))
                if cfb.checkPathCollsion(states[2], fit, params, p2):
                    PressKey(A)
                else:
                    ReleaseKey(A)

                if params['walldist'] > 150:
                    #print("UP   |", "DIST: ", params['walldist'], "ANGLE: ", params['angle']
                    ReleaseKey(A)
                else:
                    # print("DOWN |", "DIST: ", params['walldist'], "ANGLE: ", params['angle'])
                    # press = np.abs(params['angle']) * 1.2 / 180
                    PressKey(A)

                states.pop(0)
def restart():
    wait()
    time.sleep(1)
    PressKey(SPACE)
    time.sleep(0.05)
    ReleaseKey(SPACE)
    time.sleep(0.2)
Beispiel #7
0
def straight():
    ##    if random.randrange(4) == 2:
    ##        ReleaseKey(W)
    ##    else:
    PressKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
def straight():
    # ReleaseKey(A)
    # ReleaseKey(D)
    PressKey(W)

    time.sleep(t_time_for_fwd)

    ReleaseKey(W)
Beispiel #9
0
def no_keys():

    if random.randrange(0, 3) == 1:
        PressKey(W)
    else:
        ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(S)
    ReleaseKey(D)
Beispiel #10
0
def go_right():
    i = 5
    while (i < 0):
        PressKey(D)
        i = i - 1
    #PressKey(D)
    ReleaseKey(A)
    ReleaseKey(S)
    time.sleep(d_time)
Beispiel #11
0
def go_left():
    i = 5
    while (i < 0):
        PressKey(A)
        i = i - 1

    ReleaseKey(S)
    ReleaseKey(D)
    time.sleep(d_time)
Beispiel #12
0
def controller(key):
    if chr(key) == 'A':
        PressKey(A)
        print("A")
        time.sleep(0.10)
        ReleaseKey(A)
    if chr(key) == 'B':
        PressKey(B)
        print("B")
        time.sleep(0.10)
        ReleaseKey(B)
    if chr(key) == 'U':
        PressKey(Z)
        print("U")
        time.sleep(0.10)
        ReleaseKey(Z)
    if chr(key) == 'D':
        PressKey(S)
        print("D")
        time.sleep(0.10)
        ReleaseKey(S)
def main():
    last_time = time.time()
    while True:
        # 800x600 windowed mode
        PressKey(R_A)
        screen = np.array(ImageGrab.grab(bbox=(0, 40, 800, 640)))

        last_time = time.time()

        # Code to change the new image screen to gray
        # new_image = process_image(screen)
        # cv2.imshow('window', new_image)

        cv2.imshow('window', cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break
Beispiel #14
0
def screen_record(): 
	bulletsFired = 1
	clipSize = 6
	while(True):
		image =  np.array(ImageGrab.grab(bbox=(startx,starty,1200,958)))
		original_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
		cv2.imshow("origi", original_image)
		print("brown ", original_image[761 - starty, 649 - startx])
		if original_image[761 - starty, 649 - startx] > 180 :
			time.sleep(3)
			upgradeGun()
			clipSize+=3
			time.sleep(3)

		for cordsy in range(1,original_image.shape[0], 2):
					for cordsx in range(1,original_image.shape[1], 2):
						if original_image[cordsy][cordsx] < 5:
							max_previous_click_length = 5
							click_bubble_range = 50
							too_close = False
							for pos in previous_clicks:
								if dist(cordsx + startx, cordsy+ starty, pos[0], pos[1]) < click_bubble_range:
									too_close = True
									break
							if too_close:
								continue
							print("Clicked ", cordsx, cordsy)
							pyautogui.click(cordsx + startx + 10, cordsy + starty, 2)
							bulletsFired+=2
							previous_clicks.append([cordsx +startx, cordsy+ starty])
							if len(previous_clicks) > max_previous_click_length:
								del previous_clicks[0]
							if bulletsFired>clipSize:
								PressKey(SPACE)
								time.sleep(0.05)
								bulletsFired = 1
								ReleaseKey(SPACE)
							break

		
		if cv2.waitKey(25) & 0xFF == ord('q'):
			cv2.destroyAllWindows()
			break
Beispiel #15
0
 def take_action(self, action):
     PressKey(self.moves[action])
     self.logger.info('Taking action {}'.format(self.print_moves[action]))
Beispiel #16
0
def forward():
     PressKey(W)
     ReleaseKey(A)
     ReleaseKey(D)
Beispiel #17
0
def DrawCircles(image):
    circles = cv2.HoughCircles(image, cv2.HOUGH_GRADIENT, 1, 5)
    try:
        circles = numpy.uint16(numpy.around(circles))
        for ii in circles[0, :]:
            cv2.circle(image, (ii[0], ii[1]), ii[2], (255, 255, 255), 3)
    except:
        print("no circles")
    return image


for i in list(range(5))[::-1]:
    print(i + 1)
    time.sleep(1)
'''
PressKey(W)
time.sleep(1)
ReleaseKey(W)
PressKey(D)
time.sleep(1)
ReleaseKey(D)
'''
while True:
    screen = numpy.array(sct.grab(window), numpy.uint8)  # GRABS AREA
    blackAndWhite = ProcessImage(screen)  # CREATE GRAYSCALE IMAGE
    blackAndWhite = DrawCircles(blackAndWhite)  # DRAW CIRCLES
    #cv2.moveWindow(title, 950, 100)                     # MOVE WINDOW
    #checkPixels(screen)                                 # CHECK PIXELS
    cv2.imshow(title, blackAndWhite)  # GRAYSCALE WINDOW
    if frames == 100:  # FPS
def left():
    PressKey(A)
    # ReleaseKey(W) # this was commented
    ReleaseKey(D)
Beispiel #19
0
def right():
     PressKey(W)
     PressKey(D)
     ReleaseKey(A)
     time.sleep(deviationSpeed)
     ReleaseKey(D)
Beispiel #20
0
vid = cv2.VideoCapture(0)

SpaceBar = 0x20

previous_key = 0
while True:
    _, frame = vid.read()

    frame = cv2.resize(frame, (600, 600))  # frame = [600,600, 3]
    crop = frame[50:400, 200:500]
    crop = cv2.resize(crop, (100, 100))

    crop_dim = tf.expand_dims(crop, 0)

    prediction = model.predict(crop_dim)
    print(prediction[0][0])

    if int(np.around(prediction[0][0])) == 1:
        previous_key = 1
        PressKey(SpaceBar)
        ReleaseKey(SpaceBar)
        time.sleep(0.005)
        print('pressed')

    cv2.rectangle(frame, (200, 50), (500, 400), (255, 0, 0), 2)

    cv2.imshow('frame', frame)

    if cv2.waitKey(1) == ord('q'):
        cv2.destroyAllWindows()
        break
        # find the center from the moments 0.000001 is added to the denominator so that divide by
        # zero exception doesn't occur
        center_left = (int(M["m10"] / (M["m00"] + 0.000001)),
                       int(M["m01"] / (M["m00"] + 0.000001)))

        # only proceed if the radius meets a minimum size
        if radius > circle_radius:
            # draw the circle and centroid on the frame,
            cv2.circle(frame, (int(x), int(y)), int(radius), (0, 255, 255), 2)
            cv2.circle(frame, center_left, 5, (0, 0, 255), -1)

            #the window size is kept 160 pixels in the center of the frame(80 pixels above the center and 80 below)
            if center_left[0] < (width // 2 - windowSize // 2):
                cv2.putText(frame, 'LEFT', (20, 50), cv2.FONT_HERSHEY_SIMPLEX,
                            1, (0, 0, 255))
                PressKey(A)
                current_key_pressed.add(A)
                keyPressed = True
                keyPressed_lr = True
            elif center_left[0] > (width // 2 + windowSize // 2):
                cv2.putText(frame, 'RIGHT', (20, 50), cv2.FONT_HERSHEY_SIMPLEX,
                            1, (0, 0, 255))
                PressKey(D)
                current_key_pressed.add(D)
                keyPressed = True
                keyPressed_lr = True

    # show the frame to our screen
    frame_copy = frame.copy()
    frame_copy = cv2.rectangle(
        frame_copy, (width // 2 - windowSize // 2, 0),
Beispiel #22
0
def go_reverse_left():
    PressKey(S)
    PressKey(A)
    ReleaseKey(W)
    ReleaseKey(D)
Beispiel #23
0
def go_forward_right():
    PressKey(W)
    PressKey(D)
    ReleaseKey(A)
    ReleaseKey(S)
Beispiel #24
0
def go_reverse_right():
    PressKey(S)
    PressKey(D)
    ReleaseKey(W)
    ReleaseKey(A)
def t_key(key_a, key_b, key_c):
    PressKey(key_a)
    ReleaseKey(key_b)
    ReleaseKey(key_c)
    time.sleep(keytime)
def straight():
    PressKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
Beispiel #27
0
from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM
import sys
from directKeys import PressKey, ReleaseKey, W, A
import time

PORT_NUMBER = 5000
SIZE = 1024

hostName = gethostbyname('192.168.1.125')

mySocket = socket(AF_INET, SOCK_DGRAM)
mySocket.bind((hostName, PORT_NUMBER))

print("Test server listening on port {0}\n".format(PORT_NUMBER))

while True:
    (data, addr) = mySocket.recvfrom(SIZE)
    meme = data.decode('utf-8')
    print(meme)
    if meme == 'On':
        PressKey(W)
        time.sleep(1)
        ReleaseKey(W)
    else:
        ReleaseKey(W)

sys.ext()
Beispiel #28
0
def left():
     PressKey(W)
     PressKey(A)
     ReleaseKey(D)
     time.sleep(deviationSpeed)
     ReleaseKey(A)
Beispiel #29
0
    print(ammo_screen[5][5])


while True:
    if keyboard.is_pressed('a'):
        while True:
            ammo_screen = np.array(
                ImageGrab.grab(bbox=ammo_coords))  #shape is [y,x]
            ammo_screen = cv2.cvtColor(
                ammo_screen, cv2.COLOR_BGR2GRAY)  # convert to grey image

            #checkscreen()
            #shoot()

            if ammo_screen[5][5] > 200:  #ammo empty
                PressKey(SPACE)
                time.sleep(0.05)
                ReleaseKey(SPACE)
                time.sleep(0.5)

            if ammo_screen[5][5] < 190:  #ammo full
                screen = np.array(
                    ImageGrab.grab(bbox=game_coords))  # shape is [y,x]
                screen = cv2.cvtColor(
                    screen, cv2.COLOR_BGR2GRAY)  # convert to grey image
                shoot()

            if keyboard.is_pressed('q'):
                break

            #time.sleep(0.001)
def right():
    PressKey(D)
    ReleaseKey(A)