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


Python Camera.bound_camera方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import bound_camera [as 别名]
class View:
    
    def __init__(self, camera_bounds, event_system, world_bounds):
        pygame.init()
        self.display = pygame.display.set_mode(camera_bounds)
        pygame.display.set_caption("VV Pilot")

        icon = pygame.Surface((32, 32))
        icon.fill(WHITE)
        pygame.gfxdraw.polygon(icon, ((3, 29), (29, 29), (16, 3)), BLACK)
        pygame.gfxdraw.polygon(icon, ((4, 28), (28, 28), (16, 3)), BLACK)
        pygame.gfxdraw.aapolygon(icon, ((2, 30), (30, 30), (15, 2)), BLACK)
        pygame.display.set_icon(icon)
        # initialize the lists
        self.ship_list = []
        self.bullet_list = []
        self.wall_list = []
        self.debris = []
        # make the camera
        self.camera = Camera((camera_bounds[0]/2, camera_bounds[1]/2), camera_bounds)
        self.world_bounds = world_bounds
        # add the view to the event system
        event_system.onShipDeath+=self.onShipDeath
        event_system.onBulletDeath+=self.onBulletDeath
        
    def onShipDeath(self, ship):
        Display.death_animation(ship, self.debris, BLACK)
        
    def onBulletDeath(self, bullet, wall_rect):
        Display.bullet_death(bullet, wall_rect, self.debris, BLUE)
        
    def draw_ship(self, ship):
        if not ship.isDead():
            Display.draw_triangle(self.display, self.camera, BLACK, ship.location, ship.bounds, ship.direction, 2)
            if ship.moved:
                Display.draw_triangle_offset(self.display, self.camera, RED, (ship.location[0], ship.location[1]+ship.bounds[1]*3/2), (ship.bounds[0]/2, ship.bounds[1]/2), ship.direction-180, ship.location, 2)
            if ship.shield_obj:
                Display.draw_rect(self.display, self.camera, GREEN, ship.shield_obj, 2)
                
    def draw_bullet(self, bullet):
        Display.draw_circle(self.display, self.camera, BLUE, bullet.location, bullet.bounds[0])
        
    def draw_wall(self, wall):
        Display.draw_rect(self.display, self.camera, GREEN, wall, 2)
        
    def set_camera_loc(self, location):
        self.camera.set_camera_loc(location)
        self.camera.bound_camera(self.world_bounds)
        
    def draw_everything(self):
        self.display.fill(WHITE)
        for ship in self.ship_list:
            self.draw_ship(ship)
        for bullet in self.bullet_list:
            self.draw_bullet(bullet)
        i = 0
        while i < len(self.debris):
            debra = self.debris[i]
            loc = (debra[0][0] + debra[1][0], debra[0][1] + debra[1][1])
            dur = debra[2] - 1
            self.debris[i] = (loc, debra[1], dur, debra[3], debra[4], debra[5], debra[6], debra[7])
            debra = self.debris[i]
            Display.draw_circle(self.display, self.camera, debra[7], debra[0], int((debra[6]-debra[2])*debra[3]) + debra[4], debra[5])
            if self.debris[i][2]<=0:
                self.debris.remove(self.debris[i])
            else:
                i+=1
        for wall in self.wall_list:
            self.draw_wall(wall)
        pygame.display.update()
开发者ID:rayman42003,项目名称:INF123-VVPilot,代码行数:72,代码来源:View.py

示例2: Bullet

# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import bound_camera [as 别名]
     if keys[K_SPACE] and player_ship.delay<=0:
         bullet = Bullet((x + dimy*sinD, y-dimy*cosD), (BULLET_SIZE, BULLET_SIZE), player_ship.direction, (BULLET_SPEED*sinD, -BULLET_SPEED*cosD), BULLET_DURATION)
         #bullet = (x + dimy*sinD, y-dimy*cosD, player_ship.direction, BULLET_DURATION)
         bulletList.append(bullet)
         player_ship.delay = SHOOT_DELAY
         player_ship.move_from_force_in_direction(player_ship.acceleration, player_ship.direction+180)
 
 player_ship.update()
 
 for n in wall_list:
     if player_ship.rect.colliderect(n) and not player_ship.isDead():
         player_ship.kill(DEATH_TIME)
         Display.death_animation(player_ship, debris, BLACK)
 
 camera.set_camera_loc((x, y))
 camera.bound_camera(map_dimensions)
     
 if not player_ship.isDead():
     Display.draw_triangle(display, camera, BLACK, player_ship.location, player_ship.bounds, player_ship.direction, 2)
     if moved:
         Display.draw_triangle_offset(display, camera, RED, (player_ship.location[0], player_ship.location[1]+player_ship.bounds[1]*3/2), (player_ship.bounds[0]/2, player_ship.bounds[1]/2), player_ship.direction-180, player_ship.location, 2)
     
 i = 0
 while i < len(debris):
     debra = debris[i]
     loc = (debra[0][0] + debra[1][0], debra[0][1] + debra[1][1])
     dur = debra[2] - 1
     debris[i] = (loc, debra[1], dur, debra[3], debra[4], debra[5], debra[6], debra[7])
     debra = debris[i]
     Display.draw_circle(display, camera, debra[7], debra[0], int((debra[6]-debra[2])*debra[3]) + debra[4], debra[5])
     if debra[2]<=0:
开发者ID:rayman42003,项目名称:INF123-VVPilot,代码行数:33,代码来源:Main.py


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