Prześlij pliki do 'src'

This commit is contained in:
Yevheniia Kryzhanovska 2023-04-10 19:49:05 +02:00
parent 56b6b9b2b3
commit 56c3ede67e
2 changed files with 154 additions and 68 deletions

View File

@ -1,3 +1,4 @@
import pygame
import Flower
class Bee:
# typeOfBee = None
@ -7,13 +8,22 @@ class Bee:
# product = None
def __init__(self, typeOfBee, genotype, biome, product, favFlowerColor = Flower.Flower.color):
# self.x = 64
# self.y = 64
# self.xChange = 0
# self.yChange = 0
# self.height = 64
# self.width = 64
# self.beeImg = pygame.image.load("spritesNtiles/bee64.png")
self.typeOfBee = typeOfBee
self.genotype = genotype
self.favFlowerColor = favFlowerColor
self.biome = biome
self.product = product
self.amountOfPollinatedFlowers = 0
self.favFlowerColor = favFlowerColor
self.amountOfPollinatedFlowers = 0
# def PollinateFlower(self):
# self.amountOfPollinatedFlowers = self.amountOfPollinatedFlowers + 1
# print("pollinated")

View File

@ -1,65 +1,141 @@
import pygame
import Flower
import Beehive
import Frames
pygame.init()
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)
dis = pygame.display.set_mode((800, 600))
pygame.display.set_caption('Intelegentny Pszczelarz')
#setting caption and icon
pygame.display.set_caption('Smart Bee')
setIcon = pygame.image.load('spritesNtiles/bee64.png')
pygame.display.set_icon(setIcon)
game_over = False
#
###
########################################
x1 = 300
y1 = 300
x1_change = 0
y1_change = 0
#SHORT = pygame.image.load('spritesNtiles/shortGrass64.png') #0
#TALL = pygame.image.load('spritesNtiles/tallGrass64.png') #1
#TREE = pygame.image.load('spritesNtiles/dirtTree64.png') #10
block_xy = [[100, 20], [100, 500], [700, 20], [700, 500]]
block1 = block_xy[0]
block2 = block_xy[1]
block3 = block_xy[2]
block4 = block_xy[3]
### tilemap
SHORT = 0
TALL = 1
TREE = 10
BEE = pygame.image.load('spritesNtiles/bee64.png')
tiles = {
SHORT: pygame.image.load('spritesNtiles/shortGrass64.png'),
TALL: pygame.image.load('spritesNtiles/tallGrass64.png'),
TREE: pygame.image.load('spritesNtiles/dirtTree64.png')
}
tilemap = [
[SHORT, SHORT, SHORT, TREE, SHORT, TALL, TALL, SHORT, SHORT, TREE, SHORT, SHORT, TALL, SHORT, SHORT],
[SHORT, SHORT, SHORT, TALL, TALL, SHORT, SHORT, TREE, SHORT, SHORT, SHORT, SHORT, SHORT, SHORT, SHORT],
[SHORT, SHORT, SHORT, SHORT, TALL, SHORT, SHORT, SHORT, SHORT, SHORT, SHORT, SHORT, TALL, SHORT, SHORT],
[TALL, TREE, SHORT, SHORT, SHORT, TREE, SHORT, SHORT, SHORT, SHORT, SHORT, TALL, SHORT, SHORT, TREE],
[SHORT, SHORT, SHORT, SHORT, SHORT, SHORT, SHORT, TREE, SHORT, TREE, SHORT, SHORT, SHORT, SHORT, SHORT],
[SHORT, SHORT, SHORT, SHORT, TALL, SHORT, SHORT, SHORT, SHORT, TALL, SHORT, SHORT, SHORT, SHORT, TALL],
[SHORT, SHORT, TALL, SHORT, SHORT, SHORT, SHORT, SHORT, TREE, SHORT, SHORT, TREE, SHORT, SHORT, SHORT],
[SHORT, TREE, SHORT, TREE, SHORT, SHORT, SHORT, SHORT, TALL, TALL, SHORT, SHORT, SHORT, TALL, SHORT],
[SHORT, SHORT, SHORT, SHORT, TALL, SHORT, SHORT, SHORT, SHORT, TREE, SHORT, SHORT, SHORT, SHORT, SHORT],
[TALL, SHORT, SHORT, SHORT, SHORT, SHORT, TREE, SHORT, SHORT, SHORT, SHORT, SHORT, SHORT, SHORT, TALL],
[SHORT, SHORT, SHORT, SHORT, SHORT, TREE, SHORT, SHORT, SHORT, TALL, SHORT, SHORT, SHORT, SHORT, SHORT],
[SHORT, SHORT, SHORT, SHORT, TALL, SHORT, SHORT, SHORT, SHORT, SHORT, SHORT, SHORT, TALL, SHORT, SHORT],
]
tilemapSizeY = 12
tilemapSizeX = 15
tileSize = 64
###
#calculate the window size
disX = tilemapSizeX * tileSize
disY = tilemapSizeY * tileSize
# tilemap = [
# [0, 0, 0, 10, 0, 1, 1, 0, 0, 10],
# [0, 0, 0, 1, 1, 0, 0, 10, 0, 0],
# [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
# [1, 10, 0, 0, 0, 10, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0, 0, 10, 0, 10],
# [0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
# [0, 0, 1, 0, 0, 0, 0, 0, 10, 0],
# [0, 10, 0, 10, 0, 0, 0, 0, 1, 1],
# [0, 0, 0, 0, 1, 0, 0, 0, 0, 10],
# [1, 0, 0, 0, 0, 0, 10, 0, 0, 0]
# ]
pygame.init()
dis = pygame.display.set_mode((disX, disY))
clock = pygame.time.Clock()
while not game_over:
#position of the bee and pos changings
XChanges = 0
XPosBee = 64
YChanges = 0
YPosBee = 64
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
#check to quit
if (event.type == pygame.QUIT) or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
# game_over = True
pygame.quit()
quit()
#printing map
for i in range(len(tilemap)):
for j in range(len(tilemap[i])):
dis.blit(tiles[tilemap[i][j]], (j * tileSize, i * tileSize))
#movement speed
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
XChanges = 0
YChanges = -16
if event.key == pygame.K_DOWN:
XChanges = 0
YChanges = 16
if event.key == pygame.K_LEFT:
x1_change = -10
y1_change = 0
elif event.key == pygame.K_RIGHT:
x1_change = 10
y1_change = 0
elif event.key == pygame.K_UP:
y1_change = -10
x1_change = 0
elif event.key == pygame.K_DOWN:
y1_change = 10
x1_change = 0
XChanges = -16
YChanges = 0
if event.key == pygame.K_RIGHT:
XChanges = 16
YChanges = 0
#stopmovement when a key is up
if event.type == pygame.KEYUP:
XChanges = 0
YChanges = 0
#calculating position of the bee
if disX >= XPosBee >= 0:
XPosBee = XPosBee + XChanges
if disY >= YPosBee >= 0:
YPosBee = YPosBee + YChanges
x1 += x1_change
y1 += y1_change
dis.fill(white)
pygame.draw.rect(dis, black, [x1, y1, 10, 10])
#left and up restriction
if XPosBee <= 0:
XPosBee = 0
elif XPosBee >= disX:
XPosBee = disX
elif YPosBee <= 0:
YPosBee = 0
elif YPosBee >= disY:
YPosBee = disY
if [x1,y1] in block_xy:
game_over = True
pygame.draw.rect(dis, red, [block1[0], block1[1], 20, 20])
pygame.draw.rect(dis, red, [block2[0], block2[1], 20, 20])
pygame.draw.rect(dis, red, [block3[0], block3[1], 20, 20])
pygame.draw.rect(dis, red, [block4[0], block4[1], 20, 20])
#beatiful bee
dis.blit(BEE, (XPosBee, YPosBee))
#updating
# pygame.display.flip()
pygame.display.update()
clock.tick(10000)
clock.tick(30)
pygame.quit()
quit()