本文整理汇总了Python中Timer.Timer.time方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.time方法的具体用法?Python Timer.time怎么用?Python Timer.time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer.Timer
的用法示例。
在下文中一共展示了Timer.time方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameCounter
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import time [as 别名]
class GameCounter():
def __init__(self):
self.background = pygame.image.load('resources/background_pause.png').convert_alpha()
self.counter = 10000
self.state = True
self.timer = Timer()
self.font = pygame.font.Font('resources/ThrowMyHandsUpintheAirBold.ttf',300)
self.text_counter = Text(self.font,self.counter,(255,255,255),SCREEN_WIDTH/2,SCREEN_HEIGHT/2)
self.timer.start()
def update(self,screen):
while self.state:
self.counter -= self.timer.time() * 100
if self.counter < 0:
self.state = False
self.timer.stop()
scene.timer.start()
#make text in update, why is a object that renew
self.text_counter = Text(self.font,int(math.ceil(self.counter/4000)),(255,255,255),SCREEN_WIDTH/2,SCREEN_HEIGHT/2)
self._draw(screen)
def _draw(self,screen):
#Doesnt loss images of previous scene
screen.blit(scene.background,(0,0))
screen.blit(scene.title_shadow,(0,0))
scene.level_title.draw(screen)
screen.blit(self.background,(0,0))
self.text_counter.draw(screen)
pygame.display.flip()
示例2: Game
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import time [as 别名]
class Game():
def __init__(self, level, continent, difficult):
self.level = level
self.continent = continent
self.difficult = difficult
self.current_rating_level = int(levels_rating[self.continent+self.difficult][str(self.level)])
#Colors
self.black = (0,0,0)
self.white = (255,255,255)
self.background = pygame.image.load('resources/levels/'+self.continent+'/bglevel'+str(self.level)+'.jpg').convert()
self.name = Configuration.level_name_json(languageID, self.continent, self.level)
self.font = pygame.font.Font('resources/ThrowMyHandsUpintheAirBold.ttf',35)
self.level_title = Text(self.font,self.name,self.black,SCREEN_WIDTH/3+40,30)
#Timer
self.timer = Timer()
self.tweener = pytweener.Tweener()
self.star = Star(self.difficult)
self.button_returnmenu = Button('resources/button_returnmenu.png',830,30)
self.button_playreboot = Button('resources/button_playreboot.png',900,30)
self.button_pause = Button('resources/button_pause.png',970,30)
self.sprites = pygame.sprite.Group()
self.sprites.add(self.button_returnmenu)
self.sprites.add(self.button_playreboot)
self.sprites.add(self.button_pause)
self.title_shadow = pygame.image.load('resources/sombra_titulo_'+self.difficult+'.png').convert_alpha()
#Pause instance
self.pause = Pause()
#Game_Counter instance
self.game_counter = GameCounter()
self.clock = pygame.time.Clock()
def update(self):
for event in pygame.event.get():
if event.type == QUIT:
exit()
elif event.type == MOUSEBUTTONDOWN:
if self.button_returnmenu.rect.collidepoint(event.pos[0],event.pos[1]):
levelsselector_start(self.continent,self.difficult)
if self.button_pause.rect.collidepoint(event.pos[0],event.pos[1]):
self.timer.stop()
self.pause.status = True
if self.button_playreboot.rect.collidepoint(event.pos[0],event.pos[1]):
game_start(self.level,self.continent,self.difficult)
if (self.star.rect.collidepoint(event.pos[0],event.pos[1])
and not self.star.move):
if android:
android.vibrate(1)
self.star.change_state()
self.tweener.addTween(self.star,x=1024,tweenTime=1, tweenType=pytweener.Easing.Elastic.easeIn)
if self.timer.time()<=4:
#Write rating of level and total rating of continent
levels_rating[self.continent+self.difficult][str(self.level)] = "3"
Configuration.override_rating_json(levels_rating)
self.level_goal = LevelGoal(3)
elif self.timer.time()>4 and self.timer.time()<= 6:
if not self.current_rating_level == 3:
levels_rating[self.continent+self.difficult][str(self.level)] = "2"
Configuration.override_rating_json(levels_rating)
self.level_goal = LevelGoal(2)
elif self.timer.time()> 6:
if (not self.current_rating_level == 2 or
not self.current_rating_level == 3):
levels_rating[self.continent+self.difficult][str(self.level)] = "1"
Configuration.override_rating_json(levels_rating)
self.level_goal = LevelGoal(1)
self.timer.stop()
#print self.timer.time()
self.timer.time()
self.dt = self.clock.tick(60)
self.tweener.update(self.dt/1000.0)
def draw(self,screen):
screen.blit(self.background,(0,0))
screen.blit(self.title_shadow,(0,0))
self.level_title.draw(screen)
self.sprites.draw(screen)
screen.blit(self.star.image,(self.star.x,self.star.y))
pygame.display.flip()
#Instance pause with funcion update. Parameters: screen. __draw()
self.pause.update(screen)
#Instance GameCounter with funcion update. Parameters: screen. __draw()
self.game_counter.update(screen)
#Instance LevelGoal with funcion update. Parameters: screen. __draw()
if self.star.x > 1000:
#.........这里部分代码省略.........
示例3: Juego
# 需要导入模块: from Timer import Timer [as 别名]
# 或者: from Timer.Timer import time [as 别名]
class Juego():
def __init__(self):
self.fondo1 = Fondo(0)
self.fondo2 = Fondo(800)
self.fondo_pelicula = pygame.image.load("datos/fondopelicula.png")
self.alerta = pygame.image.load("datos/alerta.png")
#Grupos
self.sprites = pygame.sprite.Group()
self.misiles = pygame.sprite.Group()
self.disparos = pygame.sprite.Group()
self.disparos_jefe = pygame.sprite.Group()
self.enemigos = pygame.sprite.Group()
self.disparos_extra = pygame.sprite.Group()
self.misiles_extra = pygame.sprite.Group()
self.armaextra_extra = pygame.sprite.Group()
self.superpoder = pygame.sprite.GroupSingle()
self.nuevo_jefe_grupo = pygame.sprite.GroupSingle()
self.nave = NaveChus(self.sprites,self.disparos,self.misiles,self.superpoder)
self.sprites.add(self.nave)
#Contadores creación de objetos
self.contador_disparos_extra = 0
self.contador_misiles_extra = 0
self.contador_armaextra_extra = 0
self.contador_enemigosrojos = 0
self.contador_enemigosazules = 0
self.vidas = 1
self.puntos = 0
self.fuente = pygame.font.Font(None,40)
self.escudo_surface = self.fuente.render("Escudo ",1,(255,255,255))
pygame.mixer.music.load("datos/musica/nivel1.wav")
pygame.mixer.music.play(-1)
self.nuevo_jefe = None
#Creacion de temporizador
self.temporizador = Timer()
self.temporizador.start()
def update(self):
self.fondo1.update()
self.fondo2.update()
for evento in pygame.event.get():
if evento.type == QUIT or evento.type == KEYDOWN and evento.key == K_ESCAPE:
exit()
if self.temporizador.time() > 4:
#Creación de disparos extra
self.contador_disparos_extra += 2
if self.contador_disparos_extra >= 300:
self.nuevo_disparoextra =ExtraDisparo()
self.sprites.add(self.nuevo_disparoextra)
self.disparos_extra.add(self.nuevo_disparoextra)
self.contador_disparos_extra = 0
#Creación de misiles extra
self.contador_misiles_extra += 1
if self.contador_misiles_extra >= 350:
self.nuevo_misilextra = ExtraMisil()
self.sprites.add(self.nuevo_misilextra)
self.misiles_extra.add(self.nuevo_misilextra)
self.contador_misiles_extra = 0
#Creación de armas extras
self.contador_armaextra_extra +=2
if self.contador_armaextra_extra >= 320:
self.nuevo_armaextra = ExtraArmaExtra()
self.sprites.add(self.nuevo_armaextra)
self.armaextra_extra.add(self.nuevo_armaextra)
self.contador_armaextra_extra = 0
if self.temporizador.time() < 60:
#Creación de enemigos rojos
self.contador_enemigosrojos +=4
if self.contador_enemigosrojos >= 80:
self.nuevo_enemigorojo = EnemigoRojo(random.randint(500,1000),random.randint(-150,-20),"diagonal_superior_derecha")
self.sprites.add(self.nuevo_enemigorojo)
self.enemigos.add(self.nuevo_enemigorojo)
self.contador_enemigosrojos = 0
#Creación de enemigos azules
self.contador_enemigosazules +=4
if self.contador_enemigosazules >= 80:
self.nuevo_enemigoazul = EnemigoAzul(random.randint(500,1000),random.randint(850,870),"diagonal_inferior_derecha")
self.sprites.add(self.nuevo_enemigoazul)
self.enemigos.add(self.nuevo_enemigoazul)
self.contador_enemigosazules = 0
if self.temporizador.time() > 60 and self.temporizador.time() < 180:
#Creación de enemigos rojos
self.contador_enemigosrojos +=3
if self.contador_enemigosrojos >= 80:
#.........这里部分代码省略.........