Changeset 276:3153196517fc for nagslang


Ignore:
Timestamp:
Sep 5, 2013, 11:09:14 AM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Move protagonist to the world

Location:
nagslang
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • nagslang/engine.py

    r252 r276  
    2525        }
    2626        self._world.load()
    27         self.change_screen('menu', None)
     27        self.change_screen('menu')
    2828        # Dummy resize event, to force us to realise our real size
    2929        # http://stackoverflow.com/q/16442573/8629
     
    3131                                             size=(0, 0), w=0, h=0))
    3232
    33     def change_screen(self, new_screen, player):
     33    def change_screen(self, new_screen):
    3434        if self._current_screen is not None:
    3535            self._current_screen.teardown()
    3636        screen_cls = self._screens[new_screen]
    37         self._current_screen = screen_cls(new_screen, player, self._world)
     37        self._current_screen = screen_cls(new_screen, self._world)
    3838        self._current_screen.setup()
    3939
     
    5151                    self._world.save()
    5252                    self._surface.fill(pygame.color.Color(0, 0, 0))
    53                     self.change_screen(ev.screen, ev.player)
     53                    self.change_screen(ev.screen)
    5454                else:
    5555                    self._current_screen.handle_event(ev)
  • nagslang/events.py

    r261 r276  
    3838    @classmethod
    3939    def post(cls, new_screen, player=None):
    40         super(ScreenChange, cls).post(screen=new_screen, player=player)
     40        super(ScreenChange, cls).post(screen=new_screen)
    4141
    4242
  • nagslang/game_object.py

    r264 r276  
    2727    def get_space(self):
    2828        return self._space
     29
     30    def set_space(self, new_space):
     31        self._space = new_space
    2932
    3033    def set_game_object(self, game_object):
  • nagslang/protagonist.py

    r265 r276  
    8585    def _get_image(self, name, *transforms):
    8686        return resources.get_image('creatures', name, transforms=transforms)
     87
     88    def change_space(self, new_space):
     89        self.physicser.remove_from_space()
     90        self.physicser.set_space(new_space)
     91        self.physicser.add_to_space()
    8792
    8893    def _make_renderer(self):
  • nagslang/screens/area.py

    r272 r276  
    88from nagslang.events import ScreenChange, DoorEvent, FireEvent
    99from nagslang.level import Level
    10 from nagslang.protagonist import Protagonist
    1110from nagslang.screens.base import Screen
    1211from nagslang.game_object import Bullet
     
    7473        self.add_walls()
    7574        self._add_collision_handlers()
    76         if self.protagonist is not None:
    77             # We do things this way to avoid extra pymunk
    78             # juggling to move objects between spaces
    79             old_protagonist = self.protagonist
    80             self.add_protagonist()
    81             self.protagonist.copy_state(old_protagonist)
    82         else:
    83             self.add_protagonist()
     75        self.add_protagonist()
    8476        self.add_game_objects()
    8577        sound.play_music("POL-cyber-factory-short.ogg")
     
    124116
    125117    def add_protagonist(self):
    126         self.protagonist = Protagonist(self.space, (350, 300))
     118        self.protagonist = self.world.protagonist
     119        self.protagonist.change_space(self.space)
    127120        self._drawables.add(self.protagonist)
    128121
     
    143136                self._disable_render = True
    144137                self.world.rooms += 1
    145                 ScreenChange.post(ev.destination, self.protagonist)
     138                ScreenChange.post(ev.destination)
    146139                return
    147140            # else we're teleporting within the screen, and just the
  • nagslang/screens/base.py

    r180 r276  
    77class Screen(object):
    88
    9     def __init__(self, name, player, world):
     9    def __init__(self, name, world):
    1010        self.name = name
    1111        self.world = world
    12         self.protagonist = player
    1312        self.space = pymunk.Space()
    1413
  • nagslang/screens/menu.py

    r252 r276  
    4747
    4848    def play(self):
    49         ScreenChange.post('level1', None)
     49        ScreenChange.post('level1')
    5050
    5151    def restart(self):
  • nagslang/world.py

    r261 r276  
    66import sys
    77
     8import pymunk
     9
    810from nagslang.yamlish import dump, load
     11from nagslang.protagonist import Protagonist
    912
    1013
     
    1922        self.kills = 0
    2023        self.rooms = 0
     24        self.protagonist = Protagonist(pymunk.Space(), (350, 300))
    2125
    2226    def _save_location(self):
     
    3741            value = getattr(self, attr)
    3842            if hasattr(value, '__name__'):
     43                continue
     44            # Hack until we save protagonist state
     45            if hasattr(value, 'animate'):
    3946                continue
    4047            data[attr] = value
Note: See TracChangeset for help on using the changeset viewer.