flappy init
This commit is contained in:
56
flappy.py
56
flappy.py
@@ -1,12 +1,6 @@
|
|||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import numpy as np
|
|
||||||
from time import time
|
|
||||||
|
|
||||||
import pydirectinput
|
import pydirectinput
|
||||||
|
|
||||||
from game_base_class import GameBase
|
from game_base_class import GameBase
|
||||||
from pynput.keyboard import Key, Controller
|
|
||||||
|
|
||||||
from flappy_pos_discovery_thread import FlappyPosDiscovery
|
from flappy_pos_discovery_thread import FlappyPosDiscovery
|
||||||
|
|
||||||
class Flappy(GameBase):
|
class Flappy(GameBase):
|
||||||
@@ -14,24 +8,10 @@ class Flappy(GameBase):
|
|||||||
def __init__(self, overlay):
|
def __init__(self, overlay):
|
||||||
super().__init__(overlay)
|
super().__init__(overlay)
|
||||||
|
|
||||||
self.keyboard = Controller()
|
|
||||||
|
|
||||||
self.data_coordinates = np.zeros((20, 20), dtype=object)
|
|
||||||
self.observation = np.zeros((20, 20), dtype=int)
|
|
||||||
|
|
||||||
self.colors = [1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
||||||
|
|
||||||
self.offset_left = 610
|
|
||||||
self.offset_down = 40
|
|
||||||
|
|
||||||
self.fill_data_coordinates()
|
|
||||||
|
|
||||||
self.litris_reset_board = cv.imread("control_elements/sodoku_reset_button.jpg", cv.IMREAD_COLOR)
|
self.litris_reset_board = cv.imread("control_elements/sodoku_reset_button.jpg", cv.IMREAD_COLOR)
|
||||||
|
|
||||||
self.flappy_pos_disc = FlappyPosDiscovery()
|
self.flappy_pos_disc = FlappyPosDiscovery()
|
||||||
|
|
||||||
self.move_mode = 1
|
|
||||||
|
|
||||||
def assess_playfield_and_make_move(self):
|
def assess_playfield_and_make_move(self):
|
||||||
#last_letter_received = time()
|
#last_letter_received = time()
|
||||||
wait_timer = 380
|
wait_timer = 380
|
||||||
@@ -42,37 +22,5 @@ class Flappy(GameBase):
|
|||||||
cv.waitKey(50)
|
cv.waitKey(50)
|
||||||
pydirectinput.mouseUp()
|
pydirectinput.mouseUp()
|
||||||
cv.waitKey(wait_timer)
|
cv.waitKey(wait_timer)
|
||||||
|
if self.flappy_pos_disc.next_gate_height[0] is not 0:
|
||||||
offset = (self.flappy_pos_disc.next_gate_height + 170) - self.flappy_pos_disc.current_pet_height
|
wait_timer = wait_timer + (self.flappy_pos_disc.next_gate_height[0] + 120) - self.flappy_pos_disc.current_pet_height
|
||||||
if offset < -100:
|
|
||||||
#pet go down
|
|
||||||
wait_timer = 430
|
|
||||||
elif 0 > offset > -100:
|
|
||||||
wait_timer = 405
|
|
||||||
elif 0 < offset < 50:
|
|
||||||
wait_timer = 355
|
|
||||||
elif offset > 50:
|
|
||||||
wait_timer = 330
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
|
||||||
if self.stone_id_thread.get_pick_up_status() == False:
|
|
||||||
if (time() - last_letter_received) >= 5:
|
|
||||||
self.field.reset_field()
|
|
||||||
self.field.cleared_rows = 1
|
|
||||||
last_letter_received = time()
|
|
||||||
self.dig_point(1500, 980, 100)
|
|
||||||
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
|
||||||
return
|
|
||||||
continue
|
|
||||||
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
|
||||||
return
|
|
||||||
cv.waitKey(50)
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
self.stone_id_thread.set_pick_up_status(False)
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
BIN
flappy/gate.jpg
BIN
flappy/gate.jpg
Binary file not shown.
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 42 KiB |
@@ -13,15 +13,15 @@ class FlappyPosDiscovery(threading.Thread):
|
|||||||
self.capture_window = WindowCapture(None, None, self.config)
|
self.capture_window = WindowCapture(None, None, self.config)
|
||||||
self.vision_stun = Vision()
|
self.vision_stun = Vision()
|
||||||
|
|
||||||
self.needle_f = cv.imread("flappy/flappy.jpg")
|
self.needle_f = self.scale_picture(cv.imread("flappy/flappy.jpg"), 50)
|
||||||
self.mask_f = cv.imread("flappy/flappy-mask.png")
|
self.mask_f = self.scale_picture(cv.imread("flappy/flappy-mask.png"), 50)
|
||||||
|
|
||||||
self.needle_g = cv.imread("flappy/gate.png")
|
self.needle_g = self.scale_picture(cv.imread("flappy/gate.jpg"), 50)
|
||||||
self.mask_g = cv.imread("flappy/gate-mask.png")
|
self.mask_g = self.scale_picture(cv.imread("flappy/gate-mask.png"), 50)
|
||||||
|
|
||||||
self.run_mode = 'run'
|
self.run_mode = 'run'
|
||||||
self.current_pet_height = 0
|
self.current_pet_height = 0
|
||||||
self.next_gate_height = 0
|
self.next_gate_height = [0,0,0]
|
||||||
|
|
||||||
self.offset_down = 90
|
self.offset_down = 90
|
||||||
|
|
||||||
@@ -29,19 +29,38 @@ class FlappyPosDiscovery(threading.Thread):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.run_mode == 'run':
|
while self.run_mode == 'run':
|
||||||
screenshot_g = self.capture_window.get_screenshot_by_area([1600, 1200, 800, 90])
|
screenshot_g = self.scale_picture(self.capture_window.get_screenshot_by_area([700, 1200, 1860, 90]), 50)
|
||||||
screenshot_f = self.capture_window.get_screenshot_by_area([200, 1250, 610, 90])
|
screenshot_f = self.scale_picture(self.capture_window.get_screenshot_by_area([200, 1250, 610, 90]), 50)
|
||||||
rectangles_g = self.vision_stun.find(screenshot_g, self.needle_g, 0.97, 5, True, self.mask_g)
|
|
||||||
|
#cv.imshow("screenshot_g", screenshot_g)
|
||||||
|
#cv.waitKey(150)
|
||||||
|
|
||||||
|
rectangles_g = self.vision_stun.find(screenshot_g, self.needle_g, 0.95, 1)
|
||||||
rectangles_f = self.vision_stun.find(screenshot_f, self.needle_f, 0.97, 1, True, self.mask_f)
|
rectangles_f = self.vision_stun.find(screenshot_f, self.needle_f, 0.97, 1, True, self.mask_f)
|
||||||
|
|
||||||
if len(rectangles_g) is not 0:
|
if len(rectangles_g) is not 0:
|
||||||
self.next_gate_height = rectangles_g[0][1] + rectangles_g[0][3] + self.offset_down
|
height = rectangles_g[0][1] + rectangles_g[0][3] + (self.offset_down /2)
|
||||||
|
if self.next_gate_height[0] is not height:
|
||||||
|
self.next_gate_height.append(height)
|
||||||
|
if len(self.next_gate_height) > 3:
|
||||||
|
self.next_gate_height.pop(0)
|
||||||
|
#pro_screen = self.vision_stun.draw_rectangles(screenshot_g, rectangles_g)
|
||||||
|
#cv.imshow("screenshot_g", pro_screen)
|
||||||
|
#cv.waitKey(150)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
if len(rectangles_f) is not 0:
|
if len(rectangles_f) is not 0:
|
||||||
self.current_pet_height = rectangles_f[0][1] + rectangles_f[0][3] + self.offset_down
|
self.current_pet_height = rectangles_f[0][1] + rectangles_f[0][3] + self.offset_down
|
||||||
|
|
||||||
#print("pet_pos: ", self.current_pet_height)
|
print("pet_pos: ", self.current_pet_height)
|
||||||
#print("next gate: ", self.next_gate_height)
|
print("next gate: ", self.next_gate_height)
|
||||||
|
|
||||||
|
def scale_picture(self, img, scale_percent):
|
||||||
|
width = int(img.shape[1] * scale_percent / 100)
|
||||||
|
height = int(img.shape[0] * scale_percent / 100)
|
||||||
|
return cv.resize(img, (width, height), interpolation=4)
|
||||||
|
|
||||||
def get_actual_pet_height(self):
|
def get_actual_pet_height(self):
|
||||||
return self.current_pet_height
|
return self.current_pet_height
|
||||||
|
|
||||||
|
|||||||
@@ -158,10 +158,11 @@ class Vision:
|
|||||||
|
|
||||||
if mask is not None:
|
if mask is not None:
|
||||||
result = cv.matchTemplate(haystack_img, needle_img, cv.TM_CCORR_NORMED, None, mask)
|
result = cv.matchTemplate(haystack_img, needle_img, cv.TM_CCORR_NORMED, None, mask)
|
||||||
_minVal, _maxVal, minLoc, maxLoc = cv.minMaxLoc(result, None)
|
|
||||||
else:
|
else:
|
||||||
result = cv.matchTemplate(haystack_img, needle_img, self.method)
|
result = cv.matchTemplate(haystack_img, needle_img, self.method)
|
||||||
|
|
||||||
|
_minVal, _maxVal, minLoc, maxLoc = cv.minMaxLoc(result, None)
|
||||||
|
|
||||||
if normalize:
|
if normalize:
|
||||||
cv.normalize(result, result, 0, 1, cv.NORM_MINMAX, -1)
|
cv.normalize(result, result, 0, 1, cv.NORM_MINMAX, -1)
|
||||||
# Get the all the positions from the match result that exceed our threshold
|
# Get the all the positions from the match result that exceed our threshold
|
||||||
|
|||||||
Reference in New Issue
Block a user