From e4a13644d29fdbf5abd62c5a02dc4ad20404ac28 Mon Sep 17 00:00:00 2001 From: Kacper Date: Thu, 30 Mar 2023 22:30:40 +0200 Subject: [PATCH] added new classes + minor changes --- 3.png => img/cabbage.png | Bin 2.png => img/carrot.png | Bin player.png => img/player.png | Bin 1.png => img/wheat.png | Bin main.py | 85 ++++++++++++++++++++++------------- 5 files changed, 53 insertions(+), 32 deletions(-) rename 3.png => img/cabbage.png (100%) rename 2.png => img/carrot.png (100%) rename player.png => img/player.png (100%) rename 1.png => img/wheat.png (100%) diff --git a/3.png b/img/cabbage.png similarity index 100% rename from 3.png rename to img/cabbage.png diff --git a/2.png b/img/carrot.png similarity index 100% rename from 2.png rename to img/carrot.png diff --git a/player.png b/img/player.png similarity index 100% rename from player.png rename to img/player.png diff --git a/1.png b/img/wheat.png similarity index 100% rename from 1.png rename to img/wheat.png diff --git a/main.py b/main.py index 46c7311..dc03ae8 100644 --- a/main.py +++ b/main.py @@ -2,9 +2,24 @@ import pygame class Field: - def __init__(self, isWet, thingOn): - self.isWet = isWet - self.thingOn = thingOn + def __init__(self, fieldType, plantType, isWet, wetTime, isFertilized, fertilizedTime): + self.fieldType = fieldType # good/bad + self.plantType = plantType # wheat/carrot/cabbage + self.isWet = isWet # yes/no + self.wetTime = wetTime # number + self.isFertilized = isFertilized # yes/no + self.fertilizedTime = fertilizedTime # number + + +class Plant: + def __init__(self, plantType, growthState): + self.plantType = plantType # wheat/carrot/cabbage + self.growthState = growthState # growing/grown + + +class Fertilizer: + def __init__(self, fertilizerType): + self.fertilizerType = fertilizerType # wheat/carrot/cabbage class Player: @@ -13,19 +28,22 @@ class Player: rotation = 0 -T = [[Field(1, 0), Field(0, 0), Field(0, 1), Field(0, 2), Field(0, 3), Field(1, 0), Field(1, 0), Field(1, 0)], - [Field(1, 0), Field(0, 0), Field(0, 1), Field(0, 2), Field(0, 3), Field(1, 0), Field(1, 0), Field(1, 0)], - [Field(1, 0), Field(0, 0), Field(0, 1), Field(0, 2), Field(0, 3), Field(1, 0), Field(1, 0), Field(1, 0)], - [Field(1, 0), Field(0, 0), Field(0, 1), Field(0, 2), Field(0, 3), Field(1, 0), Field(1, 0), Field(1, 0)], - [Field(1, 0), Field(0, 0), Field(0, 1), Field(0, 2), Field(0, 3), Field(1, 0), Field(1, 0), Field(1, 0)], - [Field(1, 0), Field(0, 0), Field(0, 1), Field(0, 2), Field(0, 3), Field(1, 0), Field(1, 0), Field(1, 0)], - [Field(1, 0), Field(0, 0), Field(0, 1), Field(0, 2), Field(0, 3), Field(1, 0), Field(1, 0), Field(1, 0)], - [Field(1, 0), Field(0, 0), Field(0, 1), Field(0, 2), Field(0, 3), Field(1, 0), Field(1, 0), Field(1, 0)]] +T = [[Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)], + [Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)], + [Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)], + [Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)], + [Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)], + [Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)], + [Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)], + [Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)], + [Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)], + [Field(1,0,0,0,0,0),Field(0,0,1,0,0,0),Field(1,1,1,0,0,0),Field(1,2,0,0,0,0),Field(0,3,1,0,0,0),Field(0,0,0,0,0,0),Field(0,0,0,0,0,0),Field(1,0,1,0,0,0),Field(1,0,0,0,0,0),Field(1,0,1,0,0,0)]] + pygame.init() player = Player() -screen = pygame.display.set_mode([500, 500]) +screen = pygame.display.set_mode([600, 600]) running = True clock = pygame.time.Clock() @@ -37,44 +55,47 @@ while running: if event.key == pygame.K_LEFT: if player.x > 0: player.x = player.x - 1 - if event.key ==pygame.K_UP: + if event.key == pygame.K_UP: if player.y > 0: player.y = player.y - 1 - if event.key ==pygame.K_RIGHT: - if player.x < 7: + if event.key == pygame.K_RIGHT: + if player.x < 9: player.x = player.x + 1 - if event.key ==pygame.K_DOWN: - if player.y < 7: + if event.key == pygame.K_DOWN: + if player.y < 9: player.y = player.y + 1 - screen.fill((178, 255, 51)) - img1 = pygame.image.load('1.png') - img2 = pygame.image.load('2.png') - img3 = pygame.image.load('3.png') - imgPlayer = pygame.image.load('player.png') + + screen.fill((175, 255, 50)) + imgWheat = pygame.image.load('img/wheat.png') + imgCarrot = pygame.image.load('img/carrot.png') + imgCabbage = pygame.image.load('img/cabbage.png') + imgPlayer = pygame.image.load('img/player.png') + i = 0 while i < len(T): j = 0 while j < len(T[i]): color = (0, 0, 0) if T[i][j].isWet == 0: - color = (160, 82, 45) + color = (160, 80, 40) else: - color = (51, 25, 0) + color = (50, 25, 0) pygame.draw.rect(screen, color, pygame.Rect(50 + 50 * i, 50 + 50 * j, 50, 50)) - if T[i][j].thingOn==1: - screen.blit(img1, (50 + 50 * i, 50 + 50 * j)) - if T[i][j].thingOn==2: - screen.blit(img2, (50 + 50 * i, 50 + 50 * j)) - if T[i][j].thingOn==3: - screen.blit(img3, (50 + 50 * i, 50 + 50 * j)) + if T[i][j].plantType == 1: + screen.blit(imgWheat, (50 + 50 * i, 50 + 50 * j)) + if T[i][j].plantType == 2: + screen.blit(imgCarrot, (50 + 50 * i, 50 + 50 * j)) + if T[i][j].plantType == 3: + screen.blit(imgCabbage, (50 + 50 * i, 50 + 50 * j)) j = j + 1 i = i + 1 i = 0 while i < len(T)+1: - pygame.draw.line(screen, (0, 0, 0), (50 + i * 50, 50), (50 + i * 50, 50 + len(T) * 50),5) - pygame.draw.line(screen, (0, 0, 0), (50, 50 + i * 50), (50 + len(T) * 50, 50 + i * 50),5) + pygame.draw.line(screen, (0, 0, 0), (50 + i * 50, 50), (50 + i * 50, 50 + len(T) * 50), 5) + pygame.draw.line(screen, (0, 0, 0), (50, 50 + i * 50), (50 + len(T) * 50, 50 + i * 50), 5) i = i + 1 + tmpImg = pygame.transform.rotate(imgPlayer, player.rotation) screen.blit(tmpImg, (55 + 50 * player.x, 55 + 50 * player.y)) pygame.display.flip() -- 2.20.1