当前位置: 首页>>代码示例>>Python>>正文


Python Scene.translate_y方法代码示例

本文整理汇总了Python中Scene.Scene.translate_y方法的典型用法代码示例。如果您正苦于以下问题:Python Scene.translate_y方法的具体用法?Python Scene.translate_y怎么用?Python Scene.translate_y使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scene.Scene的用法示例。


在下文中一共展示了Scene.translate_y方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Simulation

# 需要导入模块: from Scene import Scene [as 别名]
# 或者: from Scene.Scene import translate_y [as 别名]
class Simulation(object):
    def __init__(self, width, height):
        # create pyglet window
        self.window = pyglet.window.Window(resizable=True)
        self.window.on_draw = self.on_draw
        self.window.on_key_press = self.on_key_press
        self.window.on_key_release = self.on_key_release
        self.window.on_mouse_press = self.on_mouse_press
        self.window.on_mouse_release = self.on_mouse_release
        self.window.on_mouse_drag = self.on_mouse_drag
        self.window.width = width
        self.window.height = height
        self.menu_window = False
        self.gen_entity = 'SQUARE'
        self.gen_size = 50
        self.gen_mass = 500
        self.key_pressed = []
        self.clicked_object = None
        self.clicked_dx = 0
        self.clicked_dy = 0

        # create fps display 
        self.fps_display = pyglet.clock.ClockDisplay()
        self.clock = 0

        # sync clock
        pyglet.clock.schedule_interval(self.tick, 1.0/60.0)   
        pyglet.clock.set_fps_limit(60)

        # create world
        world_width = 3000
        world_height = 3000
        self.world = World(world_width, world_height)

        # create scene- match dimensions of the app window
        self.scene = Scene(width=width, height=height, background_width=world_width, background_height=world_height)

        #self.demo_1(world_width, world_height)
        #self.demo_2(world_width, world_height)
        #self.demo_3(world_width, world_height)

        # initialize background music
        self.music = Music()
        self.music.play_bg()

        # Making the player here (testing)
        mag = 40000
        offset = 400
        player_type = Triangle(size=20, position=Vector2(x=offset, y=offset))
        self.scene.entities.append(player_type)
        self.player = Player(entity=player_type, mass=100)
        self.world.add_body(self.player)

    def tick(self, dt):
        # update physics 
        self.world.update(dt)
        self.player.translate(dt, self.key_pressed)
        # move scene
        if key.LEFT in self.key_pressed:
            self.scene.translate_x(-10)
        if key.RIGHT in self.key_pressed:
            self.scene.translate_x(10)
        if key.UP in self.key_pressed:
            self.scene.translate_y(-10)
        if key.DOWN in self.key_pressed:
            self.scene.translate_y(10)
        if key.M in self.key_pressed:
            self.music.pause_bg()
            self.key_pressed.remove(key.M)

        self.clock += 1

    def on_draw(self):
        # clear window
        self.window.clear()
        
        # redraw scene
        self.scene.render()

        # draw fps clock
        self.fps_display.draw()

        self.player.draw(self.scene)
        # draw foreground/ui ? in here or scene

    def on_key_press(self, symbol, modifiers):
        if symbol == key.ESCAPE:
            if not self.menu_window:
                # self.tick, self.tick_stub = self.tick_stub, self.tick
                pyglet.clock.unschedule(self.tick)
                self.menu_window = True
                self.menu_window = Menu(self, width=500, height=500)
            return pyglet.event.EVENT_HANDLED
        else:
            self.key_pressed.append(symbol)
      
    def on_key_release(self, symbol, modifiers):
        if symbol in self.key_pressed:
            self.key_pressed.remove(symbol)

#.........这里部分代码省略.........
开发者ID:bm1362,项目名称:atlas-py,代码行数:103,代码来源:Simulation.py


注:本文中的Scene.Scene.translate_y方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。