new method: land, new action: dead grass: when you underwater the grass it changes the state. (losing points in the future score updates)
This commit is contained in:
parent
01e5015b0a
commit
24497254d7
25
land.py
Normal file
25
land.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
|
||||||
|
class Land:
|
||||||
|
def __init__(self, cell_size, cell_number, grass_body):
|
||||||
|
self.grass_image = pygame.image.load(r'resources/grass.png').convert()
|
||||||
|
self.grass_image = pygame.transform.scale(self.grass_image, (cell_size, cell_size))
|
||||||
|
|
||||||
|
self.bad_grass_image = pygame.image.load(r'resources/bad_grass.png').convert()
|
||||||
|
self.bad_grass_image = pygame.transform.scale(self.bad_grass_image, (cell_size, cell_size))
|
||||||
|
|
||||||
|
for i in range(0, cell_number):
|
||||||
|
for k in range(0, cell_number):
|
||||||
|
grass_body.append([i,k])
|
||||||
|
|
||||||
|
|
||||||
|
def place_grass(self, parent_screen, cell_number, cell_size, grass_body, name):
|
||||||
|
for body in grass_body:
|
||||||
|
x = int(body[0] * cell_size)
|
||||||
|
y = int(body[1] * cell_size)
|
||||||
|
if(name == 'good'):
|
||||||
|
parent_screen.blit(self.grass_image, (x, y))
|
||||||
|
if(name == 'bad'):
|
||||||
|
parent_screen.blit(self.bad_grass_image, (x, y))
|
||||||
|
|
19
main.py
19
main.py
@ -1,5 +1,6 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import random
|
import random
|
||||||
|
import land
|
||||||
import tractor
|
import tractor
|
||||||
import blocks
|
import blocks
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
@ -16,6 +17,8 @@ class Game:
|
|||||||
self.green_leaf_body = []
|
self.green_leaf_body = []
|
||||||
self.stone_body = []
|
self.stone_body = []
|
||||||
self.flower_body = []
|
self.flower_body = []
|
||||||
|
self.dead_grass_body = []
|
||||||
|
self.grass_body = []
|
||||||
|
|
||||||
|
|
||||||
self.entire_block = {}
|
self.entire_block = {}
|
||||||
@ -23,11 +26,7 @@ class Game:
|
|||||||
pygame.init()
|
pygame.init()
|
||||||
self.surface = pygame.display.set_mode((self.cell_size*self.cell_number, self.cell_size*self.cell_number)) # initialize a window
|
self.surface = pygame.display.set_mode((self.cell_size*self.cell_number, self.cell_size*self.cell_number)) # initialize a window
|
||||||
|
|
||||||
self.grass_image = pygame.image.load(r'resources/grass.png').convert()
|
self.land = land.Land(self.cell_size, self.cell_number, self.grass_body)
|
||||||
self.grass_image = pygame.transform.scale(self.grass_image, (self.cell_size, self.cell_size))
|
|
||||||
|
|
||||||
self.bad_grass_image = pygame.image.load(r'resources/bad_grass.png').convert()
|
|
||||||
self.bad_grass_image = pygame.transform.scale(self.bad_grass_image, (self.cell_size, self.cell_size))
|
|
||||||
|
|
||||||
self.blocks = blocks.Blocks(self.surface,self.cell_size)
|
self.blocks = blocks.Blocks(self.surface,self.cell_size)
|
||||||
|
|
||||||
@ -62,17 +61,15 @@ class Game:
|
|||||||
self.tractor.move('right',self.cell_size, self.cell_number)
|
self.tractor.move('right',self.cell_size, self.cell_number)
|
||||||
if pygame.key.get_pressed()[K_SPACE]:
|
if pygame.key.get_pressed()[K_SPACE]:
|
||||||
self.tractor.water(self.dead_leaf_body, self.green_leaf_body, self.cell_size)
|
self.tractor.water(self.dead_leaf_body, self.green_leaf_body, self.cell_size)
|
||||||
|
#self.tractor.water(self.grass_body, self.dead_grass_body, self.cell_size)
|
||||||
|
|
||||||
elif event.type == QUIT:
|
elif event.type == QUIT:
|
||||||
running = False
|
running = False
|
||||||
|
|
||||||
self.surface.fill((140, 203, 97)) # background color
|
self.surface.fill((140, 203, 97)) # background color
|
||||||
|
|
||||||
for i in range(0, self.cell_number):
|
self.land.place_grass(self.surface, self.cell_number, self.cell_size, self.grass_body, 'good')
|
||||||
for k in range(0, self.cell_number):
|
#self.land.place_grass(self.surface, self.cell_number, self.cell_size, self.dead_grass_body, 'bad')
|
||||||
x = int(i * self.cell_size)
|
|
||||||
y = int(k * self.cell_size)
|
|
||||||
self.surface.blit(self.grass_image, (x, y))
|
|
||||||
|
|
||||||
|
|
||||||
self.blocks.place_blocks(self.surface, self.cell_size, self.dead_leaf_body, 'leaf')
|
self.blocks.place_blocks(self.surface, self.cell_size, self.dead_leaf_body, 'leaf')
|
||||||
self.blocks.place_blocks(self.surface, self.cell_size, self.green_leaf_body, 'alive')
|
self.blocks.place_blocks(self.surface, self.cell_size, self.green_leaf_body, 'alive')
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 1.4 KiB |
@ -1,6 +1,5 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import random
|
import random
|
||||||
from pygame.math import Vector2
|
|
||||||
|
|
||||||
class Tractor:
|
class Tractor:
|
||||||
def __init__(self, parent_screen, cell_size):
|
def __init__(self, parent_screen, cell_size):
|
||||||
|
Loading…
Reference in New Issue
Block a user