Question
Help: I got this game where I am making a maze but the maze will blit at the top left corner of the 1000x600 size
Help: I got this game where I am making a maze but the maze will blit at the top left corner of the 1000x600 size screen. How do I change where the blit of the maze takes place so that I can adjust the location? I tried changing the i and itr variables but that just cuts off the maze. I will post my main function and maze_class.
import pygame,sys from pygame.locals import* from maze_class import Maze
pygame.init()
WHITE=(255,255,255) block=pygame.image.load('square1.png')
DISPLAYSURF=pygame.display.set_mode((1000,600),DOUBLEBUF,32) #BG=pygame.image.load(BGimage).convert() pygame.display.set_caption("ARGG") player=pygame.image.load('rat.png').convert_alpha() player=pygame.transform.scale(player,(30,30)) walk=['rat.png','rat.png']
x=60 y=365 px=0 py=0 CLOCK=pygame.time.Clock()
count=0
while True:
DISPLAYSURF.fill(WHITE) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if (event.type == pygame.KEYDOWN): if (event.key==pygame.K_LEFT): player=pygame.image.load(walk[count]) player=pygame.transform.scale(player,(30,30)) count=(count +1) % len(walk) px=-5 if (event.key==pygame.K_RIGHT): player=pygame.image.load(walk[count]) player=pygame.transform.scale(player,(30,30)) count=(count +1) % len(walk) px=5 if (event.key==pygame.K_UP): py=-5 if (event.key==pygame.K_DOWN): py=5 if (event.type == pygame.KEYUP): if (event.key==pygame.K_LEFT): px=0 if (event.key==pygame.K_RIGHT): px=0 if (event.key==pygame.K_UP): py=0 if (event.key==pygame.K_DOWN): py=0 maze=Maze() maze.draw(DISPLAYSURF,block) DISPLAYSURF.blit(player,(x,y)) x+=px y+=py CLOCK.tick(50) pygame.display.update()
Class:
import pygame,sys from pygame.locals import*
pygame.init()
class Maze: def __init__(self): self.row = 11 self.col=11 self.maze=[1,1,1,1,1,1,1,1,1,0,0, 1,1,0,0,0,0,0,0,0,0,1, 1,1,1,0,1,0,1,1,0,0,0, 1,0,0,0,0,1,0,1,1,1,1, 1,0,1,0,1,1,0,0,0,1,1, 1,1,1,0,0,0,0,0,0,1,1, 1,1,1,1,1,1,0,1,0,1,1, 1,0,0,1,1,1,0,1,0,1,1, 1,1,0,0,1,1,0,1,1,1,1, 1,0,0,0,0,0,0,0,0,1,1, 1,1,1,1,1,1,1,1,1,1,1] def draw(self,window,block): x=0 y=0 itr = 0 while itr < self.row: for i in range (0, self.col - 1): if self.maze[itr * 11 + i] == 1: window.blit(block, (100,100)) itr = itr + 1 x=x+1 if x>=self.col: x=0 y=y+1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started