def object(self, object_name): """ 构造object对象 参数: object_name: object名称 """ return Object(self, object_name)
def addObject(self, listPoint: list) -> None: """creat and add one Object by list of Vector Args: listPoint (list(Vector)): list of Vector """ self.objects.append(Object(listPoint)) self.nb_objects += 1
def enter(): global mario, map, enemy, object, fire_ball, chimney, mario_life global mario_life2, mario_life3, mario_life4 mario = Mario() map = Map() enemy = Enemy() object = Object() fire_ball = Ball() chimney = Chimney() mario_life = Mario_Life() mario_life2 = Mario_Life2() mario_life3 = Mario_Life3() mario_life4 = Mario_Life4() game_world.add_object(map, 0) game_world.add_object(object, 1) game_world.add_object(mario, 0) game_world.add_object(enemy, 1) game_world.add_object(chimney, 0) game_world.add_object(mario_life, 1) game_world.add_object(mario_life2, 0) game_world.add_object(mario_life3, 1) game_world.add_object(mario_life4, 0) pass
def addobject(self): """Command of the "Add Object" option in "Object" menu. Creates an Object object to support object creation. """ newobj = Object(self) newobj.config()
def generate_random(self, name, character, weight, amount): """ Add objects of type dirt to the board. Each position is generated randomly and is unique. Position values are limited by the size of the board. Parameters: - name - all objects generated here will have this name - character - all objects generated here will be represented by this character (e.g. when printing board in console) - weight - this will influence on creating path by an algorithm (A*) - amount - number of objects to be generated """ for _ in range(amount): (x, y) = ( randrange(0, self.width, 1), randrange(0, self.height, 1) ) while (x, y) in self.get_points(): (x, y) = ( randrange(0, self.width, 1), randrange(0, self.height, 1) ) self.add_object((x, y), character) self.add_weight((x, y), weight) self.add_dirt(Object(name, (x, y)))
def generate_objectmap(terrain, key): logger.debug('Generating objects...') objectmap_start = time.perf_counter() # Create a blank slate to fill with terrain values objectmap = _create_blank(len(terrain), len(terrain[0])) # Calculate the total number of objects to generate objectcount = math.floor(MAP_WIDTH * MAP_HEIGHT * MAP_OBJECTPOP) objects = { 'shrub': 0.75, 'tree_stump': 0.05, 'rock': 0.07 } objterrain = { 'shrub': ['grass'], 'tree_stump': ['grass'], 'rock': ['dirt'] } for i in range(objectcount): x = random.randint(0, MAP_WIDTH - 1) y = random.randint(0, MAP_HEIGHT - 1) objname = _choose_value(objects) # Restricts objects to certain kinds of terrain if key[terrain[x][y]] in objterrain[objname]: objimage = GRAPHICS[objname] obj = Object(objimage, x, y) objectmap[x][y] = obj objectmap_end = time.perf_counter() logger.debug(f'Objectmap generated in {objectmap_start - objectmap_end} seconds') # Return the objectmap return objectmap
def detect_objects(self, image): """ Detect the objects in the image. :param image: the input image :return: the list of detected objects """ # List of the detected objects objects_detected = [] # Preprocess image for network image = preprocess_image(image) image, scale = resize_image(image) # Process image start = time.time() boxes, scores, labels = self.model.predict_on_batch( np.expand_dims(image, axis=0)) print("Processing time: ", time.time() - start) # Correct for image scale boxes /= scale # Add detected objects to the list for box, score, label in zip(boxes[0], scores[0], labels[0]): if score < DETECTION_TRESHOLD: continue box = box.astype(int) objects_detected.append(Object(box, score, label)) return objects_detected
def read_object(file_name): faces = [] vertices = [] file = open(file_name, "r") lines = file.readlines() for line in lines: if line.startswith("o"): name_line = line.split() name = name_line[1] elif line.startswith("v"): vertices_line = line.split() vertex = Vec3d(float(vertices_line[1]), float(vertices_line[2]), float(vertices_line[3])) vertices.append(vertex) elif line.startswith("f"): faces_line = line.split() face = [ int(faces_line[1]), int(faces_line[2]), int(faces_line[3]), int(faces_line[4]) ] faces.append(face) obj = Object(name, vertices, faces) return obj
def enter(): global mario, map, enemy, object mario = Mario() map = Map() enemy = Enemy() object = Object() pass
def enter(): global mario, map, enemy, object, fire_ball, chimney, mario_life global mario_life2, mario_life3, mario_life4 global item_box, brick, item mario = Mario() map = Map() enemy = Enemy() object = Object() fire_ball = Ball() chimney = Chimney() mario_life = Mario_Life() mario_life2 = Mario_Life2() mario_life3 = Mario_Life3() mario_life4 = Mario_Life4() item_box = Object_Item() brick = Brick() item = Item() game_world.add_object(map, 0) game_world.add_object(object, 1) game_world.add_object(mario, 0) game_world.add_object(enemy, 1) game_world.add_object(chimney, 0) game_world.add_object(mario_life, 1) game_world.add_object(mario_life2, 0) game_world.add_object(mario_life3, 1) game_world.add_object(mario_life4, 0) game_world.add_object(item_box, 1) game_world.add_object(brick, 0) pass
def create_object(self, offset): x = random.randint(0, self.size[0] - Object.size[0]) y = random.randint(0, self.size[1]) - offset speed = random.randint(7, 10) / 10 color = [200, 0, 0] obj = Object([x, y], speed, color) return obj
def draw(self, surface, camera=Object()): """ Draws the Superclass' `Display`. `surface` - The surface being drawn to. `camera` - An `Object` which the `Display` will be drawn relative to. """ self._display.draw(surface, camera)
def create_random_trees(num): global screen for _ in range(0,num): x = random.randint(0,1000) y = random.randint(0,1000) tree_obj = Object('tree', tree, x, y, screen) list_of_trees.append(tree_obj)
def place_object(map, item, x, y): class_name = type(item).__name__ blocks = True if class_name == 'Creature' else False map_object = Object(item.character, blocks=blocks) map_object.set_position(x, y) map_object.add_component(item) map_object.level_map = map map.objects.append(map_object) return map_object
def _getFileAutocreate(self, realFileName): fileObj = self.store.find(Object, Object.realFileName == realFileName).any() if fileObj is None: fileObj = Object() fileObj.realFileName = realFileName self.store.add(fileObj) return fileObj else: return fileObj
def new_game(): Game.state = 'playing' Game.dungeon_level = 1 Game.game_msgs = [] Game.mouse = libtcod.Mouse() Game.key = libtcod.Key() Game.inventory = [] Game.panel = libtcod.console_new(Game.SCREEN_WIDTH, Game.PANEL_HEIGHT) Game.map = Map(Game.MAP_WIDTH, Game.MAP_HEIGHT) libtcod.console_clear(Game.main_console) _fighter_component = Components.Fighter( hp=100, dexterity=4, accuracy=20, power=4, xp=0, death_function=Components.player_death) Game.player = Object(Game.map.origin[0], Game.map.origin[1], '@', 'Drew', libtcod.pink, blocks=True, fighter=_fighter_component) Game.player.level = 1 Game.map.add_object(Game.player) _equipment_component = Equipment(slot='right hand', power_bonus=2) _obj = Object(0, 0, '-', 'dagger', libtcod.sky, equipment=_equipment_component) Game.inventory.append(_obj) _equipment_component.equip() Game.message( 'Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.', libtcod.light_green)
def build(self): ix = self._image.get_width() / self._tLength iy = self._image.get_height() self._anim[1][1][False].append(self._image.subsurface(Object(rect=(0, 0, ix, iy)).asRect())) top = self._anim[1][1][False][-1] self._anim[-1][1][False].append(pygame.transform.flip(top, True, False)) self._anim[1][-1][False].append(pygame.transform.flip(top, False, True)) self._anim[-1][-1][False].append(pygame.transform.flip(top, True, True)) for i in range(1, self._tLength): for e in range(2): self._anim[1][1][True].append(self._image.subsurface(Object(rect=(ix * i, 0, ix, iy)).asRect())) top = self._anim[1][1][True][-1] if self._hFlip: self._anim[-1][1][True].append(pygame.transform.flip(top, True, False)) if self._vFlip: self._anim[1][-1][True].append(pygame.transform.flip(top, False, True)) if self._hFlip and self._vFlip: self._anim[-1][-1][True].append(pygame.transform.flip(top, True, True))
def draw(self, surface, camera=Object()): """ Draws the `Display`'s `Surface` to `surface`. `surface` - The surface being drawn to. `camera` - An `Object` which the `Display` will be drawn relative to. """ if self._animation: self.replace(self._animation.animate()) rect = Display.translate(self._klass, camera) surface.blit(self._image, (rect.x, rect.y))
def iterate(self): if self.rt == 1: self.iter_list = np.zeros( (self.num_pts, self.err_pts * np.power(2, (self.num_pts - 1)))) for i in range(0, self.num_pts): self.dt.append(self.dt_start) self.dt_start = self.dt_start / 2 for p in range(0, self.num_pts): objectList = [] for i in range(0, 3): Obj = Object(self.mass_list[i] * phys.MASS_SCALING, \ phys.State(self.xy[2 * i], self.xy[2 * i + 1], self.vel_list[2 * i], self.vel_list[2 * i+1], i+1)) objectList.append(Obj) # Only saves the data for Object 1's x-velocity for j in range(0, self.err_pts * np.power(2, p)): self.iter_list[p, j] = objectList[0].state.get_vel()[1] for k in range(0, len(objectList)): objectList[k].state = phys.iterate( objectList[k].get_state(), self.dt[p], self.method) phys.G_OBJECTS.clear() else: self.iter_list = np.zeros((self.num_pts, self.err_pts)) for i in range(0, self.num_pts): dt.append(self.dt_start) self.dt_start = self.dt_start / self.stepsize for p in range(0, self.num_pts): objectList = [] for i in range(0, 3): Obj = Object(self.mass_list[i] * phys.MASS_SCALING, \ phys.State(self.xy[2 * i], self.xy[2 * i + 1], self.vel_list[2 * i], self.vel_list[2 * i+1], i+1)) objectList.append(Obj) for j in range(0, self.err_pts): self.iter_list[p, j] = objectList[0].state.get_vel()[1] for k in range(0, len(objectList)): objectList[k].state = phys.iterate( objectList[k].get_state(), self.dt[p], self.method) phys.G_OBJECTS.clear() self.iter_flag = 1
def update(self): self._heartLen = self._parent.getBaseHealth() self.w, self.h = 10 * self._heartLen + 2 * ceil(self._heartLen / 2), 16 surf = Surface((self.w, self.h)) trans = self._heartFilled[0].get_at((0, 0)) surf.fill(trans) surf.set_colorkey(trans) self._display = Display(surface=surf, klass=self) for i in range(self._heartLen): self._hearts.append(surf.subsurface(Object(rect=(10 * i + 2 * (i // 2), 0, 10, 16)).asRect()))
def move(self, apple, x_max, y_max): self.tail.append(self.head) if self.direction == Direction.UP: self.head = Object(self.head.x, self.head.y - 1) elif self.direction == Direction.DOWN: self.head = Object(self.head.x, self.head.y + 1) elif self.direction == Direction.LEFT: self.head = Object(self.head.x - 1, self.head.y) elif self.direction == Direction.RIGHT: self.head = Object(self.head.x + 1, self.head.y) if self.head == apple: return ObjectName.APPLE else: self.tail.pop(0) if self.head.x > x_max or self.head.y > y_max or self.head.x < 0 or self.head.y < 0: return ObjectName.WALL elif self.head in self.tail: return ObjectName.TAIL else: return ObjectName.FREE
def setupGlobal(self): self.scope = None global_shape = Shape(0xf, 'Global', None, "", -1, 0, 0xff, None) global_properties = (c_int * 0xff)() global_object = PlainObject(addressof(global_shape), global_properties, None) self.root = [global_shape, global_properties, global_object] self.this = Value.object(global_object) self.object = Object(addressof(global_object))
def enter(): global mario, map, enemy, object mario = Mario() map = Map() enemy = Enemy() object = Object() game_world.add_object(map, 0) game_world.add_object(object, 1) game_world.add_object(mario, 2) game_world.add_object(enemy, 3) pass
def create_object(name): if name in docs.svg_elements: return SVGElement.create(name) elif name in docs.html_elements: return HTMLElement.create(name) elif name == "Function": return Function() elif name == "EventHandler": return EventHandler() elif name == "Dummy": return dummy else: return Object(name)
def enter(): global mario, map, enemy, object, fire_ball mario = Mario() map = Map() enemy = Enemy() object = Object() fire_ball = Ball() game_world.add_object(map, 0) game_world.add_object(object, 1) game_world.add_object(mario, 0) game_world.add_object(enemy, 1) pass
def init(): objects.append(Object('sofa', (80, 60), (280, 200), 30, background)) objects.append(Object('chair', (50, 50), (380, 300), 40, background)) objects.append(Object('chair', (50, 50), (190, 420), 120, background)) objects.append(Object('tv', (130, 10), (280, 300), -50, background)) objects.append(Object('plant', (30, 30), (420, 280), -150, background)) objects.append(Object('plant', (30, 30), (320, 190), -120, background)) objects.append(Object('plant', (30, 30), (230, 50), -100, background)) #cv2.rectangle(background, (100,100), (200,300), (0,0,255)) cv2.imshow("background", background) cv2.waitKey()
def iterate_methods(self): for p in range(0, 3): objectList = [] for i in range(0, 3): Obj = Object(self.mass_list[i] * phys.MASS_SCALING, \ phys.State(self.xy[2 * i], self.xy[2 * i + 1], self.vel_list[2 * i], self.vel_list[2 * i+1], i+1)) objectList.append(Obj) for j in range(0, self.err_pts): self.methods_list[p, j] = objectList[0].state.get_vel()[1] for k in range(0, len(objectList)): objectList[k].state = phys.iterate( objectList[k].get_state(), self.dt_start1, p) phys.G_OBJECTS.clear() self.meth_flag = 1
def __init__(self, xml_filename): tree = ET.parse(xml_filename) root = tree.getroot() self.object_list = [] self.blank_gap_dictionary = {} self.last_blank_start = 0 for object_element in root.iter('OBJECT'): object_ = Object(object_element) object_.extract_words() object_.extract_possible_page_numbers() self.object_list.append(object_) self.__perform_temporary_prediction() self.__perform_fillup_gaps_arabic() self.__perform_fillup_roman_numerals()
def load_map(self,folder,name): #This should be read from layout.txt self.spawn_x = 50 self.spawn_y = 50 #opens an .oel file and create map from it tree = ET.parse(os.path.join('data','maps',folder,name)) root = tree.getroot() self.camera.map_w = int(root.attrib['width']) self.camera.map_h = int(root.attrib['height']) self.map_size = (self.camera.map_w, self.camera.map_h) for r in root: for o in r: if o.tag == 'tile': size = 25 target = Platform(int(o.attrib['x'])*size,int(o.attrib['y'])*size,int(o.attrib['tx']),int(o.attrib['ty']),size) if int(o.attrib['ty']) == 0: self.platforms.append(target) elif int(o.attrib['tx']) == 7 and int(o.attrib['ty']) == 1: self.spawn_x = int(o.attrib['x']) * size self.spawn_y = int(o.attrib['y']) * size elif int(o.attrib['tx']) == 4 and int(o.attrib['ty']) == 1: self.interactables.append(target) elif int(o.attrib['tx']) == 5 and int(o.attrib['ty']) == 1: self.previous_stage = target elif int(o.attrib['tx']) == 6 and int(o.attrib['ty']) == 1: self.next_stage = target elif int(o.attrib['tx']) == 7 and int(o.attrib['ty']) == 2: self.coins.append(target) self.entity.append(target) else: self.entity.append(target) else: target = Object(int(o.attrib['x']),int(o.attrib['y']),o.tag+'.png',colorkey=None,folder='maps') target.set_message('This is a ' + o.tag) self.objects.append(target) self.entity.append(target) return self
def __init__(self): self.running = True self.rows = 10 self.cols = 20 # Create the display grid self.grid = [] for i in range(self.rows): # Append a row of dots to the grid self.grid.append(["."] * self.cols) # Create a moveable object at position (5, 5) self.obj = Object("o", 5, 5, self)