Ejemplo n.º 1
0
 def update_state(self):
     RIGHT = get_button('player_right')
     LEFT = get_button('player_left')
     UP = get_button('player_up')
     DOWN = get_button('player_down')
     
     horizontal = RIGHT-LEFT
     vertical = UP-DOWN
     
     physics_events = get_physics_event()
     
     for event in physics_events:
         if (event.a.userData == 2 and event.b.userData == 11 ) or \
                 ( event.b.userData == 2 and event.a.userData == 11):
             if event.begin:
                 self.foot += 1
             else:
                 self.foot -= 1
     
     if horizontal == -1:
         self.direction = False
         if self.foot:
             self.state = 'move'
         self.player.flip = True
         physics_manager.move(self.player.body, -self.speed)
     elif horizontal == 1:
         self.direction = True
         if self.foot:
             self.state = 'move'
         self.player.flip = False
         physics_manager.move(self.player.body, self.speed)
     else:
         if self.foot:
             if self.direction:
                 self.state = 'still'
                 self.player.flip = False
             else:
                 self.state = 'still'
                 self.player.flip = True
         physics_manager.move(self.player.body, 0)
     if not self.foot:
         if self.direction:
             self.state = 'jump'
             self.player.flip = False
         else:
             self.state = 'jump_left'
             self.player.flip = True
     physics_pos = physics_manager.get_body_position(self.player.body)
     
     if physics_pos:
         pos = physics_pos-self.player.size/2
     else:
         pos = self.player.pos
     if self.player.screen_relative_pos:
         pos = pos-self.player.screen_relative_pos*engine.get_screen_size()
     self.player.pos = pos
Ejemplo n.º 2
0
    def loop(self):
        add_button('quit', ['LCTRL+q'])
        add_button('reset', ['r'])
        while not self.finish:
            self.pre_update()
            update_event()

            self.finish = get_button('quit')

            f = level_manager.update_level()

            if f == 0:
                log("No scene loaded",1)
                break
            else:
                f(self.screen)
            if get_button('reset'):
                from levels.gamestate import GameState
                level_manager.switch_level(GameState(CONST.startup))
            self.post_update()
Ejemplo n.º 3
0
    def loop(self, screen,screen_pos):
        if not (self.editor_click or not get_button('editor')):
            self.editor = not self.editor
            self.lock = self.editor
            self.editor_click = True
            if self.editor:
                log("Editor mode activate")
            else:
                self.current_selected = None
        if not get_button('editor'):
            self.editor_click = False
        if self.editor:
            show_mouse()

        mouse_pos, pressed = get_mouse()
        if not self.editor:
            return

        self.gui_editor_mode.loop(screen,screen_pos)

        '''Save Level'''
        if self.save_clicked:
            self.gui_saved.loop(screen,screen_pos)
        if get_button('save') and not self.save_clicked:
            save_level(self)
            self.save_clicked = True
        elif not get_button('save'):
            self.save_clicked = False

        '''Left click,
        select a object and move it'''
        if not get_button('box'):
            self.new_obj = None
            if pressed[0] and not self.mouse_clicked[0]:
                '''Set current_selected'''
                self.current_selected = None
                for layer in self.objects:
                    for image in layer:
                        if not image.screen_relative and image.check_click(mouse_pos, self.screen_pos):
                            log("Current_object is: " + str(image))
                            self.current_selected = image
                            self.obj_init_pos = self.current_selected.pos
                            self.mouse_init_pos = mouse_pos + self.screen_pos
                self.mouse_clicked = (1, self.mouse_clicked[1], self.mouse_clicked[2])
            elif pressed[0] and self.mouse_clicked[0]:
                '''Move the current object'''
                if self.current_selected is not None:
                    self.current_selected.set_pos(self.obj_init_pos, mouse_pos + self.screen_pos - self.mouse_init_pos)
        else:
            """Create a static physic with CTRL-left mouse"""
            if pressed[0] and not self.mouse_clicked[0]:
                self.mouse_clicked = (1, self.mouse_clicked[1], self.mouse_clicked[2])
                self.new_obj = GameObject()
                self.new_obj.pos = mouse_pos + self.screen_pos
                self.objects[4].append(self.new_obj)
            elif self.mouse_clicked[0]:
                self.new_obj.size = mouse_pos + self.screen_pos - self.new_obj.pos
                if not pressed[0]:
                    """Create a static physics body"""
                    self.new_obj.body = add_static_object(self.new_obj, self.new_obj.pos+self.new_obj.size/2)
                    add_static_box(self.new_obj.body, Vector2(), self.new_obj.size/2, data=11)
                self.new_obj.update_rect()


        if not pressed[0] and self.mouse_clicked[0]:
            self.mouse_clicked = (0, self.mouse_clicked[1], self.mouse_clicked[2])

        if self.current_selected:
            self.gui_current_selected.change_text(str(self.current_selected.__class__)+" "+str(self.current_selected.id)
                                                  +" "+str(self.current_selected.angle))
            self.gui_current_selected.loop(screen, screen_pos)

        '''Size scale'''
        scale_x = get_button("scale_x_up")-get_button("scale_x_down")
        scale_y = get_button("scale_y_up")-get_button("scale_y_down")

        if self.current_selected:
            self.current_selected.scale(scale_x,scale_y)
        '''Angle'''
        angle = get_button("angle_up")-get_button("angle_down")
        if self.current_selected:
            self.current_selected.set_angle(self.current_selected.angle+angle)