Mercurial > nagslang
comparison tools/area_editor.py @ 544:ea396ebc7a92
Less leaky object movement
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 07 Sep 2013 21:26:32 +0200 |
parents | 80264aee0af2 |
children | 15f066cc5bf1 |
comparison
equal
deleted
inserted
replaced
543:80264aee0af2 | 544:ea396ebc7a92 |
---|---|
185 pygame.draw.lines(self._surface, LINE_COLOR, False, pointlist, 1) | 185 pygame.draw.lines(self._surface, LINE_COLOR, False, pointlist, 1) |
186 return self._surface | 186 return self._surface |
187 | 187 |
188 def reset_objs(self): | 188 def reset_objs(self): |
189 # Reset the object state - needed when changing stuff | 189 # Reset the object state - needed when changing stuff |
190 old_drawable = self.drawables[:] | |
190 self.drawables = [] | 191 self.drawables = [] |
191 self.overlay_drawables = [] | 192 self.overlay_drawables = [] |
192 self._glue = np.PuzzleGlue() | 193 self._glue = np.PuzzleGlue() |
193 for game_object_dict in self._game_objects: | 194 for game_object_dict in self._game_objects: |
194 obj = self._create_game_object(pymunk.Space(), **game_object_dict) | 195 obj = self._create_game_object(pymunk.Space(), **game_object_dict) |
631 old_pos = self.mouse_pos | 632 old_pos = self.mouse_pos |
632 self.mouse_pos = ev.pos | 633 self.mouse_pos = ev.pos |
633 if self.move_obj: | 634 if self.move_obj: |
634 corrected_pos = self._level_coordinates(ev.pos) | 635 corrected_pos = self._level_coordinates(ev.pos) |
635 snapped_pos = self.snap_to_grid(corrected_pos) | 636 snapped_pos = self.snap_to_grid(corrected_pos) |
636 self._update_pos(self.move_obj, snapped_pos) | 637 self._move_obj(self.move_obj, snapped_pos) |
637 if old_pos != self.mouse_pos and (self.cur_poly or self._draw_lines | 638 if old_pos != self.mouse_pos and (self.cur_poly or self._draw_lines |
638 or self._move_point_mode | 639 or self._move_point_mode |
639 or self._move_poly_mode): | 640 or self._move_poly_mode): |
640 self.invalidate() | 641 self.invalidate() |
641 | 642 |
870 if self.level.try_new_object(classname, | 871 if self.level.try_new_object(classname, |
871 self.level._game_objects, | 872 self.level._game_objects, |
872 new_cls, None): | 873 new_cls, None): |
873 edit_dlg.cleanup() | 874 edit_dlg.cleanup() |
874 | 875 |
875 def _update_pos(self, obj, new_pos): | 876 def _move_obj(self, obj, new_pos): |
877 new_coords = self.level.point_to_pymunk(new_pos) | |
878 shape = obj.get_shape() | |
879 shape.body.position = (new_coords[0], new_coords[1]) | |
880 self.invalidate() | |
881 | |
882 def _update_pos(self, obj, new_pos, final=False): | |
876 data = self.level.lookup[obj] | 883 data = self.level.lookup[obj] |
877 new_coords = self.level.point_to_pymunk(new_pos) | 884 new_coords = self.level.point_to_pymunk(new_pos) |
878 args = data['args'] | 885 args = data['args'] |
879 old_coords = list(args[0]) | 886 old_coords = list(args[0]) |
880 args[0][0] = new_coords[0] | 887 args[0][0] = new_coords[0] |