From 7d0416f1308b780efeefcd9cc2a12a6be099e16b Mon Sep 17 00:00:00 2001 From: Maciej Niedzielski Date: Tue, 27 Apr 2021 20:28:44 +0200 Subject: [PATCH] added obstacles --- main/src/main.py | 9 +++++++ main/src/obstacle.py | 61 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 main/src/obstacle.py diff --git a/main/src/main.py b/main/src/main.py index d9b6876..71fff59 100644 --- a/main/src/main.py +++ b/main/src/main.py @@ -5,6 +5,7 @@ from trash import * from truck1 import * from walls import * from settings import * +from obstacle import * class Game: @@ -39,6 +40,14 @@ class Game: garbageTruck(self, col, row) if tile == 't': Trash(self, col, row) + if tile == 'g': + Granny(self, col, row) + if tile == 's': + Sh(self, col, row) + if tile == 'p': + Puddle(self, col, row) + if tile == 'd': + Dog(self, col, row) def run(self): self.playing = True diff --git a/main/src/obstacle.py b/main/src/obstacle.py new file mode 100644 index 0000000..286ef9e --- /dev/null +++ b/main/src/obstacle.py @@ -0,0 +1,61 @@ +import pygame as pg +from settings import TILESIZE + + +class Puddle(pg.sprite.Sprite): + def __init__(self, game, x, y): + image = pg.image.load("img\\kaluza.png") + self.groups = game.all_sprites + pg.sprite.Sprite.__init__(self, self.groups) + self.game = game + self.image = pg.Surface((TILESIZE, TILESIZE)) + self.rect = self.image.get_rect() + self.image.blit(image, (0, 0)) + self.x = x + self.y = y + self.rect.x = x * TILESIZE + self.rect.y = y * TILESIZE + + +class Dog(pg.sprite.Sprite): + def __init__(self, game, x, y): + image = pg.image.load("img\\pies.png") + self.groups = game.all_sprites + pg.sprite.Sprite.__init__(self, self.groups) + self.game = game + self.image = pg.Surface((TILESIZE, TILESIZE)) + self.rect = self.image.get_rect() + self.image.blit(image, (0, 0)) + self.x = x + self.y = y + self.rect.x = x * TILESIZE + self.rect.y = y * TILESIZE + +class Granny(pg.sprite.Sprite): + def __init__(self, game, x, y): + image = pg.image.load("img\\granny.png") + self.groups = game.all_sprites + pg.sprite.Sprite.__init__(self, self.groups) + self.game = game + self.image = pg.Surface((TILESIZE, TILESIZE)) + self.rect = self.image.get_rect() + self.image.blit(image, (0, 0)) + self.x = x + self.y = y + self.rect.x = x * TILESIZE + self.rect.y = y * TILESIZE + + +class Sh(pg.sprite.Sprite): + def __init__(self, game, x, y): + image = pg.image.load("img\\g.png") + self.groups = game.all_sprites + pg.sprite.Sprite.__init__(self, self.groups) + self.game = game + self.image = pg.Surface((TILESIZE, TILESIZE)) + self.rect = self.image.get_rect() + self.image.blit(image, (0, 0)) + self.x = x + self.y = y + self.rect.x = x * TILESIZE + self.rect.y = y * TILESIZE