From c55a6ebd354f68f16b47bb68866ebf60f4449850 Mon Sep 17 00:00:00 2001 From: Kacper Date: Sun, 3 Apr 2022 15:47:41 +0200 Subject: [PATCH] Merge branch 'master' of https://git.wmi.amu.edu.pl/s462072/WALL-E --- main.py | 49 +++-- map.py | 70 ++++++- resources/textures/Ground.tsx | 2 + resources/textures/Roads.tsx | 142 +++++++++++++ resources/textures/Trash.tsx | 49 +++++ resources/textures/Walls.tsx | 139 +++++++++++++ resources/textures/map/map1.tmx | 143 +++++++++++++ resources/textures/map/roads.tmx | 335 +++++++++++++++++++++++++++++++ resources/textures/player.tsx | 31 +++ sprites.py | 80 ++++++++ 10 files changed, 1018 insertions(+), 22 deletions(-) create mode 100644 resources/textures/Ground.tsx create mode 100644 resources/textures/Roads.tsx create mode 100644 resources/textures/Trash.tsx create mode 100644 resources/textures/Walls.tsx create mode 100644 resources/textures/map/map1.tmx create mode 100644 resources/textures/map/roads.tmx create mode 100644 resources/textures/player.tsx create mode 100644 sprites.py diff --git a/main.py b/main.py index 8c1daf1..899ca1b 100644 --- a/main.py +++ b/main.py @@ -1,36 +1,60 @@ import pygame -from map import preparedMap +from map import * from agent import trashmaster from house import House +from sprites import * class WalleGame(): def __init__(self): - self.SCREEN_SIZE = [512, 512] - self.BACKGROUND_COLOR = '#ffffff' + self.SCREEN_SIZE = [1024, 768] + #self.BACKGROUND_COLOR = '#ffffff' pygame.init() pygame.display.set_caption('Wall-e') self.screen = pygame.display.set_mode(self.SCREEN_SIZE) - self.screen.fill(pygame.Color(self.BACKGROUND_COLOR)) + # self.screen.fill(pygame.Color(self.BACKGROUND_COLOR)) # krata - self.map = preparedMap(self.SCREEN_SIZE) - self.screen.blit(self.map, (0,0)) - + # self.map = preparedMap(self.SCREEN_SIZE) + # self.screen.blit(self.map, (0,0)) + self.walls = pg.sprite.Group() + self.player_img = pg.image.load("./resources/textures/garbagetruck/trashmaster_blu.png").convert_alpha() + self.all_sprites = pg.sprite.Group() + + + self.map = TiledMap("resources/textures/map/roads.tmx") + self.map_img = self.map.make_map() + self.map_rect = self.map_img.get_rect() + self.screen.blit(self.map_img, (0,0)) + + for tile_object in self.map.tmxdata.objects: + if tile_object.name == 'player': + self.player = Player(self, tile_object.x, tile_object.y) + if tile_object.name == 'wall': + Obstacle(self, tile_object.x, tile_object.y, tile_object.width, tile_object.height) + + + + # self.camera = Camera(self.map.width, self.map.height) + # self.screen.blit(self.map_img, self.camera.apply_rect(self.map_rect)) + + def update_window(self): pygame.display.update() + # self.camera.update(self.image) def draw_object(self, drawable_object, pos): # pos => (x, y) # drawable object must have .image field inside class self.screen.blit(drawable_object.image, pos ) + def reloadMap(self): - self.screen.fill(pygame.Color(self.BACKGROUND_COLOR)) - self.screen.blit(self.map, (0,0)) + #self.screen.fill(pygame.Color(self.BACKGROUND_COLOR)) + self.screen.blit(self.map_img, (0,0)) def main(): game = WalleGame() @@ -39,9 +63,9 @@ def main(): smieciara_object = trashmaster(16,16,"./resources/textures/garbagetruck/trashmaster_blu.png") game.draw_object(smieciara_object, (0, 0)) - house_object = House(20, 20) + #house_object = House(20, 20) # Test draw house object - game.draw_object(house_object, (20,20)) + #game.draw_object(house_object, (20,20)) game.update_window() @@ -53,8 +77,7 @@ def main(): running = False if event.type == pygame.KEYDOWN: game.reloadMap() - game.draw_object(smieciara_object, - smieciara_object.movement(event.key, 16)) + game.draw_object(smieciara_object, smieciara_object.movement(event.key, 16)) game.update_window() diff --git a/map.py b/map.py index bbede27..645c8b1 100644 --- a/map.py +++ b/map.py @@ -1,13 +1,65 @@ -import pygame +import pygame as pg +import pytmx # config -TILE_SIZE = 16 +# TILE_SIZE = 16 + +# def preparedMap(screenSize): +# tileImage = pg.image.load('tile1.png') +# surface = pg.Surface(screenSize) + +# for x in range(0, screenSize[0], TILE_SIZE): +# for y in range(0, screenSize[1], TILE_SIZE): +# surface.blit(tileImage, (x, y)) +# return surface +def collide_hit_rect(one, two): + return one.hit_rect.colliderect(two.rect) +class TiledMap: + #loading file + def __init__(self, filename): + tm = pytmx.load_pygame(filename, pixelalpha=True) + self.width = tm.width * tm.tilewidth + self.height = tm.height * tm.tileheight + self.tmxdata = tm + + #rendering map + def render(self, surface): + ti = self.tmxdata.get_tile_image_by_gid + for layer in self.tmxdata.visible_layers: + if isinstance(layer, pytmx.TiledTileLayer): + for x, y, gid, in layer: + tile = ti(gid) + if tile: + surface.blit(tile, (x * self.tmxdata.tilewidth, y * self.tmxdata.tilewidth)) + + def make_map(self): + temp_surface = pg.Surface((self.width, self.height)) + self.render(temp_surface) + return temp_surface + +class Camera: + def __init__(self,width,height): + self.camera = pg.Rect(0,0, width, height) + self.width = width + self.height = height + + def apply(self,entity): + return entity.rect.move(self.camera.topleft) + + # def apply_rect(self, rect): + # return rect.move(self.camera.topleft) + + def update(self,target): + x = -target.rect.x + int(1024/2) + y = -target.rect.y + int(768 / 2) + + # limit scrolling to map size + x = min(0, x) # left + y = min(0, y) # top + x = max(-(self.width - 1024), x) # right + y = max(-(self.height - 768), y) # bottom + self.camera = pg.Rect(x, y, self.width, self.height) + + -def preparedMap(screenSize): - tileImage = pygame.image.load('tile1.png') - surface = pygame.Surface(screenSize) - for x in range(0, screenSize[0], TILE_SIZE): - for y in range(0, screenSize[1], TILE_SIZE): - surface.blit(tileImage, (x, y)) - return surface \ No newline at end of file diff --git a/resources/textures/Ground.tsx b/resources/textures/Ground.tsx new file mode 100644 index 0000000..338e07b --- /dev/null +++ b/resources/textures/Ground.tsx @@ -0,0 +1,2 @@ + + diff --git a/resources/textures/Roads.tsx b/resources/textures/Roads.tsx new file mode 100644 index 0000000..9406774 --- /dev/null +++ b/resources/textures/Roads.tsx @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/textures/Trash.tsx b/resources/textures/Trash.tsx new file mode 100644 index 0000000..1d0eead --- /dev/null +++ b/resources/textures/Trash.tsx @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/textures/Walls.tsx b/resources/textures/Walls.tsx new file mode 100644 index 0000000..2fd21ae --- /dev/null +++ b/resources/textures/Walls.tsx @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/textures/map/map1.tmx b/resources/textures/map/map1.tmx new file mode 100644 index 0000000..e0c4ee0 --- /dev/null +++ b/resources/textures/map/map1.tmx @@ -0,0 +1,143 @@ + + + + + + + + +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,536870916,1610612829,67,75,1073741900,75,75,75,1073741895,0,3221225543,62,61,3221225528,3221225535,1610612793,61,62,3221225551,0,0,0,0,2684354639,0,0,0,0,0, +0,0,91,2684354626,0,536870987,0,0,0,1610612811,0,1610612811,0,0,1610612799,0,536870975,0,0,0,2684354639,0,0,0,2684354623,0,3221225519,3221225551,0,0, +0,0,90,3758096461,0,536870987,0,0,0,2147483719,1073741900,71,0,0,1610612815,0,1610612799,0,0,0,2684354618,61,62,2684354616,1610612793,0,1610612789,0,0,0, +0,0,3221225543,70,0,2147483719,75,1073741895,0,0,1610612811,0,0,0,0,0,1610612798,0,0,0,2684354623,0,0,2684354617,58,0,2684354607,3221225518,0,0, +0,0,1610612811,0,0,0,0,1610612811,0,0,1610612811,0,3758096442,61,61,1073741887,3221225528,3221225535,1073741885,1073741885,2147483706,58,0,1610612799,0,2684354639,0,1610612791,0,0, +0,0,1610612811,0,536870991,0,0,1610612811,0,0,1610612811,0,1610612800,0,0,0,2684354621,0,0,0,0,2684354622,0,2684354611,3221225524,3221225521,3221225525,1610612787,0,0, +0,0,1610612811,0,1610612814,0,0,2684354636,75,75,536870988,0,1610612804,0,0,0,2684354623,0,2684354639,0,0,3758096445,0,1610612789,0,1610612791,0,2684354612,0,0, +0,0,1610612811,0,1610612803,0,3221225543,536870983,0,0,2684354631,75,1610612809,0,2684354639,0,2684354624,0,2684354633,1610612807,0,1610612815,0,1610612788,0,2684354638,0,2684354613,0,0, +0,0,2684354636,77,76,75,1610612812,0,0,2684354639,0,0,1610612813,0,2684354627,75,71,0,0,2684354635,0,0,0,1610612791,0,1610612815,0,2684354628,0,0, +0,0,3758096459,0,0,0,2684354637,0,0,2684354635,0,0,2684354635,0,2684354635,0,0,0,0,1610612791,0,0,0,2684354638,0,0,0,2684354638,0,0, +0,0,3758096459,0,0,0,3758096460,75,75,3221225545,3221225547,78,1610612809,3221225549,76,3221225518,55,2147483703,3221225523,51,0,3221225519,53,3221225521,53,3221225523,3221225527,3221225518,0,0, +0,0,2147483719,1073741895,0,0,1610612802,0,0,2684354626,0,0,2684354635,0,0,1610612789,0,0,1610612791,0,0,1610612788,0,2684354638,0,1610612789,0,1610612791,0,0, +0,0,0,2684354636,75,75,76,75,75,3221225549,3221225547,3221225547,3221225545,0,0,1610612791,0,79,1610612785,3221225551,0,1610612789,0,1610612815,0,1610612788,0,1610612815,0,0, +0,0,0,1610612811,0,0,0,0,0,0,0,0,1610612811,0,0,1610612790,0,0,1610612791,0,0,1610612791,0,0,0,1610612789,0,0,0,0, +0,0,0,1610612811,0,0,3221225543,3221225547,78,1610612807,0,0,1610612811,0,0,2684354610,3221225521,3221225524,51,3221225527,78,1610612785,54,3221225524,3221225525,1610612785,78,3221225551,0,0, +0,0,0,1610612811,0,0,2684354635,0,0,1610612811,0,0,2684354637,0,0,0,2684354614,0,0,0,0,1610612789,0,0,0,1610612789,0,0,0,0, +0,0,0,1610612811,0,0,2684354635,0,0,2684354635,0,0,1610612811,0,79,3221225537,2684354610,78,3221225551,0,0,1610612815,0,0,0,1610612791,0,0,0,0, +0,0,0,3758096460,3221225547,75,3221225545,64,75,76,3221225548,75,70,0,0,0,2684354638,0,0,0,0,0,0,0,0,1610612813,0,0,0,0, +0,0,0,1610612811,0,0,1610612809,0,0,0,1610612815,0,0,0,3221225544,67,2684354610,3221225548,66,64,3221225548,77,3221225548,75,75,1610612809,3221225551,0,0,0, +0,0,0,1610612811,0,79,76,77,1073741895,0,0,0,0,0,2684354624,0,0,2684354625,0,0,1610612815,0,1610612801,0,0,2684354638,0,0,0,0, +0,0,0,1610612811,0,0,0,0,74,0,3221225543,75,77,3221225545,70,0,0,2684354624,0,0,0,0,1610612815,0,3221225543,76,1610612806,0,0,0, +0,0,0,2684354631,3221225547,3221225548,3221225547,3221225547,1610612812,0,1610612802,0,0,1610612815,0,0,3221225553,85,88,1610612817,0,0,0,0,1610612800,0,2684354628,0,0,0, +0,0,0,0,0,2684354635,0,0,2684354636,77,71,0,0,0,0,0,2684354644,0,0,1610612823,0,0,0,0,2684354625,0,2684354625,0,0,0, +0,0,0,536870991,0,2684354624,0,79,536870992,0,0,3221225553,1073741908,1073741908,3221225557,88,85,1610612817,0,2684354645,84,84,3221225557,88,85,84,1610612821,0,0,0, +0,0,0,3758096462,0,2684354635,0,0,0,0,0,536870996,0,0,536870996,0,0,2684354644,0,2684354646,0,0,2684354644,0,0,0,1610612819,0,0,0, +0,0,0,2147483728,78,76,84,84,84,84,84,81,0,0,1610612815,0,0,2684354641,86,85,87,84,81,0,79,87,82,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + + +11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, +11,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,11, +11,0,0,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,0,0,2684354599,35,17,25,0,24,29,33,7,11, +11,7,0,0,23,0,17,14,12,0,13,0,16,13,0,24,0,42,13,25,0,45,22,29,0,44,0,0,7,11, +11,7,0,0,15,0,45,37,17,0,0,0,24,12,0,45,0,44,24,14,0,0,0,0,0,37,0,23,7,11, +11,7,0,0,13,0,0,0,41,25,0,20,16,41,22,35,0,29,37,21,0,17,42,0,0,25,0,0,7,11, +11,7,0,26,27,28,29,0,21,43,0,29,0,0,0,0,0,0,0,0,0,0,43,0,536870952,0,2684354599,0,7,11, +11,7,0,14,0,24,21,0,15,33,0,21,0,43,21,33,0,45,30,31,16,0,12,0,0,0,0,0,7,11, +11,7,0,42,0,22,20,0,0,0,0,44,0,20,40,16,0,43,0,33,13,0,45,0,17,0,43,0,7,11, +11,7,0,25,0,13,0,0,15,24,0,0,0,41,0,29,0,15,0,0,44,0,37,0,21,0,24,0,7,11, +11,7,0,0,0,0,0,33,29,0,17,12,0,21,0,0,0,17,43,0,13,29,41,0,24,0,13,0,7,11, +11,7,0,15,18,45,0,13,41,0,24,16,0,23,0,13,41,22,16,0,20,32,17,0,29,25,35,0,7,11, +11,7,0,25,35,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,0,0,0,0,0,0,0,7,11, +11,7,0,0,34,19,0,44,15,0,2684354596,2684354596,0,18,24,0,17,35,0,41,25,0,41,0,13,0,44,0,7,11, +11,7,24,0,0,0,0,0,0,0,0,0,0,42,20,0,16,0,0,0,24,0,21,0,18,0,25,0,7,9, +11,7,22,0,33,13,16,43,21,20,29,15,0,41,24,0,29,13,0,16,43,0,18,24,42,0,42,23,7,9, +11,7,21,0,21,20,0,0,0,0,41,44,0,42,15,0,0,0,0,0,0,0,0,0,0,0,0,0,7,9, +11,7,24,0,41,24,0,3221225510,1610612774,0,24,21,0,13,40,20,0,17,32,15,44,0,26,27,28,0,18,25,7,11, +11,7,18,0,44,12,0,2684354598,38,0,17,22,0,41,0,0,0,0,0,24,20,0,21,35,33,0,12,24,7,11, +11,7,13,0,0,0,0,0,0,0,0,0,0,12,15,21,0,13,35,18,41,37,43,39,15,0,22,18,7,11, +11,7,15,0,43,15,0,33,17,41,0,29,18,33,0,0,0,0,0,0,0,0,0,0,0,0,0,24,7,11, +11,7,13,0,25,0,0,0,0,39,21,42,44,14,0,18,45,0,13,14,0,29,0,42,13,0,25,35,7,11, +11,7,24,0,14,18,23,24,0,13,0,0,0,0,0,21,42,0,41,15,2684354599,21,0,15,0,0,0,24,7,11, +11,7,18,0,0,0,0,0,0,3221225508,0,21,15,0,41,29,0,0,0,0,43,14,18,42,0,14,0,18,7,11, +11,7,14,40,43,0,43,14,0,0,0,29,17,18,22,24,0,17,23,0,13,30,31,25,0,33,0,32,7,11, +11,7,14,0,44,0,12,0,0,24,14,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,15,7,11, +11,7,25,0,29,0,14,13,25,14,43,0,15,13,0,44,33,0,25,0,13,44,0,43,15,44,0,42,7,11, +11,7,23,0,0,0,0,0,0,0,0,0,32,45,0,35,25,0,0,0,0,0,0,32,0,0,0,18,7,11, +11,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,11, +11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11 + + + + +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,536871021,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,105,0,0,0,0, +0,0,0,0,101,0,0,0,0,0,107,0,2684354662,0,0,0,0,0,0,0,0,0,0,0,0,0,2684354662,0,0,0, +0,0,2684354658,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,105,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,101,0,0,0,0,0,0,3221225579,0,0,0,0,0,0,0,0,0,0,0,0,3221225579,0,0, +0,0,0,0,0,0,0,0,0,102,0,0,0,0,0,0,0,0,0,3758096482,0,0,0,0,0,105,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,101,0,101,0,0,106,0,0,101,0,536871010,0,105,0,0,0,3221225579,0,0, +0,0,101,0,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,101,0,0,0,0,0,0,0,105,0,105,0,106,0,0,0,536871013,0,0,0,1610612834,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,105,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,106,0,105,0,0,0,0,0,0,2684354658,0,0,0,0,0,0,0,0,1073741922,0,0,536871013,0,0, +0,0,0,105,0,0,0,0,0,0,0,0,107,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,2684354665,0,0,0,102,0,0,2684354665,0,0,0,107,0,0,0,0, +0,0,0,0,0,0,0,98,0,0,0,105,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,105,0,0,0,0,0,0,0,0,0,0,0,107,0,0,0,0,0,0,0,0,2147483746,0,106,0,0,0, +0,0,0,0,0,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2684354658,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,98,0,0,0,0,1610612834,0,0,0,0,2684354665,0,0,0,105,0,0,0, +0,0,0,0,0,105,0,0,0,0,0,0,0,101,0,0,0,0,3221225579,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,107,0,0,0,3221225574,0,0,0,0,0,536871013,0,107,0,0,0,0,0,3221225570,0,0,0,0,536871013,0,0,0, +0,0,0,0,0,1610612834,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2684354658,0,0,0, +0,0,0,0,105,0,0,0,101,0,3221225570,0,0,0,101,0,0,536871013,0,0,101,0,107,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + diff --git a/resources/textures/map/roads.tmx b/resources/textures/map/roads.tmx new file mode 100644 index 0000000..caf8d95 --- /dev/null +++ b/resources/textures/map/roads.tmx @@ -0,0 +1,335 @@ + + + + + + + + +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,536870916,1610612829,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,3221225551,0,0,0,0,2684354639,0,0,0,0,0, +0,0,91,50,0,50,0,0,0,50,0,50,0,0,50,0,50,0,0,0,2684354639,0,0,0,50,0,78,3221225551,0,0, +0,0,90,50,0,50,0,0,0,50,50,50,0,0,1610612815,0,50,0,0,0,78,78,78,78,78,0,50,0,0,0, +0,0,50,50,0,78,78,78,0,0,50,0,0,0,0,0,50,0,0,0,50,0,0,78,78,0,78,78,0,0, +0,0,50,0,0,0,0,50,0,0,50,0,78,78,78,78,78,78,78,78,78,78,0,50,0,2684354639,0,50,0,0, +0,0,50,0,536870991,0,0,50,0,0,50,0,50,0,0,0,50,0,0,0,0,50,0,78,78,78,78,78,0,0, +0,0,50,0,50,0,0,78,78,78,78,0,50,0,0,0,50,0,2684354639,0,0,50,0,50,0,50,0,50,0,0, +0,0,50,0,50,0,78,78,0,0,50,50,50,0,2684354639,0,50,0,50,50,0,1610612815,0,50,0,2684354638,0,50,0,0, +0,0,78,78,78,78,78,0,0,2684354639,0,0,50,0,50,50,50,0,0,50,0,0,0,50,0,1610612815,0,50,0,0, +0,0,50,0,0,0,50,0,0,50,0,0,50,0,50,0,0,0,0,50,0,0,0,2684354638,0,0,0,2684354638,0,0, +0,0,50,0,0,0,78,78,78,78,78,78,78,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,0,0, +0,0,78,78,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,0,50,0,2684354638,0,50,0,50,0,0, +0,0,0,78,78,78,78,78,78,78,78,78,78,0,0,50,0,79,50,3221225551,0,50,0,1610612815,0,50,0,1610612815,0,0, +0,0,0,50,0,0,0,0,0,0,0,0,50,0,0,1610612790,0,0,50,0,0,50,0,0,0,50,0,0,0,0, +0,0,0,50,0,0,50,50,50,50,0,0,50,0,0,78,78,78,78,78,78,78,78,78,78,78,78,3221225551,0,0, +0,0,0,50,0,0,50,0,0,50,0,0,50,0,0,0,50,0,0,0,0,50,0,0,0,50,0,0,0,0, +0,0,0,50,0,0,50,0,0,50,0,0,50,0,79,50,2684354610,78,3221225551,0,0,1610612815,0,0,0,50,0,0,0,0, +0,0,0,78,78,78,78,78,78,78,78,78,78,0,0,0,2684354638,0,0,0,0,0,0,0,0,50,0,0,0,0, +0,0,0,50,0,0,50,0,0,0,1610612815,0,0,0,78,78,78,78,78,78,78,78,78,78,78,78,3221225551,0,0,0, +0,0,0,50,0,79,78,78,78,0,0,0,0,0,50,0,0,50,0,0,1610612815,0,50,0,0,50,0,0,0,0, +0,0,0,50,0,0,0,0,50,0,78,78,78,78,78,0,0,50,0,0,0,0,1610612815,0,78,78,78,0,0,0, +0,0,0,78,78,78,78,78,78,0,50,0,0,1610612815,0,0,50,50,50,50,0,0,0,0,50,0,50,0,0,0, +0,0,0,0,0,50,0,0,50,50,50,0,0,0,0,0,50,0,0,50,0,0,0,0,50,0,50,0,0,0, +0,0,0,536870991,0,50,0,79,50,0,0,78,78,78,78,78,78,78,0,78,78,78,78,78,78,78,78,0,0,0, +0,0,0,50,0,50,0,0,0,0,0,50,0,0,50,0,0,50,0,50,0,0,50,0,0,0,50,0,0,0, +0,0,0,2147483728,78,78,78,78,78,78,78,78,0,0,1610612815,0,0,78,78,78,78,78,78,0,79,78,78,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + + +11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, +11,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,11, +11,0,0,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,0,0,2684354599,35,17,25,0,24,29,33,7,11, +11,7,0,0,23,0,17,14,12,0,13,0,16,13,0,24,0,42,13,25,0,45,22,29,0,44,0,0,7,11, +11,7,0,0,15,0,45,37,17,0,0,0,24,12,0,45,0,44,24,14,0,0,0,0,0,37,0,23,7,11, +11,7,0,0,13,0,0,0,41,25,0,20,16,41,22,35,0,29,37,21,0,17,42,0,0,25,0,0,7,11, +11,7,0,26,27,28,29,0,21,43,0,29,0,0,0,0,0,0,0,0,0,0,43,0,536870952,0,2684354599,0,7,11, +11,7,0,14,0,24,21,0,15,33,0,21,0,43,21,33,0,45,30,31,16,0,12,0,0,0,0,0,7,11, +11,7,0,42,0,22,20,0,0,0,0,44,0,20,40,16,0,43,0,33,13,0,45,0,17,0,43,0,7,11, +11,7,0,25,0,13,0,0,15,24,0,0,0,41,0,29,0,15,0,0,44,0,37,0,21,0,24,0,7,11, +11,7,0,0,0,0,0,33,29,0,17,12,0,21,0,0,0,17,43,0,13,29,41,0,24,0,13,0,7,11, +11,7,0,15,18,45,0,13,41,0,24,16,0,23,0,13,41,22,16,0,20,32,17,0,29,25,35,0,7,11, +11,7,0,25,35,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,0,0,0,0,0,0,0,7,11, +11,7,0,0,34,19,0,44,15,0,2684354596,2684354596,0,18,24,0,17,35,0,41,25,0,41,0,13,0,44,0,7,11, +11,7,24,0,0,0,0,0,0,0,0,0,0,42,20,0,16,0,0,0,24,0,21,0,18,0,25,0,7,9, +11,7,22,0,33,13,16,43,21,20,29,15,0,41,24,0,29,13,0,16,43,0,18,24,42,0,42,23,7,9, +11,7,21,0,21,20,0,0,0,0,41,44,0,42,15,0,0,0,0,0,0,0,0,0,0,0,0,0,7,9, +11,7,24,0,41,24,0,3221225510,1610612774,0,24,21,0,13,40,20,0,17,32,15,44,0,26,27,28,0,18,25,7,11, +11,7,18,0,44,12,0,2684354598,38,0,17,22,0,41,0,0,0,0,0,24,20,0,21,35,33,0,12,24,7,11, +11,7,13,0,0,0,0,0,0,0,0,0,0,12,15,21,0,13,35,18,41,37,43,39,15,0,22,18,7,11, +11,7,15,0,43,15,0,33,17,41,0,29,18,33,0,0,0,0,0,0,0,0,0,0,0,0,0,24,7,11, +11,7,13,0,25,0,0,0,0,39,21,42,44,14,0,18,45,0,13,14,0,29,0,42,13,0,25,35,7,11, +11,7,24,0,14,18,23,24,0,13,0,0,0,0,0,21,42,0,41,15,2684354599,21,0,15,0,0,0,24,7,11, +11,7,18,0,0,0,0,0,0,3221225508,0,21,15,0,41,29,0,0,0,0,43,14,18,42,0,14,0,18,7,11, +11,7,14,40,43,0,43,14,0,0,0,29,17,18,22,24,0,17,23,0,13,30,31,25,0,33,0,32,7,11, +11,7,14,0,44,0,12,0,0,24,14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0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + + +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,3221225579,0,0,0,0,0,0,0,0,106,0,0,0,3221225579,0,0,0,0,3221225579,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,1610612836,0,0,0,0,0,0,1610612836,0,0,0,3221225579,0,0,0,2684354662,0,0,3221225579,0,0, +0,0,0,0,0,0,0,0,0,0,0,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,1610612836,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,0,0,0,107,0,0, +0,0,0,0,0,0,0,3221225579,0,0,0,0,0,0,3221225570,0,0,0,106,0,0,0,0,0,0,105,0,0,0,0, +0,0,0,0,101,0,0,0,0,0,107,0,2684354662,0,0,0,0,0,0,0,0,0,0,0,0,0,2684354662,0,0,0, +0,0,2684354658,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,105,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,101,0,0,0,0,0,0,3221225579,0,0,0,0,0,0,0,0,0,0,0,0,3221225579,0,0, +0,0,0,0,0,0,0,0,0,102,0,0,0,0,0,0,0,0,0,3758096482,0,0,0,0,0,105,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,101,0,101,0,0,106,0,0,101,0,536871010,0,105,0,0,0,3221225579,0,0, +0,0,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,101,0,0,0,0,0,0,0,105,0,105,0,106,0,0,0,536871013,0,0,0,1610612834,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,105,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,106,0,105,0,0,0,0,0,0,2684354658,0,0,0,0,0,0,0,0,1073741922,0,0,536871013,0,0, +0,0,0,105,0,0,0,0,0,0,0,0,107,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,2684354665,0,0,0,102,0,0,2684354665,0,0,0,107,0,0,0,0, +0,0,0,0,0,0,0,98,0,0,0,105,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,105,0,0,0,0,0,0,0,0,0,0,0,107,0,0,0,0,0,0,0,0,2147483746,0,106,0,0,0, +0,0,0,0,0,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2684354658,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,98,0,0,0,0,1610612834,0,0,0,0,2684354665,0,0,0,105,0,0,0, +0,0,0,0,0,105,0,0,0,0,0,0,0,101,0,0,0,0,3221225579,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,107,0,0,0,3221225574,0,0,0,0,0,536871013,0,107,0,0,0,0,0,3221225570,0,0,0,0,536871013,0,0,0, +0,0,0,0,0,1610612834,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2684354658,0,0,0, +0,0,0,0,105,0,0,0,101,0,3221225570,0,0,0,101,0,0,536871013,0,0,101,0,107,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/textures/player.tsx b/resources/textures/player.tsx new file mode 100644 index 0000000..80f5d22 --- /dev/null +++ b/resources/textures/player.tsx @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sprites.py b/sprites.py new file mode 100644 index 0000000..0c439e1 --- /dev/null +++ b/sprites.py @@ -0,0 +1,80 @@ +import pygame as pg +from random import uniform +from map import collide_hit_rect + +vec = pg.math.Vector2 + + +def collide_with_walls(sprite, group, dir): + if dir == 'x': + hits = pg.sprite.spritecollide(sprite, group, False, collide_hit_rect) + if hits: + if hits[0].rect.centerx > sprite.hit_rect.centerx: + sprite.pos.x = hits[0].rect.left - sprite.hit_rect.width / 2 + if hits[0].rect.centerx < sprite.hit_rect.centerx: + sprite.pos.x = hits[0].rect.right + sprite.hit_rect.width / 2 + sprite.vel.x = 0 + sprite.hit_rect.centerx = sprite.pos.x + if dir == 'y': + hits = pg.sprite.spritecollide(sprite, group, False, collide_hit_rect) + if hits: + if hits[0].rect.centery > sprite.hit_rect.centery: + sprite.pos.y = hits[0].rect.top - sprite.hit_rect.height / 2 + if hits[0].rect.centery < sprite.hit_rect.centery: + sprite.pos.y = hits[0].rect.bottom + sprite.hit_rect.height / 2 + sprite.vel.y = 0 + sprite.hit_rect.centery = sprite.pos.y + +class Player(pg.sprite.Sprite): + def __init__(self, game, x, y): + self.groups = game.all_sprites + pg.sprite.Sprite.__init__(self, self.groups) + self.game = game + self.image = game.player_img + self.rect = self.image.get_rect() + # self.hit_rect = PLAYER_HIT_RECT + # self.hit_rect.center = self.rect.center + self.vel = vec(0, 0) + self.pos = vec(x, y) + self.rot = 0 + + + def get_keys(self): + self.rot_speed = 0 + self.vel = vec(0, 0) + keys = pg.key.get_pressed() + if keys[pg.K_LEFT] or keys[pg.K_a]: + self.rot_speed = PLAYER_ROT_SPEED + if keys[pg.K_RIGHT] or keys[pg.K_d]: + self.rot_speed = -PLAYER_ROT_SPEED + if keys[pg.K_UP] or keys[pg.K_w]: + self.vel = vec(PLAYER_SPEED, 0).rotate(-self.rot) + if keys[pg.K_DOWN] or keys[pg.K_s]: + self.vel = vec(-PLAYER_SPEED / 2, 0).rotate(-self.rot) + + + def update(self): + self.get_keys() + self.rot = (self.rot + self.rot_speed * self.game.dt) % 360 + self.image = pg.transform.rotate(self.game.player_img, self.rot) + self.rect = self.image.get_rect() + self.rect.center = self.pos + self.pos += self.vel * self.game.dt + self.hit_rect.centerx = self.pos.x + collide_with_walls(self, self.game.walls, 'x') + self.hit_rect.centery = self.pos.y + collide_with_walls(self, self.game.walls, 'y') + self.rect.center = self.hit_rect.center + + +class Obstacle(pg.sprite.Sprite): + def __init__(self, game, x, y, w, h): + self.groups = game.walls + pg.sprite.Sprite.__init__(self, self.groups) + self.game = game + self.rect = pg.Rect(x, y, w, h) + self.hit_rect = self.rect + self.x = x + self.y = y + self.rect.x = x + self.rect.y = y \ No newline at end of file