Esempio n. 1
0
class PlayApp(DirectObject):
    def __init__(self):
        base.disableMouse()
        self.world = World()
        self.mouse = PlayMouse(self)
        self.state = PlayState('state')
        self.accept('l', self.load_world)
        self.accept('L', self.load_world)
        self.welcome = None
        self.winner = None

    def load_world(self):
        def load(filename):
            self.delete_world()
            F = open(filename, 'rb')
            self.world = cPickle.load(F)
            F.close()
            entry.destroy()
            self.world.position_camera()
            self.state.request('Charge')
        self.welcome.removeNode()
        self.state.request('AwaitLoad')
        entry = DirectEntry(text='', scale=0.05, command=load,
                initialText='level.hm', focus=1)

    def delete_world(self):
        self.world.clear()
Esempio n. 2
0
 def __init__(self):
     base.disableMouse()
     self.selected_object = None
     self.init_mouse()
     self.state = EditState('state')
     self.world = World()
     self.accept('c', self.generate_world)
     self.accept('s', self.save_world)
     self.accept('l', self.load_world)
     self.accept('d', self.delete_world)
     self.init_buttons()
Esempio n. 3
0
 def __init__(self):
     base.disableMouse()
     self.world = World()
     self.mouse = PlayMouse(self)
     self.state = PlayState('state')
     self.accept('l', self.load_world)
     self.accept('L', self.load_world)
     self.welcome = None
     self.winner = None
Esempio n. 4
0
 def __init__(self):
     base.disableMouse()
     self.selected_object = None
     self.init_mouse()
     self.state = EditState('state')
     self.world = World()
     self.accept('c', self.generate_world)
     self.accept('s', self.save_world)
     self.accept('l', self.load_world)
     self.accept('d', self.delete_world)
     self.init_buttons()
Esempio n. 5
0
    def generate_world(self):
        self.delete_world()
        self.world = World()
        self.world.generate()
        self.world.init_nodepath()
        self.world.position_camera()
        text = OnscreenText(text='World created.',
                            pos=(-0.9, -0.9),
                            fg=(1.0, 1.0, 1.0, 1.0))

        def fadeText(task):
            alpha = 1.0 - task.time * 6.0
            if alpha > 0:
                text.setAlphaScale(alpha)
                return task.cont
            else:
                text.removeNode()
                return task.done

        taskMgr.doMethodLater(1.0, fadeText, 'fade')
Esempio n. 6
0
 def generate_world(self):
     self.delete_world()
     self.world = World()
     self.world.generate()
     self.world.init_nodepath()
     self.world.position_camera()
     text = OnscreenText(text='World created.', pos=(-0.9, -0.9), fg=(1.0, 1.0, 1.0, 1.0))
     def fadeText(task):
         alpha = 1.0 - task.time * 6.0
         if alpha > 0:
             text.setAlphaScale(alpha)
             return task.cont
         else:
             text.removeNode()
             return task.done
     taskMgr.doMethodLater(1.0, fadeText, 'fade')
Esempio n. 7
0
class EditApp(DirectObject):
    def __init__(self):
        base.disableMouse()
        self.selected_object = None
        self.init_mouse()
        self.state = EditState('state')
        self.world = World()
        self.accept('c', self.generate_world)
        self.accept('s', self.save_world)
        self.accept('l', self.load_world)
        self.accept('d', self.delete_world)
        self.init_buttons()

    def init_buttons(self):
        mode_buttons = [
                DirectRadioButton(text='Height', variable=mouse_mode,
                        value=['Height'], scale=0.05, pos=(0.0, 0, -0.9),
                        command=set_mouse_mode),
                DirectRadioButton(text='Material', variable=mouse_mode,
                        value=['Material'], scale=0.05, pos=(0.25, 0, -0.9),
                        command=set_mouse_mode),
                DirectRadioButton(text='Character', variable=mouse_mode,
                        value=['Character'], scale=0.05, pos=(0.75, 0, -0.9),
                        command=set_mouse_mode),
        ]
        for button in mode_buttons:
            button.setOthers(mode_buttons)
        material_buttons = [
                DirectRadioButton(text='Grass', variable=material,
                        value=['grass'], scale=0.05, pos=(0.5, 0, -0.7),
                        command=set_material),
                DirectRadioButton(text='Stone', variable=material,
                        value=['stone'], scale=0.05, pos=(0.5, 0, -0.8),
                        command=set_material),
                DirectRadioButton(text='Water', variable=material,
                        value=['water'], scale=0.05, pos=(0.5, 0, -0.9),
                        command=set_material),
        ]
        for button in material_buttons:
            button.setOthers(material_buttons)
        character_buttons = [
                DirectRadioButton(text='Team 1', variable=team_mode,
                        value=[0], scale=0.05, pos=(1.0, 0, -0.8),
                        command=set_team_mode),
                DirectRadioButton(text='Team 2', variable=team_mode,
                        value=[1], scale=0.05, pos=(1.0, 0, -0.9),
                        command=set_team_mode),
        ]
        for button in character_buttons:
            button.setOthers(character_buttons)

    def init_mouse(self):
        self.mouse = EditMouse(self)

    def generate_world(self):
        self.delete_world()
        self.world = World()
        self.world.generate()
        self.world.init_nodepath()
        self.world.position_camera()
        text = OnscreenText(text='World created.', pos=(-0.9, -0.9), fg=(1.0, 1.0, 1.0, 1.0))
        def fadeText(task):
            alpha = 1.0 - task.time * 6.0
            if alpha > 0:
                text.setAlphaScale(alpha)
                return task.cont
            else:
                text.removeNode()
                return task.done
        taskMgr.doMethodLater(1.0, fadeText, 'fade')

    def save_world(self):
        def save(filename):
            F = open(filename, 'wb')
            cPickle.dump(self.world, F, True)
            F.close()
            entry.destroy()
        entry = DirectEntry(text='', scale=0.05, command=save,
                initialText='level.hm', focus=1)

    def load_world(self):
        def load(filename):
            self.delete_world()
            F = open(filename, 'rb')
            self.world = cPickle.load(F)
            F.close()
            entry.destroy()
            self.world.position_camera()
        entry = DirectEntry(text='', scale=0.05, command=load,
                initialText='level.hm', focus=1)

    def delete_world(self):
        self.world.clear()
