update flappy
This commit is contained in:
13
flappy.py
13
flappy.py
@@ -2,6 +2,7 @@ import cv2 as cv
|
||||
import pydirectinput
|
||||
from game_base_class import GameBase
|
||||
from flappy_pos_discovery_thread import FlappyPosDiscovery
|
||||
from keyboard_thread import KeyboardEvent
|
||||
|
||||
class Flappy(GameBase):
|
||||
|
||||
@@ -11,23 +12,25 @@ class Flappy(GameBase):
|
||||
self.litris_reset_board = cv.imread("control_elements/sodoku_reset_button.jpg", cv.IMREAD_COLOR)
|
||||
|
||||
self.flappy_pos_disc = FlappyPosDiscovery()
|
||||
self.keyboard_listener = KeyboardEvent()
|
||||
|
||||
def assess_playfield_and_make_move(self):
|
||||
#last_letter_received = time()
|
||||
wait_timer = 380
|
||||
|
||||
while True:
|
||||
if self.overlay.run_mode == 'stopped' or self.overlay.run_mode == 'paused':
|
||||
return
|
||||
tmp = 20
|
||||
wait_timer = 380 + self.keyboard_listener.offset_value
|
||||
self.click()
|
||||
cv.waitKey(int(100))
|
||||
cv.waitKey(wait_timer)
|
||||
'''
|
||||
if self.flappy_pos_disc.next_gate_height[0] is not 0:
|
||||
offset = (self.flappy_pos_disc.next_gate_height[0] + 120) - self.flappy_pos_disc.current_pet_height
|
||||
offset = (self.flappy_pos_disc.next_gate_height[0] + 120) - self.flappy_pos_disc.get_actual_pet_height()
|
||||
if offset > 50:
|
||||
self.click()
|
||||
cv.waitKey(int(wait_timer -100))
|
||||
print("pet_pos: ", self.flappy_pos_disc.get_actual_pet_height())
|
||||
'''
|
||||
|
||||
if self.flappy_pos_disc.next_gate_height[0] is not 0:
|
||||
offset = (self.flappy_pos_disc.next_gate_height[0] + 120) - self.flappy_pos_disc.current_pet_height
|
||||
if offset > 50:
|
||||
|
||||
32
keyboard_thread.py
Normal file
32
keyboard_thread.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import threading
|
||||
import cv2 as cv
|
||||
import keyboard
|
||||
|
||||
|
||||
class KeyboardEvent(threading.Thread):
|
||||
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
self.run_mode = 'run'
|
||||
self.offset_value = 0
|
||||
self.start()
|
||||
def run(self):
|
||||
while self.run_mode == 'run':
|
||||
if keyboard.is_pressed('up'): # if key 'q' is pressed
|
||||
self.offset_value = -50
|
||||
elif keyboard.is_pressed('down'):
|
||||
self.offset_value = 50
|
||||
elif keyboard.is_pressed('left') or keyboard.is_pressed('right'):
|
||||
self.offset_value = 0
|
||||
cv.waitKey(10)
|
||||
|
||||
def callback(self):
|
||||
pass
|
||||
|
||||
def destroy(self):
|
||||
self.destroy()
|
||||
|
||||
def get_run_mode(self):
|
||||
return self.run_mode
|
||||
|
||||
Reference in New Issue
Block a user