Esempio n. 1
0
def test_image(console, tmpdir):
    img = libtcodpy.image_new(16, 16)
    libtcodpy.image_clear(img, libtcodpy.Color(0, 0, 0))
    libtcodpy.image_invert(img)
    libtcodpy.image_hflip(img)
    libtcodpy.image_rotate90(img)
    libtcodpy.image_vflip(img)
    libtcodpy.image_scale(img, 24, 24)
    libtcodpy.image_set_key_color(img, libtcodpy.Color(255, 255, 255))
    libtcodpy.image_get_alpha(img, 0, 0)
    libtcodpy.image_is_pixel_transparent(img, 0, 0)
    libtcodpy.image_get_size(img)
    libtcodpy.image_get_pixel(img, 0, 0)
    libtcodpy.image_get_mipmap_pixel(img, 0, 0, 1, 1)
    libtcodpy.image_put_pixel(img, 0, 0, libtcodpy.Color(255, 255, 255))
    libtcodpy.image_blit(img, console, 0, 0, libtcodpy.BKGND_SET, 1, 1, 0)
    libtcodpy.image_blit_rect(img, console, 0, 0, 16, 16, libtcodpy.BKGND_SET)
    libtcodpy.image_blit_2x(img, console, 0, 0)
    libtcodpy.image_save(img, tmpdir.join('test.png').strpath)
    libtcodpy.image_delete(img)

    # Not portable.
    #img = libtcodpy.image_from_console(console)
    #libtcodpy.image_refresh_console(img, console)
    #libtcodpy.image_delete(img)

    libtcodpy.image_delete(libtcodpy.image_load('../data/img/circle.png'))
Esempio n. 2
0
    def draw(self, main_map):
        #Settings
        libtcod.console_set_default_background(self.console, libtcod.black)
        libtcod.console_set_alignment(self.console, libtcod.CENTER)

        if main_map.selected_unit:
            start = (self.width - 4)/2
            #Draw all units in the unit image
            for x in range(self.width - 4):
                for y in range(self.width - 4):
                    libtcod.image_put_pixel(self.unit_image, x, y, main_map.map_list[main_map.selected_unit.x + x - start][main_map.selected_unit.y + y - start].color)
                    for u in main_map.units:
                        if u.x == (main_map.selected_unit.x + x - start) and u.y == (main_map.selected_unit.y + y - start):
                            libtcod.console_set_char_foreground(self.console, x + 2, y + 4, u.color)
                            libtcod.console_set_char(self.console, x + 2, y + 4, u.char)

            libtcod.console_print_frame(self.console, 0, 0, self.width, self.height, False, libtcod.BKGND_NONE, main_map.selected_unit.name)
            libtcod.console_rect(self.console, 0,0, 20, 1, False)
            libtcod.image_blit_rect(self.unit_image, self.console, 2, 4, self.width - 4, self.width - 4, libtcod.BKGND_SET)

            libtcod.console_set_alignment(self.console, libtcod.LEFT)
            #Unit stats
            statx = self.width + 1
            libtcod.console_print(self.console, 2, statx, 'Speed')
            libtcod.console_print(self.console, 2, statx + 1, 'Attack')
            libtcod.console_print(self.console, 2, statx + 2, 'Armor')

            libtcod.console_set_alignment(self.console, libtcod.RIGHT)
            libtcod.console_print(self.console, self.width - 2, statx, str(main_map.selected_unit.speed))
            libtcod.console_print(self.console, self.width - 2, statx + 1, str(main_map.selected_unit.attack))
            libtcod.console_print(self.console, self.width - 2, statx + 2, str(main_map.selected_unit.armor))

            libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, 1, 60 - self.height/2, 1, 0.75)
Esempio n. 3
0
 def blit_to(self, tcod_console, ox=0, oy=0, sx=-1, sy=-1):
     """Copy lighting information to libtcod console"""
     libtcod.image_blit_rect(self.__tcod_light_image, tcod_console,
                             self.pos.x + ox - 1,
                             self.pos.y + oy - 1,
                             sx, sy,
                             libtcod.BKGND_ADD)
