static plants added

This commit is contained in:
countingthedots 2023-03-28 21:32:07 +02:00
parent 7358cb73fe
commit 77feab6a4e
4 changed files with 38 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

View File

@ -20,6 +20,13 @@ def initial_draw(window_dimensions, board_size):
newGrid = Grid(board_size, window_dimensions=window_dimensions, board_size=board_size) newGrid = Grid(board_size, window_dimensions=window_dimensions, board_size=board_size)
newGrid.add(objectOnTile(1, 1, acceptedType.PLAYER)) newGrid.add(objectOnTile(1, 1, acceptedType.PLAYER))
newGrid.add(objectOnTile(7, 8, acceptedType.ANIMAL)) newGrid.add(objectOnTile(7, 8, acceptedType.ANIMAL))
newGrid.add(objectOnTile(2, 8, acceptedType.PLANT1))
newGrid.add(objectOnTile(4, 1, acceptedType.PLANT1))
newGrid.add(objectOnTile(3, 4, acceptedType.PLANT2))
newGrid.add(objectOnTile(8, 8, acceptedType.PLANT2))
newGrid.add(objectOnTile(9, 3, acceptedType.PLANT3))
player = newGrid.findFirst(acceptedType.PLAYER) player = newGrid.findFirst(acceptedType.PLAYER)
newGrid.move(1, 1, 1, 2) newGrid.move(1, 1, 1, 2)
newGrid.move(1, 2, 1, 1) newGrid.move(1, 2, 1, 1)
@ -52,7 +59,9 @@ class acceptedType(Enum):
EMPTY = "empty" EMPTY = "empty"
PLAYER = "player" PLAYER = "player"
RUBBISH = "rubbish" RUBBISH = "rubbish"
PLANT = "plant" PLANT1 = "plant1"
PLANT2 = "plant2"
PLANT3 = "plant3"
ANIMAL = "animal" ANIMAL = "animal"
@ -79,6 +88,7 @@ class Grid:
self.list: List[objectOnTile] = [] self.list: List[objectOnTile] = []
self.tile_size = window_dimensions / board_size self.tile_size = window_dimensions / board_size
self.board_size = board_size
self.cat_last_tick = pygame.time.get_ticks() self.cat_last_tick = pygame.time.get_ticks()
self.cat_cooldown = 1000 self.cat_cooldown = 1000
@ -91,6 +101,9 @@ class Grid:
self.cat_left_image = pygame.transform.scale(pygame.image.load("Interface/images/cat/standing_left.png"), (self.tile_size, self.tile_size)) self.cat_left_image = pygame.transform.scale(pygame.image.load("Interface/images/cat/standing_left.png"), (self.tile_size, self.tile_size))
self.cat_right_image = pygame.transform.scale(pygame.image.load("Interface/images/cat/standing_right.png"), (self.tile_size, self.tile_size)) self.cat_right_image = pygame.transform.scale(pygame.image.load("Interface/images/cat/standing_right.png"), (self.tile_size, self.tile_size))
self.cat_current_image = self.cat_front_image self.cat_current_image = self.cat_front_image
self.plant1 = pygame.transform.scale(pygame.image.load("Interface/images/plants/plant1.png"), (self.tile_size + self.tile_size/4, self.tile_size + self.tile_size/4))
self.plant2 = pygame.transform.scale(pygame.image.load("Interface/images/plants/plant2.png"), (self.tile_size + self.tile_size/4, self.tile_size + self.tile_size/4))
self.plant3 = pygame.transform.scale(pygame.image.load("Interface/images/plants/plant3.png"), (self.tile_size + self.tile_size/4, self.tile_size + self.tile_size/4))
#endregion #endregion
# render the array # render the array
@ -123,8 +136,12 @@ class Grid:
now = pygame.time.get_ticks() now = pygame.time.get_ticks()
#region cat random movement #region cat random movement
if now - self.cat_last_tick >= self.cat_cooldown: if now - self.cat_last_tick >= self.cat_cooldown:
if self.cat_busy == False: if self.cat_busy == False:
self.cat_direction = random.randint(0,3) while True:
self.cat_direction = random.randint(0,3)
if not((self.cat_direction == 0 and item.position_y == 0) or (self.cat_direction == 1 and item.position_x == self.board_size - 1) or (self.cat_direction == 2 and item.position_y == self.board_size - 1) or (self.cat_direction == 3 and item.position_x == 0)):
break
if self.cat_direction == 0: #up if self.cat_direction == 0: #up
if self.cat_current_image == self.cat_back_image: if self.cat_current_image == self.cat_back_image:
@ -162,7 +179,16 @@ class Grid:
drawer.image(render_x, render_y, self.cat_current_image) drawer.image(render_x, render_y, self.cat_current_image)
# TODO act accordingly to other options if item.type == acceptedType.PLANT1:
drawer.image((item.position_x - 0.1) * self.tile_size, (item.position_y - 0.25) * self.tile_size, self.plant1)
if item.type == acceptedType.PLANT2:
drawer.image((item.position_x - 0.1) * self.tile_size, (item.position_y - 0.25) * self.tile_size, self.plant2)
if item.type == acceptedType.PLANT3:
drawer.image((item.position_x - 0.1) * self.tile_size, (item.position_y - 0.25) * self.tile_size, self.plant3)
# TODO act accordingly to other options(rubbish)
# add new object on grid # add new object on grid
def add(self, newObject: objectOnTile): def add(self, newObject: objectOnTile):
@ -200,6 +226,13 @@ class Grid:
if start_x == end_x and start_y == end_y: if start_x == end_x and start_y == end_y:
return return
#check if object moves beyond border
if end_x > self.board_size - 1 or end_y > self.board_size - 1 or end_x < 0 or end_y < 0:
print(
f"Cannot move object beyond board"
)
return
# check if obj exist at starting position # check if obj exist at starting position
if self.array[start_x][start_y].type == acceptedType.EMPTY: if self.array[start_x][start_y].type == acceptedType.EMPTY:
print( print(
@ -214,6 +247,8 @@ class Grid:
) )
return return
# all OK # all OK
# change position attribute in array # change position attribute in array
self.array[start_x][start_y].position_x = end_x self.array[start_x][start_y].position_x = end_x