Why does nothing show up on the screen?

Viewed 17

I know you shouldn't post all of your code and ask somebody to find the error, but I have no other idea how to make my program work. The program should make a few blocks appear on the screen.

I used some of the Zelda Clear Code tutorial.

main.py

#import
import sys
from level import *
from settings import *

class Game:
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode((1280,720))
#       print(self.screen)
        pygame.display.set_caption('Miau!')
        self.clock = pygame.time.Clock()

        self.level = Level()

    def run(self):
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
            self.screen.fill('black')
            self.level.run()
            pygame.display.update()
            self.clock.tick(FPS)

#running game
if __name__ == '__main__':
    game = Game()
    game.run()

level.py

# imports
import pygame
from settings import WORLD_MAP,TILESIZE
from tiles import Tile

class Level:
    def __init__(self):
        self.display_surface = pygame.display.get_surface()
        self.level_index = 1

        #sprite groups
        self.visible_sprites = pygame.sprite.Group()
        self.obstacle_sprites = pygame.sprite.Group()
        self.enemy_sprites = pygame.sprite.Group()

        #create map
        self.create_map()

    def run(self):
        self.visible_sprites.update()

    def create_map(self):
        for row_index, row in enumerate(WORLD_MAP):
            for col_index, col in enumerate(row):
                #setting coordinates
                x = row_index * TILESIZE
                y = col_index * TILESIZE
                #setting right tile
                if col == 'x':
                    surface = pygame.image.load('C:/Users/Asus/PycharmProjects/Miau(CatGame)/graphics/Tiles/test_tile.png').convert_alpha()
                    Tile([self.visible_sprites], (x,y), surface)

class TileGroup(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.display_surface = pygame.display.get_surface()
        self.half_width = self.display_surface.get_size()[0] // 2
        self.half_height = self.display_surface.get_size()[1] // 2
        #offset so the player is in the middle
        self.offset = pygame.math.Vector2()


    def custom_draw(self, player):
        self.offset.x = player.rect.centerx - self.half_width
        self.offset.y = player.rect.centery - self.half_height

        for sprite in sorted(self.sprites(), key=lambda sprite: sprite.rect.centery):
            offset_pos = sprite.rect.topleft - self.offset
            self.display_surface.blit(sprite.image, offset_pos)

debug.py

import pygame
pygame.init()
font = pygame.font.Font(None,30)

def debug(info,y=10,x=10):
    display_surface = pygame.display.get_surface()
    debug_surf = font.render(str(info), True, 'White')
    debug_rect = debug_surf.get_rect(topleft = (x,y))
    pygame.draw.rect(display_surface,'Black',debug_rect)
    display_surface.blit(debug_surf,debug_rect)

load_files.py

import csv
from os import walk
import pygame


def import_csv_map(path):
    terrain_map = []
    with open(path) as level_map:
        layout = csv.reader(level_map, delimiter=',')
        for row in layout:
            terrain_map.append(list(row))
        return terrain_map

def change_elment_csv(path, row, col, value):
    with open(path) as i:
        list(i)[row][col] = value

        writer = csv.writer(open(path, 'w'))
        writer.writerows(list(i))

def import_folder(path):
    surface_list = []

    for _,__,img_files in walk(path):
        for image in img_files:
            full_path = path + '/' + image
            image_surf = pygame.image.load(full_path).convert_alpha()
            surface_list.append(image_surf)
    return surface_list

player.py

import pygame
from settings import TILESIZE


class Player(pygame.sprite.Sprite):
    def __init__(self, groups, center, display_surface, surface=pygame.surface((TILESIZE, TILESIZE))):
        super().__init__(groups)
        self.image = surface.fill('blue')
        self.rect = self.image.get_rect()
        self.hitbox = self.rect.inflate(0, -14)

        #movement
        self.direction = pygame.math.Vector2()
        self.speed = 5


    def input(self):
        keys = pygame.key.get_pressed()

        # movement
        if not self.attacking:
           if keys[pygame.K_UP]:
               self.direction.y = -1
           elif keys[pygame.K_DOWN]:
               self.direction.y = 1
           else:
               self.direction.y = 0

           if keys[pygame.K_LEFT]:
               self.direction.x = -1
           elif keys[pygame.K_RIGHT]:
               self.direction.x = 1
           else:
               self.direction.x = 0

    def run(self):
        self.input()

settings.py

TILESIZE = 64
FPS = 60

WORLD_MAP = [
    ['x','x','x','x','x','x','x','x','x','x','x','x','x','x','x'],
    ['x','x','x','x','x','x','x','x','x','x','x','x','x','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ','p',' ',' ',' ',' ',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x','x'],
    ['x','x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x','x'],
    ['x','x','x','x','x','x','x','x','x','x','x','x','x','x','x'],
    ['x','x','x','x','x','x','x','x','x','x','x','x','x','x','x']
]

tiles.py

import pygame
from settings import *

class Tile(pygame.sprite.Sprite):
    def __init__(self, groups, pos, sprite_type='test', surface=pygame.Surface((TILESIZE, TILESIZE)), color=None):
        super().__init__(groups)
        self.sprite_type = sprite_type
        self.image = surface
        #if color != None:
        #    self.image.fill(color)
        self.rect = self.image.get_rect(topleft=pos)

        self.hitbox = self.rect.inflate(0, -10)
0 Answers
Related