def main_loop(tree, width, height, colour, alg): '''(tree, int, int, bool) -> NoneType Runs Pygame and tiles the treemap in window of given width and height.''' h = height + 28 # Adds space to bottom of screen for blitted text. pygame.init() screen = pygame.display.set_mode((width, h)) # Chooses tiling algorithm. if alg is True: tile(tree, 0, 0, width, height, screen, colour) # Build basic treemap. else: square(tree, width, height, screen) screen2 = screen.copy() running = True while running: event = pygame.event.poll() if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEMOTION: # Blit file under mouse. screen.blit(screen2, (0, 0)) blit_text(tree, event.pos, screen, h) elif event.type == pygame.MOUSEBUTTONDOWN: # Open file clicked. open_folder(tree, event.pos) pygame.display.flip()
def create_object(ch, x, y): global OBJECT_COUNT for i in range(len(ch)): if ch[i] == '1': remove_double(x, y) obj = tile('cave_block', x, y) gfw.world.add(gfw.layer.tile, obj) x += BLOCK_SIZE elif ch[i] == 'A': remove_double(x, y) obj = arrow_trap('arrow_block', x, y, True) gfw.world.add(gfw.layer.tile, obj) x += BLOCK_SIZE elif ch[i] == 'a': remove_double(x, y) obj = arrow_trap('arrow_block', x, y, False) gfw.world.add(gfw.layer.tile, obj) x += BLOCK_SIZE elif ch[i] == 'L': remove_double(x, y) obj = tile('ledder_top', x, y) gfw.world.add(gfw.layer.tile, obj) x += BLOCK_SIZE elif ch[i] == 'l': remove_double(x, y) obj = tile('ledder_bottom', x, y) gfw.world.add(gfw.layer.tile, obj) x += BLOCK_SIZE elif ch[i] == 'S': remove_double(x, y) obj = spike('spike', x, y) gfw.world.add(gfw.layer.tile, obj) x += BLOCK_SIZE elif ch[i] == '9': obj = entrance('entrance', x, y) gfw.world.add(gfw.layer.tile, obj) x += BLOCK_SIZE elif ch[i] == '8': obj = exit('exit', x, y) gfw.world.add(gfw.layer.tile, obj) x += BLOCK_SIZE elif ch[i] == '-': global OBJECT_COUNT if OBJECT_COUNT < MAX_OBJECT_COUNT and random.randint(0, 100) > 50: choice = random.choice( [objects.Something, objects.Treasure_box, monster.Monster]) if choice == monster.Monster: name = random.choice(['snake', 'bat']) pos = x + BLOCK_SIZE // 2, y + BLOCK_SIZE // 2 obj = choice(pos, name) gfw.world.add(gfw.layer.monster, obj) else: pos = x + BLOCK_SIZE // 2, y + BLOCK_SIZE // 2 obj = choice(pos) gfw.world.add(gfw.layer.object, obj) OBJECT_COUNT += 1 x += BLOCK_SIZE else: x += BLOCK_SIZE
def __init__(self, bot, channel): self.bot = bot self.channel = channel self.boardState = [[], [], []] for i in range(0, 3): for j in range(0, 3): self.boardState[i].append(tile())
def change(self,x,y,to): '''(world,int,int,string) -> NoneType''' if self.map[x][y].type == "T": if (x,y) in self.torches: self.torches.remove((x,y)) if to=="A": self.map[x][y] = tile() elif to=="B": self.map[x][y] = block() elif to=="T": self.map[x][y] = torch() self.torches.append((x,y)) way = ["w","a","s","d",""] direction = ' ' while not direction in way: box=wx.TextEntryDialog(None,str(way),"On Block?","") if box.ShowModal()==wx.ID_OK: direction=box.GetValue() if direction == "w": temp = (x-1,y) elif direction == "a": temp = (x,y-1) elif direction == "s": temp = (x+1,y) elif direction == "d": temp = (x,y+1) else: return if self.map[temp[0]][temp[1]].type == "B": self.map[x][y].onbox = direction self.map[x][y].box = self.map[temp[0]][temp[1]] elif to=="R": self.map[x][y] = redstone() elif to=="P": direction = "" way = ["w","a","s","d"] if ((x==MAP_SIZE-1 and y==MAP_SIZE-1) or (x==0 and y==0) or (x==0 and y==MAP_SIZE-1) or (x==MAP_SIZE-1 and y==0)): print ("Can't place repeater there") return if (y==MAP_SIZE-1 or y==0): way = ["w","s"] elif (x==0 or x==MAP_SIZE-1): way = ["a","d"] while not direction in way: box=wx.TextEntryDialog(None,str(way),"Facing?",way[0]) if box.ShowModal()==wx.ID_OK: direction=box.GetValue() if direction == "w": temp = (x-1,y) temp2 = (x+1,y) elif direction == "a": temp = (x,y-1) temp2 = (x,y+1) elif direction == "s": temp = (x+1,y) temp2 = (x-1,y) elif direction == "d": temp = (x,y+1) temp2 = (x,y-1) self.map[x][y] = repeater(temp,temp2)
def _clear(self): '''(world) -> NoneType Fills the map with air blocks''' i = 0 while i<MAP_SIZE: k = 0 while k<MAP_SIZE: self.map[i][k] = tile() self.torches = [] k+=1 i+=1
def load_world(self, filename): '''(world, string) -> NoneType Load a saved world''' #Files must be named *.map #MAP_SIZE X MAP_SIZE matrix with letters {A/B/R/P/T} #After a "P" for repeater you must enter the direction it is facing # "a" --> left, "s" --> down, "d" --> right, "w" --> up mapfile = open(filename + ".map", "r") assert mapfile.readline() == "MAPSTART\n" currline = mapfile.readline() self.map = [] i = 0 while currline != "MAPFINISH\n": self.map.append([]) times = 1 l = 0 rep = False tor = False for o in currline: if tor: if o in ['a','w','s','d','n']: self.map[i][l-1].onbox = o self.torches.append((i,l-times)) times +=1 tor = False if rep: x=i y=l-times times +=1 to = {'a':(x,y-1),'w':(x-1,y),'d':(x,y+1),'s':(x+1,y)} rev = {'a':'d','d':'a','w':'s','s':'w'} self.map[i].append(repeater(to[o],to[rev[o]])) rep = False elif o == "A": self.map[i].append(tile()) elif o == "B": self.map[i].append(block()) elif o == "R": self.map[i].append(redstone()) elif o == "T": self.map[i].append(torch()) tor = True elif o == "P": rep = True l+=1 i+=1 currline = mapfile.readline()
def create_world(self): '''(world) -> NoneType Create a 2-D list by creating a list that has lists in it.''' #Create a simple empty list self.map = [] i = 0 while i<MAP_SIZE: k = 0 #Add a new element in the list, this element is also an empty list self.map.append([]) while k<MAP_SIZE: #Add a new element in the list that you just created. #so our list will look somewhat like this #self.map = [[...],[...],...,[...],[...]] self.map[i].append(tile()) k+=1 i+=1
def setBoard(self, adjacencyMatrixArray, colorArray, strengthArray): validLength = (self.numberOfRows/2)*self.evenRowColumnNumber + (self.numberOfRows/2 + self.numberOfRows % 2)*self.oddRowColumnNumber if len(adjacencyMatrixArray) != validLength or len(colorArray) != validLength or len(strengthArray) != validLength: print "invalid lengths. valid length = " + str(validLength) + ", invalid length = " + str(len(adjacencyMatrixArray)) + " or " + str(len(colorArray)) + " or " + str(len(strengthArray)) return -1 columnIndex = 0 rowIndex = 1 self.listOfTiles = {} for i in range(1,validLength+1): columnIndex = columnIndex + 1 if (rowIndex % 2 == 1 and columnIndex > self.oddRowColumnNumber) or (rowIndex % 2 == 0 and columnIndex > self.evenRowColumnNumber): columnIndex = 1 rowIndex = rowIndex + 1 self.listOfTiles[i] = tile(self.getCoor(columnIndex,rowIndex), adjacencyMatrixArray[i-1], colorArray[i-1], strengthArray[i-1]) #
def __init__(self, data=None): if data is not None: self.map = data else: self.map = [] for i in range(100): self.map.append(tile()) self.map[0].isOpen = True self.map[1].mana = 5 self.map[2].state = ('chance', None, None) self.map[3].state = ('heal', 30, None) self.map[4].state = ('battle', 'wolf', None) self.map[5].state = ('move', 'push', 3) self.map[6].state = ('move', 'portal', 1) self.map[7].state = ('move', 'player', 0) self.map[8].state = ('trap', 'poison', 10) self.map[9].state = ('trap', 'overLoad', None) self.map[10].state = ('trap', 'atomic', None)
def Decorator(self, tile, number, base_tile='all', z=2, stack=False, also_avoid=[]): for _ in range(number): stacked = False rx = randint(0, self.size_x * self.scale - 1) ry = randint(0, self.size_y * self.scale - 1) if not stack: for li in self.contents: for item in li: if type(item) == tile or type(item) in also_avoid: x = self.scale * item.size_rescale[0] y = self.scale * item.size_rescale[1] if (item.x - x + 1 < rx < item.x + x - 1 and item.y - y + 1 < ry < item.y + y - 1 ) or stacked: stacked = True break while base_tile not in self.map[ry // self.scale][ rx // self.scale].name or stacked: stacked = False rx = randint(0, self.size_x * self.scale - 1) ry = randint(0, self.size_y * self.scale - 1) if not stack: for li in self.contents: for item in li: if type(item) == tile or type(item) in also_avoid: x = self.scale * item.size_rescale[0] y = self.scale * item.size_rescale[1] if (item.x - x < rx < item.x + x and item.y - y < ry < item.y + y) or stacked: stacked = True break self.addRenderingComponent(tile(rx, ry), zprior=z)
fileMenu.add_command(label="Save", command=saveFile) fileMenu.add_command(label="Load", command=loadFile) editMenu.add_command(label="Clear", command=gm.clearBoard) menubar.add_cascade(label="File", menu=fileMenu) menubar.add_cascade(label="Edit", menu=editMenu) window.config(menu=menubar) with open("newMaster.json", 'r') as jsonInput: gm.jsonTiles = js.load(jsonInput) i = 0 j = 0 for boardTile in gm.jsonTiles: btn = tile(window, boardTile, (i, j)) gm.allTiles.append(btn) btn.tile.grid(row=i, column=j, sticky="NSWE") window.rowconfigure(i, weight=1) window.columnconfigure(j, weight=1) j += 1 if (j >= gm.COLS): j = 0 i += 1 if i >= gm.ROWS: i = 0 window.rowconfigure(gm.ROWS, weight=1) gm.player1.setFrame(window, gm.ROWS)
def dont_fall_tile(): for i in range(40): tmp = tile('cant_break', i * BLOCK_SIZE, -BLOCK_SIZE) gfw.world.add(gfw.layer.tile, tmp)
def handle_line(self, line, y_pos): global spawn_locations x_pos = 0 for cell in line: if cell == 'l':#normal block new_cell = tile(x_pos, y_pos, 0, self) new_cell.load_model() self.cell_list.append(new_cell) elif cell == 'e':#edge block new_cell = edge_tile(x_pos, y_pos, 0, self) new_cell.load_model() self.cell_list.append(new_cell) elif cell == 'v':#spike new_cell = spike(x_pos, y_pos) new_cell.load_model() self.cell_list.append(new_cell) elif cell == 'r':#rumble new_cell = sticky(x_pos, y_pos) new_cell.load_model() self.cell_list.append(new_cell) elif cell == '+':#boost new_cell = boost(x_pos, y_pos) new_cell.load_model() self.cell_list.append(new_cell) elif cell == 'p':#piston new_cell = piston(x_pos, y_pos) new_cell.load_model() self.cell_list.append(new_cell) elif cell == '0':#empty new_cell = pit(x_pos, y_pos) new_cell.load_model() self.cell_list.append(new_cell) elif cell == 'b':#barrier new_cell = bumper(x_pos, y_pos) new_cell.load_model() self.cell_list.append(new_cell) elif cell == '_':#barrier new_cell = bumper(x_pos, y_pos) new_cell.load_model() self.cell_list.append(new_cell) elif cell == '-':#barrier new_cell = bumper(x_pos, y_pos) new_cell.load_model() new_cell.model.setH(180) self.cell_list.append(new_cell) elif cell == '[':#barrier new_cell = bumper(x_pos, y_pos) new_cell.load_model() new_cell.model.setH(270) self.cell_list.append(new_cell) elif cell == ']':#barrier new_cell = bumper(x_pos, y_pos) new_cell.load_model() new_cell.model.setH(90) self.cell_list.append(new_cell) elif cell == 's':#spawn spawn_locations.append((x_pos + 25, y_pos + 25),) print spawn_locations new_cell = tile(x_pos, y_pos, 0, self) new_cell.load_model() self.cell_list.append(new_cell) else: pass # new_cell = terrain(x_pos, y_pos, 0, self) # new_cell.load_model() # self.cell_list.append(new_cell) x_pos = x_pos + self.cell_width
camera_offset = sf.Vector2(0,0) # create the main window window = sf.RenderWindow(sf.VideoMode(const.SCREEN_SIZE[0], const.SCREEN_SIZE[1]), "PySFML") tiles = [] shuf_tiles = list(const.TILE_RATIO) random.shuffle(shuf_tiles) for y in range(0,7): tiles.append([]) for x in range(0,6): tiles[y].append(None) for c in const.VALID_COORDINATES: tile_texture = const.TYPES[shuf_tiles.pop()] tiles[c[0]][c[1]] = tile(1, tile_texture, c) std_texture = sf.Texture.from_file("media/1x1.png") calibrationTexture = sf.Texture.from_file("media/Calibration.png") calibrationSprite = sf.Sprite(calibrationTexture); calibrationSprite.scale((const.SCREEN_CORRECTION, const.SCREEN_CORRECTION)) game_state = GameState.WAIT_CALIBRATE calibratePressed = False; camera_wait_start = 0 TrackTalker.tell_restart();