本文整理汇总了Python中Camera.Camera.apply方法的典型用法代码示例。如果您正苦于以下问题:Python Camera.apply方法的具体用法?Python Camera.apply怎么用?Python Camera.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera.Camera
的用法示例。
在下文中一共展示了Camera.apply方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scene
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import apply [as 别名]
class Scene(BackgroundLayer, KeyListener):
def __init__(self, engine):
self.engine = engine
self.camera = Camera()
self.time = 0.0
self.player = self.engine.world.getPlayers()[0]
self.controls = Player.Controls()
def shown(self):
self.engine.input.addKeyListener(self)
def hidden(self):
self.engine.input.removeKeyListener(self)
def keyPressed(self, key, unicode):
c = self.controls.keyPressed(key)
if c:
return True
return False
def keyReleased(self, key):
c = self.controls.keyReleased(key)
if c:
return True
return False
def run(self, ticks):
self.time += ticks / 50.0
def render3D(self):
pass
def render(self, visibility, topMost):
font = self.engine.data.font
# render the scene
try:
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
gluPerspective(60, self.engine.view.aspectRatio, 0.1, 1000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glPushMatrix()
self.camera.apply()
self.render3D()
finally:
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
示例2: SongChooser
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import apply [as 别名]
#.........这里部分代码省略.........
glMatrixMode(GL_MODELVIEW)
glDisable(GL_TEXTURE_2D)
glDisable(GL_NORMALIZE)
def render(self, visibility, topMost):
v = (1 - visibility) ** 2
# render the background
t = self.time / 100
w, h, = self.engine.view.geometry[2:4]
r = .5
self.background.transform.reset()
self.background.transform.translate(v * 2 * w + w / 2 + math.sin(t / 2) * w / 2 * r, h / 2 + math.cos(t) * h / 2 * r)
self.background.transform.rotate(-t)
self.background.transform.scale(math.sin(t / 8) + 2, math.sin(t / 8) + 2)
self.background.draw()
# render the item list
try:
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
gluPerspective(60, self.engine.view.aspectRatio, 0.1, 1000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glEnable(GL_DEPTH_TEST)
glDisable(GL_CULL_FACE)
glDepthMask(1)
offset = 10 * (v ** 2)
self.camera.origin = (-10 + offset, -self.cameraOffset, 4 + offset)
self.camera.target = ( 0 + offset, -self.cameraOffset, 2.5 + offset)
self.camera.apply()
y = 0.0
for i, item in enumerate(self.items):
if not self.matchesSearch(item):
continue
c = math.sin(self.itemAngles[i] * math.pi / 180)
if isinstance(item, Song.SongInfo):
h = c * self.cassetteWidth + (1 - c) * self.cassetteHeight
else:
h = c * self.libraryWidth + (1 - c) * self.libraryHeight
d = (y + h * .5 + self.camera.origin[1]) / (4 * (self.camera.target[2] - self.camera.origin[2]))
if i == self.selectedIndex:
self.selectedOffset = y + h / 2
Theme.setSelectedColor()
else:
Theme.setBaseColor()
glTranslatef(0, -h / 2, 0)
glPushMatrix()
if abs(d) < 1.2:
if isinstance(item, Song.SongInfo):
glRotate(self.itemAngles[i], 0, 0, 1)
self.renderCassette(item.cassetteColor, self.itemLabels[i])
elif isinstance(item, Song.LibraryInfo):
glRotate(-self.itemAngles[i], 0, 0, 1)
if i == self.selectedIndex:
glRotate(self.time * 4, 1, 0, 0)
示例3: Editor
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import apply [as 别名]
#.........这里部分代码省略.........
self.controlReleased(c)
return True
def run(self, ticks):
self.time += ticks / 50.0
if not self.song:
return
self.guitar.run(ticks, self.scrollPos, self.controls)
if not self.song.isPlaying():
if self.controls.getState(Player.RIGHT) and not self.controls.getState(Player.LEFT):
self.pos += self.song.period * self.scrollSpeed
self.scrollSpeed += ticks / 4096.0
elif self.controls.getState(Player.LEFT) and not self.controls.getState(Player.RIGHT):
self.pos -= self.song.period * self.scrollSpeed
self.scrollSpeed += ticks / 4096.0
else:
self.scrollSpeed = 0
else:
self.pos = self.song.getPosition() - self.song.info.delay
self.pos = max(0, self.pos)
quarterBeat = int(self.pos / (self.song.period / 4) + .5)
self.snapPos = quarterBeat * (self.song.period / 4)
# note adding
if self.newNotes:
if self.snapPos < self.newNotePos:
self.newNotes = []
for note in self.newNotes:
self.song.track.removeEvent(self.newNotePos, note)
note.length = max(self.song.period / 4, self.snapPos - self.newNotePos)
# remove all notes under the this new note
oldNotes = [(time, event) for time, event in self.song.track.getEvents(self.newNotePos, self.newNotePos + note.length) if isinstance(event, Note)]
for time, event in oldNotes:
if event.number == note.number:
self.song.track.removeEvent(time, event)
if time < self.newNotePos:
event.length = self.newNotePos - time
self.song.track.addEvent(time, event)
self.song.track.addEvent(self.newNotePos, note)
if self.song.isPlaying():
self.scrollPos = self.pos
else:
self.scrollPos = (self.scrollPos + self.snapPos) / 2.0
def render(self, visibility, topMost):
if not self.song:
return
v = 1.0 - ((1 - visibility) ** 2)
# render the background
t = self.time / 100 + 34
w, h, = self.engine.view.geometry[2:4]
r = .5
self.background.transform.reset()
self.background.transform.translate(w / 2 + math.sin(t / 2) * w / 2 * r, h / 2 + math.cos(t) * h / 2 * r)
self.background.transform.rotate(-t)
self.background.transform.scale(math.sin(t / 8) + 2, math.sin(t / 8) + 2)
self.background.draw()
self.camera.target = ( 2, 0, 5.5)
self.camera.origin = (-2, 9, 5.5)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60, 4.0 / 3.0, 0.1, 1000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
self.camera.apply()
self.guitar.render(v, self.song, self.scrollPos, self.controls)
self.engine.view.setOrthogonalProjection(normalize = True)
font = self.engine.data.font
try:
Theme.setSelectedColor()
w, h = font.getStringSize(" ")
if self.song.isPlaying():
status = _("Playing")
else:
status = _("Stopped")
t = "%d.%02d'%03d" % (self.pos / 60000, (self.pos % 60000) / 1000, self.pos % 1000)
font.render(t, (.05, .05 - h / 2))
font.render(status, (.05, .05 + h / 2))
font.render(unicode(self.song.difficulty), (.05, .05 + 3 * h / 2))
Theme.setBaseColor()
text = self.song.info.name + (self.modified and "*" or "")
Dialogs.wrapText(font, (.5, .05 - h / 2), text)
finally:
self.engine.view.resetProjection()
示例4: game
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import apply [as 别名]
#.........这里部分代码省略.........
if col == "I":
i = Sword(x, y, directory)
platforms.append(i)
entities.add(i)
if col == "E":
e = Enemy(x, y, directory)
enemy.append(e)
entities.add(e)
x += 32
y += 32
x = 0
y = 0
total_level_width = (len(level[0])-2)*32
total_level_height = len(level)*32
camera = Camera(total_level_width, total_level_height)
entities.add(player)
font = pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',20) #Форматиране на текста в score line-а
while 1:
timer.tick(60)
#Пояснителен текст
lives_text = font.render("LIVES:", 1,(255,255,255))
for e in pygame.event.get(): #Проверка за натиснати бутони
if e.type == QUIT: raise SystemExit, "QUIT"
if e.type == KEYDOWN and e.key == K_ESCAPE:
menu_game()
if e.type == KEYDOWN and e.key == K_SPACE:
up = True
if e.type == KEYDOWN and e.key == K_LEFT:
left = True
if e.type == KEYDOWN and e.key == K_RIGHT:
right = True
if e.type == KEYUP and e.key == K_SPACE:
up = False
if e.type == KEYUP and e.key == K_RIGHT:
right = False
if e.type == KEYUP and e.key == K_LEFT:
left = False
# Извеждане на фона
for y in range(32):
for x in range(64):
screen.blit(bg, (x*32 , y*32))
#Текст, който показва прогреса по събиране на точки и броя скокове, които са направени
# Ъпдейтване на играча и извеждане на всичко останало
for i in enemy:
i.update(True, platforms, total_level_height)
player.update(up, left, right, running, platforms, enemy, gears, total_level_height)
for e in entities:
screen.blit(e.image, camera.apply(e))
camera.update(player, WIN_WIDTH, WIN_HEIGHT)
screen.blit(lives_text, (900 , 4))
for i in range(player.lives):
screen.blit(lives_image, ((1100 - i*35), 0))
#Текст, който показва прогреса по събиране на точки и броя скокове, които са направени
scoretext = font.render("Score:"+str(player.score)+"/"+str(player.gears_count*16)+" Jumps:"+str(player.jumps), 1,(255,255,255))
screen.blit(scoretext, (10 , 4))
#Проверка дали играта е свършила
if player.score == player.gears_count*16: #Ако са събрани всички зъбни колела, изведи съобщение и се върни в началното меню
font_end = pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',30)
end_text_first_line = font_end.render("Congratulations! ", 1,(255,0,0))
end_text_second_line = font_end.render("You collected maximum points! ", 1,(255,0,0))
screen.blit(end_text_first_line, (500 , 350))
screen.blit(end_text_second_line, (430 , 380))
screen.blit(scoretext, (10 , 4))
pygame.display.update()
pygame.time.delay(2000)
pygame.event.wait()
current_level+=1
game('Level_'+str(current_level), player.lives)
if player.lives == 0: #Ако играча е загубил всичките си животи, изведи съобщение и се върни в началното меню
font_end = pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',30)
end_text_first_line = font_end.render("Game Over! ", 1,(255,0,0))
end_text_second_line = font_end.render("You died!", 1,(255,0,0))
screen.blit(end_text_first_line, (500 , 350))
screen.blit(end_text_second_line, (515 , 380))
pygame.display.update()
pygame.time.delay(2000)
pygame.event.wait()
menu_game()
pygame.display.update()
示例5: Scene
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import apply [as 别名]
class Scene(BackgroundLayer, KeyListener):
def __init__(self, engine):
self.engine = engine
self.actors = []
self.camera = Camera()
self.world = None
self.space = None
self.time = 0.0
self.actors = []
self.players = self.engine.world.getPlayers()
self.controls = engine.input.controls
#for simplification of theme writing
self.fontDict = self.engine.data.fontDict
self.geometry = self.engine.view.geometry[2:4]
self.fontScreenBottom = self.engine.data.fontScreenBottom
self.aspectRatio = self.engine.view.aspectRatio
self.drawImage = self.engine.drawImage
self.drawStarScore = self.engine.drawStarScore
def addPlayer(self, player):
self.players.append(player)
def removePlayer(self, player):
self.players.remove(player)
def run(self, ticks):
self.time += ticks / 50.0
def shown(self):
self.engine.input.addKeyListener(self)
def hidden(self):
self.engine.input.removeKeyListener(self)
def keyPressed(self, key, unicode):
c = self.controls.keyPressed(key)
if c:
return True
return False
def keyReleased(self, key):
c = self.controls.keyReleased(key)
if c:
return True
return False
def render3D(self):
pass
def render(self, visibility, topMost):
font = self.engine.data.font
# render the scene
try:
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
gluPerspective(60, self.engine.view.aspectRatio, 0.1, 1000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glPushMatrix()
self.camera.apply()
self.render3D()
finally:
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
示例6: main_game
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import apply [as 别名]
def main_game(self):
# Set the default control flags
up = down = left = right = False
exit_game = False
walking = False
self.load_level() # Create the environment assets
level_size = (len(self.level[0]) * self.block_size[0], len(self.level) * self.block_size[1])
camera = Camera(level_size, self.window_size)
mouse = Mouse(pygame.mouse.get_pos())
mouse_clicked = False
mosue_right_clicked = False
while not exit_game:
# Reset control flags each loop
mouse_clicked = False
mouse_right_clicked = False
# Handle pygame
self.clock.tick(self.fps)
# Load title displaying true FPS
current_fps = float(self.clock.get_fps())
pygame.display.set_caption("The Forming | FPS: " + str(current_fps))
# Event Handling
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
# Keydown events
if event.type == KEYDOWN:
if event.key == K_UP or event.key == K_w:
up = True
elif event.key == K_DOWN or event.key == K_s:
down = True
elif event.key == K_LEFT or event.key == K_a:
left = True
elif event.key == K_RIGHT or event.key == K_d:
right = True
if event.type == KEYUP:
if event.key == K_UP or event.key == K_w:
up = False
elif event.key == K_DOWN or event.key == K_s:
down = False
elif event.key == K_LEFT or event.key == K_a:
left = False
elif event.key == K_RIGHT or event.key == K_d:
right = False
# Mouse events
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
mouse_clicked = True
elif event.button == 3:
mouse_right_clicked = True
if event.type == MOUSEBUTTONUP:
if event.button == 1:
mouse_clicked = False
elif event.button == 3:
mouse_right_clicked = False
# Update the entities
camera.update(self.player)
self.player.update(up, down, left, right, level_size)
for tile in self.environment_entities:
self.screen.blit(tile.image, camera.apply(tile))
for player in self.player_entities:
self.screen.blit(player.image, camera.apply(player))
mouse.update(pygame.mouse.get_pos())
pygame.display.update()
示例7: Level
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import apply [as 别名]
#.........这里部分代码省略.........
self.Enem[i].ai(self.Nahui, time)
self.Enem[i].update()
def nahui_move(self, time, key, events):
self.Nahui.move(time,key)
self.Nahui.update(None)
for event in events:
if event.type == KEYUP:
self.Nahui.update(event.key)
def gods_update(self):
for god in self.Teo:
god.update(self.Nahui, self.Enem)
def control_attacks(self):
for i in range(self.NoE):
if abs(self.Enem[i].rect.centerx - self.Nahui.rect.centerx) <= 90:
if self.Nahui.on_attack == True:
self.Enem[i].hitBy(self.Nahui)
if self.Enem[i].on_attack == True:
#Attack when invocation
if self.Nahui.on_invoke == False:
self.Nahui.hitBy(self.Enem[i])
elif self.Nahui.on_invoke == True:
self.Enem[i].hitBy(self.Nahui)
if abs(self.Enem[i].rect.centery - self.Nahui.rect.centery) < 50:
if self.Nahui.on_invoke == False:
if self.Enem[i].on_attack == True:
self.Nahui.hitBy(self.Enem[i])
for god in self.Teo:
if god.on_sub_action == True:
if god.sub_action_target == self.Enem[i]:
if type(god) is Tlaloc:
self.Enem[i].hitBy(god)
if type(god) is Ehecatl:
self.Enem[i].hitBy(god)
if type(god) is Xiuhtecuhtli:
if god.rect.bottom >= god.ground:
self.Enem[i].hitBy(god)
def control_invocations(self):
for god in self.Teo:
if pygame.sprite.collide_rect(self.Nahui, god):
if self.Nahui.on_cover == True:
if god.invokable == True:
self.Nahui.invoke(god)
god.invoked(self.Nahui)
def focus_camera(self, screen):
self.camera.update(screen, self.Nahui)
def blit_all(self, screen):
screen.blit(self.level_background.image, self.camera.apply(self.level_background, False))
screen.blit(self.level_foreground.image, self.camera.apply(self.level_foreground))
level_elements = back2front(self.Teo, self.Enem, self.Nahui)
for i in level_elements:
screen.blit(i.image, self.camera.apply(i))
def hud_update(self, screen):
self.hud.update(screen, self.Nahui, self.Teo, self.Cdx)
def play_music(self):
if not self.music.is_playing():
self.music.get_sfx().play(-1)
def stop_music(self):
self.music.get_sfx().fadeout(100)
def update(self, time, key, events, screen):
self.play_music()
self.codex_update()
self.spanish_move(time)
self.nahui_move(time, key, events)
self.gods_update()
self.control_attacks()
self.control_invocations()
self.focus_camera(screen)
self.blit_all(screen)
self.hud_update(screen)
def completed(self):
enem_health = []
for enemy in self.Enem:
enem_health.append(enemy.health)
if self.Nahui.health <= 0 or all(h <= 0 for h in enem_health):
if self.delay >= 1:
self.delay -= 0.5
return False
else:
self.stop_music()
return True
else:
return False
def victory(self):
if self.Nahui.health > 0: return True
else: return False