示例#1
0
文件: ai.py 项目: jcandres/deth
 def update(self):
     dx = 0
     dy = 0
     if game.key.vk == tcod.KEY_RIGHT:
         dx = +1
     elif game.key.vk == tcod.KEY_LEFT:
         dx = -1
     elif game.key.vk == tcod.KEY_UP:
         dy = -1
     elif game.key.vk == tcod.KEY_DOWN:
         dy = +1
     else:
         self.handle_action_key(game.key.c)
         
     #process attacks or movement
     if dx != 0 or dy != 0:
         e = map.get_actor_alive(self.owner.x+dx, self.owner.y+dy)
         if e and e.blocks and e.destructible:
             nam = e.name
             self.owner.attacker.attack(e)
             if tcod.random_get_int(0,0,10)<1 and e.body:
                 game.log(self.owner.name, 'hit the', nam, 'in the', enum.rand_body_part(e))
             else:
                 game.log(self.owner.name, 'hit the', nam)
             if e.destructible.is_dead():
                 game.log(self.owner.name, 'killed the', nam+'!')
             game.game_state = enum.GameS.NEW_TURN #
         elif game.player.move(dx, dy):
             game.game_state = enum.GameS.NEW_TURN #
示例#2
0
文件: item.py 项目: jcandres/deth
 def use(self, wearer, target):
     d = game.player.ai.choose_direction()
     if d is None:
         return False
     
     dist = self.length + wearer.power / 3
     tx =  wearer.x# + d[0]
     ty =  wearer.y# + d[1]
     while dist:
         dist -= 1
         tx += d[0]
         ty += d[1]
         a = map.get_actor_alive(tx, ty)
         if (a and a is not wearer) or map.is_blocked(tx, ty):
             dist = 0
     target_x = tx#wearer.x + (d[0] * self.throw)
     target_y = ty#wearer.y + (d[1] * self.throw)
     
     game.log(wearer.name,"threw the", self.owner.name+'!')
     game.log_turn()
     game.log('BOOOM!!')
     game.log_turn()
     did_hole = False
     for x in range(target_x-self.radius+1, target_x+self.radius):
         for y in range(target_y-self.radius+1, target_y+self.radius):
             if map.is_diggable(x, y):
                 map.set_wall(x, y, False, False)
                 did_hole = True
             if not map.is_wall(x, y):
                 if map.get_distance_coord(target_x, target_y, x, y) < self.radius:
                     s = ent.Smoke(x, y, tcod.random_get_int(0, 0, game.NORMAL_SPEED*5),
                                   was_visible=not map.is_wall(x,y))
                     game.actors.append(s)
                     s = ent.Projectile(x, y, self.damage, wearer, name='explosion', self_remove=True)
                     game.actors.append(s)
                     
     if did_hole:
         game.log("the", self.owner.name, 'made a huge hole in the walls!')
     map.fov_recompute(game.player.x, game.player.y)
     if wearer and wearer.container:
         wearer.container.inventory.remove(self.owner)
         pass
     return True
示例#3
0
文件: ai.py 项目: jcandres/deth
 def seek_and_destroy(self, target):
     if target:
         dx = target.x - self.owner.x
         dy = target.y - self.owner.y
         distance = map.get_distance(self.owner, target)
         if distance > 0:
             dx = int(round(dx / distance))
             dy = int(round(dy / distance))
             d = tcod.random_get_int(0,0,1) #make them zombies move orthogonally f**k
             if d == 0:
                 if dx != 0:
                     dy = 0
                 else:
                     dx = 0
             self.owner.move(dx, dy)
             e = map.get_actor_alive(self.owner.x+dx, self.owner.y+dy)
             if e and map.is_fov(self.owner.x, self.owner.y):
                 self.owner.attacker.attack(e)
                 if e is game.player:
                     game.log('the', self.owner.name, 'hits!')
                 elif e.destructible:
                     game.log('a', self.owner.name, 'hits the', e.name)
示例#4
0
文件: item.py 项目: jcandres/deth
 def use(self, wearer, target):
     if not wearer.ai:
         return False
     d = wearer.ai.choose_direction()
     if d is None:
         return False
     
     dist = self.length + wearer.power / 3
     x =  wearer.x# + d[0]
     y =  wearer.y# + d[1]
     while dist:
         dist -= 1
         x += d[0]
         y += d[1]
         a = map.get_actor_alive(x, y)
         if (a and a is not wearer) or map.is_blocked(x, y):
             dist = 0
             if map.is_wall(x, y):
                 x -= d[0]
                 y -= d[1]
     p = ent.Projectile(x, y, self.damage, wearer)
     game.actors.append(p)
     return True
示例#5
0
文件: core.py 项目: jcandres/deth
 def attack_tile(self, x, y):
     target = map.get_actor_alive(x, y)
     if target:
         if self.attack(target):
             return target
     return None