def drawPlayer(): x, y = player.getPos() if player.checkPos(x, y): BLOCKID = gametiles.getActiveTile(x, y).blockid if BLOCKID in ANIMATIONIMAGE: IMG = ANIMATIONIMAGE[BLOCKID][player.orientation] else: IMG = ANIMATIONIMAGE[1][player.orientation] DISPLAYSURF.blit(pygame.transform.scale(IMG, (TILESIZE, TILESIZE)), (player.getPos()))
def checkPos(self, x, y): if (x // TILESIZE >= gametiles.TILEWIDTH or y // TILESIZE >= gametiles.TILEHEIGHT) or (x < 0 or y < 0): return False else: TargetTile = gametiles.getActiveTile(x, y) if not TargetTile.blockid in PASSABLEBLOCKS: TargetTile.setBlockID(100) return False else: return True
def placeTile(self): global BLOCKCOUPLER, NewPlacedTiles BLOCKCOUPLER = gametiles.BLOCKCOUPLER inv = self.inv tile = gametiles.getActiveTile(self.xpos, self.ypos) if not inv.isEmpty(): d = random.choice(list(inv.grabList().keys())) if inv.inInv(d): try: BLOCKCOUPLER[tile.getBlockID()].remove(tile) inv.removeItem(d, 1) tile.setBlockID(d) if d in BLOCKCOUPLER.keys(): BLOCKCOUPLER[d].append(tile) else: BLOCKCOUPLER[d] = [tile] drawStack.stackToDraw.addToStack(tile) except: return False return True else: return False
def grabTile(self): tile = gametiles.getActiveTile(self.xpos, self.ypos) self.inv.addItem(tile.blockid, 1)
font = pygame.font.Font(None, 30) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == K_q: pygame.quit() sys.exit() if event.key == pygame.K_m: MAPGENERATED = 0 if event.key == pygame.K_w: x, y = player.getPos() TILE = gametiles.getActiveTile(x, y) for Tile in gametiles.getSurrounding(TILE): Tile.setBlockID(100) displayTile(Tile, Tile.xpos, Tile.ypos, wholesurf) if event.key == pygame.K_SPACE: player.grabTile() if event.key == pygame.K_p: player.placeTile() # player movements pressed = pygame.key.get_pressed() if pressed[pygame.K_UP]: movePlayer("up") elif pressed[pygame.K_RIGHT]: movePlayer("right") elif pressed[pygame.K_LEFT]: movePlayer("left") elif pressed[pygame.K_DOWN]: movePlayer("down") DISPLAYSURF.fill(WHITE)