Загрузка данных
import sys
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
clock = pygame.time.Clock()
run = True
ground = [
[1, 1, 1, 1],
[1, 1, 1, 1],
[3, 1, 1, 2],
]
ground1 = [
[2, 2, 2, 2, 2],
[2, 3, 2, 2, 2],
[2, 2, 2, 2, 2],
[2, 2, 2, 3, 2],
[3, 2, 2, 2, 2]
]
magdesk = [1, 1, 1]
x1 = 400
y1 = 300
w1 = 8
h1 = 15
w2 = 8
h2 = 15
leg1 = True
leg12 = True
leg2 = True
leg22 = True
shag = 0
tx1 = 390
tx2 = 402
money = 10
magaz = False
my_font = pygame.font.SysFont('Comic Sans MS', 30)
fontprice = pygame.font.SysFont('Arial', 24)
invent = False
pech = False
mestopech = [0]
timer = False
time = 10
def psheno(x, y):
pygame.draw.rect(screen, (255, 215, 0), (x, y, 5, 40))
pygame.draw.rect(screen, (255, 215, 0), (x + 5, y + 8, 10, 5))
pygame.draw.rect(screen, (255, 215, 0), (x - 10, y + 15, 10, 5))
pygame.draw.rect(screen, (255, 215, 0), (x + 5, y + 25, 10, 5))
def tablo(z):
pygame.draw.rect(screen, (0, 0, 0), (100, z * 150 + 100, 1, 75))
pygame.draw.rect(screen, (0, 0, 0), (600, z * 150 + 100, 1, 75))
pygame.draw.rect(screen, (0, 0, 0), (100, z * 150 + 100, 500, 1))
pygame.draw.rect(screen, (0, 0, 0), (100, z * 150 + 175, 500, 1))
pygame.draw.rect(screen, (0, 0, 0), (110, z * 150 + 110, 55, 1))
pygame.draw.rect(screen, (0, 0, 0), (110, z * 150 + 110, 1, 55))
pygame.draw.rect(screen, (0, 0, 0), (110, z * 150 + 165, 55, 1))
pygame.draw.rect(screen, (0, 0, 0), (165, z * 150 + 110, 1, 55))
inv = []
while run:
screen.fill((0, 0, 0))
for z in range(3):
for w in range(4):
if ground[z][w] == 1:
for x in range(5):
for y in range(5):
if ground1[x][y] == 2:
pygame.draw.rect(screen, (74, 120, 35), ((w * 200) + x * 40 + 2, (z * 200) + y * 40 + 2, 36, 36))
if ground1[x][y] == 3:
pygame.draw.rect(screen, (85, 107, 47), ((w * 200) + x * 40 + 2, (z * 200) + y * 40 + 2, 36, 36))
if ground[z][w] == 2:
pygame.draw.rect(screen, (105, 105, 105), (600, 400, 200, 200))
if ground[z][w] == 3:
pygame.draw.rect(screen, (150, 105, 0), (0, 400, 200, 200))
pygame.draw.rect(screen, (255, 255, 255), (0, 0, 200, 75))
textshop = my_font.render(f'Магазин', True, (255, 255, 255))
textmoney = my_font.render(f'' + str(money) + '$', True, (0, 255, 0))
textpech = my_font.render(f'Печь', True, (255, 255, 255))
if (pygame.draw.rect(screen, (200, 0, 0), (tx1, y1 + 34, w1, h1)).colliderect(pygame.draw.rect(screen, (105, 105, 105), (600, 400, 200, 200))) or
pygame.draw.rect(screen, (200, 0, 0), (tx2, y1 + 34, w2, h2)).colliderect(pygame.draw.rect(screen, (105, 105, 105), (600, 400, 200, 200))) or
pygame.draw.rect(screen, (0, 120, 200), (x1 + 10, y1 + 9, 7, 15)).colliderect(pygame.draw.rect(screen, (105, 105, 105), (600, 400, 200, 200)))):
x1 = 400
y1 = 300
w1 = 8
h1 = 15
w2 = 8
h2 = 15
leg1 = True
leg12 = True
leg2 = True
leg22 = True
shag = 0
tx1 = 390
tx2 = 402
magaz = True
shagtime = 0
if (pygame.draw.rect(screen, (200, 0, 0), (tx1, y1 + 34, w1, h1)).colliderect(pygame.draw.rect(screen, (150, 105, 0), (0, 400, 200, 200))) or
pygame.draw.rect(screen, (200, 0, 0), (tx2, y1 + 34, w2, h2)).colliderect(pygame.draw.rect(screen, (150, 105, 0), (0, 400, 200, 200))) or
pygame.draw.rect(screen, (0, 120, 200), (x1 - 17, y1 + 9, 7, 15)).colliderect(pygame.draw.rect(screen, (150, 105, 0), (0, 400, 200, 200)))):
x1 = 400
y1 = 300
w1 = 8
h1 = 15
w2 = 8
h2 = 15
leg1 = True
leg12 = True
leg2 = True
leg22 = True
shag = 0
tx1 = 390
tx2 = 402
pech = True
screen.blit(textmoney, (10, 15))
screen.blit(textshop, (640, 475))
screen.blit(textpech, (60, 475))
pygame.draw.circle(screen, (241, 194, 125), (x1, y1), 9)
pygame.draw.rect(screen, (0, 50, 200), (x1 - 10, y1 + 9, 20, 25))
pygame.draw.rect(screen, (0, 120, 200), (x1 - 17, y1 + 9, 7, 15))
pygame.draw.rect(screen, (0, 120, 200), (x1 + 10, y1 + 9, 7, 15))
pygame.draw.rect(screen, (200, 0, 0), (tx1, y1 + 34, w1, h1))
pygame.draw.rect(screen, (200, 0, 0), (tx2, y1 + 34, w2, h2))
keys = pygame.key.get_pressed()
while magaz:
screen.fill((255, 255, 255))
for event in pygame.event.get():
if event.type == pygame.QUIT:
magaz = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
evx1 = event.pos[0]
evy1 = event.pos[1]
if 495 <= evx1 <= 585 and 140 <= evy1 <= 170:
if money >= 10:
if len(inv) < 5:
inv.append(1)
money -= 10
print('Добавлено')
else:
inv = inv
print('Нету места')
else:
print('Нету денег')
if 495 <= evx1 <= 585 and 105 <= evy1 <= 135:
if 2 in inv:
money += 15
inv.remove(2)
for xxx in range(3):
if magdesk[xxx] == 1:
tablo(xxx)
psheno(134, 120)
texttowar = my_font.render(f'Пшено', True, (0, 0, 0))
screen.blit(texttowar, (180, 100))
textmoney = my_font.render(f'' + str(money) + '$', True, (0, 255, 0))
screen.blit(textmoney, (10, 550))
textprice = my_font.render(f'10$', True, (0, 255, 0))
screen.blit(textprice, (300, 100))
pygame.draw.rect(screen, (0, 255, 0), (495, 140, 90, 30))
textkup = fontprice.render(f'Купить', True, (255, 255, 255))
screen.blit(textkup, (500, 140))
pygame.draw.rect(screen, (0, 255, 0), (495, 105, 90, 30))
textsell = fontprice.render(f'Продать', True, (255, 255, 255))
screen.blit(textsell, (495, 105))
pygame.display.flip()
clock.tick(30)
if magaz == False and pech == False:
while invent:
screen.fill((0, 0, 0))
for mesto in range(5):
pygame.draw.rect(screen, (255, 255, 255), (mesto * 125 + 100, 100, 55, 1))
pygame.draw.rect(screen, (255, 255, 255), (mesto * 125 + 100, 100, 1, 55))
pygame.draw.rect(screen, (255, 255, 255), (mesto * 125 + 155, 100, 1, 55))
pygame.draw.rect(screen, (255, 255, 255), (mesto * 125 + 100, 155, 55, 1))
for into in range(len(inv)):
if inv[into] == 1:
psheno(into * 125 + 127, 107)
if inv[into] == 2:
pygame.draw.rect(screen, (255, 140, 0), (into * 125 + 110, 115, 35, 25))
for event in pygame.event.get():
if event.type == pygame.QUIT:
invent = False
pygame.display.flip()
clock.tick(30)
while pech:
screen.fill((180, 185, 190))
texttimer = my_font.render(f'' + str(time) + ' сек', True, (0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pech = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
evx2 = event.pos[0]
evy2 = event.pos[1]
if 350 <= evx2 <= 490 and 250 <= evy2 <= 290:
if 1 in inv and mestopech[0] == 0:
inv.remove(1)
mestopech[0] = 1
timer = True
pygame.draw.rect(screen, (255, 255, 255), (100, 100, 400, 200))
pygame.draw.rect(screen, (0, 0, 0), (110, 110, 55, 1))
pygame.draw.rect(screen, (0, 0, 0), (110, 110, 1, 55))
pygame.draw.rect(screen, (0, 0, 0), (110, 165, 55, 1))
pygame.draw.rect(screen, (0, 0, 0), (165, 110, 1, 55))
pygame.draw.rect(screen, (0, 0, 0), (100, 100, 400, 1))
pygame.draw.rect(screen, (0, 0, 0), (100, 100, 1, 200))
pygame.draw.rect(screen, (0, 0, 0), (100, 300, 400, 1))
pygame.draw.rect(screen, (0, 0, 0), (500, 100, 1, 200))
pygame.draw.rect(screen, (0, 0, 0), (350, 250, 140, 40))
for mesto in range(5):
pygame.draw.rect(screen, (0, 0, 0), (mesto * 125 + 100, 400, 55, 1))
pygame.draw.rect(screen, (0, 0, 0), (mesto * 125 + 100, 400, 1, 55))
pygame.draw.rect(screen, (0, 0, 0), (mesto * 125 + 155, 400, 1, 55))
pygame.draw.rect(screen, (0, 0, 0), (mesto * 125 + 100, 455, 55, 1))
for into in range(len(inv)):
if inv[into] == 1:
psheno(into * 125 + 127, 407)
if inv[into] == 2:
pygame.draw.rect(screen, (255, 140, 0), (into * 125 + 110, 415, 35, 25))
if mestopech[0] == 1:
psheno(134, 117)
if timer == True:
screen.blit(texttimer, (300, 110))
shagtime += 1
if shagtime == 30:
time -= 1
shagtime = 0
if time == 0:
timer = False
time = 10
mestopech[0] = 0
inv.append(2)
textpolo = fontprice.render(f'Положить', True, (255, 255, 255))
screen.blit(textpolo, (360, 255))
pygame.display.flip()
clock.tick(30)
if keys[pygame.K_a]:
x1 -= 2
tx1 -= 2
tx2 -= 2
shag += 1
if shag == 10:
tx1 -= 7
w1 = 15
h1 = 8
if shag == 20:
tx1 = x1 - 10
w1 = 8
h1 = 15
if shag == 30:
tx2 -= 7
w2 = 15
h2 = 8
if shag == 40:
tx2 = x1 + 2
w2 = 8
h2 = 15
shag = 0
elif keys[pygame.K_d]:
x1 += 2
tx1 += 2
tx2 += 2
shag += 1
if shag == 10:
w2 = 15
h2 = 8
if shag == 20:
w2 = 8
h2 = 15
if shag == 30:
w1 = 15
h1 = 8
if shag == 40:
w1 = 8
h1 = 15
shag = 0
elif keys[pygame.K_w]:
y1 -= 2
elif keys[pygame.K_s]:
y1 += 2
else:
w1 = 8
h1 = 15
w2 = 8
h2 = 15
shag = 0
tx1 = x1 - 10
tx2 = x1 + 2
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_e:
invent = True
pygame.display.flip()
clock.tick(60)
pygame.quit()