Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

npcs snap to tiles when being talked to

  • Loading branch information...
commit bf04819cfe2fc80c15874bbb4df9e76a9267ac1d 1 parent ca9bb7c
@tpwrules authored
Showing with 10 additions and 5 deletions.
  1. +8 −1 objects.py
  2. +2 −4 trainer.py
View
9 objects.py
@@ -123,6 +123,12 @@ def move_to(self, dir, dist, speed, resume=True): #set a movement
self.running = False #we're not supposed to be automatically moving any more
self.moving = True #we're moving
self._start_move() #start moving
+ def align(self): #align ourselves to the next tile
+ #snap to tile
+ self.obj.pos = [((self.obj.tile_pos[0]-1)*16)+8, (self.obj.tile_pos[1]-1)*16]
+ if self.pix_pos % 16 != 0: #if we're not on a tile boundary
+ self.pix_pos += (16-(self.pix_pos%16)) #put us there
+ self.obj.rect = pygame.Rect(self.obj.pos, (32, 32)) #set proper position
def update(self): #update movement
if not self.moving: #if we're not doing anything
return True #don't do anything
@@ -140,6 +146,7 @@ def update(self): #update movement
self.obj.pos[0] += self.delta[0] #move object according to speed
self.obj.pos[1] += self.delta[1]
self.pix_pos += speed #add speed to pixel position
+ self.obj.rect = pygame.Rect(self.obj.pos, (32, 32)) #set proper position
if self.pix_pos > 15: #if we've gone a whole tile
self.curr_movement[1] -= 1 #remove one from distance
self.pix_pos -= 16 #remove a tile's worth of pixels
@@ -271,7 +278,7 @@ def interact(self, pos):
#make ourselves face to who's talking
new_pos = [1, 0, 3, 2][pos]
self.stored_anim = self.animator.curr_animation #store current animation
- self.pos = [((self.tile_pos[0]-1)*16)+8, (self.tile_pos[1]-1)*16] #snap to tile
+ self.move_manager.align()
self.animator.set_animation("stand_"+get_direction_name(new_pos)) #set standing one
self.interacting = True #we're currently interacting
self.script_manager.start_script(self.interaction_script) #start interaction script
View
6 trainer.py
@@ -48,7 +48,7 @@ def move_done(self):
def interact(self, pos): #do interaction
if not self.fought: #if we haven't been fought yet
self.seen = True #we have been seen
- self.pos = [((self.tile_pos[0]-1)*16)+8, (self.tile_pos[1]-1)*16] #set proper position
+ self.move_manager.align()
self.move_manager.curr_movement[0] = [1, 0, 3, 2][pos] #set proper direction
self.move_done() #begin battle
else: #if we have
@@ -57,14 +57,12 @@ def interacting_stopped(self):
if self.seen: #if we have seen somebody and interaction stopped
self.game.transition(transition.WavyScreen(), self.start_battle) #do transition
def do_seen(self, dir, dist, tp): #somebody has been seen
- self.tile_pos = tp[:]
self.game.set_obj_pos(self, tp)
- self.pos = [((self.tile_pos[0]-1)*16)+8, (self.tile_pos[1]-1)*16]
self.seen = True #we've seen somebody
self.wait_time = 30 #set amount of time to display icon
self.move_data[0] = dir #store movement
self.move_data[1] = dist
- self.move_manager.move_to(dir, 0, 1, False) #stop current movement
+ self.move_manager.move_to(dir, 0, 0, False) #stop current movement
#set standing animation
self.animator.set_animation("stand_"+objects.get_direction_name(dir))
self.game.stopped = True #stop player from moving
Please sign in to comment.
Something went wrong with that request. Please try again.