import pygame pygame.init() clock = pygame.time.Clock() FPS = 60 #game window SCREEN_WIDTH = 800 SCREEN_HEIGHT = 640 LOWER_MARGIN = 100 SIDE_MARGIN = 300 screen = pygame.display.set_mode((SCREEN_WIDTH + SCREEN_HEIGHT, SCREEN_HEIGHT + LOWER_MARGIN)) pygame.display.set_caption('Level Editor') #define game veribals ROWS = 16 MAX_COLS = 150 TILE_SIZE = SCREEN_HEIGHT // ROWS TILE_TYPES = 21 scroll_left = False scroll_right = False scroll = 0 scroll_speed = 1 #Load images pine1_img = pygame.image.load('img/pine1.png').convert_alpha() pine2_img = pygame.image.load('img/pine2.png').convert_alpha() mountion_img = pygame.image.load('img/mountain.png').convert_alpha() sky_img = pygame.image.load('img/sky_cloud.png').convert_alpha() #store tiles in a list img_list = [] for x in range(TILE_TYPES): img = pygame.image.load(f'img/tile/{x}') #define the clours GREEN = (144, 201, 120) WHITE = (255, 255, 255) RED = (200, 25, 25) #draw function for drawing the background def draw_bg(): screen.fill(GREEN) Width = sky_img.get_width() for x in range(4): screen.blit(sky_img, ((x * Width) - scroll * 0.5, 0)) screen.blit(mountion_img, ((x * Width) - scroll * 0.6, SCREEN_HEIGHT - mountion_img.get_height() - 300)) screen.blit(pine1_img, ((x * Width) - scroll * 0.7, SCREEN_HEIGHT - pine1_img.get_height() - 150)) screen.blit(pine2_img, ((x * Width) - scroll * 0.8, SCREEN_HEIGHT - pine2_img.get_height())) #draw grid def draw_grid(): #vertical lines for c in range(MAX_COLS + 1): pygame.draw.line(screen, WHITE, (c * TILE_SIZE - scroll, 0), (c * TILE_SIZE - scroll, SCREEN_HEIGHT)) #horizontal lines for c in range(ROWS+ 1): pygame.draw.line(screen, WHITE, (0, c * TILE_SIZE), (SCREEN_WIDTH, c * TILE_SIZE)) run = True while run: clock.tick(FPS) draw_bg() draw_grid() #scroll the map if scroll_left == True and scroll > 0: scroll-= 5 * scroll_speed if scroll_right == True: scroll += 5 * scroll_speed for event in pygame.event.get(): if event.type == pygame.QUIT: run = False #keybord press if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: scroll_left = True if event.key == pygame.K_RIGHT: scroll_right = True if event.key == pygame.K_RSHIFT: scroll_speed = 5 if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: scroll_left = False if event.key == pygame.K_RIGHT: scroll_right = False if event.key == pygame.K_RSHIFT: scroll_speed = 1 pygame.display.update() pygame.quit()