0

[Python]Array map in pygame

The code is below. I tried running my WIP project, however, the titled map didn't show like my array, can anyone help? code: import pygame import sys import os import time import random pygame.init() w = int(800) h = int(600) level = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] clock = pygame.time.Clock() block = pygame.image.load("brick.png") player = pygame.image.load("Player1.png") title = pygame.image.load("Arena.png") P_button = pygame.image.load("Play.png") size = [w, h] screen = pygame.display.set_mode(size)

20th Mar 2020, 12:33 PM
Chaney Chan
Chaney Chan - avatar
3 Respuestas
0
seems like the number of characters is full, let me post the code in two parts here.
20th Mar 2020, 12:35 PM
Chaney Chan
Chaney Chan - avatar
0
part one import pygame import sys import os import time import random pygame.init() w = int(800) h = int(600) level = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] clock = pygame.time.Clock() block = pygame.image.load("brick.png") player = pygame.image.load("Player1.png") title = pygame.image.load("Arena.png") P_button = pygame.image.load("Play.png") size = [w, h] screen = pygame.display.set_mode(size) scale = 0 pygame.display.set_caption("Arena") menu = True game = True playerW = 40 playerH = 32 buttonW = 87 buttonH = 40 buttonX = 20 buttonY = 200 x = w/2 y= h/2 def animation(w, h): temp = 0 for i in range(20): D_button = pygame.transform.scale(P_button,(w+temp*2, h+temp*2)) screen.fill((0,0,0)) screen.blit(title, [300, 100]) screen.blit(D_button, [buttonX, buttonY]) pygame.display.flip() def mapmaking(): k = 0 tx = 0 ty = 0 for i in range(len(level)): if level[k] == 1: screen.blit(block, [tx, ty]) k += 1 if tx > 799: tx = 0 ty += 50 else: tx += 50 while menu: mx, my = pygame.mouse.get_pos() for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() pygame.display.flip() screen.blit(title, [300, 100]) screen.blit(P_button, [buttonX, buttonY])
20th Mar 2020, 12:36 PM
Chaney Chan
Chaney Chan - avatar
0
part two: #button script if event.type == pygame.MOUSEBUTTONDOWN: if mx > buttonX and mx <= buttonX + buttonW: if my >= buttonY and my <= buttonY + buttonH: animation(buttonW, buttonH) menu = False pygame.display.flip() clock.tick(15) #clearing Background #screen.fill((0,0,0)) pygame.display.flip() screen.fill((0,0,0)) while game: screen.blit(player, [0, 0]) pygame.display.flip() mapmaking() clock.tick(15)
20th Mar 2020, 12:36 PM
Chaney Chan
Chaney Chan - avatar