Exemplo n.º 1
0
 def fire(self, x, y, dx, dy):
     # The distance this bullet has traveled.
     steps = 0
     shot_accuracy=self.accuracy
     libtcod.map_compute_fov (P.player.fov, x, y, int(P.player.view_distance*1.5),
                               True,libtcod.FOV_SHADOW)
     R.render()
     libtcod.line_init(x, y, dx, dy)
     lx,ly=libtcod.line_step()
     while (not lx is None):
         steps = steps + 1
         if not M.gameworld[lx][ly].characters:
             libtcod.console_set_char_background(
                     cons.game_console,
                     lx,
                     ly,
                     libtcod.white,
                     libtcod.BKGND_OVERLAY)
             libtcod.console_blit(cons.game_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,1)
             libtcod.console_flush()
             lx,ly=libtcod.line_step()
         else:
             if random.random() <= shot_accuracy:
                 S.add_status("You hit!")
                 libtcod.console_set_char_background(
                         cons.game_console,
                         lx,
                         ly,
                         libtcod.red,
                         libtcod.BKGND_OVERLAY)
                 libtcod.console_blit(cons.game_console,0,0,M.MAP_WIDTH,M.MAP_HEIGHT,0,0,0,1)
                 libtcod.console_flush()
                 M.gameworld[lx][ly].characters[-1].take_damage(
                         int(self.damage*random.uniform(self.accuracy, 1.0)))
             else:
                 S.add_status("You fire and miss!")
             break
     self.ammo = self.ammo-1
     self.owner.name = self.owner.name.rsplit('(')[0] + '(' + str(self.ammo) + ')'
     P.player.compute_fov()
Exemplo n.º 2
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!")