Beispiel #1
0
def display_status ():
    global status
    if status:
        libtcod.console_rect(status_console, 0, 0, M.SCREEN_WIDTH,
            (M.SCREEN_HEIGHT - M.MAP_HEIGHT), True)
        libtcod.console_set_default_foreground (status_console, libtcod.white)
        while len(status) > M.SCREEN_WIDTH*2:
            display_statusline(status[:M.SCREEN_WIDTH*2])
            key = libtcod.console_wait_for_keypress(True)
            while not key.vk == libtcod.KEY_SPACE:
                key = libtcod.console_wait_for_keypress(True)
            status = status[M.SCREEN_WIDTH*2:]
        display_statusline(status)
        libtcod.console_blit(status_console,0,0,M.SCREEN_WIDTH,
            (M.SCREEN_HEIGHT-M.MAP_HEIGHT-1),0,0,M.MAP_HEIGHT+1,1)
        libtcod.console_flush()
    else:
        display_statusline()
        libtcod.console_flush()
Beispiel #2
0
def draw_menu(con, header, options, w, screen_w, screen_h):
    if len(options) > 26:
        raise ValueError('Menu "' + header + '" has ' + str(len(options)) +
                         ' options but max is 26')

    # calculate height (header is word-wrapped)
    header_h = ltc.console_get_height_rect(con, 0, 0, w, screen_h, header)
    h = len(options) + header_h

    # add space for border
    w += 2
    h += 2

    # create new console window
    window = ltc.console_new(w, h)

    # draw border and header
    draw_panel_border(window, w, h)
    dotext(window, 1, 1, header)

    # draw options
    y = header_h + 1
    letter_index = ord('a')
    for o in options:
        text = '(' + chr(letter_index) + ') ' + o
        dotext(window, 1, y, text)
        y += 1
        letter_index += 1

    # blit menu to main console
    x = screen_w / 2 - w / 2
    y = screen_h / 2 - h / 2
    ltc.console_blit(window, 0, 0, w, h, 0, x, y, 1.0, 0.7)

    # show menu and wait for player choice
    ltc.console_flush()
    key = ltc.console_wait_for_keypress(True)
    index = key.c - ord('a')
    return index if 0 <= index < len(options) else None
Beispiel #3
0
	def input (self):
		""" Handle input

			Returns True if a turn was taken """
		key = libtcod.console_wait_for_keypress(True)

		if key.vk == libtcod.KEY_ENTER and key.lalt:
			return libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

		# Try commands
		for k in self.commands:
			if key.vk == k:
				self.commands[k](self)
				return False

		# Try ingame commands
		try:
			for k in self.ingame_commands:
				if key.vk == k:
					self.ingame_commands[k](self)
					return True
		except CouldNotMove as e:
			self.log.debug(e)
			return False
Beispiel #4
0
    def shoot(self):
        gun = -1
        for i in range(len(self.equipped)):
            if self.equipped[i].gun and self.equipped[i].gun.ammo > 0:
                gun = i
        if not gun==-1:
            class Target:
                def __init__(self, x, y):
                    self.x = x
                    self.y = y
            target = Target(self.x, self.y)
            libtcod.console_blit(cons.game_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,1)
            libtcod.console_flush()
            key = libtcod.console_wait_for_keypress(True)
            while not key.vk == libtcod.KEY_SPACE:
                R.render()
                if key.pressed:
                    if ord('k') == key.c:
                        target.y=target.y-1
                    elif ord('j') == key.c:
                        target.y=target.y+1
                    elif ord('h') == key.c:
                        target.x=target.x-1
                    elif ord('l') == key.c:
                        target.x=target.x+1
                    elif ord('y') == key.c:
                        target.x=target.x-1
                        target.y=target.y-1
                    elif ord('u') == key.c:
                        target.x=target.x+1
                        target.y=target.y-1
                    elif ord('i') == key.c:
                        target.x=target.x-1
                        target.y=target.y+1
                    elif ord('o') == key.c:
                        target.x=target.x+1
                        target.y=target.y+1
                libtcod.line_init(self.x, self.y, target.x, target.y)
                x,y=libtcod.line_step()

                # Clear the console that shows our target line.
                libtcod.console_clear(cons.gun_console)
                # Draw the target line on the gun console.
                while (not x is None):
                    if (M.gameworld[x][y].is_floor() and
                        libtcod.map_is_in_fov (player.fov, x, y)
                       ):
                        libtcod.console_set_char_background(cons.gun_console, x, y,
                            libtcod.white, libtcod.BKGND_OVERLAY)
                        target.x=x
                        target.y=y
                        x,y=libtcod.line_step()
                    else:
                        break
                # Draw the gun console to the root console.
                libtcod.console_blit(cons.gun_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,0,0.5)
                libtcod.console_flush()
                key = libtcod.console_wait_for_keypress(True)
            self.equipped[gun].gun.fire(self.x, self.y, target.x, target.y)
        else:
            S.add_status("No gun in hand!")
