Esempio n. 1
0
    def __init__(self, parent):
        super(GameViewFrame, self).__init__(parent)
        layout = QVBoxLayout(self)
        layout.setContentsMargins(20, 15, 20, 20)

        self.title = Title('', 23)
        titleLayout = QHBoxLayout()
        titleLayout.setAlignment(Qt.AlignTop)
        titleLayout.addWidget(QLabel(' ' * 5))
        titleLayout.addWidget(self.title, 1)
        layout.addLayout(titleLayout, 0)

        self.loading = Loading(200)
        self.loading.hide()
        layout.addWidget(self.loading, 1, Qt.AlignCenter)

        self.countDown = CountDown(200, self)
        self.countDown.hide()

        self.gameView = None
Esempio n. 2
0
 def __init__(self):
     # Players group used to draw multiple players
     self.player = Sumilidon(90, 200, 1256, keys=self.keys1)
     self.player2 = Metabee(290, 300, 1257, keys=self.keys2)
     self.players = {}
     self.add_player(self.player)
     self.add_player(self.player2)
     arenas = arena_info()
     self.rooms = [Room(arenas[0][0] + ".txt"), Room(arenas[1][0] + ".txt")]
     self.current_room = 0
     self.countdown = CountDown()
     # Main Game Loop variables
     self.done = False
     self.fps = 60.0
     self.clock = pygame.time.Clock()
     self.screen = None
     pygame.font.init()  # you have to call this at the start,
     # if you want to use this module.
     self.game_font = pygame.font.SysFont('times', 20)
     self.game_over = False
     self.winner = ""
Esempio n. 3
0
def main():
    CountDown(5)

    if os.path.isfile(file_name):
        print('Existing Training Data:' + str(len(training_data)))
        print('Capturing Data!')
    else:
        print('Capturing Data Freshly!')

    paused = False
    while True:

        if not paused:
            screen = grab_screen(region=(270, 250, 650, 450))
            minimap = grab_screen(region=(100, 390, 230, 490))
            screen = cv2.resize(screen, (200, 80))
            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)
            minimap = cv2.resize(minimap, (50, 50))
            minimap = cv2.cvtColor(minimap, cv2.COLOR_BGR2GRAY)

            keys = key_check()
            output = keys_to_output(keys)
            training_data.append([screen, minimap, output])

            # prints the size of the object every often so that RAM doesn't filled up
            # saves the training data file every 1000 frames collected
            if len(training_data) % 1000 == 0:
                print('Saving data...')
                np.save(file_name, training_data)
                print(f'Saved {file_name} successfully!')
                print(
                    f'System Memory Usage: {psutil.virtual_memory().percent} %'
                )
                print(f'New Training Data: {len(training_data)} frames')
                print('-' * 80)

        keys = key_check()
        '''
        you can press 'e' while in game to pause/unpause the script from
        capturing data.
        '''
        if 'E' in keys:
            if paused:
                paused = False
                print('Unpaused!')
                time.sleep(1)
                print('Capturing Data!')
            else:
                paused = True
                print('Paused!')
                time.sleep(1)
Esempio n. 4
0
def main():
    CountDown(5)

    paused = False
    while True:
        if not paused:
            screen = grab_screen(region=(270, 250, 650, 450))
            minimap = grab_screen(region=(100, 390, 230, 490))

            screen = cv2.resize(screen, (200, 80))
            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)
            screen = screen.reshape(1, 80, 200, 3).astype(np.float32)

            minimap = cv2.resize(minimap, (50, 50))
            minimap = cv2.cvtColor(minimap, cv2.COLOR_BGR2GRAY)
            minimap = minimap.reshape(1, 50, 50, 1).astype(np.float32)

            screen *= 1 / 255.
            minimap *= 1 / 255.

            prediction = DriveNet.predict([screen, minimap])[0]
            decoded = CrashNet.predict(screen)[0]
            mse = np.mean((screen - decoded)**2)

            if np.argmax(prediction) == 0:
                left()
            elif np.argmax(prediction) == 1:
                straight()
            elif np.argmax(prediction) == 2:
                right()

            if mse >= THRESHOLD:
                print(f'WARNING! MSE:{mse:.4f}')
                winsound.Beep(1000, 25)  # freq, duration

        keys = key_check()

        if 'E' in keys:
            if paused:
                paused = False
                print('Unpaused!')
                time.sleep(1)
            else:
                print('Pausing!')
                paused = True
                ReleaseKey(A)
                ReleaseKey(W)
                ReleaseKey(D)
                time.sleep(1)
