本文整理汇总了Python中background.Background.update方法的典型用法代码示例。如果您正苦于以下问题:Python Background.update方法的具体用法?Python Background.update怎么用?Python Background.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类background.Background
的用法示例。
在下文中一共展示了Background.update方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Vacuum
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import update [as 别名]
#.........这里部分代码省略.........
#handle input events
ok = self.handle_keys()
if ok == False:
return
if self.game_started == False:
start_text = self.font.render('Press any key to start', 2, (0,0,0))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
continue
if self.game_paused == 1:
start_text = self.font.render('Game paused', 2, (255,255,255))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
continue
new_enemies = self.level.getenemies()
for enemy_y in new_enemies:
#if random.randint(0,50) == 0:
alien = Alien(enemy_y)
alien.set_target(self.ship)
self.enemies.add(alien)
#aliens damaging the player, remove them
damage = pygame.sprite.spritecollide(self.ship, self.enemies, True)
self.process_powerups()
#check colisions with stage
if self.level.checkcollide(self.ship.rect):
#add some fancy explosions in the damage area
self.explosions.add(Explosion(pygame.Rect(self.ship.rect.x,self.ship.rect.y,0,0)))
damage.append(1)
#Apply damages to the player
if len(damage) > 0:
self.background.warning()
self.ship.damage()
self.lifemeter.shake()
self.explosions.add(Explosion(self.ship.rect))
self.sounds['warning'].play()
self.lifemeter.life = self.ship.life
if self.lifemeter.life < 1:
self.game_finished = True
self.sounds['warning'].stop()
#print (pygame.sprite.spritecollide(ship, level, True))
#aliens hit by the fire, remove them
penetration = self.ship.powerup['penetrate']
for fireball in self.fire:
hit = pygame.sprite.spritecollide(fireball, self.enemies, True)
for dead in hit:
if dead.has_powerup():
powerup = Powerup(dead.rect, dead.value)
self.powerups.add(powerup)
self.explosions.add(Explosion(pygame.Rect(dead.rect.x,dead.rect.y,0,0)))
self.score+=dead.value*1000
if penetration == False:
fireball.kill()
#draw the level
all_sprites = pygame.sprite.Group()
all_sprites.add(self.player.sprites())
all_sprites.add(self.enemies.sprites())
all_sprites.add(self.powerups.sprites())
all_sprites.add(self.fire.sprites())
all_sprites.add(self.hud.sprites())
all_sprites.add(self.explosions.sprites())
all_sprites.update()
self.level.update()
self.background.update()
#Move and draw the background
score_text = 'Score: {0}'.format((self.score))
text = self.font.render(score_text, 1, (255, 255, 255))
text_shadow = self.font.render(score_text, 1, (0,0,0))
self.screen.blit(self.background, (0, 0))
self.screen.blit(self.level, (0, 0))
self.screen.blit(text_shadow, (12, 12))
self.screen.blit(text, (10, 10))
if self.game_finished == True:
gameover_text = self.font.render("Game Over", 2, (255, 255, 255))
self.screen.blit(gameover_text, (280, 200))
gameover_text = self.font.render("Press Esc", 2, (255, 255, 255))
self.screen.blit(gameover_text, (280, 230))
else:
all_sprites.draw(self.screen)
#draw all the groups of sprites
pygame.display.flip()
示例2: range
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import update [as 别名]
#.........这里部分代码省略.........
self.map.object[i][j] = color
def GetCharCrash(self, x, y, w):
if w == 0: # 점프
if self.CrashDetection(x + 2, y) != 0:
return 1
elif self.CrashDetection(x + 18, y) != 0:
return 1
elif w == 1: # 이동
if self.CrashDetection(x + 2, y) != 0:
return 1
elif self.CrashDetection(x + 18, y) != 0:
return 1
elif self.CrashDetection(x + 2, y + 48) != 0:
return 1
elif self.CrashDetection(x + 18, y + 48) != 0:
return 1
return 0
def collide(self, aX, aY, bX, bY): # End라인 충돌처리
left_a, top_a, right_a, bottom_a = aX, aY, aX + 25, aY + 50
left_b, top_b, right_b, bottom_b = bX + 5, bY + 5, bX + 60, bY + 60
if left_a > right_b:
return False
if right_a < left_b:
return False
if top_a > bottom_b:
return False
if bottom_a < top_b:
return False
return True
def update(self):
self.background.update()
if self.clearWin:
if self.clearTime == 0:
self.clearTime = SDL_GetTicks()
if SDL_GetTicks() - self.clearTime > 70:
if self.clearDir == False:
if self.clear_frames < 10:
self.clear_frames += 1
elif self.clear_frames < 17:
self.clear_frames += 1
else:
self.clear_frames = 10
self.clearTime = SDL_GetTicks()
return
if self.Charview == False:
if self.laserTime == 0:
self.laserTime = SDL_GetTicks()
if SDL_GetTicks() - self.laserTime > 55:
self.laser_frames = (self.laser_frames + 1) % 19
self.laserTime = SDL_GetTicks()
if self.laser_frames == 18:
self.Charview = True
if SDL_GetTicks() - self.map.dotTime > 200:
self.map.dot_frames = (self.map.dot_frames + 1) % 2
self.map.dotTime = SDL_GetTicks()
if SDL_GetTicks() - self.map.flagTime > 150:
示例3: __init__
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import update [as 别名]
#.........这里部分代码省略.........
# self.dbz_theme = pygame.mixer.music.load("DBZ_theme.wav")
# self.player_hit_points = 5
# self.baddie_hit_points = 25
# Use code for boss to shoot at random times #
#
# def boss_shoot():
# time.sleep(random.choice([0, 1, 2])
# Number of Player Health
self.health = self.spaceship.getHitPoints()
# Kill Points
self.kills = 0
# Display the health
self.health_color = (255,255,255)
self.health_x = self.width/2
self.health_y = self.height - 30
# Display the Score
self.score_color = (0,150,0)
self.score_x = 20
self.score_y = 50
return
def evolve(self, keys, newkeys, buttons, newbuttons, mouse_position):
self.bg.update() # Update Background
if pygame.K_w in keys:
self.spaceship.setHitPoints(10)
self.spaceship.setWidth(225)
self.spaceship.setHeight(75)
self.spaceship.setImage('pelican_250x99.png')
self.spaceship.setName('Pelican')
self.spaceship_speed = 15
self.health = self.spaceship.getHitPoints()
self.bullet_sound = self.pelican_shoot
self.bg.setSpeed(-20)
if pygame.K_LEFT in keys:
self.spaceship.moveLeft(self.spaceship_speed)
if pygame.K_RIGHT in keys:
self.spaceship.moveRight(self.spaceship_speed,self.upper_limit)
if pygame.K_UP in keys:
self.spaceship.moveUp(self.spaceship_speed)
if pygame.K_DOWN in keys:
self.spaceship.moveDown(self.spaceship_speed,self.height)
if self.spaceship.getAlive() == True: # If space ship is alive, then
# it can fire.
if pygame.K_SPACE in newkeys:
self.bullet_sound.play()
self.bullets.append(self.spaceship.fire(self.bullet_width,
self.bullet_height,
self.bullet_color))
if pygame.K_q in newkeys:
print "PRESSED Q"
pygame.quit()
示例4: Vacuum
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import update [as 别名]
#.........这里部分代码省略.........
self.score.add_score(scored)
self.hud.add(Flying_Label( fireball.rect, scored))
if penetration == False:
fireball.kill()
#Main Loop
def loop(self):
count = 0
count = (count+1)%50
#handle input events
ok = self.handle_keys()
if ok == False:
return
if self.game_started == False:
start_text = self.font.render('Press any key to start', 2, (0,0,0))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
return
if self.game_paused == 1:
start_text = self.font.render('Game paused', 2, (255,255,255))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
return
try:
(new_enemies, new_minibosses, new_bosses, end) = self.level.getenemies()
for enemy_y in new_enemies:
alien = Alien(enemy_y)
alien.set_target(self.ship)
self.enemies.add(alien)
for enemy_y in new_minibosses:
miniboss = Miniboss(enemy_y, self)
miniboss.set_target(self.ship)
self.minibosses.add(miniboss)
if end:
self.level_finished = True
except ValueError:
self.level_finished = True
#aliens damaging the player, remove them
damage = pygame.sprite.spritecollide(self.ship, self.enemies, True)
damage.extend(pygame.sprite.spritecollide(self.ship, self.enemylasers, True))
for miniboss in self.minibosses:
if pygame.sprite.collide_mask(self.ship, miniboss):
damage.append(miniboss)
self.process_powerups()
collisions = self.process_stagecollisions()
for collision in collisions:
damage.append(1)
self.process_damage(damage)
self.process_killedaliens()
#Dummy lines to show the ship's current limits
if show_dummies:
the_limits = self.level.the_limits(self.ship.rect)
self.dummy.rect.top = the_limits[0]*self.level.ratio
self.dummy2.rect.top = the_limits[1]*self.level.ratio
self.dummy.rect.height = 2
self.dummy2.rect.height = 2
self.dummy.rect.left = self.ship.rect.left
self.dummy2.rect.left = self.ship.rect.left
#draw the level
all_sprites = pygame.sprite.Group()
all_sprites.add(self.player.sprites())
all_sprites.add(self.enemies.sprites())
all_sprites.add(self.minibosses.sprites())
all_sprites.add(self.powerups.sprites())
all_sprites.add(self.buddies.sprites())
all_sprites.add(self.fire.sprites())
all_sprites.add(self.enemylasers.sprites())
all_sprites.add(self.hud.sprites())
all_sprites.add(self.explosions.sprites())
all_sprites.update()
if len(self.minibosses.sprites()) == 0:
self.level.update()
self.background.update()
#Move and draw the background
self.screen.blit(self.background, (0, 0))
self.screen.blit(self.level, (-self.level.scrolled, 0))
if self.level_finished == True:
level_text = self.font.render("Level finished", 2, (255, 255, 255))
self.screen.blit(level_text, (280, 200))
elif self.game_finished == True:
gameover_text = self.font.render("Game Over", 2, (255, 255, 255))
self.screen.blit(gameover_text, (280, 200))
gameover_text = self.font.render("Press Esc", 2, (255, 255, 255))
self.screen.blit(gameover_text, (280, 230))
else:
all_sprites.draw(self.screen)
all_sprites.empty()
示例5: Director
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import update [as 别名]
class Director(object):
"""
This class controls the whole scene
"""
def __init__(self, dt=0.1, auto_dt=False):
"""
Class constructor
"""
self.background = Background()
# check width and height
ret, cap = self.background.capture.read()
height, width, channels = np.array(cap).shape
self.render = vtk.vtkRenderer()
self.render.SetLayer(2)
# self.camera = vtk.vtkCamera()
# self.camera.SetPosition(-10, 0, 0)
# self.camera.SetFocalPoint(0, 0, 0)
# self.render.SetActiveCamera(self.camera)
# self.render.ResetCamera()
self.render_window = vtk.vtkRenderWindow()
self.render_window.SetNumberOfLayers(3)
self.render_window.SetSize(width, height)
self.render_window.AddRenderer(self.background.render)
self.render_window.AddRenderer(self.render)
self.t = 0
self.dt = dt
self.auto_dt = auto_dt
self.actors = []
def add_actor(self, actor):
self.actors.append(actor)
self.render.AddActor(actor.actor)
def pause(self):
self.keep_playing = False
def play(self):
self.keep_playing = True
t0 = time()
self.run_events()
# update
self.update()
self.render_window.Render()
dt = time() - t0
if dt < self.dt:
sleep(self.dt - dt)
if self.keep_playing:
self.play()
def run_events(self):
pass
def stop(self):
self.keep_playing = False
self.render_window.Finalize()
def update(self):
self.background.update()
for actor in self.actors:
actor.update(dt=self.dt)
示例6: __init__
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import update [as 别名]
class level:
# Constructor
def __init__(self, joystickList, screenSize, initialPath):
self.screenSize = screenSize
self.joystickList = joystickList
self.font = pygame.font.SysFont("arial", 16)
self.pauseGame = False
self.gameOver = False
self.playerInDeadZone = False
self.totalElapsedTime = 0
self.background = Background(self.screenSize, initialPath)
x = self.background.levelMaker.startXPosition
y = self.background.levelMaker.startYPosition
if len(self.joystickList) == 2 and self.joystickList != None:
self.player1 = Player(self.joystickList[1], ProjectileMotion(), FreeFall(15), StoryBoard2(), x, y)
self.player2 = Player(self.joystickList[0], ProjectileMotion(), FreeFall(15), StoryBoard2(), x, y) #-----------------#
else:
self.player1 = Player(self.joystickList[0], ProjectileMotion(), FreeFall(15), StoryBoard2(), x, y)
self.player2 = Player(self.joystickList[0], ProjectileMotion(), FreeFall(15), StoryBoard2(), x, y) #-----------------#
self.player1.id = "p1"
self.player2.id = "p2"
self.player1.companero = self.player2
self.player2.companero = self.player1
# Flecha guia (para ubicar a otro player
self.compassImageUp = pygame.image.load("blocks//arrowUp.png").convert_alpha()
self.compassImageDown = pygame.image.load("blocks//arrowDown.png").convert_alpha()
self.compassImageRight = pygame.image.load("blocks//arrowRight.png").convert_alpha()
self.compassImageLeft = pygame.image.load("blocks//arrowLeft.png").convert_alpha()
self.compass = pygame.sprite.Sprite()
self.compass.image = self.compassImageUp
self.verticalCompassNeeded = False
self.horizontalCompassNeeded = False
self.P1horizontalCompassNeeded = False
# Update de todas las variables relevantes
def update(self, elapsedTime):
# Tiempo
self.totalElapsedTime += elapsedTime
"""
# Tiempo maximo para pasar etapa
if self.totalElapsedTime > 100:
self.gameOver = True
"""
# Brujula que apunta a player 2
if self.player2.Y <= -50 or self.player2.Y >= self.screenSize[1]:
self.horizontalCompassNeeded = True
elif self.player2.X <= -50 or self.player2.X >= self.screenSize[0]:
self.verticalCompassNeeded = True
else:
self.horizontalCompassNeeded = False
self.verticalCompassNeeded = False
# Brujula que apunta a player 1
if self.player1.Y <= -50 or self.player1.Y >= self.screenSize[1]:
self.P1horizontalCompassNeeded = True
else:
self.P1horizontalCompassNeeded = False
# Update a las instancias del nivel
#for sprite in self.background.group:
# if sprite.activada:
# if not((self.player1.color == sprite.color and pygame.sprite.collide_rect(sprite,self.player1.sprite))) and not((self.player2.color == sprite.color and pygame.sprite.collide_rect(sprite,self.player2.sprite))) :
# sprite.activada = False
# if not((self.player2.color == sprite.color and pygame.sprite.collide_rect(sprite,self.player2.sprite))):
# sprite.activada = False
#else:
# sprite.activada = False
#for sprite in self.background.group:
# if sprite.activada:
# if (pygame.sprite.collide_rect(sprite,self.player1.sprite)):
# if(self.player1.color == sprite.color):
# sprite.activada = True
# if (pygame.sprite.collide_rect(sprite,self.player2.sprite)):
# if(self.player2.color == sprite.color):
# sprite.activada = True
for sprite in self.background.group:
sprite.activada = False
self.player2.update(elapsedTime, self.background.group, self.background.exitGroup, self.background.damageGroup, self.background.groupList)#-----------------#
self.player1.update(elapsedTime, self.background.group, self.background.exitGroup, self.background.damageGroup, self.background.groupList)
self.backgroundXMovementManager(self.player1, self.player2)
self.backgroundYMovementManager(self.player1, self.player2)
for torreta in self.background.levelMaker.torretas:
torreta.update(elapsedTime,self.background.group,[self.player1.X,self.player1.Y],self.background.xAdvance, self.background.yAdvance, self.player1, self.screenSize)
self.background.update(elapsedTime, self.player1.X, self.player1.Y)
"""
# DISTANCIA PERSONAJES (TEMPORAL)
if abs(self.player1.X - self.player2.X) >= self.screenSize[0]:
self.player2.X = self.player1.X
#.........这里部分代码省略.........
示例7: Game
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import update [as 别名]
class Game():
def __init__(self):
"""
Initialize the game
"""
pygame.init()
self.screen = pygame.display.set_mode(consts.RESOLUTION)
pygame.event.set_allowed([pygame.QUIT, pygame.KEYDOWN, pygame.KEYUP])
# Blit background
self.background = Background((0, 0))
# TODO avoid acting on sprite and do actions on group?
self.player = player.Player({
'tilesGroup': 'new',
'x': 400,
'y': 300
})
self.background.setMainSprite(self.player)
self.init_joystick()
def init_joystick(self):
"""
Initialize a joystick if available
"""
pygame.joystick.init()
if pygame.joystick.get_count() == 0:
return
for joystick_id in range(0, pygame.joystick.get_count()):
joystick = pygame.joystick.Joystick(joystick_id)
# Stop on first matching joystick
if joystick.get_name() in consts.JOYSTICK:
print "Initializing Joystick id:%d" % joystick.get_id()
joystick.init()
self.joystick_mapping = consts.JOYSTICK[joystick.get_name()]
self.joystick = joystick
joystick_info = (joystick.get_name(), joystick.get_numaxes())
print "%s (%d axis)" % joystick_info
break
def run(self):
"""
Main loop
"""
running = True
# run until an event tells us to stop
while running:
pygame.time.Clock().tick(consts.FPS)
running = self.handleEvents()
self.background.update(self.screen.get_size())
camera = - self.background.xCamera, - self.background.yCamera
self.screen.blit(self.background.fond, (0, 0))
# update screen
rect = pygame.Rect(
0,
0,
consts.RESOLUTION[0],
consts.RESOLUTION[1]
)
pygame.display.update(rect)
def handleEvents(self):
"""
Poll for pygame events
"""
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
# handle user input
elif event.type == pygame.KEYDOWN:
# if the user presses escape or 'q', quit the event loop.
if event.key in (pygame.K_ESCAPE, pygame.K_q):
return False
# handle speed
if event.key in (pygame.K_LSHIFT, pygame.K_RSHIFT):
self.player.speed = 6
# movement control
if event.key == pygame.K_UP:
self.player.moveVertical(-1)
if event.key == pygame.K_DOWN:
self.player.moveVertical(1)
if event.key == pygame.K_LEFT:
self.player.moveHorizontal(-1)
if event.key == pygame.K_RIGHT:
self.player.moveHorizontal(1)
if event.key == pygame.K_c:
#~ create new sprite
s = player.Player({
'tilesGroup': 'scholar',
'x': 300,
'y': 300,
'movePattern': {
'type': 'rect',
'attributes': {
'width': 200,
'height': 200
}
}
})
self.background.addSprite(s, Background.LAYER_CHARACTERS)
#.........这里部分代码省略.........
示例8: GameWindow
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import update [as 别名]
class GameWindow(pyglet.window.Window):
def __init__(self, *args, **kwargs):
super(GameWindow, self).__init__(*args, **kwargs)
self.mainBatch = pyglet.graphics.Batch() #"Misc" drawables
self.hudBatch = pyglet.graphics.Batch() #Drawn after everything
self.background = Background()
self.playerShip = physicalobject.Player(x=0, y=0)
self.push_handlers(self.playerShip.keyHandler)
self.paused = False
self.camera = Vector(0,0)
#Basically targetting either 1920x1080 (and 1920x1200) at 1, or 1366x768 ish at 0.5
self.uiScale = 1
if self.width < 1400 or self.height < 800: self.uiScale = 0.5
self.hud = hud.HUD(window=self, batch=self.hudBatch)
self.currentSystem = solarsystem.SolarSystem(x=0, y=0, seed=0)
self.currentSystem.ships.append(self.playerShip)
components.init()
pyglet.clock.schedule_interval(self.update, 1/60.0)
def update(self, dt):
if not self.paused:
#self.playerShip.update(dt) #player now updated in ships list
self.background.update(dt)
self.currentSystem.update(dt)
self.hud.update(dt)
#print self.mainBatch
def on_draw(self):
pyglet.gl.glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
pyglet.gl.glLoadIdentity() #Set camera to middle
pyglet.gl.glTranslatef(-self.camera[0], -self.camera[1], 0.5) #Set camera position
self.background.draw()
self.currentSystem.batch.draw()
self.mainBatch.draw()
self.playerShip.draw()
pyglet.gl.glLoadIdentity()
self.hudBatch.draw()
def dispatch_event(self, event_type, *args):
"""This function is Pyglet's; I'm overriding a piece of it"""
if event_type=='on_draw':
#PYGLET HACK: We want it to iterate through the on_draws backwards, and self.on_draw contains the glClear()
self.on_draw()
for frame in reversed(self._event_stack):
handler = frame.get(event_type, None)
if handler:
try:
if handler(*args): return True
except TypeError:
self._raise_dispatch_exception(event_type, args, handler)
return True
else:
return super(GameWindow, self).dispatch_event(event_type, *args)
def enterSystem(self, target):
self.currentSystem.ships.remove(self.playerShip)
self.currentSystem = solarsystem.SolarSystem(x=0, y=0, seed=target)
self.currentSystem.ships.append(self.playerShip)
self.background.generate(seed=self.currentSystem.seed)
self.playerShip.position = self.playerShip.vel * -2.5
self.camera = self.playerShip.vel * -2.5
def leaveJumpspeed(dt):
self.playerShip.brake(dt, mul=1)
if self.playerShip.vel.length() < 75: pyglet.clock.unschedule(leaveJumpspeed)
pyglet.clock.schedule_interval(leaveJumpspeed, 0.1)
示例9: __init__
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import update [as 别名]
class level:
# Constructor
def __init__(self, joystickList, screenSize, initialPath, container):
self.screenSize = screenSize
self.joystickList = joystickList
self.container = container
self.font = pygame.font.SysFont("arial", 18)
self.font.set_bold(True)
self.pauseGame = False
self.gameOver = False
self.playerInDeadZone = False
self.totalElapsedTime = 0
self.deadMessage = ""
self.walk = self.container.soundDictionary["walk"]
self.walk.set_volume(0.1)
self.jump = self.container.soundDictionary["jump"]
self.jump.set_volume(0.1)
self.slide = self.container.soundDictionary["slide1"]
self.slide.set_volume(0.1)
self.background = Background(self.screenSize, initialPath, self.container)
self.backgroundImage = self.container.imageDictionary[self.background.levelMaker.actualBackgroundKey]
self.backgroundImage = pygame.transform.scale(self.backgroundImage, (self.screenSize[0], self.screenSize[1]))
# Relacionado al hub
self.lifeSprite = Items(self.background.itemAnimation2, pygame.Rect((0,0), (20,20)))
self.hub = pygame.image.load("blocks//hub.png").convert_alpha()
self.hub = pygame.transform.scale(self.hub, (670, 65))
x = self.background.levelMaker.startXPosition
y = self.background.levelMaker.startYPosition
if len(self.joystickList) == 2 and self.joystickList != None:
self.player1 = Player(self.joystickList[0], ProjectileMotion(), FreeFall(15), StoryBoard2(), self.container, x, y)
self.player2 = Player(self.joystickList[1], ProjectileMotion(), FreeFall(15), StoryBoard2(), self.container, x, y)
else:
self.player1 = Player(self.joystickList[0], ProjectileMotion(), FreeFall(15), StoryBoard2(), self.container, x, y)
self.player2 = Player(self.joystickList[0], ProjectileMotion(), FreeFall(15), StoryBoard2(), self.container, x, y)
self.player1.id = "p1"
self.player2.id = "p2"
self.player1.companero = self.player2
self.player2.companero = self.player1
# Flecha guia (para ubicar a otro player
self.compassImageUp = pygame.image.load("blocks//arrowUp.png").convert_alpha()
self.compassImageDown = pygame.image.load("blocks//arrowDown.png").convert_alpha()
self.compassImageRight = pygame.image.load("blocks//arrowRight.png").convert_alpha()
self.compassImageLeft = pygame.image.load("blocks//arrowLeft.png").convert_alpha()
self.compass = pygame.sprite.Sprite()
self.compass.image = self.compassImageUp
self.verticalCompassNeeded = False
self.horizontalCompassNeeded = False
self.P1horizontalCompassNeeded = False
self.buttonPressed = False##
self.joystickButtonActivated = True
self.allowButtonPressing = False
self.button2Pressed = False##
self.joystickButton2Activated = True
self.allowButton2Pressing = False
# Update de todas las variables relevantes
def update(self, elapsedTime):
# Tiempo
self.totalElapsedTime += elapsedTime
if self.totalElapsedTime > 200:
self.gameOver = True
self.deadMessage = "TIME'S UP!"
# Brujula que apunta a player 2
if self.player2.Y <= -50 or self.player2.Y >= self.screenSize[1]:
self.horizontalCompassNeeded = True
elif self.player2.X <= -50 or self.player2.X >= self.screenSize[0]:
self.verticalCompassNeeded = True
else:
self.horizontalCompassNeeded = False
self.verticalCompassNeeded = False
# Brujula que apunta a player 1
if self.player1.Y <= -50 or self.player1.Y >= self.screenSize[1]:
self.P1horizontalCompassNeeded = True
else:
self.P1horizontalCompassNeeded = False
# Update a las instancias del nivel
#for sprite in self.background.group:
# if sprite.activada:
# if not((self.player1.color == sprite.color and pygame.sprite.collide_rect(sprite,self.player1.sprite))) and not((self.player2.color == sprite.color and pygame.sprite.collide_rect(sprite,self.player2.sprite))) :
# sprite.activada = False
# if not((self.player2.color == sprite.color and pygame.sprite.collide_rect(sprite,self.player2.sprite))):
# sprite.activada = False
#else:
# sprite.activada = False
#.........这里部分代码省略.........
示例10: len
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import update [as 别名]
Background.init(screen)
while run:
clock.tick(60)
screen.fill((0, 0, 0))
if len(EnemiesList.enemies)<=0:
screen.blit(fontLarge.render("Venceu!", True, (255,255,255)), (gameConfigs["width"]/2 - 240, gameConfigs["height"]/2 - 100))
elif player.lifes<=0:
pygame.mixer.music.load("assets/audios/gunshot2.ogg")
pygame.mixer.music.play()
screen.blit(fontLarge.render("Perdeu!", True, (255,255,255)), (gameConfigs["width"]/2 - 240, gameConfigs["height"]/2 - 100))
else:
Background.update(screen)
player.update()
ProjectileList.update()
ProjectileEnemiesList.update()
EnemiesList.update()
lifesImage = pygame.image.load("assets/images/lifes.png")
lifesText = fontSmall.render(": "+str(player.lifes), True, (255,255,255))
# screen.blit(lifesText, (45,110))
tam = 40
for i in range(player.lifes):
screen.blit(lifesImage, (800, tam))
tam += 30