本文整理汇总了Python中Camera.apply方法的典型用法代码示例。如果您正苦于以下问题:Python Camera.apply方法的具体用法?Python Camera.apply怎么用?Python Camera.apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera
的用法示例。
在下文中一共展示了Camera.apply方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import Camera [as 别名]
# 或者: from Camera import apply [as 别名]
def main():
# Initialise screen
pygame.init()
screen = display.set_mode(DISPLAY)
display.set_caption("Game")
# create npc
npc_list = []
npc = Npc(200, 120)
npc1 = Npc(300, 160)
npc_list.append(npc)
npc_list.append(npc1)
# create player
player = Player(HERO_X, HERO_X, npc_list)
# Fill background
background = pygame.Surface(screen.get_size())
background.fill(Color(BACKGROUND_COLOR))
#create level
ar_level_size = create_level(background)
level_width = ar_level_size[0] * 32
level_height = ar_level_size[1] * 32
entities = ar_level_size[2]
timer = time.Clock()
camera = Camera(level_width, level_height)
while 1:
timer.tick(240)
if player.rect.x + player.rect.width >= level_width:
right = False
if player.rect.x <= 0:
left = False
if player.rect.y + player.rect.height >= level_height:
down = False
if player.rect.y <= 0:
up = False
for event in pygame.event.get():
if event.type == QUIT:
return
# Move the player if an arrow key is pressed
key_press = pygame.key.get_pressed()
if key_press[pygame.K_LEFT]:
player.update(-1, 0)
if key_press[pygame.K_RIGHT]:
player.update(1, 0)
if key_press[pygame.K_UP]:
player.update(0, -1)
if key_press[pygame.K_DOWN]:
player.update(0, 1)
camera.update(player)
for e in entities:
screen.blit(e.image, camera.apply(e))
player.draw(screen, camera)
for npc in npc_list:
npc.draw(screen, camera)
display.flip()
示例2: GameScene
# 需要导入模块: import Camera [as 别名]
# 或者: from Camera import apply [as 别名]
class GameScene(Scene):
def __init__(self, music, host):
super(GameScene, self).__init__()
self.background = Surface((WINDOW_WIGTH, WINDOW_HEIGHT))
self.background.fill(Color(BACKGROUND_COLOR))
timer = pygame.time.Clock()
self.music = music
self.enemy = []
self.net=Net()
self.net.subscribe(self.sync)
self.host = host
mouse.set_pos([200, 300])
self.heroes = []
self.up = self.down = self.left = self.right = False
self.entitles_walls = pygame.sprite.Group()
self.entitles = pygame.sprite.Group()
self.addHero(Player(300, 55, 1))
self.walls = []
#map:
self.map = open("maps/testmap.txt", "r")
self.x = 0
self.y = 0
self.lenx = 0
self.leny = 0
for self.row in self.map:
for self.col in self.row:
if self.col == "-":
self.wall = wall(self.x, self.y)
self.entitles_walls.add(self.wall)
self.walls.append(self.wall)
if self.col == " ":
self.floor = floor1(self.x, self.y)
self.entitles_walls.add(self.floor)
self.x = self.x + BLOCK_X
self.y = self.y + BLOCK_Y
self.lenx = self.x / BLOCK_X
self.leny += 1
self.x = 0
for i in self.heroes:
self.entitles.add(i)
total_level_width = self.lenx*WINDOW_WIGTH
total_level_height = self.leny*WINDOW_HEIGHT
self.camera = Camera(camera_configure, total_level_width, total_level_height)
self.enemy = []
if self.host:
self.enemy = [Enemy(100, 100, 1), Enemy(200, 200, 2), Enemy(100, 500, 3)]
for i in self.enemy:
self.entitles.add(i)
self.bul = []
self.bul.append(Bullet(0,0))
if self.music == True:
pygame.mixer.music.load("music/Game.mp3")
pygame.mixer.music.play(-1)
def render(self, screen):
screen.blit(self.background, (0, 0))
for i in self.entitles_walls:
screen.blit(i.image, self.camera.apply(i))
for i in self.entitles:
screen.blit(i.image, self.camera.apply(i))
def update(self, dt):
self.send_sync(self.net)
self.heroes[0].update(self.up, self.down, self.left, self.right, self.walls, dt)
for i in self.enemy:
i.update(self.walls, self.heroes, self.bul, dt)
if i.hp == 0:
self.enemy.remove(i)
del i
for i in self.bul:
i.update(self.walls, dt)
if i.col == True:
self.bul.remove(i)
del i
self.camera.update(self.heroes[0])
for i in self.entitles:
if i.par == "bul":
if i.col == True:
self.entitles.remove(i)
if i.par == "enemy" or i.par == "player":
if i.hp == 0:
self.entitles.remove(i)
if self.heroes[0].hp == 0:
if self.music == True:
pygame.mixer.music.stop()
self.manager.go_to(LoseScreen())
def handle_events(self, events):
#.........这里部分代码省略.........