Skip to content
This repository
Browse code

npcs snap to tiles when being talked to

  • Loading branch information...
commit bf04819cfe2fc80c15874bbb4df9e76a9267ac1d 1 parent ca9bb7c
Thomas authored

Showing 2 changed files with 10 additions and 5 deletions. Show diff stats Hide diff stats

  1. +8 1 objects.py
  2. +2 4 trainer.py
9 objects.py
@@ -123,6 +123,12 @@ def move_to(self, dir, dist, speed, resume=True): #set a movement
123 123 self.running = False #we're not supposed to be automatically moving any more
124 124 self.moving = True #we're moving
125 125 self._start_move() #start moving
  126 + def align(self): #align ourselves to the next tile
  127 + #snap to tile
  128 + self.obj.pos = [((self.obj.tile_pos[0]-1)*16)+8, (self.obj.tile_pos[1]-1)*16]
  129 + if self.pix_pos % 16 != 0: #if we're not on a tile boundary
  130 + self.pix_pos += (16-(self.pix_pos%16)) #put us there
  131 + self.obj.rect = pygame.Rect(self.obj.pos, (32, 32)) #set proper position
126 132 def update(self): #update movement
127 133 if not self.moving: #if we're not doing anything
128 134 return True #don't do anything
@@ -140,6 +146,7 @@ def update(self): #update movement
140 146 self.obj.pos[0] += self.delta[0] #move object according to speed
141 147 self.obj.pos[1] += self.delta[1]
142 148 self.pix_pos += speed #add speed to pixel position
  149 + self.obj.rect = pygame.Rect(self.obj.pos, (32, 32)) #set proper position
143 150 if self.pix_pos > 15: #if we've gone a whole tile
144 151 self.curr_movement[1] -= 1 #remove one from distance
145 152 self.pix_pos -= 16 #remove a tile's worth of pixels
@@ -271,7 +278,7 @@ def interact(self, pos):
271 278 #make ourselves face to who's talking
272 279 new_pos = [1, 0, 3, 2][pos]
273 280 self.stored_anim = self.animator.curr_animation #store current animation
274   - self.pos = [((self.tile_pos[0]-1)*16)+8, (self.tile_pos[1]-1)*16] #snap to tile
  281 + self.move_manager.align()
275 282 self.animator.set_animation("stand_"+get_direction_name(new_pos)) #set standing one
276 283 self.interacting = True #we're currently interacting
277 284 self.script_manager.start_script(self.interaction_script) #start interaction script
6 trainer.py
@@ -48,7 +48,7 @@ def move_done(self):
48 48 def interact(self, pos): #do interaction
49 49 if not self.fought: #if we haven't been fought yet
50 50 self.seen = True #we have been seen
51   - self.pos = [((self.tile_pos[0]-1)*16)+8, (self.tile_pos[1]-1)*16] #set proper position
  51 + self.move_manager.align()
52 52 self.move_manager.curr_movement[0] = [1, 0, 3, 2][pos] #set proper direction
53 53 self.move_done() #begin battle
54 54 else: #if we have
@@ -57,14 +57,12 @@ def interacting_stopped(self):
57 57 if self.seen: #if we have seen somebody and interaction stopped
58 58 self.game.transition(transition.WavyScreen(), self.start_battle) #do transition
59 59 def do_seen(self, dir, dist, tp): #somebody has been seen
60   - self.tile_pos = tp[:]
61 60 self.game.set_obj_pos(self, tp)
62   - self.pos = [((self.tile_pos[0]-1)*16)+8, (self.tile_pos[1]-1)*16]
63 61 self.seen = True #we've seen somebody
64 62 self.wait_time = 30 #set amount of time to display icon
65 63 self.move_data[0] = dir #store movement
66 64 self.move_data[1] = dist
67   - self.move_manager.move_to(dir, 0, 1, False) #stop current movement
  65 + self.move_manager.move_to(dir, 0, 0, False) #stop current movement
68 66 #set standing animation
69 67 self.animator.set_animation("stand_"+objects.get_direction_name(dir))
70 68 self.game.stopped = True #stop player from moving

0 comments on commit bf04819

Please sign in to comment.
Something went wrong with that request. Please try again.