diff --git a/main/src/__pycache__/bfs.cpython-38.pyc b/main/src/__pycache__/bfs.cpython-38.pyc deleted file mode 100644 index 94d45fc..0000000 Binary files a/main/src/__pycache__/bfs.cpython-38.pyc and /dev/null differ diff --git a/main/src/__pycache__/bfs.cpython-39.pyc b/main/src/__pycache__/bfs.cpython-39.pyc deleted file mode 100644 index 6b65ee1..0000000 Binary files a/main/src/__pycache__/bfs.cpython-39.pyc and /dev/null differ diff --git a/main/src/__pycache__/settings.cpython-38.pyc b/main/src/__pycache__/settings.cpython-38.pyc deleted file mode 100644 index aeffc6f..0000000 Binary files a/main/src/__pycache__/settings.cpython-38.pyc and /dev/null differ diff --git a/main/src/__pycache__/settings.cpython-39.pyc b/main/src/__pycache__/settings.cpython-39.pyc deleted file mode 100644 index 753cedf..0000000 Binary files a/main/src/__pycache__/settings.cpython-39.pyc and /dev/null differ diff --git a/main/src/__pycache__/trash.cpython-38.pyc b/main/src/__pycache__/trash.cpython-38.pyc deleted file mode 100644 index 69ed6e2..0000000 Binary files a/main/src/__pycache__/trash.cpython-38.pyc and /dev/null differ diff --git a/main/src/__pycache__/trash.cpython-39.pyc b/main/src/__pycache__/trash.cpython-39.pyc deleted file mode 100644 index d706826..0000000 Binary files a/main/src/__pycache__/trash.cpython-39.pyc and /dev/null differ diff --git a/main/src/__pycache__/truck.cpython-38.pyc b/main/src/__pycache__/truck.cpython-38.pyc deleted file mode 100644 index fb084ea..0000000 Binary files a/main/src/__pycache__/truck.cpython-38.pyc and /dev/null differ diff --git a/main/src/__pycache__/truck1.cpython-38.pyc b/main/src/__pycache__/truck1.cpython-38.pyc deleted file mode 100644 index edbf9a2..0000000 Binary files a/main/src/__pycache__/truck1.cpython-38.pyc and /dev/null differ diff --git a/main/src/__pycache__/truck1.cpython-39.pyc b/main/src/__pycache__/truck1.cpython-39.pyc deleted file mode 100644 index 4e95f86..0000000 Binary files a/main/src/__pycache__/truck1.cpython-39.pyc and /dev/null differ diff --git a/main/src/__pycache__/walls.cpython-38.pyc b/main/src/__pycache__/walls.cpython-38.pyc deleted file mode 100644 index e926528..0000000 Binary files a/main/src/__pycache__/walls.cpython-38.pyc and /dev/null differ diff --git a/main/src/__pycache__/walls.cpython-39.pyc b/main/src/__pycache__/walls.cpython-39.pyc deleted file mode 100644 index d928995..0000000 Binary files a/main/src/__pycache__/walls.cpython-39.pyc and /dev/null differ diff --git a/main/src/bfs.py b/main/src/bfs.py deleted file mode 100644 index 3a17379..0000000 --- a/main/src/bfs.py +++ /dev/null @@ -1,75 +0,0 @@ -import pygame as pg -import sys -from os import path -from collections import deque -from time import sleep - - -def bfs(): - class Map: - def __init__(self, x, y, state): - self.x = x - self.y = y - self.pos = [self.x, self.y] - self.nodes = [] - self.prev = None - self.wall = False if state not in ('b', 'w') else True - self.visited = False - - def add_nodes(self, arr): - if self.x < len(map_raw)-1: - self.nodes.append(arr[self.x+1][self.y]) - if self.x > 0: - self.nodes.append(arr[self.x-1][self.y]) - if self.y < len(map_raw[0])-1: - self.nodes.append(arr[self.x][self.y+1]) - if self.y > 0: - self.nodes.append(arr[self.x][self.y-1]) - - def __str__(self): - return f'{self.x}, {self.y}' - - game_path = path.join(path.dirname(__file__), 'map.txt') - - map_raw = [line.strip() for line in open(game_path, 'rt')] - map_arr = [] - queue = deque() - bfs_path = [] - - truck = [0, 0] - trash = [0, 0] - - for x in range(len(map_raw)): - temp = [] - for y in range(len(map_raw[0])): - temp.append(Map(x, y, map_raw[x][y])) - if map_raw[x][y] == 'P': - truck = temp[-1] - if map_raw[x][y] == 't': - trash = temp[-1] - map_arr.append(temp) - - for x in range(len(map_raw)): - for y in range(len(map_raw[0])): - map_arr[x][y].add_nodes(map_arr) - - queue.append(truck) - - while True: - if len(queue) > 0: - cur_node = queue.popleft() - cur_node.visited = True - if cur_node == trash: - temp = cur_node - while temp.prev: - bfs_path.append(temp.prev) - temp = temp.prev - break - else: - for node in cur_node.nodes: - if not node.visited and not node.wall: - node.visited = True - node.prev = cur_node - queue.append(node) - - return [node.pos for node in bfs_path[:-1]] diff --git a/main/src/img/bg.png b/main/src/img/bg.png deleted file mode 100644 index c5f9eb8..0000000 Binary files a/main/src/img/bg.png and /dev/null differ diff --git a/main/src/img/g.png b/main/src/img/g.png deleted file mode 100644 index ccf2bcb..0000000 Binary files a/main/src/img/g.png and /dev/null differ diff --git a/main/src/img/granny.png b/main/src/img/granny.png deleted file mode 100644 index 64dd1ee..0000000 Binary files a/main/src/img/granny.png and /dev/null differ diff --git a/main/src/img/house.png b/main/src/img/house.png deleted file mode 100644 index 909c694..0000000 Binary files a/main/src/img/house.png and /dev/null differ diff --git a/main/src/img/house1.png b/main/src/img/house1.png deleted file mode 100644 index cf9c5be..0000000 Binary files a/main/src/img/house1.png and /dev/null differ diff --git a/main/src/img/kaluza.png b/main/src/img/kaluza.png deleted file mode 100644 index a119ea9..0000000 Binary files a/main/src/img/kaluza.png and /dev/null differ diff --git a/main/src/img/pies.png b/main/src/img/pies.png deleted file mode 100644 index 323fbc6..0000000 Binary files a/main/src/img/pies.png and /dev/null differ diff --git a/main/src/img/trash.png b/main/src/img/trash.png deleted file mode 100644 index ce64e37..0000000 Binary files a/main/src/img/trash.png and /dev/null differ diff --git a/main/src/img/trash1.png b/main/src/img/trash1.png deleted file mode 100644 index fd4e1f6..0000000 Binary files a/main/src/img/trash1.png and /dev/null differ diff --git a/main/src/img/truck — kopia.png b/main/src/img/truck — kopia.png deleted file mode 100644 index 7860105..0000000 Binary files a/main/src/img/truck — kopia.png and /dev/null differ diff --git a/main/src/img/truck.png b/main/src/img/truck.png deleted file mode 100644 index 317ffa8..0000000 Binary files a/main/src/img/truck.png and /dev/null differ diff --git a/main/src/main.py b/main/src/main.py deleted file mode 100644 index 71fff59..0000000 --- a/main/src/main.py +++ /dev/null @@ -1,95 +0,0 @@ -import pygame as pg -import sys -from os import path -from trash import * -from truck1 import * -from walls import * -from settings import * -from obstacle import * - - -class Game: - def __init__(self): - pg.init() - self.screen = pg.display.set_mode((WIDTH, HEIGHT)) - pg.display.set_caption(TITLE) - self.clock = pg.time.Clock() - pg.key.set_repeat(500, 100) - self.load_data() - - def load_data(self): - game_folder = path.dirname(__file__) - self.map_data = [] - with open(path.join(game_folder, 'map.txt'), 'rt') as f: - for line in f: - self.map_data.append(line.strip()) - print(line.strip()) - - def new(self): - self.all_sprites = pg.sprite.Group() - self.walls = pg.sprite.Group() - self.trash = pg.sprite.Group() - self.player = pg.sprite.Group() - for row, tiles in enumerate(self.map_data): - for col, tile in enumerate(tiles): - if tile == 'b': - Wall(self, col, row) - if tile == 'w': - Wall1(self, col, row) - if tile == 'P': - 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 - while self.playing: - self.dt = self.clock.tick(40) / 1000 - self.events() - self.update() - self.draw() - - def quit(self): - pg.quit() - sys.exit() - - def update(self): - self.all_sprites.update() - - def draw(self): - bg = pg.image.load("img\\bg.png") - self.screen.blit(bg, (0, 0)) - self.screen.fill(BGCOLOR) - self.all_sprites.draw(self.screen) - pg.display.flip() - - def events(self): - # catch all events here - for event in pg.event.get(): - if event.type == pg.QUIT: - self.quit() - if event.type == pg.KEYDOWN: - if event.key == pg.K_ESCAPE: - self.quit() - - def show_start_screen(self): - pass - - def show_go_screen(self): - pass - - -g = Game() -g.show_start_screen() -while True: - g.new() - g.run() - g.show_go_screen() diff --git a/main/src/map.txt b/main/src/map.txt deleted file mode 100644 index 7c16ce6..0000000 --- a/main/src/map.txt +++ /dev/null @@ -1,18 +0,0 @@ -bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb -bbbbb bbb bbb bb bb b bb -b p w s p b -b p d w t g w b -b wwwwww wwwww bbb -bbb w p wddw p w b -b w w b -b wwwww wwwwwww bb -b wwwwww w w b -b w w wwwgdwwwwdk bbbb -b w w w b -b wwwww www www w b -b w p ww w g b -b Pp b -b w www w www w ww b -b w p wwww p bb -b bbbb b b bb b -bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb \ No newline at end of file diff --git a/main/src/obstacle.py b/main/src/obstacle.py deleted file mode 100644 index 286ef9e..0000000 --- a/main/src/obstacle.py +++ /dev/null @@ -1,61 +0,0 @@ -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 diff --git a/main/src/settings.py b/main/src/settings.py deleted file mode 100644 index 6533bbd..0000000 --- a/main/src/settings.py +++ /dev/null @@ -1,7 +0,0 @@ -WIDTH = 1280 -HEIGHT = 720 -TITLE = "Smieciarka" -TILESIZE = 40 -DARKGREY = (40, 40, 40) -BGCOLOR = DARKGREY -TRUCK_SPEED = 240 diff --git a/main/src/trash.py b/main/src/trash.py deleted file mode 100644 index 47ac7d6..0000000 --- a/main/src/trash.py +++ /dev/null @@ -1,35 +0,0 @@ -import random -import pygame as pg -from settings import TILESIZE - - -class Trash(pg.sprite.Sprite): - def __init__(self, game, x, y): - image = pg.image.load("img\\trash.png") - image1 = pg.image.load("img\\trash1.png") - self.groups = game.all_sprites, game.trash - 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 - self.position = (x, y) - self.randomize_position() - - def randomize_position(self): - self.position = (random.randint(0, 32-1)*40, - random.randint(0, 18-1)*40) - - def collected(self): - hits = pg.sprite.spritecollide(self, self.game.player, False) - if hits: - self.image.blit(image1, (0, 0)) - self.x = 0 - self.y = 0 - - def update(self): - self.collected() diff --git a/main/src/truck.py b/main/src/truck.py deleted file mode 100644 index 9c8f817..0000000 --- a/main/src/truck.py +++ /dev/null @@ -1,83 +0,0 @@ -import pygame as pg -from settings import * -class garbageTruck(pg.sprite.Sprite): - def __init__(self, game, x, y): - image = pg.image.load("img\\truck.png") - self.groups = game.all_sprites - pg.sprite.Sprite.__init__(self, self.groups) - self.game = game - self.image = pg.Surface((TILESIZE, TILESIZE)) - self.image.blit(image,(0,0)) - self.rect = self.image.get_rect() - self.capacity = 0 - self.vx, self.vy = 0, 0 - self.max_capacity=3000 - self.x=x*TILESIZE - self.y=y*TILESIZE - self.position=[((self.x),(self.y))] - self.direction=0 - - def get_position(self): - return self.position[0] - - def turn(self): - if self.direction==0: - self.direction=1 - else: - self.direction=0 - - def move(self, r): - current = self.get_position() - if self.direction==0: - new = (((current[0]+(r*40))%1280),current[1]%720) - else: - new = (current[0]%1280,(current[1]+(r*40))%720) - self.position.insert(0,new) - self.position.pop() - - def throw(self): - self.capacity=0 - - - def handle_keys(self): - keys = pg.key.get_pressed() - if keys[pg.K_LEFT] or keys[pg.K_a]: - if self.direction == 0: - self.move(-1) - else: self.turn() - elif keys[pg.K_RIGHT] or keys[pg.K_d]: - if self.direction == 0: - self.move(1) - else: self.turn() - elif keys[pg.K_UP] or keys[pg.K_w]: - if self.direction == 1: - self.move(-1) - else: self.turn() - elif keys[pg.K_DOWN] or keys[pg.K_s]: - if self.direction == 1: - self.move(1) - else: self.turn() - - def get_keys(self): - self.vx, self.vy = 0, 0 - keys = pg.key.get_pressed() - if keys[pg.K_LEFT] or keys[pg.K_a]: - self.vx = -TRUCK_SPEED - if keys[pg.K_RIGHT] or keys[pg.K_d]: - self.vx = TRUCK_SPEED - if keys[pg.K_UP] or keys[pg.K_w]: - self.vy = -TRUCK_SPEED - if keys[pg.K_DOWN] or keys[pg.K_s]: - self.vy = TRUCK_SPEED - if self.vx != 0 and self.vy != 0: - self.vx *= 1 - self.vy *= 1 - - def update(self): - self.get_keys() - self.x += self.vx * self.game.dt - self.y += self.vy * self.game.dt - - - - diff --git a/main/src/truck1.py b/main/src/truck1.py deleted file mode 100644 index 62ec9c6..0000000 --- a/main/src/truck1.py +++ /dev/null @@ -1,138 +0,0 @@ -import pygame as pg -from settings import TILESIZE, TRUCK_SPEED -from bfs import bfs -from time import sleep - - -class garbageTruck(pg.sprite.Sprite): - def __init__(self, game, x, y): - self.og_image = pg.image.load("img\\truck.png") - self.groups = game.all_sprites, game.player - pg.sprite.Sprite.__init__(self, self.groups) - self.game = game - self.image = pg.Surface((TILESIZE, TILESIZE)) - self.image.blit(self.og_image, (0, 0)) - self.rect = self.image.get_rect() - self.vx = 0 - self.vy = 0 - self.x = x * TILESIZE - self.y = y * TILESIZE - self.capacity = 0 - self.max_capacity = 3000 - self.position = [self.x, self.y] - self.directions = [-1, 1, 1, -1] # góra prawo dół lewo - self.d = 1 - self.turned = False - self.bfs_path = bfs() - - def get_position(self): - return [self.x, self.y] - - def turn(self, d): - self.og_image = pg.transform.rotate( - self.og_image, 90*d*-1) - self.image.blit(self.og_image, (0, 0)) - self.d = (self.d+d) % 4 - - def move(self): - if self.d in [1, 3]: - self.vx = (TRUCK_SPEED*self.directions[self.d]) - else: - self.vy = (TRUCK_SPEED*self.directions[self.d]) - - def throw(self): - self.capacity = 0 - - def get_keys(self): - self.vx, self.vy = 0, 0 - keys = pg.key.get_pressed() - if not self.turned and (keys[pg.K_LEFT] or keys[pg.K_a]): - self.turn(-1) - self.turned = True - if not self.turned and (keys[pg.K_RIGHT] or keys[pg.K_d]): - self.turn(1) - self.turned = True - if not (keys[pg.K_RIGHT] or keys[pg.K_d] or keys[pg.K_LEFT] or keys[pg.K_a]) and self.turned: - self.turned = False - if keys[pg.K_UP] or keys[pg.K_w]: - self.move() - if keys[pg.K_g] and len(self.bfs_path) != 0: - self.navigate_bfs() - - def collide_with_walls(self, dir): - if dir == 'x': - hits = pg.sprite.spritecollide(self, self.game.walls, False) - if hits: - if self.vx > 0: - self.x = hits[0].rect.left - self.rect.width - if self.vx < 0: - self.x = hits[0].rect.right - self.vx = 0 - self.rect.x = self.x - if dir == 'y': - hits = pg.sprite.spritecollide(self, self.game.walls, False) - if hits: - if self.vy > 0: - self.y = hits[0].rect.top - self.rect.height - if self.vy < 0: - self.y = hits[0].rect.bottom - self.vy = 0 - self.rect.y = self.y - - def collecting_trash(self, dir): - if dir == 'x': - hits = pg.sprite.spritecollide(self, self.game.trash, False) - if hits: - if self.vx > 0: - self.x = hits[0].rect.left - self.rect.width - if self.vx < 0: - self.x = hits[0].rect.right - self.vx = 0 - self.rect.x = self.x - if dir == 'y': - hits = pg.sprite.spritecollide(self, self.game.trash, False) - if hits: - if self.vy > 0: - self.y = hits[0].rect.top - self.rect.height - if self.vy < 0: - self.y = hits[0].rect.bottom - self.vy = 0 - self.rect.y = self.y - - def auto_drive(self, direction): - while self.d != direction: - self.turn(1) - - if direction in [1, 3]: - self.x += self.directions[self.d] * TILESIZE - else: - self.y += self.directions[self.d] * TILESIZE - - def navigate_bfs(self): - print(self.bfs_path) - dest = self.bfs_path.pop() - dest[0], dest[1] = dest[1]*TILESIZE, dest[0]*TILESIZE - - pos = [int(i) for i in self.get_position()] - print(pos[0] - dest[0], pos[1] - dest[1]) - - if pos[0] - dest[0] < 0: - self.auto_drive(1) - elif pos[0] - dest[0] > 0: - self.auto_drive(3) - - if pos[1] - dest[1] < 0: - self.auto_drive(2) - elif pos[1] - dest[1] > 0: - self.auto_drive(0) - - def update(self): - self.get_keys() - self.x += self.vx * self.game.dt - self.y += self.vy * self.game.dt - self.rect.x = self.x - self.collide_with_walls('x') - self.collecting_trash('x') - self.rect.y = self.y - self.collide_with_walls('y') - self.collecting_trash('y') diff --git a/main/src/walls.py b/main/src/walls.py deleted file mode 100644 index 8293db9..0000000 --- a/main/src/walls.py +++ /dev/null @@ -1,32 +0,0 @@ -import pygame as pg -from settings import TILESIZE - - -class Wall(pg.sprite.Sprite): - def __init__(self, game, x, y): - image = pg.image.load("img\\house1.png") - self.groups = game.all_sprites, game.walls - 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 Wall1(pg.sprite.Sprite): - def __init__(self, game, x, y): - image = pg.image.load("img\\house.png") - self.groups = game.all_sprites, game.walls - 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, (-1, -1)) - self.x = x - self.y = y - self.rect.x = x * TILESIZE - self.rect.y = y * TILESIZE