当前位置: 首页>>代码示例>>Python>>正文


Python Convert类代码示例

本文整理汇总了Python中Convert的典型用法代码示例。如果您正苦于以下问题:Python Convert类的具体用法?Python Convert怎么用?Python Convert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Convert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_telemetry

 def update_telemetry(self, telemetry_data):
     if (self.view_type == ViewTypes.ARDUINO):
         #tlv = ArduinoHelper.create_tlv(telemetry_data)
         tlv_lcd = ArduinoHelper.create_lcd_tlv(telemetry_data)
         tlv_led = ArduinoHelper.create_led_tlv(telemetry_data)
         #print("".join("%02x" % b for b in tlv.serialize()))
         self.serial.write(tlv_lcd.serialize())
         self.serial.write(tlv_led.serialize())
         print("------------SPEED-------------")
         print("           " + str(int(Convert.speed_to_kph(telemetry_data.speed))) + " KPH")
     elif (self.view_type == ViewTypes.GPIO):
         print("------------GEAR-------------")
         print("            " + str(telemetry_data.current_gear))
         print("------------------------------")
         self.gpio.update_all(telemetry_data)
     elif (self.view_type == ViewTypes.CONSOLE):
         os.system('cls' if os.name=='nt' else 'clear')
         print("------------------------------")
         print("-------------RPM--------------")
         print("            " + str(telemetry_data.rpm))
         aux = int((telemetry_data.rpm / telemetry_data.max_rpm) * 10)
         string_rpm = "----["
         for i in range(0,aux):
             string_rpm += '**'
         for i in range(aux, 10):
             string_rpm += '  '
         string_rpm += "]----"
         print(string_rpm)
         print("------------SPEED-------------")
         print("           " + str(int(Convert.speed_to_kph(telemetry_data.speed))) + " KPH")
         print("------------GEAR-------------")
         print("            " + str(telemetry_data.current_gear))
         print("------------------------------")
开发者ID:fsikansi,项目名称:simple-dash-pcars,代码行数:33,代码来源:ViewController.py

示例2: render

def render():
    if gamemode == MENU:
        menu.render(screen)
    elif gamemode == PLAYING:
        screen.fill(SKY)
        world.render(screen, viewport)
        if DEBUG:
            #render debug text
            h = 10
            fpsimg = font.render("fps: " + str(clock.get_fps()), 0, WHITE)
            screen.blit(fpsimg, (10, h))
            h += fpsimg.get_height()
            posimg = font.render("pos: [{0:.2f}".format(player.pos[0]) + ", {0:.2f}]".format(player.pos[1]), 0, WHITE)
            screen.blit(posimg, (10, h))
            h += posimg.get_height()
            chunk = world.loaded_chunks.get(Convert.world_to_chunk(player.pos[0])[1])
            chunkimg = font.render("chunk: " + str(chunk.x), 0, WHITE)
            screen.blit(chunkimg, (10, h))
            h += chunkimg.get_height()
            biomeimg = font.render("biome: " + str(chunk.biome["name"]), 0, WHITE)
            screen.blit(biomeimg, (10, h))
            h += biomeimg.get_height()
        player.render(screen, Convert.world_to_viewport(player.pos, viewport))
        if gui is None:
            target_pos = world.find_pos(world.find_angle(player, pygame.mouse.get_pos(), viewport), 
                                        Convert.pixels_to_viewport(player.pixel_pos(True), viewport), 
                                        pygame.mouse.get_pos(),
                                        player.get_break_distance())
            screen.blit(img_target, [x - y for x, y in zip(target_pos, [dim / 2 for dim in img_target.get_size()])]) #zoo-wee mama!
        else:
            gui.render(screen)
    pygame.display.flip()
开发者ID:rystills,项目名称:Oceania,代码行数:32,代码来源:Game.py

