https://pastein.ru/t/aRF
скопируйте уникальную ссылку для отправки
import pygame as pg
from spriteball import Ball
from random import randint
from sprite_telega import Telega
from fileMenus import Game_menu
WIDTH=1233
HEUGHT=719
FPS=60
BLACK=(0,0,0)
GREEN=(0,255,0)
RED=(255,0,0)
BLUE=(0,0,255)
pg.init()
screen=pg.display.set_mode((WIDTH,HEUGHT))
pg.display.set_caption('my game')
clock=pg.time.Clock()
pg.time.set_timer(pg.USEREVENT,2000)
f1=pg.font.SysFont('arial',25,True)
f = pg.font.SysFont('arial',25,True)
speed=10
punkts=[((WIDTH//2,HEUGHT//2),'Start',RED,BLUE,0),
((WIDTH//2,HEUGHT//2+100),'Quit',RED,BLUE,1)]
menu = Game_menu(punkts)
menu.choice_menu(screen)
score_fon=pg.image.load('images/score_fon.png')
bg=pg.image.load('images/mountain_full_background1.png')
ball_images = ({'img':'ball_lion.png','score':50},
{'img':'ball_bear.png','score':100},
{'img':'ball_fox.png','score':150},
{'img':'ball_tiger.png','score':200}
,{'img':'ball_pantera.png','score':250})
game_score = 0
def creatball(group):
x=randint(30,WIDTH-30)
index_image=randint(0,len(ball_images)-1)
speed=randint(1,5)
return Ball(x,'images/'+ball_images[index_image]['img'],ball_images[index_image]['score'],speed,group)
def collidbaalls():
global game_score
for ball in balls:
if telega.rect.collidepoint(ball.rect.centerx,ball.rect.centery):
game_score+=ball.score
ball.kill()
balls=pg.sprite.Group()
telega=Telega(WIDTH//2,HEUGHT-135,'images/telega.png',speed)
creatball(balls)
start=True
while start:
events = pg.event.get()
for event in events:
if event.type==pg.QUIT:
start=False
elif event.type == pg.USEREVENT:
creatball(balls)
screen.blit(bg,(0,0))
balls.draw(screen)
screen.blit(telega.image,telega.rect)
screen.blit(score_fon,(10,35))
score_img=f.render(str(game_score),True,GREEN)
screen.blit(score_img,(100,50))
score_f = f1.render('score', True, GREEN)
screen.blit(score_f, (20, 50))
telega.update(WIDTH)
balls.update(HEUGHT)
collidbaalls()
pg.display.flip()
clock.tick(FPS)
pg.quit()
import pygame as pg
class Telega(pg.sprite.Sprite):
'''солдаем класс Telega '''
def __init__(self,x,y, filename,speed):
pg.sprite.Sprite.__init__(self)
self.image = pg.image.load(filename).convert_alpha()
self.rect=self.image.get_rect(center=(x,y))
self.speed=speed
def update(self,*args):
keys = pg.key.get_pressed()
if keys[pg.K_a] and self.rect.x >0:
self.rect.x-=self.speed
if keys[pg.K_d] and self.rect.x+self.rect.width < args[0]:
self.rect.x += self.speed
import pygame as pg
class Ball(pg.sprite.Sprite):
'''солдаем класс Ball '''
def __init__(self,x, filename,score,speed,group):
pg.sprite.Sprite.__init__(self)
self.image = pg.image.load(filename).convert_alpha()
self.rect=self.image.get_rect(center=(x,0))
self.speed=speed
self.score=score
self.add(group)
def update(self,*args):
if self.rect.y < args[0]:
self.rect.y += self.speed
else:
self.kill()
import pygame as pg
import sys
class Game_menu():
def __init__(self,punkts=[((100,100),'Start',(255,0,0),(0,0,255),0)]):
self.punkts=punkts
def drow_menu(self,screen,num_punkt):
f = pg.font.SysFont('arial', 25, True)
for i in self.punkts:
if num_punkt == i[4]:
img1=f.render(i[1],True,i[2])
screen.blit(img1,i[0])
else:
img2 = f.render(i[1], True, i[3])
screen.blit(img2, i[0])
def choice_menu(self,screen):
num_punkt = 0
menu_start = True
while menu_start:
for event in pg.event.get():
if event.type == pg.QUIT:
sys.exit()
screen.fill((255, 255, 255))
self.drow_menu(screen, num_punkt)
pg.display.flip()