Bat flying test pydroid

import pygame
import math
import sys

# Initialize Pygame
pygame.init()

# Set screen size
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption(“Flying Bat”)

clock = pygame.time.Clock()

# Bat position
x = 0
y = HEIGHT // 2

# Wing flap variables
wing_angle = 0
flap_speed = 0.15

# Colors
BLACK = (0, 0, 0)
DARK_GREY = (50, 50, 50)
WHITE = (255, 255, 255)

def draw_bat(surface, x, y, angle):
    body_width = 40
    body_height = 20

    # Draw bat body
    pygame.draw.ellipse(surface, DARK_GREY, (x, y, body_width, body_height))

    # Left wing
    left_points = [
        (x + 10, y + 10),
        (x – 30, y – 10 – int(math.sin(angle) * 20)),
        (x – 10, y + 10),
    ]
    pygame.draw.polygon(surface, DARK_GREY, left_points)

    # Right wing
    right_points = [
        (x + 30, y + 10),
        (x + 70, y – 10 – int(math.sin(angle) * 20)),
        (x + 50, y + 10),
    ]
    pygame.draw.polygon(surface, DARK_GREY, right_points)

# Main loop
running = True
while running:
    screen.fill(BLACK)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Animate
    wing_angle += flap_speed
    x += 3
    if x > WIDTH:
        x = -60  # Reset when offscreen

    draw_bat(screen, x, y + int(math.sin(wing_angle) * 10), wing_angle)

    pygame.display.flip()
    clock.tick(60)

pygame.quit()
sys.exit()

Leave a Reply