0

I'm trying to make the sprite(ball) rotate in order to look realistic when I control its movement, but instead of just rotating the ball, there is a distorted clone of the ball that rotates instead of the normal ball. The game is going to be about a basketball that jumps over obstacles. Here is my program:

# Simple pygame program 

# Import and initialize the pygame library
import pygame
import time 
import random
import winsound
import sys
pygame.init()
keys = pygame.key.get_pressed()
x = (250)
y = (375)
red = (255, 0, 0)
white = (255, 255, 255)
blue = (0, 0, 255)
green = (40, 180, 76)
yellow = (255, 255, 0)
orange = (255, 165, 0)
loop = 2
obx = 600
oby = 350
angle = 0
WIDTH = 50
HEIGHT = 50

# Set up the drawing window
screen = pygame.display.set_mode([1500, 775])
pygame.display.set_caption("Game")
# Speed
speed = (3)
# Run until the user asks to quit
running = True
while running:
    # Did the user click the window close button?
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Fill the background with blue
    screen.fill((200, 200, 255))

    # Draw the ball
    
    ball = pygame.image.load(r'C:\Users\xenia\Desktop\Python Games\game\basketball.png')
    screen.blit(ball, (x, y))
    ball = pygame.transform.rotate(ball, angle)
    rect0 = ball.get_rect
    #rect0.center=(WIDTH//2, HEIGHT//2)

    ball = pygame.transform.scale(ball, (200, 20))
    screen.blit(ball, (x, y))
    ball = pygame.transform.rotate(ball, angle)
    # Draw the terrain

    grass = pygame.draw.rect(screen,green,(0, 425, 1000000000, 4000))
    image1 = pygame.image.load(r'C:\Users\xenia\Desktop\Python Games\game\terrain..jpg')
    screen.blit(image1, (0, 425))
    ob = pygame.image.load(r'C:\Users\xenia\Desktop\Python Games\game\obstacle.jpg')
    obe = ob.get_rect()
    screen.blit(ob, (obx, oby))
    # Key gets pressed
    keys = pygame.key.get_pressed()
    pygame.transform.rotate(ball, angle)
    # If left arrow key is pressed then move left
    
    if keys[pygame.K_LEFT] and x>0:

        #dicrease x coordinate to move left
        angle -= 2
        x -= speed
        if x <= obx and x <= 750:
            obx += 0.1
            obx += 0.1
            obx += 0.1
            obx += 0.1
        if x >= obx and x >= 750:
            obx += 0.1
            obx += 0.1
            obx += 0.1
            obx += 0.1

Image with the error Image with the error

What is wrong with the program?

ti7
  • 16,375
  • 6
  • 40
  • 68
ItzMeNick
  • 1
  • 1

0 Answers0