示例3: generate_structure

 def generate_structure(self, structure, x):
     #TODO: add background blocks defined separately
     if structure["type"] == "column":
         height = random.randint(structure["minheight"], structure["maxheight"])
         for y in range(self.heights[x] - height, self.heights[x]):
             self.set_block_at(x, y, World.get_block(structure["block"]), False)
     elif structure["type"] == "json":
         structure_file = open(structure["location"])
         structure_json = json.load(structure_file)
         curr_y = self.heights[x] - len(structure_json["shape"])
         for line in structure_json["shape"]:
             curr_world_x = Convert.chunk_to_world(x, self)
             for char in line:
                 #find the right chunk
                 chunk = self #world.chunks[Convert.world_to_chunk(x)[1]]- can't really do this...
                 curr_chunk_x = Convert.world_to_chunk(curr_world_x)[0]
                 if curr_chunk_x < WIDTH:
                     if char == " ":
                         block_name = "water"
                     else:
                         block_name = structure_json["blocks"][char]
                     block = World.get_block(block_name)
                     #TODO: add background
                     chunk.set_block_at(curr_chunk_x, curr_y, block, False)
                     if block["entity"] != "":
                         #generate the block entity
                         EntityClass = getattr(importlib.import_module("ent." + block["entity"]), block["entity"])
                         instance = EntityClass([curr_world_x, curr_y], self)
                         self.entities.append(instance)
                 curr_world_x += 1
             curr_y += 1
         structure_file.close()
     elif structure["type"] == "singleblock":
         self.set_block_at(x, self.heights[x] - 1, World.get_block(structure["block"]), False)
开发者ID:kaikue,项目名称:Oceania,代码行数:34,代码来源:Chunk.py

示例4: generate_structure

 def generate_structure(self, structure, x):
     if structure["type"] == "column":
         height = random.randint(structure["minheight"], structure["maxheight"])
         for y in range(self.heights[x] - height, self.heights[x]):
             self.blocks[y][x] = World.get_block(structure["block"])
     elif structure["type"] == "json":
         structure_file = open(structure["location"])
         structure_json = json.load(structure_file)
         curr_y = self.heights[x] - len(structure_json["shape"])
         for line in structure_json["shape"]:
             curr_world_x = Convert.chunk_to_world(x, self)
             for char in line:
                 #find the right chunk
                 chunk = self #world.chunks[Convert.world_to_chunk(x)[1]]- can't really do this...
                 curr_chunk_x = Convert.world_to_chunk(curr_world_x)[0]
                 if curr_chunk_x < WIDTH:
                     if char == " ":
                         block = "water"
                     else:
                         block = structure_json["blocks"][char]
                     chunk.blocks[curr_y][curr_chunk_x] = World.get_block(block)
                 curr_world_x += 1
             curr_y += 1
         structure_file.close()
     elif structure["type"] == "other":
         #why did I write this?
         pass
开发者ID:rystills,项目名称:Oceania,代码行数:27,代码来源:Chunk.py

示例5: break_block

 def break_block(self, player, mouse_pos, viewport):
     angle = self.find_angle(player, mouse_pos, viewport)
     block_pos = Convert.pixels_to_world(self.find_pos(angle, player.pixel_pos(True), Convert.viewport_to_pixels(mouse_pos, viewport), player.get_break_distance())) #it aint right
     chunk = self.loaded_chunks.get(Convert.world_to_chunk(block_pos[0])[1])
     block = self.get_block(block_pos)
     if block["breakable"]:
         chunk.blocks[block_pos[1]][Convert.world_to_chunk(block_pos[0])[0]] = get_block("water")
         chunk.entities.append(BlockDrop.BlockDrop(block_pos, block["name"]))
开发者ID:rystills,项目名称:Oceania,代码行数:8,代码来源:World.py

示例6: update

 def update(self):
     for x in range(self.loaded_chunks.first, self.loaded_chunks.end):
         chunk = self.loaded_chunks.get(x)
         for entity in chunk.entities:
             entity.update(self)
             if Convert.world_to_chunk(entity.pos[0])[1] != chunk.x:
                 print("Moving", entity, entity.pos)
                 chunk.entities.remove(entity)
                 self.loaded_chunks.get(Convert.world_to_chunk(entity.pos[0])[1]).entities.append(entity)
开发者ID:rystills,项目名称:Oceania,代码行数:9,代码来源:World.py

示例7: render_break_preview

 def render_break_preview(self, background, world, block, block_pos, screen, viewport):
     chunk = world.loaded_chunks.get(Convert.world_to_chunk(block_pos[0])[1])
     blockimg = world.get_block_render(World.get_block_id(block["name"]), block_pos, block["connectedTexture"], background, chunk, background).copy()
     mask = pygame.mask.from_surface(blockimg)
     olist = mask.outline()
     polysurface = pygame.Surface((Game.BLOCK_SIZE * Game.SCALE, Game.BLOCK_SIZE * Game.SCALE), pygame.SRCALPHA)
     color = self.get_color(background)
     pygame.draw.polygon(polysurface, color, olist, 0)
     screen.blit(polysurface, Convert.world_to_viewport(block_pos, viewport))
