# -*- coding: utf-8 -*- """ Created on Fri Apr 14 10:40:56 2023 Credit on usage via @DrPupper_RG on twitter """ import pygame import sys import time import pyautogui from pynput import mouse import pygetwindow as gw from threading import Thread pygame.init() # Screen settings WIDTH, HEIGHT = 800, 600 FPS = 60 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Python Aimbot Test Ex 1") clock = pygame.time.Clock() # Ball settings BALL_RADIUS = 10 ball_speed_x = 10 ball_speed_y = 4 ball_color = (255, 0, 0) # Score settings score = 0 score_font = pygame.font.Font(None, 30) # Accuracy settings clicks_on_target = 0 total_clicks = 0 accuracy_font = pygame.font.Font(None, 30) # Slider settings slider_width = 150 slider_height = 20 slider_x = 20 slider_y = HEIGHT - slider_height - 20 slider_rect = pygame.Rect(slider_x, slider_y, slider_width, slider_height) slider_button_rect = pygame.Rect(slider_x, slider_y, slider_height, slider_height) slider_dragging = False mouse4_pressed = False def on_click(x, y, button, pressed): global mouse4_pressed if button == mouse.Button.x1: mouse4_pressed = pressed if pressed: t = Thread(target=snap_cursor_to_ball) t.start() def snap_cursor_to_ball(): while mouse4_pressed: window = gw.getWindowsWithTitle('Red Ball Game')[0] window_x, window_y = window.left, window.top pyautogui.moveTo(ball_x + window_x, ball_y + window_y) time.sleep(0.001) def draw_ball(x, y): pygame.draw.circle(screen, ball_color, (x, y), BALL_RADIUS) def draw_score(): score_text = score_font.render(f"Score: {score}", True, (0, 0, 0)) screen.blit(score_text, (10, 10)) def draw_accuracy(): if total_checks == 0: accuracy_text = accuracy_font.render(f"Accuracy: N/A", True, (0, 0, 0)) else: accuracy = successful_checks / total_checks * 100 accuracy_text = accuracy_font.render(f"Accuracy: {accuracy:.1f}%", True, (0, 0, 0)) screen.blit(accuracy_text, (10, 40)) def draw_slider(): pygame.draw.rect(screen, (0, 0, 0), slider_rect, 2) pygame.draw.rect(screen, (0, 0, 255), slider_button_rect) def update_ball_speed(): global ball_speed_x ratio = (slider_button_rect.x - slider_x) / (slider_width - slider_height) ball_speed_x = 10 * ratio ball_x, ball_y = WIDTH // 2, HEIGHT // 2 score_timer = pygame.time.get_ticks() successful_checks = 0 total_checks = 0 accuracy_timer = pygame.time.get_ticks() mouse_listener = mouse.Listener(on_click=on_click) mouse_listener.start() while True: screen.fill((255, 255, 255)) draw_ball(ball_x, ball_y) draw_score() draw_accuracy() draw_slider() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: total_clicks += 1 if event.button == 1: # Left click x, y = event.pos if ball_x - BALL_RADIUS < x < ball_x + BALL_RADIUS and ball_y - BALL_RADIUS < y < ball_y + BALL_RADIUS: clicks_on_target += 1 if slider_button_rect.collidepoint(x, y): slider_dragging = True if event.type == pygame.MOUSEBUTTONUP: if event.button == 1: # Left click slider_dragging = False if pygame.time.get_ticks() - score_timer >= 100 and pygame.mouse.get_pressed()[0] and ball_x - BALL_RADIUS < pygame.mouse.get_pos()[0] < ball_x + BALL_RADIUS and ball_y - BALL_RADIUS < pygame.mouse.get_pos()[1] < ball_y + BALL_RADIUS: score += 1 score_timer = pygame.time.get_ticks() if slider_dragging: slider_button_rect.x = pygame.mouse.get_pos()[0] - slider_height // 2 if slider_button_rect.x < slider_x: slider_button_rect.x = slider_x if slider_button_rect.x > slider_x + slider_width - slider_height: slider_button_rect.x = slider_x + slider_width - slider_height update_ball_speed() ball_x += ball_speed_x ball_y += ball_speed_y if ball_x - BALL_RADIUS <= 0: ball_x = BALL_RADIUS ball_speed_x = abs(ball_speed_x) elif ball_x + BALL_RADIUS >= WIDTH: ball_x = WIDTH - BALL_RADIUS ball_speed_x = -abs(ball_speed_x) if ball_y - BALL_RADIUS <= 0 or ball_y + BALL_RADIUS >= HEIGHT: ball_speed_y = -ball_speed_y if pygame.time.get_ticks() - accuracy_timer >= 100: total_checks += 1 cursor_x, cursor_y = pygame.mouse.get_pos() if ball_x - BALL_RADIUS < cursor_x < ball_x + BALL_RADIUS and ball_y - BALL_RADIUS < cursor_y < ball_y + BALL_RADIUS: successful_checks += 1 accuracy_timer = pygame.time.get_ticks() clock.tick(FPS) pygame.display.flip()