Esempio n. 5
0
        def __init__(self, parent):
                super(GameViewFrame, self).__init__(parent)
                layout = QVBoxLayout(self)
                layout.setContentsMargins(20, 15, 20, 20)
                
                self.title = Title('', 23)
                titleLayout = QHBoxLayout()
                titleLayout.setAlignment(Qt.AlignTop)
                titleLayout.addWidget(QLabel(' ' * 5))
                titleLayout.addWidget(self.title, 1)
                layout.addLayout(titleLayout, 0)

                self.loading = Loading(200)
                self.loading.hide()
                layout.addWidget(self.loading, 1, Qt.AlignCenter)

                self.countDown = CountDown(200, self)
                self.countDown.hide()

                self.gameView = None
Esempio n. 6
0
def StartGame():
    print('Make sure the game window is on focus...')
    CountDown(5)

    # going into free roam mode
    for action in free_roam:
        action()
    time.sleep(5)

    # changing graphic settings
    for action in graphic:
        action()
    time.sleep(5)

    # changing advanced graphic settings
    for action in advanced:
        action()

    esc()
    esc()

    print('Game is now ready')
Esempio n. 7
0
    try:
        for coords in lines:
            coords = coords[0]
            try:
                cv2.line(image, (coords[0], coords[1]), (coords[2], coords[3]),
                         [255, 0, 0], 3)
            except Exception:
                pass
    except Exception:
        pass

    return image, org_image, m1, m2


if __name__ == '__main__':
    CountDown(5)
    while True:
        screen = grab_screen(region=(270, 250, 650, 450))
        new_screen, original_image, m1, m2 = LaneFinder(screen)
        # cv2.imshow('window', new_screen)
        # cv2.imshow('window2', cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB))

        if m1 < 0 and m2 < 0:
            right()
        elif m1 > 0 and m2 > 0:
            left()
        else:
            straight()

        if cv2.waitKey(25) == ord('q'):
            cv2.destroyAllWindows()
Esempio n. 8
0
class GameViewFrame(QWidget):
    def __init__(self, parent):
        super(GameViewFrame, self).__init__(parent)
        layout = QVBoxLayout(self)
        layout.setContentsMargins(20, 15, 20, 20)

        self.title = Title('', 23)
        titleLayout = QHBoxLayout()
        titleLayout.setAlignment(Qt.AlignTop)
        titleLayout.addWidget(QLabel(' ' * 5))
        titleLayout.addWidget(self.title, 1)
        layout.addLayout(titleLayout, 0)

        self.loading = Loading(200)
        self.loading.hide()
        layout.addWidget(self.loading, 1, Qt.AlignCenter)

        self.countDown = CountDown(200, self)
        self.countDown.hide()

        self.gameView = None

    def setTitle(self, title):
        self.title.setText(title)

    def showLoading(self):
        if self.gameView is not None:
            self.gameView.hide()
        self.loading.show()

    def showCountDown(self, quick=False):
        center = self.gameView.pos() + QPoint(self.gameView.width() / 2,
                                              self.gameView.height() / 2)
        self.countDown.move(center - QPoint(self.countDown.width() / 2,
                                            self.countDown.height() / 2))
        self.countDown.show()
        self.countDown.raise_()
        self.countDown.start(5 if not quick else 0)

    def showGameView(self, gameMap):
        self.loading.hide()
        self.gameView = GameView(gameMap)
        self.layout().addWidget(self.gameView, 1, Qt.AlignCenter)
