2022-03-09 21:27:57 +01:00
|
|
|
import pygame
|
2022-04-03 15:47:41 +02:00
|
|
|
from map import *
|
2022-03-09 22:39:34 +01:00
|
|
|
from agent import trashmaster
|
2022-03-24 21:20:07 +01:00
|
|
|
from house import House
|
2022-04-03 15:47:41 +02:00
|
|
|
from sprites import *
|
2022-03-10 15:53:41 +01:00
|
|
|
|
2022-03-10 16:16:59 +01:00
|
|
|
class WalleGame():
|
|
|
|
|
|
|
|
def __init__(self):
|
2022-04-03 15:47:41 +02:00
|
|
|
self.SCREEN_SIZE = [1024, 768]
|
|
|
|
#self.BACKGROUND_COLOR = '#ffffff'
|
2022-03-10 16:16:59 +01:00
|
|
|
|
|
|
|
pygame.init()
|
|
|
|
pygame.display.set_caption('Wall-e')
|
|
|
|
|
|
|
|
|
2022-03-10 16:18:06 +01:00
|
|
|
self.screen = pygame.display.set_mode(self.SCREEN_SIZE)
|
2022-04-03 15:47:41 +02:00
|
|
|
# self.screen.fill(pygame.Color(self.BACKGROUND_COLOR))
|
2022-03-10 16:16:59 +01:00
|
|
|
|
|
|
|
# krata
|
2022-04-03 15:47:41 +02:00
|
|
|
# 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))
|
|
|
|
|
|
|
|
|
2022-03-10 16:16:59 +01:00
|
|
|
def update_window(self):
|
|
|
|
pygame.display.update()
|
2022-04-03 15:47:41 +02:00
|
|
|
# self.camera.update(self.image)
|
2022-03-10 16:16:59 +01:00
|
|
|
|
2022-03-24 21:20:07 +01:00
|
|
|
def draw_object(self, drawable_object, pos):
|
2022-03-22 11:55:01 +01:00
|
|
|
# pos => (x, y)
|
2022-03-24 21:20:07 +01:00
|
|
|
# drawable object must have .image field inside class
|
|
|
|
self.screen.blit(drawable_object.image, pos )
|
2022-04-03 15:47:41 +02:00
|
|
|
|
2022-03-24 21:20:07 +01:00
|
|
|
|
2022-03-22 11:55:01 +01:00
|
|
|
def reloadMap(self):
|
2022-04-03 15:47:41 +02:00
|
|
|
#self.screen.fill(pygame.Color(self.BACKGROUND_COLOR))
|
|
|
|
self.screen.blit(self.map_img, (0,0))
|
2022-03-10 16:16:59 +01:00
|
|
|
|
|
|
|
def main():
|
|
|
|
game = WalleGame()
|
|
|
|
game.update_window()
|
|
|
|
|
2022-03-24 20:35:06 +01:00
|
|
|
smieciara_object = trashmaster(16,16,"./resources/textures/garbagetruck/trashmaster_blu.png")
|
2022-03-24 21:20:07 +01:00
|
|
|
game.draw_object(smieciara_object, (0, 0))
|
|
|
|
|
2022-04-03 15:47:41 +02:00
|
|
|
#house_object = House(20, 20)
|
2022-03-24 21:20:07 +01:00
|
|
|
# Test draw house object
|
2022-04-03 15:47:41 +02:00
|
|
|
#game.draw_object(house_object, (20,20))
|
2022-03-09 22:39:34 +01:00
|
|
|
|
2022-03-10 16:16:59 +01:00
|
|
|
game.update_window()
|
2022-03-09 21:27:57 +01:00
|
|
|
|
2022-03-10 16:16:59 +01:00
|
|
|
running = True
|
|
|
|
|
|
|
|
while running:
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
running = False
|
2022-03-22 11:55:01 +01:00
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
game.reloadMap()
|
2022-04-03 15:47:41 +02:00
|
|
|
game.draw_object(smieciara_object, smieciara_object.movement(event.key, 16))
|
2022-03-24 21:20:07 +01:00
|
|
|
|
2022-03-22 11:55:01 +01:00
|
|
|
game.update_window()
|
2022-03-24 21:20:07 +01:00
|
|
|
|
2022-03-10 16:16:59 +01:00
|
|
|
pygame.quit()
|
2022-03-09 21:27:57 +01:00
|
|
|
|
|
|
|
|
2022-03-10 16:16:59 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|