本文整理汇总了Python中Camera.Camera.move方法的典型用法代码示例。如果您正苦于以下问题:Python Camera.move方法的具体用法?Python Camera.move怎么用?Python Camera.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera.Camera
的用法示例。
在下文中一共展示了Camera.move方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SVGBuild
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import move [as 别名]
#.........这里部分代码省略.........
self.printText.emit('Starting buildup of %s...' % self.filename)
try:
self.svg = SVG()
elementCount = self.svg.read(str(self.filename))
if self.options['page']:
self.options['width'] = self.svg.root.attrib['width']
self.options['height'] = self.svg.root.attrib['height']
except Exception as e:
print 'error'
self.finished.emit()
return
if self.options['fullpath']:
defs_element = self.svg.root.find('{http://www.w3.org/2000/svg}defs')
markers = defs_element.findall('{http://www.w3.org/2000/svg}marker')
if len(markers) == 0:
self.addMarker(defs_element, self.options['marker'])
else:
self.marker = '%s' % markers[0].attrib['id']
self.printText.emit('Surveyed %d elements.' % elementCount)
self.camera = Camera(self.options)
self.camera.printText.connect(self.printText)
# self.finished.emit()
# return 0
if self.camera.survey(self.svg):
#self.printText.emit('ok')
self.camera.move(self.svg.root.attrib['id'])
self.build(self.svg, self.camera, self.svg.root, self.options)
if self.isRunning:
self.printText.emit('Finishing...')
self.options['camera'] = False
self.camera.shoot(self.svg)
self.camera.hold(self.options['hold'])
self.camera.cleanup()
else:
self.printText.emit('Canceled...')
finish = time.time()
hours = int((finish - start) / 60) / 60
minutes = int((finish - start) / 60) % 60
folder = self.options['folder']
self.printText.emit('Finished %s to %s in %dh:%02dm.' % (self.filename, folder, hours, minutes))
self.finished.emit()
def build(self, svg, camera, entity, options):
'''Recursively build up the given entity, by removing all its children
and adding them back in one at a time, and shooting the progress with
the given camera.
'''
if not self.isRunning: return
id = entity.attrib['id']
name = id
label = 'http://www.inkscape.org/namespaces/inkscape}label'
if label in entity.attrib:
name = entity.attrib[label]
示例2: CreatureSim
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import move [as 别名]
#.........这里部分代码省略.........
self.quadtree.update_objects(self.entities)
self.handle_collisions()
self.do_obj_events()
self.render_frame()
def render_frame(self):
pygame.display.set_caption(str(self.clock.get_fps()))
# Find all objects in nodes intersecting the screen
objects_to_draw = self.quadtree.get_objects_at_bounds(self.camera.get_bounds())
for scene_object in objects_to_draw:
scene_object.draw(self.screen, self.camera)
if self.draw_quadtree:
self.quadtree.draw_tree(self.screen, self.camera)
self.draw_ui()
pygame.display.flip()
def center_camera(self):
if self.selected_creature and self.follow_creature:
self.camera.position[0] = self.selected_creature.position[0]
self.camera.position[1] = self.selected_creature.position[1]
def do_obj_events(self):
if not self.paused:
self.check_healths()
def remove_creature(self, creature):
if creature.selected:
self.unfollow_creature()
self.quadtree.remove(creature)
self.entities.remove(creature)
self.entities.remove(creature.vision_cone)
self.scene_graph.remove(creature)
def check_healths(self):
for creature in self.get_creatures():
if creature.health <= 0:
self.remove_creature(creature)
self._breed_creature()
for food in self.get_foods():
if food.eaten == True:
self.quadtree.remove(food)
self.entities.remove(food)
self._insert_new_food()
def _insert_new_creature(self):
new_creature = Creature(
x=randrange(*self.game_bounds),
y=randrange(*self.game_bounds),
color=WHITE
)
new_creature.vision_cone = VisionCone(parent=new_creature, x=265, color=RED)
self.entities.append(new_creature.vision_cone)
self._insert_creature(new_creature)
示例3: __init__
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import move [as 别名]
class RenderCube:
'''This is the class that renders a rainbow cube
Camera angles are handled by Camera.py.
'''
WINDOW_WIDTH = 700
WINDOW_HEIGHT = 700
MAP_SIZE =100
def __init__(self):
'''Sets up camera, modes, lighting, sounds, and objects.'''
self.set_up_graphics()
self.makeLights()
self.camera = Camera(0,0,5)
self.verts=self.GenArray()
self.colors=self.GenArray('color')
glClearColor(1,1,1,0)
glutIdleFunc(self.display)
glutDisplayFunc(self.display)
glutIgnoreKeyRepeat(GLUT_KEY_REPEAT_OFF)
glutKeyboardFunc(self.keyPressed)
glutKeyboardUpFunc(self.keyUp)
glutSetCursor(GLUT_CURSOR_NONE)
glutPassiveMotionFunc(self.mouseMove)
glutMainLoop()
def set_up_graphics(self):
'''Sets up OpenGL to provide double buffering, RGB coloring,
depth testing, the correct window size, and a title.'''
glutInit()
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(self.WINDOW_WIDTH, self.WINDOW_HEIGHT)
glutCreateWindow('RainbowCube!')
glMatrixMode(GL_PROJECTION)
gluPerspective(45,1,.15,100)
glMatrixMode(GL_MODELVIEW)
glEnable(GL_DEPTH_TEST)
def makeLights(self):
'''Sets up the light sources and their positions. We have an
ambient light and two sets of specular/diffuse lights.'''
self.diffuse_pos1 = (50,5,0,1)
glLightfv(GL_LIGHT0, GL_DIFFUSE, (.5, .5, .5, 1))
glLightfv(GL_LIGHT0, GL_POSITION, self.diffuse_pos1)
glLightfv(GL_LIGHT1, GL_AMBIENT, (.2, .2, .2, 1))
glLightfv(GL_LIGHT1, GL_POSITION, (0, 0, 1, 0))
glLightfv(GL_LIGHT2, GL_SPECULAR, (.8, .8, .8, 1))
glLightfv(GL_LIGHT2, GL_POSITION, self.diffuse_pos1)
self.diffuse_pos2 = (0,1,0,1)
glLightfv(GL_LIGHT3, GL_DIFFUSE, (.5, .5, .5, 1))
glLightfv(GL_LIGHT3, GL_POSITION, self.diffuse_pos2)
glLightfv(GL_LIGHT4, GL_SPECULAR, (.8, .8, .8, 1))
glLightfv(GL_LIGHT4, GL_POSITION, self.diffuse_pos2)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glEnable(GL_LIGHT1)
glEnable(GL_LIGHT2)
def display(self, x=0, y=0):
'''Called for every refresh; redraws the cube at current position
based on the camera angle.'''
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
self.camera.move()
self.camera.renderCamera()
self.renderLightSource()
glPushMatrix()
# Set the object shininess, ambient, diffuse, and
# specular reflections.
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 75)
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [.4, .4, .4, 1])
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [.9, .9, .9, .8])
glTranslate(0,0,0)
self.MakeCube()
glPopMatrix()
glutSwapBuffers()
def mouseMove(self, x, y):
'''Called when the mouse is moved.'''
factor = 2
tmp_x = (self.camera.mouse_x - x)/factor
tmp_y = (self.camera.mouse_y - y)/factor
if tmp_x > self.camera.ROTATE:
tmp_x = self.camera.ROTATE
self.camera.rotate(0, tmp_x, 0)
x = self.WINDOW_WIDTH/2
y = self.WINDOW_HEIGHT/2
#.........这里部分代码省略.........
示例4: Level
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import move [as 别名]
#.........这里部分代码省略.........
tile_map[row_num][col_num] = base_tile
elif TileType.TURRET_LEFT in \
tile_map[row_num][col_num].special_attr:
self.add_turret(row_num, col_num, True)
elif TileType.TURRET_RIGHT in \
tile_map[row_num][col_num].special_attr:
self.add_turret(row_num, col_num, False)
def add_enemy(self, row_num, col_num):
y = self.tile_rect.height * row_num - self.camera.viewpoint.top
x = self.tile_rect.width * col_num - self.camera.viewpoint.left
self.enemySprites.add(Enemy(Globals.WIDTH, Globals.HEIGHT, x=x, y=y))
def add_turret(self, row_num, col_num, left):
row_num += 1
if not left:
col_num += 1
y = self.tile_rect.height * row_num - self.camera.viewpoint.top
x = self.tile_rect.width * col_num - self.camera.viewpoint.left
self.turrets.append(Turret(x, y, left))
def check_collisions(self):
# radius = max(self.player.rect.size) * 1.5
# center = self.player.rect.center
for turret in self.turrets:
for syringe in turret.syringeSprites:
if self.player.rect.colliderect(syringe):
Globals.PLAYER_HEALTH += syringe.health_effect
print Globals.PLAYER_HEALTH
syringe.kill()
def render(self):
self.camera.render(Globals.SCREEN)
self.enemySprites.draw(Globals.SCREEN)
for turret in self.turrets:
turret.render(Globals.SCREEN)
self.playerSprites.draw(Globals.SCREEN)
def update(self, time):
self.player.update(time, self.camera, self.enemySprites, self)
self.enemySprites.update(time, self.camera)
for turret in self.turrets:
turret.update(time, self.camera)
self.checkCameraPosition()
self.check_collisions()
def event(self, event):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
self.reload_level()
elif event.key == pygame.K_ESCAPE:
self.handle_escape()
else:
self.keyCode = event.key
for p in self.playerSprites:
p.keyPressed(event.key)
elif event.type == pygame.KEYUP and event.key == self.keyCode:
self.keyCode = None
for p in self.playerSprites:
p.keyReleased(event.key)
def checkCameraPosition(self):
dist_x = self.camera.container.centerx - self.player.rect.centerx
dist_y = self.camera.container.centery - self.player.rect.centery
if abs(dist_x) > Level.MAX_OFFSET_X:
diff = abs(dist_x) - Level.MAX_OFFSET_X
# player is to the right of center
if dist_x < 0:
pass
# player is to the left of center
else:
diff *= -1
self.camera.move(diff, 0)
self.player.rect.centerx -= diff
for enemy in self.enemySprites:
enemy.rect.centerx -= diff
for turret in self.turrets:
turret.move(-diff, 0)
if abs(dist_y) > Level.MAX_OFFSET_Y:
diff = abs(dist_y) - Level.MAX_OFFSET_Y
# player is below center
if dist_y < 0:
pass
# player is above center
else:
diff *= -1
self.camera.move(0, diff)
self.player.rect.centery -= diff
for enemy in self.enemySprites:
enemy.rect.centery -= diff
for turret in self.turrets:
turret.move(0, -diff)
def reload_level(self):
try:
new_state = Level(self.definition_path, self.map_path)
Globals.STATE = new_state
print "Reloaded level"
except Exception as e:
print "Reload failed: ", e
示例5: __init__
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import move [as 别名]
class TestRender:
'''This is the class that renders maze.
Camera angles are handled by Camera.py.
'''
WINDOW_WIDTH = 700
WINDOW_HEIGHT = 700
SCALE = .5
MAP_SIZE =100
X_FACTOR = 1
Y_FACTOR = 1
Z_FACTOR = 1
MAP_SIZE = 100
SEA_LEVEL = 4
def __init__(self):
self.set_up_graphics()
self.load_object()
self.set_up_glut()
self.camera = Camera(0,60,0)
self.camera.rotate(-75,-150,0)
self.poly_view = False
self.start_loop()
def set_up_glut(self):
glutIdleFunc(self.display)
glutDisplayFunc(self.display)
glutIgnoreKeyRepeat(GLUT_KEY_REPEAT_OFF)
glutKeyboardFunc(self.keyPressed)
glutKeyboardUpFunc(self.keyUp)
glutSetCursor(GLUT_CURSOR_NONE)
glutPassiveMotionFunc(self.mouseMove)
#glGenLists(50)
#glNewList(1, GL_COMPILE)
#glNewList(1, GL_COMPILE)
def start_loop(self):
glutMainLoop()
def set_up_graphics(self):
glutInit()
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(self.WINDOW_WIDTH, self.WINDOW_HEIGHT)
glutCreateWindow('Terrains!')
glMatrixMode(GL_PROJECTION)
gluPerspective(45,1,.1,500)
glMatrixMode(GL_MODELVIEW)
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable (GL_BLEND)
glClearColor(.529,.8078,.980,0)
glEnable(GL_NORMALIZE)
glEnable (GL_DEPTH_TEST)
#glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
def load_object(self):
self.load = Structure()
self.structure = self.load.create_structure()
def load_object2(self):
self.load = Grass()
self.structure = self.load.create_grass_list()
def display(self, x=0, y=0):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
#Put camera and light in the correct position
self.camera.move()
self.camera.renderRotateCamera()
self.camera.renderTranslateCamera()
glCallList(self.structure)
glDisable(GL_TEXTURE_2D)
glutSwapBuffers()
def mouseMove(self, x, y):
'''Called when the mouse is moved.'''
factor = 2
tmp_x = (self.camera.mouse_x - x)/factor
tmp_y = (self.camera.mouse_y - y)/factor
if tmp_x > self.camera.ROTATE:
tmp_x = self.camera.ROTATE
self.camera.rotate(tmp_y, tmp_x, 0)
x = self.WINDOW_WIDTH/2
y = self.WINDOW_HEIGHT/2
glutWarpPointer(x, y)
self.camera.mouse_x = x
self.camera.mouse_y = y
#.........这里部分代码省略.........
示例6: LevelEditor
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import move [as 别名]
#.........这里部分代码省略.........
if extra_x > 0:
self.camera_dest.width -= extra_x
self.camera_dest.centery = self.globals.HEIGHT / 2
def init_highlight(self, source=None, alpha=HIGHLIGHT_ALPHA, border=False):
self.highlight_surf = pygame.Surface(self.tile_rect.size).convert()
if source is None:
self.highlight_surf.fill(LevelEditor.HIGHLIGHT_COLOR)
self.highlight_surf.set_alpha(alpha)
else:
self.highlight_surf.blit(source, (0, 0))
self.highlight_surf.set_alpha(alpha)
if border:
pygame.draw.rect(self.highlight_surf,
LevelEditor.HIGHLIGHT_BORDER, self.tile_rect, 1)
def render(self):
self.globals.SCREEN.fill((0, 0, 0))
self.camera.render(self.globals.SCREEN, False)
self.handle_mouse()
if self.message_surf is not None:
self.globals.SCREEN.blit(self.message_surf, self.message_rect)
self.globals.SCREEN.blit(self.title_surf, self.title_rect)
self.browser.render(self.globals.SCREEN)
self.globals.SCREEN.blit(
self.second_title_surf, self.second_title_rect)
self.combo_browser.render(self.globals.SCREEN)
def update(self, time):
if self.key_code is not None:
if self.key_code == pygame.K_UP or self.key_code == pygame.K_w:
self.camera.move(0, -self.shift_factor)
elif self.key_code == pygame.K_DOWN or self.key_code == pygame.K_s:
self.camera.move(0, self.shift_factor)
elif self.key_code == pygame.K_LEFT or self.key_code == pygame.K_a:
self.camera.move(-self.shift_factor, 0)
elif self.key_code == pygame.K_RIGHT or \
self.key_code == pygame.K_d:
self.camera.move(self.shift_factor, 0)
if self.message_surf is not None:
self.message_time -= time
if self.message_time <= 0:
self.message_surf = None
if self.mouse_down:
self.handle_mouse_click()
def set_message(self, content, timeout=MESSAGE_TIMEOUT,
color=DEFAULT_MESSAGE_COLOR):
temp_surf = LevelEditor.MESSAGE_FONT.render(content, True, color)
self.message_rect = temp_surf.get_rect()
self.message_rect.bottom = self.camera_dest.bottom
self.message_rect.centerx = self.camera_dest.centerx
self.message_rect.inflate_ip(LevelEditor.MESSAGE_PADDING * 2,
LevelEditor.MESSAGE_PADDING * 2)
self.message_surf = pygame.Surface(self.message_rect.size).convert()
self.message_surf.fill(LevelEditor.MESSAGE_BACKGROUND)
self.message_surf.blit(
temp_surf, (LevelEditor.MESSAGE_PADDING,
LevelEditor.MESSAGE_PADDING))
if self.message_rect.left < 0:
self.message_rect.left = 0
self.message_time = timeout
def handle_mouse(self):
示例7: __init__
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import move [as 别名]
#.........这里部分代码省略.........
'''Called for every refresh; redraws the floor and objects
based on the camera angle. Calls collision detection, handles
the appropriate objects for keys, doors, etc.'''
#print "loopdy loop"
# print self.curr_time - time.time()
f_rate = 1.0/60
if self.last_time+f_rate <= time.time():
self.last_time = time.time()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glDisable(GL_LIGHTING)
self.camera.renderRotateCamera()
glTranslate(-self.skybox.x/2, -1-self.camera.pos_Y, -self.skybox.z/2)
glCallList(self.sky_index)
if abs(self.curr_time - time.time()) >= 1:
print "FPS:", self.count
print time.time()
self.count = 0
self.curr_time = time.time()
else:
self.count+=1
if self.need_lists:
self.create_render_newlist()
#self.lock.acquire()
glLoadIdentity()
#Put camera and light in the correct position
self.camera.move()
self.camera.renderRotateCamera()
self.camera.renderTranslateCamera()
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glEnable(GL_LIGHT1)
self.renderLightSource()
for index in self.land_index_list:
#print "INDEX:", index
glCallList(index)
for index in self.water_index_list:
glCallList(index)
for index in self.building_index_list:
glCallList(index[0])
glDisable(GL_TEXTURE_2D)
glutSwapBuffers()
def renderLightSource(self):
'''Resets the light sources to the right position.'''
if self.camera.pos_Y <= self.convert.sea_level:
glLightfv(GL_LIGHT0, GL_DIFFUSE, (0, .2, 1, 1))
else:
glLightfv(GL_LIGHT0, GL_DIFFUSE, (1, 1, 1, 1))
glLightfv(GL_LIGHT0, GL_POSITION, self.diffuse_pos1)
def mouseMove(self, x, y):
示例8: TileTest
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import move [as 别名]
class TileTest(GameState):
FACTOR = 35
INDEX_DOWN = 0
INDEX_UP = 1
INDEX_LEFT = 2
INDEX_RIGHT = 3
NUM_ENEMY = 13
WALL_WIDTH = 50
def __init__(self):
self.tileEngine = TileEngine("test_def.txt", "test_map.txt", 1, 3)
self.camera = Camera(self.tileEngine, pygame.Rect(
0, 0, Globals.WIDTH, Globals.HEIGHT))
self.keyCode = None
self.testPoint = [Globals.WIDTH / 2, int(Globals.HEIGHT -
self.camera.tileEngine.get_tile_rect().height * 3.5)]
self.object_radius = \
self.camera.tileEngine.get_tile_rect().height * 1.5
self.direction = -1
self.has_collided = False
self.enemySprites = pygame.sprite.Group()
self.playerSprites = pygame.sprite.Group()
# for x in range(MainGame.NUM_ENEMY):
# self.enemySprites.add(Enemy(Globals.WIDTH, Globals.HEIGHT))
self.playerSprites.add(Player(Globals.WIDTH, Globals.HEIGHT,
self.testPoint[0], self.testPoint[1]))
def render(self):
self.camera.render(Globals.SCREEN)
self.checkCollisions()
# pygame.draw.circle(Globals.SCREEN, (255, 0, 0), self.testPoint, 6)
# Globals.SCREEN.fill(Globals.BACKGROUND_COLOR)
# self.enemySprites.draw(Globals.SCREEN)
self.playerSprites.draw(Globals.SCREEN)
# self.wallSprites.draw(Globals.SCREEN)
def checkCollisions(self):
solid_tiles = \
self.camera.get_solid_tiles(self.testPoint, self.object_radius)
solid_rects = [pair.rect for pair in solid_tiles]
# # curr_rect = \
# # pygame.Rect(self.testPoint[0] - 3, self.testPoint[1] - 3, 6, 6)
# curr_rect = self.playerSprites.get
# for i in curr_rect.collidelistall(solid_rects):
for p in self.playerSprites:
curr_rect = p.rect
for i in curr_rect.collidelistall(solid_rects):
wall_rect = solid_rects[i]
if self.direction == TileTest.INDEX_UP:
curr_rect.top = wall_rect.bottom
self.has_collided = True
elif self.direction == TileTest.INDEX_DOWN:
curr_rect.bottom = wall_rect.top
self.has_collided = True
elif self.direction == TileTest.INDEX_LEFT:
curr_rect.left = wall_rect.right
self.has_collided = True
elif self.direction == TileTest.INDEX_RIGHT:
curr_rect.right = wall_rect.left
self.has_collided = True
else:
self.has_collided = False
self.testPoint[1] = curr_rect.top + 3
self.testPoint[0] = curr_rect.left + 3
special_tiles = \
self.camera.get_special_tiles(self.testPoint,
self.object_radius)
stair_rects = [pair.rect for pair in special_tiles
if pair.tile.special_attr == TileType.STAIR_ATTR]
for p in self.playerSprites:
num_stairs = len(p.rect.collidelistall(stair_rects))
if num_stairs > 0:
# fix the import and this should be done
Globals.STATE = WinGame()
pass
def update(self, time):
if self.keyCode is not None:
if self.keyCode == pygame.K_UP:
self.direction = TileTest.INDEX_UP
if self.has_collided:
self.camera.move(0, 0)
else:
self.camera.move(0, -TileTest.FACTOR)
elif self.keyCode == pygame.K_DOWN:
self.direction = TileTest.INDEX_DOWN
if self.has_collided:
self.camera.move(0, 0)
else:
self.camera.move(0, TileTest.FACTOR)
elif self.keyCode == pygame.K_LEFT:
self.direction = TileTest.INDEX_LEFT
if self.has_collided:
#.........这里部分代码省略.........