Esempio n. 9
0
def game_play(screen, screen_rect):
    playing = True
    game_state = GameState.STARTING
    number_of_laps = 2

    # Load images, assign to sprite classes
    img = fileUtils.load_image('rider1-placeholder.png')
    Player.images = [img, pygame.transform.flip(img, 1, 0)]

    # decorate the game window
    # icon = pygame.transform.scale(Rider.images[0], (32, 32))
    # pygame.display.set_icon(icon)
    # pygame.display.set_caption('Pygame Aliens')
    # pygame.mouse.set_visible(0)

    # create the background, tile the bgd image
    background = fileUtils.load_image('pumptrack.png')
    background_rect = background.get_rect()
    screen.blit(background, background_rect)
    pygame.display.flip()

    background_in_alpha = pygame.Surface(
        (screen_rect.size[0], screen_rect.size[1]))
    background_in_alpha.set_alpha(128)
    background_in_alpha.fill(colors.black)

    # load the sound effects
    # shoot_sound = load_sound('car_door.wav')
    """if pygame.mixer:
        music = os.path.join(main_dir, 'data', 'house_lo.wav')
        pygame.mixer.music.load(music)
        pygame.mixer.music.play(-1)"""
    # fileUtils.load_music("Lame_Drivers_-_01_-_Frozen_Egg.mp3")
    # pygame.mixer.music.play(-1)

    # Initialize Game Groups
    aliens = pygame.sprite.Group()
    all = pygame.sprite.RenderUpdates()
    lastalien = pygame.sprite.GroupSingle()

    # assign default groups to each sprite class
    Player.containers = all
    Rider.containers = aliens, all, lastalien
    TimeCounter.containers = all

    # Create Some Starting Values
    clock = pygame.time.Clock()

    # initialize our starting sprites
    player = Player(screen_rect, way_points_pump_track, True)
    time_counter = TimeCounter()
    time_countdown = CountDown()
    game_over = GameOverScreen()
    pause_menu = PauseScreen()
    if pygame.font:
        all.add(time_counter)

    button_down = False

    while playing:

        # get input
        for event in pygame.event.get():
            game_over_state = game_over.update_input(event)
            if game_over_state == GameOverState.RESTART:
                game_state = GameState.RESTART
            elif game_over_state == GameOverState.QUIT:
                return

            quit_game = pause_menu.update_input(event)
            if quit_game:
                return

            if event.type == pygame.QUIT \
                    or (event.type == pygame.KEYDOWN
                        and event.key == pygame.K_ESCAPE
                        and game_state == GameState.PLAYING):
                game_state = GameState.PAUSED

            if event.type == pygame.KEYDOWN \
                    and event.key == pygame.K_SPACE \
                    and button_down is False \
                    and game_state == GameState.PLAYING:
                button_down = True

        all.clear(screen, background)
        all.update()
        # player.update_state(game_state)
        time_counter.set_state(game_state)
        time_countdown.set_state(game_state)
        game_over.set_state(game_state)
        time_countdown.update()

        if time_countdown.countdown <= 0 and game_state == GameState.STARTING:
            game_state = GameState.PLAYING
            screen.blit(background, background_rect)
            pygame.display.flip()

        if game_state == GameState.PLAYING:
            player.pump()
            if button_down is True:
                player.add_pump()
                button_down = False
            if player.lap >= number_of_laps:
                game_state = GameState.GAME_OVER
                game_over.set_final_time(time_counter.time_in_millis)

        if game_state == GameState.STARTING:
            time_countdown.draw(screen, screen_rect, background,
                                background_in_alpha)
            pygame.display.update()

        if game_state == GameState.PAUSED:
            pause_menu.draw(screen, screen_rect, background,
                            background_in_alpha)
            pygame.display.update()

        if game_state == GameState.GAME_OVER:
            game_over.draw(screen, screen_rect, background,
                           background_in_alpha)
            pygame.display.update()

        if game_state == GameState.RESTART:
            clock = pygame.time.Clock()
            player = Player(screen_rect, way_points_pump_track, True)
            time_counter = TimeCounter()
            time_countdown = CountDown()
            game_state = GameState.STARTING

        dirty = all.draw(screen)
        pygame.display.update(dirty)

        clock.tick(30)