Esempio n. 8
0
class EditApp(DirectObject):
    def __init__(self):
        base.disableMouse()
        self.selected_object = None
        self.init_mouse()
        self.state = EditState('state')
        self.world = World()
        self.accept('c', self.generate_world)
        self.accept('s', self.save_world)
        self.accept('l', self.load_world)
        self.accept('d', self.delete_world)
        self.init_buttons()

    # this function occurs at every editApp object made. which displays radio buttons
    def init_buttons(self):
        mode_buttons = [
            DirectRadioButton(text='Height',
                              variable=mouse_mode,
                              value=['Height'],
                              scale=0.05,
                              pos=(0.0, 0, -0.9),
                              command=set_mouse_mode),
            DirectRadioButton(text='Material',
                              variable=mouse_mode,
                              value=['Material'],
                              scale=0.05,
                              pos=(0.25, 0, -0.9),
                              command=set_mouse_mode),
            DirectRadioButton(text='Character',
                              variable=mouse_mode,
                              value=['Character'],
                              scale=0.05,
                              pos=(0.75, 0, -0.9),
                              command=set_mouse_mode),
        ]
        for button in mode_buttons:
            button.setOthers(mode_buttons)
        material_buttons = [
            DirectRadioButton(text='Grass',
                              variable=material,
                              value=['grass'],
                              scale=0.05,
                              pos=(0.5, 0, -0.7),
                              command=set_material),
            DirectRadioButton(text='Stone',
                              variable=material,
                              value=['stone'],
                              scale=0.05,
                              pos=(0.5, 0, -0.8),
                              command=set_material),
            #TODO: check
            DirectRadioButton(text='Objective',
                              variable=material,
                              value=['objective'],
                              scale=0.05,
                              pos=(0.5, 0, -0.9),
                              command=set_material),
            DirectRadioButton(text='Obstacle',
                              variable=material,
                              value=['obstacle'],
                              scale=0.05,
                              pos=(0.5, 0, -0.6),
                              command=set_material),
        ]
        for button in material_buttons:
            button.setOthers(material_buttons)
        character_buttons = [
            DirectRadioButton(text='Team 1',
                              variable=team_mode,
                              value=[0],
                              scale=0.05,
                              pos=(1.0, 0, -0.8),
                              command=set_team_mode),
            DirectRadioButton(text='Team 2',
                              variable=team_mode,
                              value=[1],
                              scale=0.05,
                              pos=(1.0, 0, -0.9),
                              command=set_team_mode),
        ]
        for button in character_buttons:
            button.setOthers(character_buttons)

    def init_mouse(self):
        self.mouse = EditMouse(self)

    # creates world
    def generate_world(self):
        self.delete_world()
        self.world = World()
        self.world.generate()
        self.world.init_nodepath()
        self.world.position_camera()
        text = OnscreenText(text='World created.',
                            pos=(-0.9, -0.9),
                            fg=(1.0, 1.0, 1.0, 1.0))

        def fadeText(task):
            alpha = 1.0 - task.time * 6.0
            if alpha > 0:
                text.setAlphaScale(alpha)
                return task.cont
            else:
                text.removeNode()
                return task.done

        taskMgr.doMethodLater(1.0, fadeText, 'fade')

    # saves world
    def save_world(self):
        def save(filename):
            F = open(filename, 'wb')
            cPickle.dump(self.world, F, True)
            F.close()
            entry.destroy()

        entry = DirectEntry(text='',
                            scale=0.05,
                            command=save,
                            initialText='debug.hm',
                            focus=1)

    # loads world
    def load_world(self):
        def load(filename):
            self.delete_world()
            F = open(filename, 'rb')
            self.world = cPickle.load(F)
            F.close()
            entry.destroy()
            self.world.position_camera()

        entry = DirectEntry(text='',
                            scale=0.05,
                            command=load,
                            initialText='debug.hm',
                            focus=1)

    # deletes world
    def delete_world(self):
        self.world.clear()