def makeouterwalls(color, size): wall_list = [] wall = entity.Wall(0, 0, wall_width, size[1], color) wall_list.append(wall) wall = entity.Wall(0, 0, size[0], wall_width, color) wall_list.append(wall) wall = entity.Wall(size[0] - wall_width, 0, wall_width, size[1], color) wall_list.append(wall) wall = entity.Wall(0, size[1] - wall_width, size[0], wall_width, color) wall_list.append(wall) return wall_list
def __init__(self, display, state, camera_size=(700, 700)): self.state = state # self.camera = camera menu_height = 40 self.size = (camera_size[0], camera_size[1] + menu_height) self.display = display # self.selected_list = [] self.selection_store = SimpleStore() self.start_wall_V = None self.ui_elements = {} # > python 3.7 dict ordering from order added # Instantiate surfaces self.ui_elements["screen"] = Screen(None, self.display, self.size) # Camera setup camera_size = (self.size[0], self.size[1] - menu_height) self.ui_elements["camera"] = Camera(self.ui_elements["screen"], self.state, camera_size) self.ui_elements["camera"].specific_setup( (0, 0)) # Center camera around origin self.ui_elements["menu"] = Menu(self.ui_elements["screen"], menu_height) self.ui_elements["menu_box"] = MenuBox(self.ui_elements["menu"], menu_height) self.ui_elements["selection_box"] = SelectionBox( self.ui_elements["menu"], menu_height, self.selection_store) entity_menu_items = [entity.Turret((0, 0)), entity.Wall((0, 0))] self.ui_elements["menu_box"].add_menu_entity(entity_menu_items) # populate ui_children for item in self.ui_elements.values(): if item.ui_parent: item.ui_parent.ui_children.append(item)
def click(self, mouse_pos): coord_store = SimpleStore() screen = self.ui_elements["screen"] camera = self.ui_elements["camera"] menu = self.ui_elements["menu"] menu_box = self.ui_elements["menu_box"] # Selection - placement if camera.rect.collidepoint(mouse_pos): if self.selection_store.shelf: if self.selection_store.shelf.type == "wall": if not self.start_wall_V: self.start_wall_V = camera.translate_camera_vector_to_map_vector( mouse_pos) else: wall = entity.Wall((0, 0)) end_wall_V = camera.translate_camera_vector_to_map_vector( mouse_pos) point_list = gen_coords_from_range( self.start_wall_V, end_wall_V, spacing=wall.rect.size[0]) for point in point_list: self.state.entity_group.add_ent( [entity.Wall(point)]) self.selection_store.change(None) self.start_wall_V = None else: mouse_pos = camera.translate_camera_vector_to_map_vector( mouse_pos) # mouse_pos = coord_sys_map_translation(camera.rect.topleft, mouse_pos) camera.add_selection(self.state, self.selection_store.shelf, mouse_pos) self.selection_store.change(None) # Selection - store elif menu.rect.collidepoint(mouse_pos): self.get_local_coord_from_target(mouse_pos, screen, menu_box, coord_store) if coord_store.shelf: self.selection_store.change(menu_box.click(coord_store.shelf))
def makeinnerblocks(color, size, count): wall_list = [] cHor = (size[0] - (wall_width * 2)) / ((count * 2) + 1) # berechne wie # breit ein "block" sein kann cVert = (size[1] - (wall_width * 2)) / ((count * 2) + 1) # berechne wie # hoch ein "block" sein kann for j in range((count * 2)): if j % 2 == 1: # jede zweite Reihe wird gefuellt (y-Achse) for i in range((count * 2)): if i % 2 == 1: # jede zweite spalte wird gefuellt (x-Achse) wall = entity.Wall(wall_width + i * cHor, wall_width + j * cVert, cHor, cVert, color) wall_list.append(wall) return wall_list
player.moving["down"] = False elif event.key == pygame.K_UP or event.key == pygame.K_w: player.moving["up"] = False elif event.key == pygame.K_SPACE: player.growing = False elif event.key == pygame.K_LSHIFT: player.shrinking = False pygame.init() windowSurface = pygame.display.set_mode((constant.WIDTH, constant.HEIGHT), 0, 32) pygame.display.set_caption('Hop Hop Hop') player = entity.Player([500, 0], 60) wall = entity.Wall([200, 200], 100, 100) while True: #game loop handleEvents() windowSurface.fill(constant.WHITE) levels.update(player) levels.draw(windowSurface) player.update() player.draw(windowSurface) wall.update(player) wall.draw(windowSurface) print(wall.rect.colliderect(player.rect))