开发者ID:kaikue,项目名称:Oceania,代码行数:9,代码来源:Player.py

示例8: __init__

 def __init__(self, pos, imageurl, scale=()):
     self.pos = pos
     self.imageurl = imageurl
     self.scale = scale
     self.load_image()
     #bounding box is in pixels because it can only have ints
     self.bounding_box = pygame.Rect(Convert.world_to_pixel(pos[0]), Convert.world_to_pixel(pos[1]), self.img.get_width(), self.img.get_height())
     self.width = Convert.pixel_to_world(self.img.get_width()) + 1
     self.height = Convert.pixel_to_world(self.img.get_height()) + 1
     self.dir = [0, 0] #direction: -1, 0, 1
     self.vel = [0, 0] #speeds: any numbers
开发者ID:rystills,项目名称:Oceania,代码行数:11,代码来源:Entity.py

示例9: render_block

 def render_block(self, block, pos, screen, viewport):
     """#fast render water
     if block["name"] == "water":
         screen.blit(World.block_images[block["id"]],
                     Convert.world_to_viewport([Convert.chunk_to_world(pos[0], self), pos[1]], viewport))"""
     #don't render air
     if block["name"] != "air":
         #print(block["name"] + " " + str(block["id"]))
         Game.get_world().render_block(block["id"], [Convert.chunk_to_world(pos[0], self), pos[1]], block["connectedTexture"], screen, viewport)
     if Game.DEBUG:
         #draw bounding box
         pygame.draw.rect(screen, Game.BLACK, pygame.Rect(Convert.chunk_to_viewport(pos, self, viewport), (Game.BLOCK_SIZE * Game.SCALE, Game.BLOCK_SIZE * Game.SCALE)), 1)
开发者ID:rystills,项目名称:Oceania,代码行数:12,代码来源:Chunk.py

示例10: tentative_move

 def tentative_move(self, world, old_pos, index):
     self.pos[index] += self.vel[index]
     if index == 0:
         self.bounding_box.x = Convert.world_to_pixel(self.pos[index])
     else:
         self.bounding_box.y = Convert.world_to_pixel(self.pos[index])
     block_left = int(Convert.world_to_chunk(self.pos[0])[0])
     chunk_left = Convert.world_to_chunk(self.pos[0])[1]
     block_right = math.ceil(Convert.world_to_chunk(self.pos[0] + self.width)[0])
     chunk_right = Convert.world_to_chunk(self.pos[0] + self.width)[1]
     block_top = int(self.pos[1])
     block_bottom = math.ceil(self.pos[1] + self.height)
     col1 = col2 = col3 = col4 = False
     if chunk_left == chunk_right:
         chunk = world.loaded_chunks.get(chunk_left)
         col1 = self.check_collision(chunk, block_left, block_right, block_top, block_bottom, old_pos, index)
     else:
         #need to check from block_left in chunk_left to block_right in chunk_right and all the blocks in any chunks between them
         chunk = world.loaded_chunks.get(chunk_left)
         col2 = self.check_collision(chunk, block_left, Chunk.WIDTH, block_top, block_bottom, old_pos, index)
         for c in range(chunk_left + 1, chunk_right):
             chunk = world.loaded_chunks.get(c)
             col3 = self.check_collision(chunk, 0, Chunk.WIDTH, block_top, block_bottom, old_pos, index)
         chunk = world.loaded_chunks.get(chunk_right)
         col4 = self.check_collision(chunk, 0, block_right, block_top, block_bottom, old_pos, index)
     if col1 or col2 or col3 or col4:
         self.vel[index] = 0 #reset acceleration?
     if index == 0:
         self.bounding_box.x = Convert.world_to_pixel(self.pos[index])
     else:
         self.bounding_box.y = Convert.world_to_pixel(self.pos[index])
开发者ID:rystills,项目名称:Oceania,代码行数:31,代码来源:Entity.py

示例11: render_blocks

 def render_blocks(self, screen, viewport, background):
     top = max(Convert.pixel_to_world(viewport.y), 0)
     bottom = min(Convert.pixel_to_world(viewport.y + viewport.height) + 1, World.HEIGHT - 1)
     for blocky in range(top, bottom):
         leftData = Convert.pixel_to_chunk(viewport.x)
         rightData = Convert.pixel_to_chunk(viewport.x + viewport.width)
         if leftData[1] == self.x:
             for blockx in range(leftData[0], WIDTH):
                 self.render_block(blockx, blocky, screen, viewport, background)
         elif leftData[1] < self.x < rightData[1]:
             for blockx in range(WIDTH):
                 self.render_block(blockx, blocky, screen, viewport, background)
         elif self.x == rightData[1]:
             for blockx in range(0, rightData[0] + 1):
                 self.render_block(blockx, blocky, screen, viewport, background)