Beispiel #5
0
    def mainloop(self):
        while 1:
            self.cons.clear()
            for x in range(self.player.x - SW,self.player.x + SW):
                for y in range(self.player.y - SH,self.player.y + SH):
                    char = self.world.char(x, y)
                    color = self.world.get(x,y).color
                    color2 = libtcod.dark_gray
                    color3 = libtcod.color_lerp(color,color2,
                        (((x - self.player.x)**2) + ((y-self.player.y)**2)) / 2500.0)
                    color = libtcod.color_lerp(color3,libtcod.white,0.1)
                    libtcod.console_put_char(self.cons.console,
                                 (W/2 - self.player.x) + x,
                                 (H/2 - self.player.y) + y,
                                 char,
                                 libtcod.BKGND_DEFAULT)
                    libtcod.console_set_char_foreground(self.cons.console,
                                (W/2 - self.player.x) + x,
                                (H/2 - self.player.y) + y,
                                color)

            self.cons.prints(W/2,H/2,"@",self.player.color,False)

            x = W/2 - (len(self.colors) * 2)
            for i in range(len(self.colors)):
                color = self.colors[i]
                if i == 9:
                    if i == self.player.ccolor:
                        self.cons.printex(x, H - 4, ("%c+%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False)
                    else:
                        self.cons.printex(x, H - 2, ("%c+%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False)
                    self.cons.printex(x, H - 3, ("%c+%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False)
                else:
                    if i == self.player.ccolor:
                        self.cons.printex(x, H - 4, ("%c#%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False)
                    else:
                        self.cons.printex(x, H - 2, ("%c#%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False)
                    self.cons.printex(x, H - 3, ("%c#%c" % (libtcod.COLCTRL_1,libtcod.COLCTRL_STOP)) * 2, color, False)
                x += 4
            
            self.cons.printex(0, H - 1, "%c%s%c" % (libtcod.COLCTRL_1,TITLE +
                    " (" + DAY + ")",libtcod.COLCTRL_STOP),libtcod.flame, True)
            
            key = self.cons.key()
        
            if key.c == ord('q'):
                break
            elif self.keyparse(key):
                self.player.move(self.keyparse(key),self.movecheck)
            elif key.c == ord('x'):
                key = libtcod.console_wait_for_keypress(True)
                if self.keyparse(key):
                    yx2 = self.keyparse(key)[0] + self.player.x
                    yy2 = self.keyparse(key)[1] + self.player.y
                    if self.world.get(yx2,yy2).walkable and self.world.get(yx2,yy2).chr != "~":
                        if self.player.ccolor == 9:
                            self.world.setCell(yx2,yy2,Door())
                        else:
                            self.world.setCell(yx2,yy2,Block(self.colors[self.player.ccolor]))
                        self.world.updateC(yx2, yy2)
                    continue

            elif key.c == ord('z'):
                key = libtcod.console_wait_for_keypress(True)
                if self.keyparse(key):
                    yx2 = self.keyparse(key)[0] + self.player.x
                    yy2 = self.keyparse(key)[1] + self.player.y
                    if self.world.get(yx2,yy2).diggable and not self.world.get(yx2,yy2).walkable:
                        self.world.setCell(yx2,yy2,Dirt())
                        self.world.updateC(yx2, yy2)
                    continue

            elif key.c == ord('c'):
                key = libtcod.console_wait_for_keypress(True)
                if self.keyparse(key):
                    yx2 = self.keyparse(key)[0] + self.player.x
                    yy2 = self.keyparse(key)[1] + self.player.y
                    if self.world.get(yx2,yy2).chr == "+" or           \
                     self.world.get(yx2,yy2).chr == "-":
                        self.world.get(yx2,yy2).toggle()
                        self.world.updateC(yx2, yy2)
                    continue
Beispiel #6
0
 def key(self):
     return libtcod.console_wait_for_keypress(True)