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


Python Weather.draw_foreground方法代码示例

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


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

示例1: MapContext

# 需要导入模块: from weather import Weather [as 别名]
# 或者: from weather.Weather import draw_foreground [as 别名]

#.........这里部分代码省略.........
        #self.camera.zoom_target = 1.5/settings.scale
        #self.camera.zoom_rate = 7.5
        for crow in self.murder.crows:
            crow.resting = False
            crow.speed = speed
            crow.moveTowards(random.random() * 4 + wx, random.random() * 4 + wy )

    def on_mouse_release(self, x, y, button, modifiers):
        if button == 1:
            wx, wy = self.camera.pixel_to_world(x, y)
            for crow in self.murder.crows:
                crow.resting = False
                crow.target = box2d.b2Vec2(
                                random.randint(int(wx)-3, int(wx)+3),
                                self.world_height*1.2)
                crow.speed = settings.crow_idle_speed
            #self.camera.zoom_target = 0.75/settings.scale
            #self.camera.zoom_rate = 7.5
        self.mouse_down = False
    
    def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
        if button == 1:
            wx, wy = self.camera.pixel_to_world(x, y)
            self.mx, self.my = wx, wy
            for crow in self.murder.crows:
                crow.moveTowards(random.random() + wx, random.random() + wy )
        else:
            self.camera.move_by(-dx, -dy)
    
    @property
    def width(self): return self.worldAABB.upperBound.x
    
    @property
    def height(self): return self.worldAABB.upperBound.y
    
    def spawn_enemies(self, dt):
        self.spawn_countdown -= dt
        if self.spawn_countdown <= 0:
            self.spawn_countdown = self.spawn_time
            if self.spawn_countdown < 3.5: self.spawn_countdown = 3.5
            self.average_speed += 0.2
            self.spawn_time -= 0.15
            if self.spawn_time < 2: self.spawn_countdown = 2
            for x in range(int(self.spawn_rate)):
                self.people.append(person.Person(self.world, (x*2, 70), self.average_speed + random.random()))
            self.spawn_rate += 0.15
            print "Spawn Countdown:", self.spawn_countdown,
            print ", Spawn Rate:", self.spawn_rate,
            print ", Average Speed:", self.average_speed
    
    def update(self, dt):
        if self.time >= 140:
            self.switch_requested("WinContext")
        
        self.time += dt
        self.spawn_enemies(dt)
        for thing in self.things:
            thing.update(dt)
        people_to_remove = []
        for person in self.people:
            person.update(dt)
            if len(self.people) > settings.max_people and len(person.joints) <= 3:
                people_to_remove.append(person)
            elif person.Chest.position.x >= self.world_width - 2 and not person.is_dead:
                person.remove_from_world()
                gamestats.add_survivor()
        
        #Only remove one of the People To Remove
        if len(people_to_remove):
            people_to_remove[-1].remove_from_world()
            self.people.remove(people_to_remove[-1])
        
        if self.mouse_down:
            d = (b2Vec2(self.mx, self.my) - self.camera.look_at).Length()
            self.camera.move_towards(self.mx, self.my, max(d, 2), dt)
        
        self.murder.update(dt)
        self.weather.update(dt)
        self.camera.update(dt)
        self.world.SetContinuousPhysics(True)
        
        # Tell Box2D to step
        if dt > .1: dt = .1
        self.world.Step(dt, 10, 10)
        self.world.Validate()
    
    def predraw(self): pass

    def draw(self):
        with Projection(self.camera) as projection:
            self.weather.draw_background()
            self.svg.draw(0,0, 0, 0, settings.scale*settings.svgscale)
            pyglet.gl.gl.glColor4f(0,0,0,1)

            self.murder.draw()
            for thing in self.things:
                thing.draw()
            for person in self.people:
                person.draw()
            self.weather.draw_foreground()
开发者ID:fathat,项目名称:a-murder-of-crows,代码行数:104,代码来源:mapcontext.py


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