Esempio n. 10
0
class World:
    keys1 = {
        'right': pygame.K_RIGHT,
        'left': pygame.K_LEFT,
        'up': pygame.K_UP,
        'down': pygame.K_DOWN,
        'space': pygame.K_SPACE,
        'attack1': pygame.K_m,
        'attack2': pygame.K_COMMA,
        'attack3': pygame.K_PERIOD,
        'attack4': pygame.K_SLASH
    }
    keys2 = {
        'right': pygame.K_d,
        'left': pygame.K_a,
        'up': pygame.K_w,
        'down': pygame.K_s,
        'space': pygame.K_f,
        'attack1': pygame.K_e,
        'attack2': pygame.K_r,
        'attack3': pygame.K_y,
        'attack4': pygame.K_y
    }

    def __init__(self):
        # Players group used to draw multiple players
        self.player = Sumilidon(90, 200, 1256, keys=self.keys1)
        self.player2 = Metabee(290, 300, 1257, keys=self.keys2)
        self.players = {}
        self.add_player(self.player)
        self.add_player(self.player2)
        arenas = arena_info()
        self.rooms = [Room(arenas[0][0] + ".txt"), Room(arenas[1][0] + ".txt")]
        self.current_room = 0
        self.countdown = CountDown()
        # Main Game Loop variables
        self.done = False
        self.fps = 60.0
        self.clock = pygame.time.Clock()
        self.screen = None
        pygame.font.init()  # you have to call this at the start,
        # if you want to use this module.
        self.game_font = pygame.font.SysFont('times', 20)
        self.game_over = False
        self.winner = ""

    def add_player(self, player):
        self.players[player.unique_id] = player

    def run(self, screen):
        self.screen = screen
        while not self.done:
            self.process_events()
            self.update()
            self.draw()
            pygame.display.update()
            self.clock.tick(self.fps)

    def process_events(self):
        keys = pygame.key.get_pressed()
        self.player.process_keys(keys)
        # Remove these line for networking
        self.player2.process_keys(keys)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.done = True

    def update(self):
        # Will only update count down timer until it's done
        if not self.countdown.should_countdown():
            self.countdown.update()
        else:
            # --- Game Logic ---
            self.player.set_room(self.rooms[self.current_room])
            self.player.update(self.players)
            # Remove these line for networking
            self.player2.set_room(self.rooms[self.current_room])
            self.player2.update(self.players)

            if (self.player.damage_taken >= 100 or
                    self.player2.damage_taken >= 100) and not self.game_over:
                self.game_over = True
                if self.player.damage_taken < 100:
                    self.winner = "P1Wins.png"
                elif self.player2.damage_taken < 100:
                    self.winner = "P2Wins.png"
                pygame.mixer.music.stop()
                pygame.mixer.music.load(get_path_name("media", "winner.mp3"))
                pygame.mixer.music.play(0)

    def draw_countdown(self):
        if not self.countdown.should_countdown():
            self.countdown.draw(self.screen)

    def draw_players(self):
        pos = 0
        for player in self.players:
            position = (pos, len(self.players))
            self.players[player].draw(self.screen, self.game_font, position)
            pos += 1

    def draw_game_over(self):
        self.countdown.draw_game_over(self.screen, self.winner)

    def draw(self):
        self.screen.fill(BACKGROUND_COLOR)
        self.rooms[self.current_room].draw(self.screen)
        self.draw_players()
        self.draw_countdown()
        if self.game_over:
            self.draw_game_over()
Esempio n. 11
0
class GameViewFrame(QWidget):
        def __init__(self, parent):
                super(GameViewFrame, self).__init__(parent)
                layout = QVBoxLayout(self)
                layout.setContentsMargins(20, 15, 20, 20)
                
                self.title = Title('', 23)
                titleLayout = QHBoxLayout()
                titleLayout.setAlignment(Qt.AlignTop)
                titleLayout.addWidget(QLabel(' ' * 5))
                titleLayout.addWidget(self.title, 1)
                layout.addLayout(titleLayout, 0)

                self.loading = Loading(200)
                self.loading.hide()
                layout.addWidget(self.loading, 1, Qt.AlignCenter)

                self.countDown = CountDown(200, self)
                self.countDown.hide()

                self.gameView = None

        def setTitle(self, title):
                self.title.setText(title)


        def showLoading(self):
                if self.gameView is not None:
                        self.gameView.hide()
                self.loading.show()

        def showCountDown(self, quick = False):
                center = self.gameView.pos() + QPoint(self.gameView.width() / 2, self.gameView.height() / 2)
                self.countDown.move(center - QPoint(self.countDown.width() / 2, self.countDown.height() / 2))
                self.countDown.show()
                self.countDown.raise_()
                self.countDown.start(5 if not quick else 0)

        def showGameView(self, gameMap):
                self.loading.hide()
                self.gameView = GameView(gameMap)
                self.layout().addWidget(self.gameView, 1, Qt.AlignCenter)
Esempio n. 12
0
my_screen = Screen()
# Changing the background color of the Turtle Screen to Black
my_screen.setup(width=700, height=750)
my_screen.bgcolor("black")
my_screen.title(" Snake Game In PYTHON ")
# Turning the turtle animation off
my_screen.tracer(0)
sleep_time = 0

border = Borders()
border.create_borders()

user_choice = my_screen.textinput(
    "Choose Level: ", "What level difficulty do you want? "
    "(EASY / NORMAL / HARD / EXPERT)").lower()
timer_c = CountDown()

if user_choice == "easy":
    sleep_time = 0.1
elif user_choice == "normal":
    sleep_time = 0.08
elif user_choice == "hard":
    sleep_time = 0.06
elif user_choice == "expert":
    sleep_time = 0.04

snake = Snake()
food = Food()
scoreboard = ScoreBoard()

# Creating the Key Strokes