示例#1
0
 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]))
示例#2
0
文件: Game.py 项目: rystills/Oceania
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()
示例#3
0
 def render_break_preview(self, background, world, block, block_pos, screen, viewport):
     blockimg = world.get_block_render(World.get_block_id(block["name"]), block_pos, block["connectedTexture"], background, 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))
示例#4
0
 def render_block_preview(self, background, held_item, world, block_pos, screen, viewport):
     held_block = World.get_block(held_item.name)
     blockimg = world.get_block_render(World.get_block_id(held_block["name"]), block_pos, held_block["connectedTexture"], background, 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)
     screen.blit(polysurface, Convert.world_to_viewport(block_pos, viewport))
     collides = False
     entities = self.get_nearby_entities(world)
     entities.append(self)
     for entity in entities:
         if entity.collides(block_pos) and entity.background == background:
             collides = True
     color = self.get_color(background)
     if collides and World.get_block(held_block["name"])["solid"]:
         color = (color[0], 0, 0, color[3])
     pygame.draw.polygon(polysurface, color, olist, 0)
     blockimg.blit(polysurface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
     screen.blit(blockimg, Convert.world_to_viewport(block_pos, viewport))
示例#5
0
文件: World.py 项目: kaikue/Oceania
 def render_breaks(self, screen, viewport, background):
     for breaking_block in self.breaking_blocks[background]:
         break_index = int(breaking_block["progress"] / breaking_block["breaktime"] * Game.BREAK_LENGTH)
         breakimg = Images.break_images[break_index].copy()
         blockimg = block_images[False][get_block_id(breaking_block["name"])] #TODO: make this support CTM
         mask = pygame.mask.from_surface(blockimg)
         olist = mask.outline()
         polysurface = pygame.Surface((Game.BLOCK_SIZE * Game.SCALE, Game.BLOCK_SIZE * Game.SCALE), pygame.SRCALPHA)
         pygame.draw.polygon(polysurface, Game.WHITE, olist, 0)
         breakimg.blit(polysurface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
         screen.blit(breakimg, Convert.world_to_viewport(breaking_block["pos"], viewport))
示例#6
0
文件: World.py 项目: rystills/Oceania
 def render_block(self, block_id, block_pos, connected, screen, viewport):
     if connected:
         #check adjacent tiles
         left_block = self.get_block((block_pos[0] - 1, block_pos[1]))["id"]
         right_block = self.get_block((block_pos[0] + 1, block_pos[1]))["id"]
         top_block = self.get_block((block_pos[0], block_pos[1] - 1))["id"]
         bottom_block = self.get_block((block_pos[0], block_pos[1] + 1))["id"]
         tile = ()
         if left_block != block_id:
             if top_block != block_id:
                 tile = (0, 0)
             elif bottom_block != block_id:
                 tile = (0, 2)
             else:
                 tile = (0, 1)
         if right_block != block_id:
             if top_block != block_id:
                 tile = (2, 0)
             elif bottom_block != block_id:
                 tile = (2, 2)
             else:
                 tile = (2, 1)
         if top_block != block_id:
             tile = (1, 0)
         elif bottom_block != block_id:
             tile = (1, 2)
         else:
             tile = (1, 1)
         
         screen.blit(block_images[block_id],
                     Convert.world_to_viewport(block_pos, viewport),
                     pygame.Rect((tile[0] * Game.BLOCK_SIZE * Game.SCALE, tile[1] * Game.BLOCK_SIZE * Game.SCALE),
                                 (Game.BLOCK_SIZE * Game.SCALE, Game.BLOCK_SIZE * Game.SCALE)))
     else:
         #just render it normally
         screen.blit(block_images[block_id], Convert.world_to_viewport(block_pos, viewport))
示例#7
0
 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
示例#8
0
文件: Chunk.py 项目: rystills/Oceania
 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))
示例#9
0
文件: Game.py 项目: kaikue/Oceania
def render():
    if gamemode == MAINMENU or gamemode == PAUSEMENU:
        menu.render_background(screen)
        menu.render(screen)
        
    elif gamemode in (PLAYING, OPENGUI):
        player = world.player
        shift = pygame.key.get_pressed()[pygame.K_LSHIFT] or pygame.key.get_pressed()[pygame.K_RSHIFT]
        screen.fill(SKY)
        
        #background
        world.render(screen, viewport, True)
        if shift:
            player.draw_block_highlight(world, pygame.mouse.get_pos(), viewport, screen, shift)
        world.render_breaks(screen, viewport, True)
        
        #foreground
        world.render(screen, viewport, False)
        if not shift:
            player.draw_block_highlight(world, pygame.mouse.get_pos(), viewport, screen, shift)
        world.render_breaks(screen, viewport, False)
        player.render(screen, Convert.world_to_viewport(player.pos, viewport))
        
        #add blue overlay- not completely sure this is good
        overlay = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT))
        overlay.set_alpha(64)
        overlay.fill(BLUE)
        screen.blit(overlay, (0, 0))
        
        if gamemode == PLAYING:
            hotbarGui.render(screen)
        else:
            gui.render(screen)
        
        if DEBUG:
            #render debug text
            chunk = world.loaded_chunks.get(Convert.world_to_chunk(player.pos[0])[1])
            debugtext = ["fps: {0:.2f}".format(clock.get_fps()),
                        "pos: [{0:.2f}".format(player.pos[0]) + ", {0:.2f}]".format(player.pos[1]),
                        "chunk: " + str(chunk.x),
                        "biome: " + str(chunk.biome["name"])]
            debugimg = GUI.render_string_array(debugtext, font, 0, WHITE)
            h = SCREEN_HEIGHT - debugimg.get_height()
            screen.blit(debugimg, (2 * SCALE, h))
    pygame.display.flip()
示例#10
0
文件: Chunk.py 项目: kaikue/Oceania
 def render_entities(self, screen, viewport, background):
     for entity in self.entities:
         entity.render(screen, Convert.world_to_viewport(entity.pos, viewport))
示例#11
0
文件: World.py 项目: kaikue/Oceania
 def render_block(self, block_id, block_pos, connected, screen, viewport, background, chunk):
     screen.blit(self.get_block_render(block_id, block_pos, connected, background, chunk), Convert.world_to_viewport(block_pos, viewport))