154
pygame.display.flip()
clock.tick(60)
pygame.quit()
Car_new.py
import pygame
WHITE = (255, 255, 255)
class Car(pygame.sprite.Sprite):
def __init__(self, color, width, height,
speed):
super().__init__()
self.image = pygame.Surface([width, height])
self.image.fill(WHITE)
self.image.set_colorkey(WHITE)
self.width=width
self.height=height
self.color = color
self.speed = speed
pygame.draw.rect(self.image,
self.color,
[0, 0, self.width, self.height])
self.rect = self.image.get_rect()
def moveRight(self, pixels):
self.rect.x += pixels
def moveLeft(self, pixels):
self.rect.x -= pixels
def moveForward(self, speed):
self.rect.y += self.speed * speed / 20
def moveBackward(self, speed):
self.rect.y -= self.speed * speed / 20
Достарыңызбен бөлісу: