diff --git a/agent.py b/agent.py
deleted file mode 100644
index 4adc04f..0000000
--- a/agent.py
+++ /dev/null
@@ -1,30 +0,0 @@
-import pygame.image
-
-class trashmaster(pygame.sprite.Sprite):
-
- def __init__(self,x,y,img):
- super().__init__()
-
- self.width=x
- self.height=y
-
- self.x = 0
- self.y = 0
-
- self.image = pygame.image.load(img)
- self.image = pygame.transform.scale(self.image, (self.width,self.height))
- self.rect = self.image.get_rect()
-
- def movement(self, key, vel):
- if key == pygame.K_LEFT:
- self.x -= vel
-
- if key == pygame.K_RIGHT:
- self.x += vel
-
- if key == pygame.K_UP:
- self.y -= vel
-
- if key == pygame.K_DOWN:
- self.y += vel
- return (self.x, self.y)
\ No newline at end of file
diff --git a/dump.py b/game_objects/dump.py
similarity index 61%
rename from dump.py
rename to game_objects/dump.py
index 725eda3..86972eb 100644
--- a/dump.py
+++ b/game_objects/dump.py
@@ -1,14 +1,10 @@
-import pygame.image
+import pygame as pg
-class Dump(pygame.sprite.Sprite):
+class Dump(pg.sprite.Sprite):
# wysypisko
def __init__(self):
super().__init__()
self.glass = []
self.paper = []
self.bio = []
- self.other_trash = []
-
-
-
-
+ self.other_trash = []
\ No newline at end of file
diff --git a/house.py b/game_objects/house.py
similarity index 96%
rename from house.py
rename to game_objects/house.py
index be5fe1e..284bbf7 100644
--- a/house.py
+++ b/game_objects/house.py
@@ -23,7 +23,4 @@ class House(pygame.sprite.Sprite):
def get_random_house_texture(self):
files = os.listdir(self.base_path)
value = randint(0, len(files)-1)
- return files[value]
-
-
-
+ return files[value]
\ No newline at end of file
diff --git a/game_objects/obstacle.py b/game_objects/obstacle.py
new file mode 100644
index 0000000..edfb2de
--- /dev/null
+++ b/game_objects/obstacle.py
@@ -0,0 +1,13 @@
+import pygame as pg
+
+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
diff --git a/game_objects/player.py b/game_objects/player.py
new file mode 100644
index 0000000..918901a
--- /dev/null
+++ b/game_objects/player.py
@@ -0,0 +1,47 @@
+import pygame as pg
+from settings import *
+from game_objects import utils
+
+vec = pg.math.Vector2
+
+class Player(pg.sprite.Sprite):
+ def __init__(self, game, x, y):
+ self.groups = game.agentSprites
+ pg.sprite.Sprite.__init__(self, self.groups)
+ self.game = game
+ self.image = game.player_img
+ self.rect = self.image.get_rect()
+ self.rect.center = (x,y)
+ 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
+ utils.collide_with_walls(self, self.game.wallTiles, 'x')
+ self.hit_rect.centery = self.pos.y
+ utils.collide_with_walls(self, self.game.wallTiles, 'y')
+ self.rect.center = self.hit_rect.center
\ No newline at end of file
diff --git a/game_objects/trash.py b/game_objects/trash.py
new file mode 100644
index 0000000..bf797cf
--- /dev/null
+++ b/game_objects/trash.py
@@ -0,0 +1,18 @@
+import pygame as pg
+
+class trash(pg.sprite.Sprite):
+
+ def __init__(self,x,y,img, type):
+ super().__init__()
+
+ self.width=16
+ self.height=16
+
+ self.type = type
+
+ self.x = x
+ self.y = y
+
+ self.image = pg.image.load(img)
+ self.image = pg.transform.scale(self.image, (self.x,self.y))
+ self.rect = self.image.get_rect()
\ No newline at end of file
diff --git a/trashbin.py b/game_objects/trashbin.py
similarity index 70%
rename from trashbin.py
rename to game_objects/trashbin.py
index a580452..1538c79 100644
--- a/trashbin.py
+++ b/game_objects/trashbin.py
@@ -1,6 +1,6 @@
-import pygame.image
+import pygame as pg
-class trashbin(pygame.sprite.Sprite):
+class trashbin(pg.sprite.Sprite):
def __init__(self,x,y,img, type):
super().__init__()
@@ -24,6 +24,6 @@ class trashbin(pygame.sprite.Sprite):
self.y = y
# load trashbin image
- self.image = pygame.image.load(img)
- self.image = pygame.transform.scale(self.image, (self.x,self.y))
- self.rect = self.image.get_rect()
+ self.image = pg.image.load(img)
+ self.image = pg.transform.scale(self.image, (self.x,self.y))
+ self.rect = self.image.get_rect()
\ No newline at end of file
diff --git a/game_objects/utils.py b/game_objects/utils.py
new file mode 100644
index 0000000..9a7edc7
--- /dev/null
+++ b/game_objects/utils.py
@@ -0,0 +1,24 @@
+import pygame as pg
+
+def collide_hit_rect(one, two):
+ return one.hit_rect.colliderect(two.rect)
+
+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
\ No newline at end of file
diff --git a/main.py b/main.py
index 42c41e8..38c0689 100644
--- a/main.py
+++ b/main.py
@@ -1,60 +1,48 @@
from calendar import c
+from game_objects.player import Player
import pygame as pg
import sys
from os import path
-from map import *
# from agent import trashmaster
# from house import House
-from sprites import *
from settings import *
-from map_new import map_new
-from map_new import map_utils
+from map import map
+from map import map_utils
import math
class Game():
def __init__(self):
pg.init()
+ self.clock = pg.time.Clock()
self.screen = pg.display.set_mode((WIDTH, HEIGHT))
pg.display.set_caption("Trashmaster")
- self.clock = pg.time.Clock()
self.load_data()
-
- def load_data(self):
- game_folder = path.dirname(__file__)
- img_folder = path.join(game_folder, 'resources/textures')
- map_folder = path.join(img_folder, 'map')
- self.map = TiledMap(path.join(map_folder, 'roads.tmx'))
- self.map_img = self.map.make_map()
- self.map_rect = self.map_img.get_rect()
+ self.init_game()
- self.player_img = pg.image.load(path.join(img_folder,PLAYER_IMG)).convert_alpha()
- self.player_img = pg.transform.scale(self.player_img, (PLAYER_WIDTH,PLAYER_HEIGHT) )
- self.wall_img = pg.image.load(path.join(img_folder, WALL_IMG)).convert_alpha()
- self.wall_img = pg.transform.scale(self.wall_img, (TILESIZE, TILESIZE))
-
- # self.new_map = map_new.getMap()
-
-
- def new(self):
+ def init_game(self):
# initialize all variables and do all the setup for a new game
# sprite groups
- self.roadTiles, self.wallTiles = map_new.getTiles()
+ self.roadTiles, self.wallTiles = map.get_tiles()
+ self.agentSprites = pg.sprite.Group()
- self.all_sprites = pg.sprite.Group()
- self.walls = pg.sprite.Group()
+ # player obj
+ self.player = Player(self, 32, 100)
- 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)
+ # camera obj
+ self.camera = map_utils.Camera(MAP_WIDTH_PX, MAP_HEIGHT_PX)
- self.camera = Camera(MAP_WIDTH_PX, MAP_HEIGHT_PX)
+ # other
self.draw_debug = False
-
+ def load_data(self):
+ game_folder = path.dirname(__file__)
+ img_folder = path.join(game_folder, 'resources/textures')
+
+ self.player_img = pg.image.load(path.join(img_folder,PLAYER_IMG)).convert_alpha()
+ self.player_img = pg.transform.scale(self.player_img, (PLAYER_WIDTH,PLAYER_HEIGHT) )
+
def run(self):
# game loop - set self.playing = False to end the game
self.playing = True
@@ -70,27 +58,25 @@ class Game():
def update(self):
# update portion of the game loop
- self.all_sprites.update()
+ self.agentSprites.update()
self.camera.update(self.player)
# pygame.display.update()
-
- def draw_grid(self):
- for x in range(0, WIDTH, TILESIZE):
- pg.draw.line(self.screen, LIGHTGREY, (x, 0), (x, HEIGHT))
- for y in range(0, HEIGHT, TILESIZE):
- pg.draw.line(self.screen, LIGHTGREY, (0, y), (WIDTH, y))
def draw(self):
+ #display fps as window title
pg.display.set_caption("{:.2f}".format(self.clock.get_fps()))
- map_new.renderTiles(self.roadTiles, self.screen, self.camera)
- map_new.renderTiles(self.wallTiles, self.screen, self.camera, self.draw_debug)
-
- for sprite in self.all_sprites:
+ #rerender map
+ map.render_tiles(self.roadTiles, self.screen, self.camera)
+ map.render_tiles(self.wallTiles, self.screen, self.camera, self.draw_debug)
+
+ #rerender additional sprites
+ for sprite in self.agentSprites:
self.screen.blit(sprite.image, self.camera.apply(sprite))
if self.draw_debug:
pg.draw.rect(self.screen, CYAN, self.camera.apply_rect(sprite.hit_rect), 1)
+ #finally update screen
pg.display.flip()
def events(self):
@@ -102,8 +88,8 @@ class Game():
self.quit()
if event.key == pg.K_h:
self.draw_debug = not self.draw_debug
- if event.type == pygame.MOUSEBUTTONUP:
- pos = pygame.mouse.get_pos()
+ if event.type == pg.MOUSEBUTTONUP:
+ pos = pg.mouse.get_pos()
clicked_coords = [math.floor(pos[0] / TILESIZE), math.floor(pos[1] / TILESIZE)]
print(clicked_coords)
@@ -112,42 +98,11 @@ class Game():
def show_go_screen(self):
pass
-
-# def main():
-# game = WalleGame()
-# game.update_window()
-
-# smieciara_object = trashmaster(16,16,"./resources/textures/garbagetruck/trashmaster_blu.png")
-# game.draw_object(smieciara_object, (100, 100))
-
-# #house_object = House(20, 20)
-# # Test draw house object
-# #game.draw_object(house_object, (20,20))
-
-# game.update_window()
-
-# running = True
-
-# while running:
-# for event in pygame.event.get():
-# if event.type == pygame.QUIT:
-# running = False
-# if event.type == pygame.KEYDOWN:
-# game.reloadMap()
-# game.draw_object(smieciara_object, smieciara_object.movement(event.key, 16))
-
-# game.update_window()
-
-# pygame.quit()
-# if __name__ == '__main__':
-# main()
-
# create the game object
g = Game()
g.show_start_screen()
while True:
- g.new()
g.run()
g.show_go_screen()
diff --git a/map.py b/map.py
deleted file mode 100644
index df387cd..0000000
--- a/map.py
+++ /dev/null
@@ -1,67 +0,0 @@
-import pygame as pg
-from settings import *
-import pytmx
-
-# config
-# 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(WIDTH/2)
- y = -target.rect.y + int(HEIGHT / 2)
-
- # limit scrolling to map size
- x = min(0, x) # left
- y = min(0, y) # top
- x = max(-(self.width - WIDTH), x) # right
- y = max(-(self.height - HEIGHT), y) # bottom
- self.camera = pg.Rect(x, y, self.width, self.height)
-
-
-
-
diff --git a/map/camera.py b/map/camera.py
new file mode 100644
index 0000000..ee229f7
--- /dev/null
+++ b/map/camera.py
@@ -0,0 +1,24 @@
+from settings import *
+
+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(WIDTH/2)
+ y = -target.rect.y + int(HEIGHT / 2)
+
+ # limit scrolling to map size
+ x = min(0, x) # left
+ y = min(0, y) # top
+ x = max(-(self.width - WIDTH), x) # right
+ y = max(-(self.height - HEIGHT), y) # bottom
+ self.camera = pg.Rect(x, y, self.width, self.height)
\ No newline at end of file
diff --git a/map/map.py b/map/map.py
new file mode 100644
index 0000000..6df4238
--- /dev/null
+++ b/map/map.py
@@ -0,0 +1,16 @@
+from map import map_utils
+from map import map_pattern
+import pygame as pg
+from settings import *
+
+def get_tiles():
+ array = map_utils.generate_map()
+ pattern = map_pattern.get_pattern()
+ tiles = map_utils.get_sprites(array, pattern)
+ return tiles
+
+def render_tiles(tiles, screen, camera, debug=False):
+ for tile in tiles:
+ screen.blit(tile.image, camera.apply_rect(tile.rect))
+ if debug:
+ pg.draw.rect(screen, RED, camera.apply_rect(tile.rect), 1)
diff --git a/map_new/map_pattern.py b/map/map_pattern.py
similarity index 65%
rename from map_new/map_pattern.py
rename to map/map_pattern.py
index fd38298..e5fb4fb 100644
--- a/map_new/map_pattern.py
+++ b/map/map_pattern.py
@@ -7,11 +7,11 @@ TEXTURES_DIR = HERE_DIR.rpartition(os.sep)[0]+"\\resources\\textures"
ROAD_DIR = TEXTURES_DIR+"\\road\\"
BUILDING_DIR = TEXTURES_DIR+"\\buliding\\"
-def loadImg(path):
+def load_img(path):
return pg.image.load(path)
-def getPattern():
+def get_pattern():
return {
- 0: loadImg(ROAD_DIR+"GTA2_TILE_257.bmp"),
- 1: loadImg(BUILDING_DIR+"GTA2_TILE_187.bmp"),
+ 0: load_img(ROAD_DIR+"GTA2_TILE_257.bmp"),
+ 1: load_img(BUILDING_DIR+"GTA2_TILE_187.bmp"),
}
\ No newline at end of file
diff --git a/map_new/map_utils.py b/map/map_utils.py
similarity index 53%
rename from map_new/map_utils.py
rename to map/map_utils.py
index f5f1a1e..adf40e0 100644
--- a/map_new/map_utils.py
+++ b/map/map_utils.py
@@ -1,16 +1,16 @@
import random
import pygame as pg
from settings import *
-from map_new.tile import Tile
+from map.tile import Tile
# tworzenie pustego arraya o podanych wymiarach
-def getBlankMapArray():
+def get_blank_map_array():
map = [[0 for x in range(0,MAP_WIDTH)] for y in range (0,MAP_HEIGHT)]
return map
# generowanie obiektow na mapie
-def generateMap():
- map = getBlankMapArray()
+def generate_map():
+ map = get_blank_map_array()
for i in range(0, 20):
x = random.randint(0, MAP_WIDTH-1)
y = random.randint(0, MAP_HEIGHT-1)
@@ -18,7 +18,7 @@ def generateMap():
return map
# tworzenie grup sprite'ow
-def getSprites(map, pattern):
+def get_sprites(map, pattern):
roadTiles = pg.sprite.Group()
wallTiles = pg.sprite.Group()
@@ -36,6 +36,29 @@ def getSprites(map, pattern):
return roadTiles, wallTiles
+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(WIDTH/2)
+ y = -target.rect.y + int(HEIGHT / 2)
+
+ # limit scrolling to map size
+ x = min(0, x) # left
+ y = min(0, y) # top
+ x = max(-(self.width - WIDTH), x) # right
+ y = max(-(self.height - HEIGHT), y) # bottom
+ self.camera = pg.Rect(x, y, self.width, self.height)
+
diff --git a/map_new/tile.py b/map/tile.py
similarity index 100%
rename from map_new/tile.py
rename to map/tile.py
diff --git a/map_new/map_new.py b/map_new/map_new.py
deleted file mode 100644
index f854a17..0000000
--- a/map_new/map_new.py
+++ /dev/null
@@ -1,16 +0,0 @@
-from map_new import map_utils
-from map_new import map_pattern
-import pygame as pg
-from settings import *
-
-def getTiles():
- array = map_utils.generateMap()
- pattern = map_pattern.getPattern()
- tiles = map_utils.getSprites(array, pattern)
- return tiles
-
-def renderTiles(tiles, screen, camera, debug=False):
- for tile in tiles:
- screen.blit(tile.image, camera.apply_rect(tile.rect))
- if debug:
- pg.draw.rect(screen, RED, camera.apply_rect(tile.rect), 1)
diff --git a/resources/textures/Ground.tsx b/resources/textures/Ground.tsx
deleted file mode 100644
index 338e07b..0000000
--- a/resources/textures/Ground.tsx
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/resources/textures/Roads.tsx b/resources/textures/Roads.tsx
deleted file mode 100644
index 9406774..0000000
--- a/resources/textures/Roads.tsx
+++ /dev/null
@@ -1,142 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/resources/textures/Trash.tsx b/resources/textures/Trash.tsx
deleted file mode 100644
index 1d0eead..0000000
--- a/resources/textures/Trash.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/resources/textures/Walls.tsx b/resources/textures/Walls.tsx
deleted file mode 100644
index 2fd21ae..0000000
--- a/resources/textures/Walls.tsx
+++ /dev/null
@@ -1,139 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/resources/textures/map/map1.tmx b/resources/textures/map/map1.tmx
deleted file mode 100644
index e0c4ee0..0000000
--- a/resources/textures/map/map1.tmx
+++ /dev/null
@@ -1,143 +0,0 @@
-
-
diff --git a/resources/textures/map/roads.tmx b/resources/textures/map/roads.tmx
deleted file mode 100644
index 2e3a2fe..0000000
--- a/resources/textures/map/roads.tmx
+++ /dev/null
@@ -1,335 +0,0 @@
-
-
diff --git a/resources/textures/player.tsx b/resources/textures/player.tsx
deleted file mode 100644
index 80f5d22..0000000
--- a/resources/textures/player.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/settings.py b/settings.py
index e5be6e6..6bb0ab2 100644
--- a/settings.py
+++ b/settings.py
@@ -1,7 +1,5 @@
import pygame as pg
-vec = pg.math.Vector2
-
#colors
LIGHTGREY = (100, 100, 100)
CYAN = (0, 255, 255)
diff --git a/sprites.py b/sprites.py
deleted file mode 100644
index 8cec298..0000000
--- a/sprites.py
+++ /dev/null
@@ -1,163 +0,0 @@
-import pygame as pg
-import pygame.image
-from settings import *
-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.rect.center = (x,y)
- 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.wallTiles, 'x')
- self.hit_rect.centery = self.pos.y
- collide_with_walls(self, self.game.wallTiles, 'y')
- self.rect.center = self.hit_rect.center
-
-class Dump(pg.sprite.Sprite):
- # wysypisko
- def __init__(self):
- super().__init__()
- self.glass = []
- self.paper = []
- self.bio = []
- self.other_trash = []
-class trash(pg.sprite.Sprite):
-
- def __init__(self,x,y,img, type):
- super().__init__()
-
- self.width=16
- self.height=16
-
- self.type = type
-
- self.x = x
- self.y = y
-
- self.image = pygame.image.load(img)
- self.image = pygame.transform.scale(self.image, (self.x,self.y))
- self.rect = self.image.get_rect()
-class trashbin(pg.sprite.Sprite):
-
- def __init__(self,x,y,img, type):
- super().__init__()
-
- # trashbin type
- self.type = type
-
- # dimensions
- if type == "small":
- self.width = 4
- self.height = 4
- elif type == "medium":
- self.width = 8
- self.height = 8
- elif type == "large":
- self.width = 16
- self.height = 16
-
- # spawn coords
- self.x = x
- self.y = y
-
- # load trashbin image
- self.image = pygame.image.load(img)
- self.image = pygame.transform.scale(self.image, (self.x,self.y))
- self.rect = self.image.get_rect()
-
-class trashmaster(pg.sprite.Sprite):
-
- def __init__(self,x,y,img):
- super().__init__()
-
- self.width=x
- self.height=y
-
- self.x = 0
- self.y = 0
-
- self.image = pygame.image.load(img)
- self.image = pygame.transform.scale(self.image, (self.width,self.height))
- self.rect = self.image.get_rect()
-
- def movement(self, key, vel):
- if key == pygame.K_LEFT:
- self.x -= vel
-
- if key == pygame.K_RIGHT:
- self.x += vel
-
- if key == pygame.K_UP:
- self.y -= vel
-
- if key == pygame.K_DOWN:
- self.y += vel
- return (self.x, self.y)
-
-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
diff --git a/trash.py b/trash.py
deleted file mode 100644
index ddeea4b..0000000
--- a/trash.py
+++ /dev/null
@@ -1,18 +0,0 @@
-import pygame.image
-
-class trash(pygame.sprite.Sprite):
-
- def __init__(self,x,y,img, type):
- super().__init__()
-
- self.width=16
- self.height=16
-
- self.type = type
-
- self.x = x
- self.y = y
-
- self.image = pygame.image.load(img)
- self.image = pygame.transform.scale(self.image, (self.x,self.y))
- self.rect = self.image.get_rect()