import pygame
 
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
crators = []
 
FPS = 60
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 420
 
pygame.init()
sc = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
clock = pygame.time.Clock()
 
pygame.display.update()
 
class Bully:
    def __init__(self, string):
        self.string = string
        self.stringLen = len(self.string)
        self.editedString = self.string
        self.tick = 0
        self.sec = 0
 
    def tickT(self):
        self.tick += 1
 
        if self.tick == 30:
            self.edit(self.sec)
 
            self.sec += 1
            self.tick = 0
 
        if self.sec == self.stringLen:
            self.sec = 0
 
    def edit(self, charPos):
        a = self.string[:charPos]
        b = self.string[charPos:].capitalize()
        self.editedString = a+b
 
    def __str__(self):
        return self.editedString
 
class Cross:
    def __init__(self, scene, color):
        self.master = scene
        self.color = color
        self.x = 0
        self.y = 0
 
    def updateCross(self, position):
        pygame.draw.rect(self.master, self.color,
                         (position[0] - 10, position[1] - 1, 7, 2))
 
        pygame.draw.rect(self.master, self.color,
                         (position[0] + 3, position[1] - 1, 7, 2))
 
        pygame.draw.rect(self.master, self.color,
                         (position[0] - 1, position[1] - 10, 2, 7))
 
        pygame.draw.rect(self.master, self.color,
                         (position[0] - 1, position[1] + 3, 2, 7))
 
class Bullet:
    inActive = 0
    def __init__(self, scene, radius=3, speed=5, mass=5):
        self.speed = speed
        self.mass = mass
        self.radius = radius
        self.master = scene
        self.color = RED
        self.x = 0
        self.y = 0
        self.yCross = 0
 
    def shoot(self, position):
        if Bullet.inActive == 0:
            Bullet.inActive = 1
            self.x = position[0]
            self.y = SCREEN_HEIGHT
            self.yCross = position[1]
            self.bullet = pygame.draw.circle(self.master, self.color, (self.x, self.y), self.radius)
 
 
    def updateBullet(self):
        if Bullet.inActive == 1:
            self.y -= self.speed
 
            if self.y <= self.yCross + self.mass and self.y >= self.yCross - self.mass:
                Bullet.inActive = 0
                crators.append([self.x, self.y, self.mass])
            else:
                self.bullet = pygame.draw.circle(self.master, self.color, (self.x, self.y), self.radius)
 
 
t = Bully("PyGame Text Animation wat")
c = Cross(sc, RED)
b = Bullet(sc)
 
while True:
    sc.fill(WHITE)
    pygame.mouse.set_visible(0)
    clock.tick(FPS)
 
    for j in crators:
        pygame.draw.circle(sc, BLACK, (j[0], j[1]), j[2])
 
    for i in pygame.event.get():
        if i.type == pygame.QUIT:
            exit()
 
    if pygame.mouse.get_focused():
        c.updateCross(pygame.mouse.get_pos())
        if i.type == pygame.MOUSEBUTTONDOWN:
            if i.button == 1:
                b.shoot(pygame.mouse.get_pos())
 
    b.updateBullet()
    t.tickT()
 
    pygame.display.set_caption(str(t))
    pygame.display.update()

Ограниченный HTML

  • Допустимые HTML-теги: <p> <br> <em> <strong> <ul> <ol> <li> <pre> <code>
  • Для синтаксической подсветки исходного кода следует использовать теги: <pre>, <code>, <bash>, <c>, <java>, <pycon>, <python>.
CAPTCHA
Этот вопрос задается для того, чтобы выяснить, являетесь ли Вы человеком или представляете из себя автоматическую спам-рассылку.