本文整理汇总了Python中scene.Scene.update方法的典型用法代码示例。如果您正苦于以下问题:Python Scene.update方法的具体用法?Python Scene.update怎么用?Python Scene.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scene.Scene
的用法示例。
在下文中一共展示了Scene.update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import update [as 别名]
class Game(engine.State):
def init(self):
self.image = load_image('bg_800x600.png')
self.screen.blit(self.image[0], (0,0))
self.speed = Speed()
self.player = objects.PigOnTractor((250, 300), self.speed)
self.police = objects.Police((-300, 300), self.speed)
self.scene = Scene(self.player)
for i in range(200):
self.do_scene()
def do_scene(self):
self.scene.generate()
self.scene.bias()
self.scene.clean()
def event(self, events):
for event in events:
if event.type == pygame.QUIT:
return engine.Quit(self.game, self.debug)
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
return MainMenu(self.game, self.debug)
elif event.key == pygame.K_LEFT:
self.speed.down()
elif event.key == pygame.K_RIGHT:
self.speed.up()
elif event.type == UPDATESCENE:
self.do_scene()
self.player.consume_gas()
self.player.event(events)
def update(self, passed_time):
self.player.update()
self.scene.update()
self.police.update()
if self.police.status == 'arrest':
return GameOver(self.game, self.debug, 'game_over_arrested.png', self.player.get_score())
if self.player.status() == 'arrested':
return GameOver(self.game, self.debug, 'game_over_arrested.png', self.player.get_score())
elif self.player.status() == 'died':
return GameOver(self.game, self.debug, 'game_over_die.png', self.player.get_score())
def paint(self):
self.screen.blit(self.image[0], (0,0))
self.scene.draw(self.screen)
self.player.draw(self.screen)
self.police.draw(self.screen)
示例2: Scene
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import update [as 别名]
fpsClock = pygame.time.Clock()
windowSurfaceObj = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), pygame.DOUBLEBUF)
pygame.display.set_caption("Street Pirates Vs. Ninja")
fontObj = pygame.font.Font('freesansbold.ttf', 42)
msg = "Hello world!"
scene = Scene([ [2, 2, 0], [1, 0, 0] ])
screen = Screen(windowSurfaceObj, scene)
listener = EventListener(scene)
bluecolor = pygame.Color(0, 0, 255)
msg = "Hello world"
while True:
listener.listen()
screen.draw()
msg = str(scene._players[0].position())
msg1 = str(scene._players[0].speed())
# msg += str(scene._players[1].position())
msgSurfaceObj = fontObj.render(msg, False, bluecolor)
msgRectObj = msgSurfaceObj.get_rect()
scene.update()
msgRectObj.topleft = (10, 20)
windowSurfaceObj.blit(msgSurfaceObj, msgRectObj)
pygame.display.update()
#scene.moveForward(0, 0.001)
#scene.moveRight(0, .001)
scene.moveLeft(0, .001)
print msg + '!' + msg1
示例3:
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import update [as 别名]
scene.add(Player("player", 5, (WIDTH / 2) - 50, 10, 50))
scene.add(Ia("ia", WIDTH - 5 - 10, (HEIGHT / 2) - 50, 10, 50))
scene.add(Ball("ball", (WIDTH / 2) - (10 / 2), (HEIGHT / 2) - (10 / 2), 10, 10))
scene.draw()
clock = pygame.time.Clock()
totalTime = pygame.time.get_ticks()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
timeChange = pygame.time.get_ticks() - totalTime
totalTime = pygame.time.get_ticks()
velocityScale = timeChange / 16
space = pygame.key.get_pressed()[pygame.K_SPACE]
if scene.state == 0:
if space:
scene.state = 1
if scene.state == 1:
scene.update(velocityScale)
scene.draw()
clock.tick(60)
scene.flip()
示例4: __init__
# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import update [as 别名]
#.........这里部分代码省略.........
self.ray_shader = self.create_shader(vert_read, ray_frag.read())
self.std_shader = self.create_shader(vert_read, std_frag.read())
self.setup(self.ray_shader, self.std_shader)
self.setup_uniforms()
def create_shader(self, vert, frag):
return compileProgram(
compileShader(vert, GL_VERTEX_SHADER),
compileShader(frag, GL_FRAGMENT_SHADER)
)
def setup(self, ray_shader, std_shader):
verts = numpy.array(
# verts uv
[-1, 1, 0, 1,
1, 1, 1, 1,
1, -1, 1, 0,
-1, -1, 0, 0],
dtype=numpy.float32)
self.vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
glBufferData(GL_ARRAY_BUFFER, 4*len(verts), verts, GL_STATIC_DRAW)
position = glGetAttribLocation(std_shader, 'position')
glEnableVertexAttribArray(position)
glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 4*4, None)
texcoord = glGetAttribLocation(std_shader, 'texcoord')
glEnableVertexAttribArray(texcoord)
glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 4*4,
ctypes.c_void_p(4*2))
self.draw_texture = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, self.draw_texture)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.width, self.height, 0,
GL_RGBA, GL_FLOAT, None)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
self.fbo = glGenFramebuffers(1)
glBindFramebuffer(GL_FRAMEBUFFER, self.fbo)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, self.draw_texture, 0)
if glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE:
raise Exception('well... fuck.')
def setup_uniforms(self):
glUseProgram(self.ray_shader)
self.scene.setup_uniforms(self.ray_shader, self.uniforms)
def set_uniforms(self):
self.scene.set_uniforms(self.uniforms)
def draw(self):
glBindFramebuffer(GL_FRAMEBUFFER, self.fbo)
glViewport(0, 0, self.width, self.height)
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(self.ray_shader)
self.set_uniforms()
glBindTexture(GL_TEXTURE_2D, self.draw_texture)
glDrawArrays(GL_QUADS, 0, 4)
glBindFramebuffer(GL_FRAMEBUFFER, 0)
glViewport(0, 0, self.real_width, self.real_height)
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(self.std_shader)
glBindTexture(GL_TEXTURE_2D, self.draw_texture)
glDrawArrays(GL_QUADS, 0, 4)
pygame.display.flip()
self.clock.tick()
print str(self.clock.get_fps()) + '\r',
def handle_events(self):
e = pygame.event.poll()
if e.type == pygame.QUIT:
self.running = False
elif e.type == pygame.KEYUP and e.key == pygame.K_RETURN:
self.reload()
self.scene.update(e, self.clock.get_time()/1000.0)
def quit(self):
glDeleteTextures([self.draw_texture])
glDeleteFramebuffers(1, [self.fbo])
glDeleteProgram(self.ray_shader)
glDeleteProgram(self.std_shader)
glDeleteBuffers(1, [self.vbo])
pygame.display.quit()
pygame.quit()