Esempio n. 4
0
 def blit_to(self, tcod_console, ox=0, oy=0, sx=-1, sy=-1):
     """Copy lighting information to libtcod console"""
     libtcod.image_blit_rect(
         self.__tcod_light_image,
         tcod_console,
         self.pos.x + ox - self.radius,
         self.pos.y + oy - self.radius,
         #self.radius*2+1-ox, self.radius*2+1-oy,
         sx,
         sy,
         libtcod.BKGND_ADD)
Esempio n. 5
0
def image(file_string):
    #Create the image console.
    imagecon = libtcod.console_new(MAP_WINDOW_WIDTH, MAP_WINDOW_HEIGHT)

    img = libtcod.image_load('resources/' + file_string)

    #Set green as the transparent colour.
    #libtcod.console_set_key_color(imagecon, libtcod.Color(0, 255, 0))

    #Render the image and blit it to the root console.
    libtcod.image_blit_rect(img, imagecon, 0, 0, -1, -1, libtcod.BKGND_SET)
    libtcod.console_blit(imagecon, 0, 0, 50, 50, 0, 0, 0)
Esempio n. 6
0
def make_title():
    libtcod.console_clear(buf)
    libtcod.console_clear(msg)
    libtcod.console_set_default_foreground(msg, colour_default)
    libtcod.console_print(msg, 4, SCREEN_HEIGHT - 18, "Controls:")
    libtcod.console_print(msg, 4, SCREEN_HEIGHT - 17, "   arrow keys - move & attack")
    libtcod.console_print(msg, 4, SCREEN_HEIGHT - 16, "   , (comma) - pick up")
    libtcod.console_print(msg, 4, SCREEN_HEIGHT - 10, "Press Enter to start")
    libtcod.console_print(msg, 4, SCREEN_HEIGHT - 4, "ENGHack 2014 @ University of Waterloo")
    bg = libtcod.image_load("bg.png")
    libtcod.image_blit_rect(bg, msg, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, libtcod.BKGND_ADD)
    libtcod.console_blit(blank, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
    libtcod.console_blit(msg, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, 1, 1)
    libtcod.console_flush()
Esempio n. 7
0
def splash_screen(img=None):
    from utils import print_colored
    from menus import menu, msgbox
    from tiles import tile
    screen.clear()

    while True:
        if img:
            screen.clear()
            libtcod.image_blit_rect(img, 0, 0,0, -1,-1, 1)
            if img == INTRO_IMAGE:
                print_colored(screen, Pos(30, 30), colors.WHITE, "PRESS ENTER TO START!")
            screen.flush()
        else:
            game_draw()
        key, mouse = libtcod.Key(), libtcod.Mouse()
        libtcod.sys_check_for_event(libtcod.EVENT_ANY, key, mouse)
        if key.pressed and key.vk == libtcod.KEY_ENTER:
            if img == INTRO_IMAGE:
                opt = menu((colors.WHITE, "Select a mode (changeable in-game with 'tab'):"), 
                            [(colors.PALE_RED, "Tiles mode"),(colors.PALE_GREEN, "Classic ASCII") ], 50, index_color=colors.YELLOW)
                global ASCII_MODE
                ASCII_MODE = (opt == 1)
                if opt != None: 
                    hole= [] if not ASCII_MODE else [colors.YELLOW, ' (O)']
                    explanation = [ colors.BABY_BLUE, "Welcome to BUGHACK\n",
                                    colors.WHITE, "You are a leader ant who must lead worker ants to delicious harvest.\n",
                                    colors.WHITE, "Every sector you must gather a certain amount of harvest.\n", 
                                    colors.PALE_RED, "Keep your ants safe, or you'll take damage!\n", 
                                    colors.WHITE, "You must call ants out of an ant hole"] + hole + [colors.WHITE,", and then lead them to \n",
                                    colors.WHITE, "to fruit.\n",colors.WHITE, '\n',
                                    colors.YELLOW, "Press C in-game to see controls."]
                    screen.clear()
                    libtcod.image_blit_rect(img, 0, 0,0, -1,-1, 1)
                    screen.flush()
                    msgbox(explanation, 70)
                    if game_save_exists():
                        game_load()
                else:
                    continue
            screen.clear()
            screen.flush()
            return
        elif (key.pressed and key.vk == libtcod.KEY_ESCAPE) or libtcod.console_is_window_closed():
            exit()
Esempio n. 8
0
def main_menu():
    img = libtcod.image_load('menu_background.png')

    while not libtcod.console_is_window_closed():
        # show the background image, at twice the regular console resolution
        libtcod.image_blit_rect(img, 0, 0, 0, -1, -1, libtcod.BKGND_ADD)

        # show options and wait for the player's choice
        choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24)

        # new game
        if choice is 0:
            new_game()
            play_game()
        elif choice is 1:
            pass
        # quit
        elif choice is 2:
            quit_game()