开发者ID:kaikue,项目名称:Oceania,代码行数:15,代码来源:Chunk.py

示例12: render_actual

 def render_actual(self, screen):
     index = int((self.max_decay - self.decay) / FRAME_LENGTH)
     #self.load_image()
     img = self.imgs[index] #TODO: these might all be dead surfaces if loading in
     pos = Convert.world_to_viewport(self.pos, Game.get_viewport())
     center = img.get_rect().center
     screen.blit(img, (pos[0] - center[0], pos[1] - center[1]))
开发者ID:kaikue,项目名称:Oceania,代码行数:7,代码来源:DamageSourceSweep.py

示例13: use_discrete

 def use_discrete(self, world, player, mouse_pos, viewport):
     #TODO: different types of projectile
     pos = player.pos[:]
     pixel_player_pos = Convert.world_to_viewport(pos, viewport)
     difference = (mouse_pos[0] - pixel_player_pos[0],
                   mouse_pos[1] - pixel_player_pos[1])
     length = math.sqrt(difference[0] ** 2 + difference[1] ** 2)
     normalized = [difference[0] / length * ToolMagicStaff.PROJECTILE_SPEED, 
                   difference[1] / length * ToolMagicStaff.PROJECTILE_SPEED]
     vel = [player.vel[0] + normalized[0],
                          player.vel[1] + normalized[1]]
     
     damage_source = DamageSourceBullet(pos, 5, 0.5, vel, "img/projectiles/orb.png", player, 60)
     world.create_entity(damage_source)
     
     world.create_entity(EntityEnemy(Convert.viewport_to_world(mouse_pos, viewport), "img/enemies/pinky.png", 10)) #TODO: remove
开发者ID:kaikue,项目名称:Oceania,代码行数:16,代码来源:ToolMagicStaff.py

示例14: render

 def render(self, screen, viewport):
     top = max(Convert.pixel_to_world(viewport.y), 0)
     bottom = min(Convert.pixel_to_world(viewport.y + viewport.height) + 1, World.HEIGHT)
     for blocky in range(top, bottom):
         leftData = Convert.pixel_to_chunk(viewport.x)
         rightData = Convert.pixel_to_chunk(viewport.x + viewport.width)
         if leftData[1] == self.x:
             for blockx in range(leftData[0], WIDTH):
                 self.render_block(self.blocks[blocky][blockx], (blockx, blocky), screen, viewport)
         elif leftData[1] < self.x < rightData[1]:
             for blockx in range(WIDTH):
                 self.render_block(self.blocks[blocky][blockx], (blockx, blocky), screen, viewport)
         elif self.x == rightData[1]:
             for blockx in range(0, rightData[0] + 1):
                 self.render_block(self.blocks[blocky][blockx], (blockx, blocky), screen, viewport)
     for entity in self.entities:
         entity.render(screen, Convert.world_to_viewport(entity.pos, viewport))
开发者ID:rystills,项目名称:Oceania,代码行数:17,代码来源:Chunk.py

示例15: update

 def update(self, world):
     old_chunk = Convert.world_to_chunk(self.pos[0])[1]
     hspeed = min(abs(self.vel[0] + self.acceleration * self.dir[0]), self.max_speed) * self.dir[0]
     vspeed = min(abs(self.vel[1] + self.acceleration * self.dir[1]), self.max_speed) * self.dir[1]
     self.vel = [hspeed, vspeed]
     super(Player, self).update(world)
     new_chunk = Convert.world_to_chunk(self.pos[0])[1]
     if new_chunk != old_chunk:
         world.load_chunks(new_chunk)
     
     entities = world.loaded_chunks.get(Convert.world_to_chunk(self.pos[0])[1]).entities
     for entity in entities:
         if(self.bounding_box.colliderect(entity.bounding_box)):
             if type(entity) is BlockDrop:
                 if self.pickup(entity.blockname):
                     entities.remove(entity)
                 print(self.inventory)
开发者ID:rystills,项目名称:Oceania,代码行数:17,代码来源:Player.py


注:本文中的Convert类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。