Commits

LorenzBreu committed 49e4486

Made gunshot lines fade. . are now allowed in names and join addresses

  • Participants
  • Parent commits cc1b5b7

Comments (0)

Files changed (1)

File test/tutorial_game.py

         self.objects = objects
         self.killed = set()
         
+        self.pillars = []
+        
         self.init_fov_map() # sets self.fov_map, self.fov_recompute
         
         self.rng = libtcod.random_new_from_seed(prng_seed)
                     not tile.block_sight,
                     not tile.blocked)
     
+    def read_map(self, filepath):
+        f = open(filepath, 'r')
+        line = f.readline()
+        y = 0
+        while line != '':
+            rough_map[y] = line
+            y += 1
+            line = f.readline()
+        f.close()
+        MAP_HEIGHT = y - 1
+        x = len(rough_map[0]) - 1
+        if rough_map[0][x] == '\n':
+            x -= 1
+        i = k = 0
+        while (k <= y):
+            while (i <= x):
+                if rough_map[k][i] != ' ':
+                    self.pillars.append((i, k))
+    
     def find_random_pos(self):
         while 1:
             # hypothetically could loop forever -- doubt it.
         
         for obj in self.killed:
             self.draw_obj(obj)
+        
+        #Gunshot grapics
+        for obj in self.objects:
+            if obj.time_left == 0:
+                obj.char = ' '
+                self.draw_obj(obj)
+                self.objects.remove(obj)
+                
         for obj in self.objects:
             if obj != self.player_obj and obj not in self.killed:
                 self.draw_obj(obj)
+                
         self.draw_obj(self.player_obj)
         
         self.blit()
         self.speed = speed
         self.wait = 0
         self.world = world
+        
+        #special attibute for timed removal
+        self.time_left = 10
     
     def move_to(self, x, y):
         #move to the given coordinates
         return False
 
     def random_move(self):
-        valx = libtcod.random_get_int(self.world.rng, -1, 1)
-        valy = libtcod.random_get_int(self.world.rng, -1, 1)
-        tx = self.x + valx
-        ty = self.y + valy
-        if self.world.is_valid_move(tx, ty):
-            self.move_to(tx, ty)
+        if self.alive:
+            valx = libtcod.random_get_int(self.world.rng, -1, 1)
+            valy = libtcod.random_get_int(self.world.rng, -1, 1)
+            tx = self.x + valx
+            ty = self.y + valy
+            if self.world.is_valid_move(tx, ty):
+                self.move_to(tx, ty)
+            
+class Pew(Object):
+    '''A bullet for a gun'''
+    def take_turn(self):
+        if self.time_left > 0:
+            self.time_left -= 1
 
 class PlayerObject(Mob):
     def take_turn(self):
     def fire_gun(self, tarx, tary):
         # LORENZ: WRITE A THING THAT READS IN MAP FILES IF I HAVEN'T DONE IT
         # ALREADY -- Devin
-        message(self.name + 'shoots his gun.', libtcod.orange)
+        message(self.name + ' shoots his gun.', libtcod.orange)
         libtcod.line_init(self.x, self.y, tarx, tary)
         self.draw_line()
         
     def draw_line(self):
         (x, y) = libtcod.line_step()
         if (x, y) != (None, None):
-            pew = Object(x, y, '*', 'pew', libtcod.silver, blocking=False, alive=False)
+            pew = Pew(x, y, '*', 'pew', libtcod.silver, blocking=False, alive=False)
             self.world.place_object(pew)
             #add special code for pew so that it kills everything it touches.
             self.draw_line()
         elif key.vk == libtcod.KEY_ENTER:
             libtcod.console_clear(0)
             return name
-        elif (c.isalnum() or c in '_-*~') and len(name) < 20:
+        elif (c.isalnum() or c in '._-*~') and len(name) < 20:
             name += c
 
 def create_game_menu():