Esempio n. 9
0
 def refresh(self):
     # First, handle the flow of combat or the active animation.
     if self.animPhase == 2: # If the blinking box phase is active, handle that.
         if time.time() >= self.animStarted + 0.5: # If a second has passed since this animation phase started, end it.
             self.animPhase = 0
             if self.checkBattleStatus() != None: # If the battle is won or lost, change the current scene.
                 return self.checkBattleStatus()
             self.advanceTurn() # Move to the next turn.
     else: # If there is no animation going on, handle the flow of combat.
         if self.turnOrder[0].isAI(): # If it's an enemy's turn, act according to their AI.
             self.parseTurnResults(self.turnOrder[0].aiAct(self.party,self.enemies)) # Execute the enemy AI, thne add the result to the log.
         elif len(self.moveBoxes) == 0: # Otherwise, it must be the player's turn. If there aren't any move boxes open, open one.
             self.moveBoxes.append(bx.SelectBox(22,3,-1,-1,None,self.turnOrder[0].getOptions(),-1))
     # Now on to the actual display.
     rl.console_clear(0) # Fill the window with the background color.
     for i,box in enumerate(self.partyBoxes): # Display the party boxes. Only the boxes themselves for now.
         if len(self.party) <= i or self.party[i].isDead(): # Draw a gray box if party member is not present or dead.
             box.draw(rl.darker_gray)
         else: # Otherwise, draw normal stats, aside from the bars.
             rl.console_print(0, 12, i*6+1, self.party[i].getHPLine()) # Draw HP.
             rl.console_print(0, 12, i*6+2, self.party[i].getAPLine()) # Draw AP.
             rl.console_print(0, 12, i*6+3, self.party[i].getMPLine()) # Draw MP.
             rl.console_print(0, 2, i*6+4, self.party[i].getStatusLine(18)) # Draw status effects.
         if len(self.party) <= i or self.party[i].getHP() <= 0: # Draw a red box if party member is unconscious.
             box.draw(rl.darker_red)
         elif self.animPhase == 2 and (self.animTarget == i or self.animTarget == ALL_ALLIES) and int((time.time() - self.animStarted) * 8) % 2 == 0: # If the current animPhase is 2, this is the current animation target, and the time since the animation started dictates the box should be dark red, make it dark red.
             pass
         else: # Otherwise, draw the normal party box.
             box.draw(rl.sky)
     for i,box in enumerate(self.enemyBoxes): # Display the enemy boxes. Only the boxes themselves for now.
         if len(self.enemies) <= i or self.enemies[i].getHP() <= 0: # Draw a gray box if enemy is not present or KO'd.
             box.draw(rl.darker_gray)
         elif self.animPhase == 2 and (self.animTarget - 4 == i or self.animTarget == ALL_ENEMIES) and int((time.time() - self.animStarted) * 8) % 2 == 0: # If the current animPhase is 2, this is the current animation target, and the time since the animation started dictates the box should be dark red, make it dark red.
             rl.console_print(0, 61, i*4+2, self.enemies[i].getStatusLine(18)) # Draw status effects.
         else:
             box.draw(rl.crimson) # Otherwise, draw the normal party box.
             rl.console_print(0, 61, i*4+2, self.enemies[i].getStatusLine(18)) # Draw status effects.
     self.infoBox.draw(rl.white) # Draw the combat log box.
     self.turnBox.draw(rl.white) # Draw the X's Turn box.
     rl.console_print_ex(0, 31, 1, rl.BKGND_NONE, rl.CENTER, "{0}".format(self.turnOrder[0].getColoredName())) # Draw whose turn it is.
     numBattlers = 0 # The number of conscious actors in the fight that will be shown in the turn order box (as such, this should never exceed 7).
     actorList = "" # The list of conscious actors in the fight, in the order they appear in turnOrder.
     for actor in self.turnOrder: # For each actor...
         if numBattlers < 8 and actor.getHP() > 0: # If they're conscious and the turn order box isn't already filled up...
             numBattlers += 1 # Increase the size of the box by one.
             actorList += actor.getColoredName()+"\n" # Add the battler to the list.
     self.turnOrderBox.setHeight(numBattlers+2) # Adjust the turn order box's size to match the amount of conscious battlers.
     self.turnOrderBox.draw(rl.white) # Draw the turn order box.
     rl.console_set_char(0, 42, 1, ">") # Draw the cursor in the turn order box. Purely aesthetic.
     rl.console_print(0, 44, 1, actorList) # Draw the list of conscious battlers in the turn order box.
     y = 11 # The line to draw the current log entry at.
     for msg in self.log: # Draw the lines of the log, advancing y as appropriate.
         rl.console_set_char(0, 24, y, ">") # Draw something to indicate when a log line starts. This ensures it is clear when one entry ends and a new one begins.
         rl.console_print_rect(0, 26, y, 31, 12, msg) # Draw the log line.
         y += rl.console_get_height_rect(0, 0, 0, 31, 12, msg) # Lower the y coordinate.
     # Once all that is drawn, draw the background image.
     rl.image_blit_rect(self.image, 0, 0, 0, 80, 24, rl.BKGND_SET) # Display the battle background image.
     rl.console_set_default_foreground(0, rl.white) # Sets the foreground (text) color to white.
     rl.console_set_default_background(0, rl.black) # Sets the background color to black.
     # However, only after that should the actual stats be drawn. This is so the life bar backgrounds can override the background image.
     for i,box in enumerate(self.partyBoxes): # Display the party boxes.
         if not len(self.party) <= i and not self.party[i].isDead(): # Don't draw stats if party member is not present or dead (should still show if merely KO'd.
             rl.console_print(0, 2, i*6+1, self.party[i].getHPBar()) # Draw HP bar.
             rl.console_print(0, 2, i*6+2, self.party[i].getAPBar()) # Draw AP bar.
             rl.console_print(0, 2, i*6+3, self.party[i].getMPBar()) # Draw MP bar.
     for i,box in enumerate(self.enemyBoxes): # Display the enemy boxes.
         if not len(self.enemies) <= i and not self.enemies[i].getHP() <= 0: # Don't draw stats if enemy is not present or KO'd.
             rl.console_print(0, 61, i*4+1, self.enemies[i].getHPBar()) # Draw HP bar.
             rl.console_print(0, 67, i*4+1, self.enemies[i].getAPBar()) # Draw AP bar.
             rl.console_print(0, 73, i*4+1, self.enemies[i].getMPBar()) # Draw MP bar.
     for i,box in enumerate(self.moveBoxes): # Draw all the move boxes, the current one being yellow. Since this can overlap the enemy stats, this must be drawn after that.
         if i+1 == len(self.moveBoxes):
             box.draw(rl.yellow)
         else:
             box.draw(rl.white)
Esempio n. 10
0
 def draw(self, con, cam):
     #libtcod.image_blit_2x(self.world_img, con, 0,0, cam.x, cam.y, cam.w, cam.h)
     libtcod.image_blit_rect(self.world_img, con, 0 - cam.x, 0 - cam.y, self.width, self.height, libtcod.BKGND_SET)