def create_all(track_name=None): # prepare_running_on_gimp() set_std_output() try: if track_name is not None: print("Creating track: " + track_name) tracks.Track().set_current_track(track_name) if track_name == "all": print("Updating all tracks: " + track_name) for track in tracks.Track().get_map(): tracks.Track().set_current_track(track) process_track() else: print("creating track: " + tracks.Track().get_title()) process_track() except Exception as ex: print("Got an exception: " + ex.message) traceback.print_exc(file=sys.stdout)
def process_track(): try: print("Processing Track:" + tracks.Track().get_title()) cfg.Config().update() start = time.time() actions = cfg.Config().config["actions"] if "process_image" in actions: process_basic_image() if "text_images" in actions: text_images() if "site_images" in actions: site_images() if "hue_images" in actions: hue_images() if "copy_directories" in actions: copy_directories() end = time.time() print "Finished, time: %.2f seconds" % (end - start) except Exception as ex: print("Got an exception: " + ex.message) traceback.print_exc(file=sys.stdout)
map_s.update(cam.x, cam.y) map_s.draw(screen) ## ##determine the center of the car moving circle in the coordinate of the sprite layer,connection between surface canvas and sprite layer car.rpl = (rpl[0] - CENTER[0] + car.x, rpl[1] - CENTER[1] + car.y) car.rpr = (rpr[0] - CENTER[0] + car.x, rpr[1] - CENTER[1] + car.y) ##determine the center of the car moving circle in the coordinate of the sprite layer,connection between surface canvas and sprite layer ## player_s.update(cam.x, cam.y) player_s.draw(screen) ## ## tracks_s.add(tracks.Track(cam.x + CENTER[0], cam.y + CENTER[1], car.dir)) tracks_s.update(cam.x, cam.y) tracks_s.draw(screen) ## ## canvas.fill((255, 255, 255, 0)) ## ##draw lines to find center of the car pygame.draw.line(canvas, (0, 100, 0), (100, CENTER[1]), (CENTER[0], CENTER[1]), 2) pygame.draw.line(canvas, (0, 100, 0), (CENTER[0], 100), (CENTER[0], CENTER[1]), 2) ##draw lines to find center of the car
def get_root_dir(): return tracks.Track().get_root_dir()
def main(): # initialize objects. clock = pygame.time.Clock() running = True font = pygame.font.Font(None, 24) car = player.Player() cam = camera.Camera() target = gamemode.Finish() bound_alert = boundary.Alert() time_alert = timeout.Alert() info = menu.Alert() pointer = direction.Tracker(int(CENTER_W * 2), int(CENTER_H * 2)) # create sprite groups. map_s = pygame.sprite.Group() player_s = pygame.sprite.Group() traffic_s = pygame.sprite.Group() tracks_s = pygame.sprite.Group() target_s = pygame.sprite.Group() pointer_s = pygame.sprite.Group() timer_alert_s = pygame.sprite.Group() bound_alert_s = pygame.sprite.Group() menu_alert_s = pygame.sprite.Group() # generate tiles for tile_num in range(0, len(maps.map_tile)): maps.map_files.append(load_image(maps.map_tile[tile_num], False)) for x in range(0, 10): for y in range(0, 10): map_s.add(maps.Map(maps.map_1[x][y], x * 1000, y * 1000, maps.map_1_rot[x][y])) # load tracks tracks.initialize() # load finish target_s.add(target) # load direction pointer_s.add(pointer) # load alerts timer_alert_s.add(time_alert) bound_alert_s.add(bound_alert) menu_alert_s.add(info) # load traffic traffic.initialize(CENTER_W, CENTER_H) for count in range(0, TRAFFIC_COUNT): traffic_s.add(traffic.Traffic()) player_s.add(car) cam.set_pos(car.x, car.y) while running: # Check for key input. (KEYDOWN, trigger often) keys = pygame.key.get_pressed() # Render loop. # Check for menu/reset, (keyup event - trigger ONCE) for event in pygame.event.get(): if event.type == pygame.KEYUP: if keys[K_m]: if (info.visibility == True): info.visibility = False if (keys[K_p]): car.reset() target.reset() if (keys[K_q]): pygame.quit() sys.exit(0) if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: running = False break if (target.timeleft > 0): if keys[K_c]: car.steerleft() if keys[K_b]: car.steerright() if keys[K_UP]: car.accelerate() else: car.soften() if keys[K_DOWN]: car.deaccelerate() if keys[K_RIGHT]: car.breakk() cam.set_pos(car.x, car.y) # Show text data. text_fps = font.render('FPS: ' + str(int(clock.get_fps())), 1, (224, 16, 16)) textpos_fps = text_fps.get_rect(centery=25, centerx=60) text_score = font.render('Score: ' + str(target.score), 1, (224, 16, 16)) textpos_score = text_fps.get_rect(centery=45, centerx=60) text_timer = font.render( 'Timer: ' + str(int((target.timeleft /1000) / 1000)) + ":" + str(int((target.timeleft / 1500) % 300)), 6, (224, 16, 16)) textpos_timer = text_fps.get_rect(centery=65, centerx=60) # Render Scene. screen.blit(background, (0, 0)) # cam.set_pos(car.x, car.y) map_s.update(cam.x, cam.y) map_s.draw(screen) # Conditional renders/effects car.grass(screen.get_at(((int(CENTER_W - 5), int(CENTER_H - 5)))).g) if (car.tracks): tracks_s.add(tracks.Track(cam.x + CENTER_W, cam.y + CENTER_H, car.dir)) # Just render.. tracks_s.update(cam.x, cam.y) tracks_s.draw(screen) player_s.update(cam.x, cam.y) player_s.draw(screen) traffic_s.update(cam.x, cam.y) traffic_s.draw(screen) target_s.update(cam.x, cam.y) target_s.draw(screen) pointer_s.update(car.x + CENTER_W, car.y + CENTER_H, target.x, target.y) pointer_s.draw(screen) # Conditional renders. if (boundary.breaking(car.x + CENTER_W, car.y + CENTER_H) == True): bound_alert_s.update() bound_alert_s.draw(screen) if (target.timeleft == 0): timer_alert_s.draw(screen) car.speed = 0 text_score = font.render('Final Score: ' + str(target.score), 1, (224, 16, 16)) textpos_score = text_fps.get_rect(centery=CENTER_H + 56, centerx=CENTER_W - 20) if (info.visibility == True): menu_alert_s.draw(screen) # Blit Blit.. screen.blit(text_fps, textpos_fps) screen.blit(text_score, textpos_score) screen.blit(text_timer, textpos_timer) pygame.display.flip() # Check collision!!! if pygame.sprite.spritecollide(car, traffic_s, False): car.impact() target.car_crash() if pygame.sprite.spritecollide(car, target_s, True): target.claim_flag() target.generate_finish() target_s.add(target) clock.tick(64)
def main(id='001'): agentePontosGanho = AI_INSTANCES.Agente_Interativo( AI_CONFIG._L3_PARAMETRO_pontos, 'gte', gameControl.setVeiculosHardmode) agenteTempoGasto = AI_INSTANCES.Agente_Interativo( AI_CONFIG._L3_PARAMETRO_tempogasto, 'gte', gameControl.setExtraTimeHardmode) agenteChamadasAtendidas = AI_INSTANCES.Agente_Interativo( AI_CONFIG._L3_PARAMETRO_chamadas_atentidas, 'gte', gameControl.setPontosHardmode) agenteParadas = AI_INSTANCES.Agente_Interativo( AI_CONFIG._L3_PARAMETRO_paradas, 'gte', gameControl.setPontosHardmode) agenteEscrita = AI_INSTANCES.Agente_de_Escrita('./logs/' + id + '.txt', id, 3) agenteEscrita.escreveLog(['NOVOJOGO', str(0)]) totalChamadasAtendidas = 0 totalParadas = 0 running = True # generate tiles for tile_num in range(0, len(maps.map_tile)): maps.map_files.append(load_image(maps.map_tile[tile_num], False)) for x in range(0, 10): for y in range(0, 10): map_s.add( maps.Map(maps.map_1[x][y], x * 1000, y * 1000, maps.map_1_rot[x][y])) # load tracks tracks.initialize() # load finish target_s.add(target) # load direction pointer_s.add(pointer) # load alerts timer_alert_s.add(time_alert) bound_alert_s.add(bound_alert) celular_s.add(celular_alert) stop_s.add(stop_alert) menu_alert_s.add(info) # load traffic traffic.initialize(CENTER_W, CENTER_H) for count in range(0, gameControl.quantidadeVeiculos): traffic_s.add(traffic.Traffic()) player_s.add(car) cam.set_pos(car.x, car.y) end = False while running: # Render loop. # Check for menu/reset, (keyup event - trigger ONCE) keys = pygame.key.get_pressed() for event in pygame.event.get(): if event.type == pygame.KEYUP: if keys[K_m]: if (info.visibility == True): info.visibility = False else: info.visibility = True if (keys[K_p]): end = False car.reset() target.reset() if (keys[K_q]): agenteEscrita.escreveLog(['SAIU', '-']) pygame.quit() sys.exit(0) if (keys[K_z]): # atende ligacao celular_alert.atender = True if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: from source.menu import Menu as menu2 aux = menu2() aux.main_menu() running = False agenteEscrita.escreveLog(['SAIU', '-']) break # Check for key input. (KEYDOWN, trigger often) if (target.timeleft > 0): if keys[K_LEFT]: car.steerleft() if keys[K_RIGHT]: car.steerright() if keys[K_UP]: car.accelerate() else: car.soften() if keys[K_DOWN]: car.deaccelerate() cam.set_pos(car.x, car.y) # Show text data. text_fps = font.render('', 1, (224, 16, 16)) textpos_fps = text_fps.get_rect(centery=25, centerx=60) text_score = font.render('Pontuacao: ' + str(target.score), 1, (224, 16, 16)) textpos_score = text_fps.get_rect(centery=45, centerx=60) text_timer = font.render( 'Tempo: ' + str(int((target.timeleft / 60) / 60)) + ":" + str(int((target.timeleft / 60) % 60)), 1, (224, 16, 16)) textpos_timer = text_fps.get_rect(centery=65, centerx=60) # Render Scene. screen.blit(background, (0, 0)) # cam.set_pos(car.x, car.y) map_s.update(cam.x, cam.y) map_s.draw(screen) # Conditional renders/effects car.grass(screen.get_at(((int(CENTER_W - 5), int(CENTER_H - 5)))).g) tracks_s = [] if car.tracks: tracks_s.add( tracks.Track(cam.x + CENTER_W, cam.y + CENTER_H, car.dir)) # Just render.. tracks_s.update(cam.x, cam.y) tracks_s.draw(screen) player_s.update(cam.x, cam.y) player_s.draw(screen) traffic_s.update(cam.x, cam.y) traffic_s.draw(screen) target_s.update(cam.x, cam.y) target_s.draw(screen) pointer_s.update(car.x + CENTER_W, car.y + CENTER_H, target.x, target.y) pointer_s.draw(screen) # stop_alert.updateTimer(time.time()) # Conditional renders. if (bounds.breaking(car.x + CENTER_W, car.y + CENTER_H) == True): bound_alert_s.update() bound_alert_s.draw(screen) if (target.timeleft == 0): timer_alert_s.draw(screen) car.speed = 0 text_score = font.render('Pontuacao Final: ' + str(target.score), 1, (224, 16, 16)) textpos_score = text_fps.get_rect(centery=CENTER_H, centerx=CENTER_W - 100) if end is False: end = True gameControl.extraTimeValue = AI_CONFIG._L3_tempo_extra_facil gameControl.quantidadeVeiculos = AI_CONFIG._L3_quantidade_veiculos_facil gameControl.pontosChamadaAtendida = AI_CONFIG._L3_ponto_atender_facil gameControl.pontosPararCarro = AI_CONFIG._L3_ponto_parar_facil agenteEscrita.escreveLog(['TERMINOU', str(target.score)]) celular_alert.grass( screen.get_at(((int(CENTER_W - 5), int(CENTER_H - 5)))).g, car.speed) if (target.totalTime > 300 and int( (target.totalTime / 60) % 60) % 20 == 0): celular_alert.visibility = True celular_alert.startTimer() if (celular_alert.tocando): celular_alert.chron.run() if (target.timeleft > 0 and celular_alert.visibility is True and celular_alert.tocando is True): celular_s.draw(screen) keys = pygame.key.get_pressed() if (keys[K_c] and car.speed > 0.4): celular_alert.visibility = False celular_alert.tocando = False target.score -= 70 agenteEscrita.escreveLog(['ATENDEUERRADO', -70]) if (celular_alert.visibility is True and celular_alert.tocando is True and keys[K_c] and car.speed <= 0.4): celular_alert.visibility = False celular_alert.tocando = False target.score += gameControl.pontosChamadaAtendida agenteEscrita.escreveLog(['ATENDEU', 200]) agenteChamadasAtendidas.analizaEntrada(totalChamadasAtendidas) if (not celular_alert.cel_time()): celular_alert.visibility = False celular_alert.tocando = False target.score -= 100 agenteEscrita.escreveLog(['NAOATENDEU', -100]) stop_alert.stop_car(car.speed) if (target.totalTime != 0 and int( (target.totalTime / 60) % 60) % 15 == 0 and car.speed >= 0.1): stop_alert.visibility = True if (target.timeleft > 0 and stop_alert.visibility is True): stop_s.draw(screen) if (car.speed < 0.1): target.score += 200 stop_alert.visibility = False agenteEscrita.escreveLog(['PAROU', 200]) agenteParadas.analizaEntrada(totalParadas) else: target.score -= 1 if (info.visibility == True): menu_alert_s.draw(screen) # Blit Blit.. pygame.draw.rect(screen, (216, 216, 216), [40, 30, 200, 55]) screen.blit(text_fps, textpos_fps) screen.blit(text_score, textpos_score) screen.blit(text_timer, textpos_timer) pygame.display.flip() # Check collision!!! if pygame.sprite.spritecollide(car, traffic_s, False): car.impact() target.car_crash() target.score -= 5 agenteEscrita.escreveLog(['BATIDA', '-5']) if pygame.sprite.spritecollide(car, target_s, True): target.claim_flag(gameControl.extraTimeValue) target.score += 50 target.generate_finish() target_s.add(target) agenteEscrita.escreveLog( ['TEMPOEXTRA', gameControl.extraTimeValue]) agentePontosGanho.analizaEntrada(target.score) agenteTempoGasto.analizaEntrada(target.totalTime) clock.tick(64) # cria semaforo # Enter the mainloop. # main() # pygame.quit() # sys.exit(0)
def run(self): # generate tiles for tile_num in range(0, len(maps.map_tile)): maps.map_files.append(load_image(maps.map_tile[tile_num], False)) for x in range(0, 10): for y in range(0, 10): self.map_s.add( maps.Map(maps.map_1[x][y], x * 1000, y * 1000, maps.map_1_rot[x][y])) # load tracks tracks.initialize() # load finish self.target_s.add(self.target) # load direction self.pointer_s.add(self.pointer) # load alerts self.timer_alert_s.add(self.time_alert) self.bound_alert_s.add(self.bound_alert) self.celular_s.add(self.celular_alert) self.stop_s.add(self.stop_alert) self.menu_alert_s.add(self.info) # load traffic traffic.initialize(CENTER_W, CENTER_H) for count in range(0, self.quantidadeVeiculos): self.traffic_s.add(traffic.Traffic()) self.player_s.add(self.car) self.cam.set_pos(self.car.x, self.car.y) while self.running: # Render loop. # Check for menu/reset, (keyup event - trigger ONCE) for event in pygame.event.get(): if event.type == pygame.KEYUP: if keys[K_m]: if (self.info.visibility == True): self.info.visibility = False else: self.info.visibility = True if (keys[K_p]): self.car.reset() self.target.reset() if (keys[K_q]): pygame.quit() sys.exit(0) if (keys[K_z]): # atende ligacao self.celular_alert.atender = True if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: from source.menu import Menu as menu2 aux = menu2() aux.main_menu() running = False break # Check for key input. (KEYDOWN, trigger often) keys = pygame.key.get_pressed() if (self.target.timeleft > 0): if keys[K_LEFT]: self.car.steerleft() if keys[K_RIGHT]: self.car.steerright() if keys[K_UP]: self.car.accelerate() else: self.car.soften() if keys[K_DOWN]: self.car.deaccelerate() self.cam.set_pos(self.car.x, self.car.y) # Show text data. text_fps = self.font.render('', 1, (224, 16, 16)) textpos_fps = text_fps.get_rect(centery=25, centerx=60) text_score = self.font.render( 'Pontuacao: ' + str(self.target.score), 1, (224, 16, 16)) textpos_score = text_fps.get_rect(centery=45, centerx=60) text_timer = self.font.render( 'Tempo: ' + str(int((self.target.timeleft / 60) / 60)) + ":" + str(int((self.target.timeleft / 60) % 60)), 1, (224, 16, 16)) textpos_timer = text_fps.get_rect(centery=65, centerx=60) # Render Scene. self.screen.blit(self.background, (0, 0)) # cam.set_pos(car.x, car.y) self.map_s.update(self.cam.x, self.cam.y) self.map_s.draw(self.screen) # Conditional renders/effects self.car.grass( self.screen.get_at( ((int(self.CENTER_W - 5), int(self.CENTER_H - 5)))).g) if self.car.tracks: self.tracks_s.add( tracks.Track(self.cam.x + self.CENTER_W, self.cam.y + self.CENTER_H, self.car.dir)) # Just render.. self.tracks_s.update(self.cam.x, self.cam.y) self.tracks_s.draw(self.screen) self.player_s.update(self.cam.x, self.cam.y) self.player_s.draw(self.screen) self.traffic_s.update(self.cam.x, self.cam.y) self.traffic_s.draw(self.screen) self.target_s.update(self.cam.x, self.cam.y) self.target_s.draw(self.screen) self.pointer_s.update(self.car.x + self.CENTER_W, self.car.y + self.CENTER_H, self.target.x, self.target.y) self.pointer_s.draw(self.screen) # stop_alert.updateTimer(time.time()) # Conditional renders. if (bounds.breaking(self.car.x + self.CENTER_W, self.car.y + self.CENTER_H) == True): self.bound_alert_s.update() self.bound_alert_s.draw(self.screen) if (self.target.timeleft == 0): self.timer_alert_s.draw(self.screen) self.car.speed = 0 text_score = self.font.render( 'Pontuacao Final: ' + str(self.target.score), 1, (224, 16, 16)) textpos_score = text_fps.get_rect(centery=self.CENTER_H + 56, centerx=self.CENTER_W - 20) self.celular_alert.grass( self.screen.get_at( ((int(self.CENTER_W - 5), int(self.CENTER_H - 5)))).g, self.car.speed) if (int((self.target.timeleft / 60) % 60) % 20 == 0): self.celular_alert.visibility = True self.celular_alert.startTimer() if (self.celular_alert.tocando): self.celular_alert.chron.run() if (self.target.timeleft > 0 and self.celular_alert.visibility is True): self.celular_s.draw(self.screen) keys = pygame.key.get_pressed() if (keys[K_c] and self.car.speed > 0.4): self.target.score -= 50 self.celular_alert.tocando = False self.celular_alert.visibility = False if (keys[K_c] and self.car.speed <= 0.4): self.target.score += 200 self.celular_alert.tocando = False self.celular_alert.visibility = False if (not self.celular_alert.cel_time()): self.target.score -= 100 self.celular_alert.tocando = False self.celular_alert.visibility = False self.stop_alert.stop_car(self.car.speed) if (int((self.target.timeleft / 60) % 60) % 15 == 0 and self.car.speed >= 0.1): self.stop_alert.visibility = True if (self.target.timeleft > 0 and self.stop_alert.visibility is True): self.stop_s.draw(self.screen) if (self.car.speed < 0.1): self.target.score += 200 self.stop_alert.visibility = False else: self.target.score -= 1 if (self.info.visibility == True): self.menu_alert_s.draw(self.screen) # Blit Blit.. pygame.draw.rect(self.screen, (216, 216, 216), [40, 30, 200, 55]) self.screen.blit(text_fps, textpos_fps) self.screen.blit(text_score, textpos_score) self.screen.blit(text_timer, textpos_timer) pygame.display.flip() # Check collision!!! if pygame.sprite.spritecollide(self.car, self.traffic_s, False): self.car.impact() self.target.car_crash() self.target.score -= 5 if pygame.sprite.spritecollide(self.car, self.target_s, True): self.target.claim_flag() self.target.score += 50 self.target.generate_finish() self.target_s.add(self.target) self.clock.tick(64) # cria semaforo # initialization pygame.init() print pygame.display.Info().current_w print pygame.display.Info().current_h ''' screen = pygame.display.set_mode((pygame.display.Info().current_w, pygame.display.Info().current_h), pygame.FULLSCREEN) ''' self.screen = pygame.display.set_mode((1024, 768), pygame.FULLSCREEN) pygame.display.set_caption('Race of Math.') pygame.mouse.set_visible(True) self.font = pygame.font.Font(None, 24) # CENTER_W = int(1024 / 2) # CENTER_H = int(768 / 2) ''' CENTER_W = int(pygame.display.Info().current_w /2) CENTER_H = int(pygame.display.Info().current_h /2) ''' # new background surface self.background = pygame.Surface(self.screen.get_size()) self.background = self.background.convert_alpha() self.background.fill((26, 26, 26))
def main(): #initialize objects. clock = pygame.time.Clock() running = True font = pygame.font.Font(None, 32) car = player.Player() cam = camera.Camera() target = gamemode.Finish() bound_alert = bounds.Alert() time_alert = timeout.Alert() celular_alert = leis_transito.CelularAlert() stop_alert = leis_transito.StopAlert() info = menu.Alert() pointer = direction.Tracker(int(CENTER_W * 2), int(CENTER_H * 2)) #create sprite groups. map_s = pygame.sprite.Group() player_s = pygame.sprite.Group() celular_s = pygame.sprite.Group() stop_s = pygame.sprite.Group() traffic_s = pygame.sprite.Group() tracks_s = pygame.sprite.Group() target_s = pygame.sprite.Group() pointer_s = pygame.sprite.Group() timer_alert_s = pygame.sprite.Group() bound_alert_s = pygame.sprite.Group() menu_alert_s = pygame.sprite.Group() #generate tiles for tile_num in range(0, len(maps.map_tile)): maps.map_files.append(load_image(maps.map_tile[tile_num], False)) for x in range(0, 10): for y in range(0, 10): map_s.add( maps.Map(maps.map_1[x][y], x * 1000, y * 1000, maps.map_1_rot[x][y])) #load tracks tracks.initialize() #load finish target_s.add(target) #load direction pointer_s.add(pointer) #load alerts timer_alert_s.add(time_alert) bound_alert_s.add(bound_alert) celular_s.add(celular_alert) stop_s.add(stop_alert) menu_alert_s.add(info) #load traffic traffic.initialize(CENTER_W, CENTER_H) for count in range(0, TRAFFIC_COUNT): traffic_s.add(traffic.Traffic()) player_s.add(car) cam.set_pos(car.x, car.y) while running: #Render loop. #Check for menu/reset, (keyup event - trigger ONCE) for event in pygame.event.get(): if event.type == pygame.KEYUP: if keys[K_m]: if (info.visibility == True): info.visibility = False else: info.visibility = True if (keys[K_p]): car.reset() target.reset() if (keys[K_q]): pygame.quit() sys.exit(0) if (keys[K_z]): # atende ligacao celular_alert.atender = True if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: from source.menu import Menu as menu2 aux = menu2() aux.main_menu() running = False break #Check for key input. (KEYDOWN, trigger often) keys = pygame.key.get_pressed() if (target.timeleft > 0): if keys[K_LEFT]: car.steerleft() if keys[K_RIGHT]: car.steerright() if keys[K_UP]: car.accelerate() else: car.soften() if keys[K_DOWN]: car.deaccelerate() cam.set_pos(car.x, car.y) #Show text data. text_fps = font.render('', 1, (224, 16, 16)) textpos_fps = text_fps.get_rect(centery=25, centerx=60) text_score = font.render('Pontuacao: ' + str(target.score), 1, (224, 16, 16)) textpos_score = text_fps.get_rect(centery=45, centerx=60) text_timer = font.render( 'Tempo: ' + str(int((target.timeleft / 60) / 60)) + ":" + str(int((target.timeleft / 60) % 60)), 1, (224, 16, 16)) textpos_timer = text_fps.get_rect(centery=65, centerx=60) #Render Scene. screen.blit(background, (0, 0)) #cam.set_pos(car.x, car.y) map_s.update(cam.x, cam.y) map_s.draw(screen) #Conditional renders/effects car.grass(screen.get_at(((int(CENTER_W - 5), int(CENTER_H - 5)))).g) if car.tracks: tracks_s.add( tracks.Track(cam.x + CENTER_W, cam.y + CENTER_H, car.dir)) #Just render.. tracks_s.update(cam.x, cam.y) tracks_s.draw(screen) player_s.update(cam.x, cam.y) player_s.draw(screen) traffic_s.update(cam.x, cam.y) traffic_s.draw(screen) target_s.update(cam.x, cam.y) target_s.draw(screen) pointer_s.update(car.x + CENTER_W, car.y + CENTER_H, target.x, target.y) pointer_s.draw(screen) # stop_alert.updateTimer(time.time()) #Conditional renders. if (bounds.breaking(car.x + CENTER_W, car.y + CENTER_H) == True): bound_alert_s.update() bound_alert_s.draw(screen) if (target.timeleft == 0): timer_alert_s.draw(screen) car.speed = 0 text_score = font.render('Pontuacao Final: ' + str(target.score), 1, (224, 16, 16)) textpos_score = text_fps.get_rect(centery=CENTER_H + 56, centerx=CENTER_W - 20) celular_alert.grass( screen.get_at(((int(CENTER_W - 5), int(CENTER_H - 5)))).g, car.speed) if (int((target.timeleft / 60) % 60) % 20 == 0): celular_alert.visibility = True if (target.timeleft > 0 and celular_alert.visibility is True): celular_s.draw(screen) keys = pygame.key.get_pressed() celular_alert.startTimer() if (keys[K_c] and car.speed > 0.4): target.score -= 15 celular_alert.visibility = False if (keys[K_c] and car.speed <= 0.4): target.score += 200 celular_alert.visibility = False if (not celular_alert.cel_time()): target.score -= 100 celular_alert.visibility = False stop_alert.stop_car(car.speed) if (int((target.timeleft / 60) % 60) % 15 == 0 and car.speed >= 0.1): stop_alert.visibility = True if (target.timeleft > 0 and stop_alert.visibility is True): stop_s.draw(screen) if (car.speed < 0.1): target.score += 200 stop_alert.visibility = False else: target.score -= 1 if (info.visibility == True): menu_alert_s.draw(screen) #Blit Blit.. pygame.draw.rect(screen, (216, 216, 216), [40, 30, 200, 55]) screen.blit(text_fps, textpos_fps) screen.blit(text_score, textpos_score) screen.blit(text_timer, textpos_timer) pygame.display.flip() #Check collision!!! if pygame.sprite.spritecollide(car, traffic_s, False): car.impact() target.car_crash() target.score -= 5 if pygame.sprite.spritecollide(car, target_s, True): target.claim_flag() target.score += 150 target.generate_finish() target_s.add(target) clock.tick(64)
def update(self): self.config = { "actions": ["process_image", "text_images", "site_images", "hue_images", "copy_directories"], # "actions": ["process_image", "text_images", "site_images", "hue_images"], # "actions": ["process_image", "site_images", "hue_images", "copy_directories"], # "actions": ["hue_images", "copy_directories"], # "actions": ["process_image"], # "actions": ["process_image","text_images","site_images", "copy_directories"], # "actions": ["text_images","site_images", "copy_directories"], # "actions": ["text_images"], # "actions": ["site_images", "copy_directories"], # "actions": [ "copy_directories"], # "process_image_fx": "fx_dreamsmooth 1,1,27,0.861,0,0,4,0,0", # "fx_dreamsmooth 1,1,1,0.8,0,0.8,1,24,0", "text_dir": "texts", "image_dir": "images", "circle": False, "basic_image": "basic.png", "hue_image": "basic2.png", "process_image": {"name": "processedImage", "gradient": {"name": "FG to BG (HSV clockwise hue)", "enable": False, "forground_color": [255, 0, 0], "background_color": [250, 0, 0]}, "fx": {"enable": False, "value": "fx_dreamsmooth 1,1,27,0.861,0,0,4,0,0"}, # "fx_dreamsmooth 1,1,1,0.8,0,0.8,1,24,0", "hue_saturation": {"enable": False, "value": [0, 0, 3, 100]} }, "hue_scale": [512, 512], "hue_circle": False, "hue_params": [0, -5, 5, 100], "hue_intervals": [-90, 90], "logo_margin": 0.03, "logo": "D:/MakingMusic/Automatic Music Machine/Images/logoWhite.png", "winamp_root": "D:/MakingMusic/Automatic Music Machine/Images/", "site_image_list": [ ["SoundCloudBanner", "jpg", 2480.0, 800.0, []], ["YouTubeThumbnail", "jpg", 1280.0, 720.0, [["logo", "upr"], ["dream_small", "lowl"], ["title_small", "centerl"], ["composer", "center"]]], ["YouTubeCompanionAddBanner", "png", 300.0, 60.0, [["composer_small", "center"]]], ["YouTubeBanner", "jpg", 2560.0, 1440.0, [["banner_center", "center"], ["composer_small", "banner_centeru"], ["dream_small", "lowl"]]], ["HDWithText", "jpg", 1920.0, 1080.0, [["logo", "lowr"], ["dream", "lowl"], ["title", "centerl"], ["composer", "center"]]], ["HD_verticalWithText", "jpg", 1080.0, 1920.0, [["logo", "lowr"], ["dream", "lowl"], ["title", "centerl"], ["composer", "center"]]], # ["HD", 1920.0, 1080.0, []], # ["HD_vertical", 1080.0, 1920.0, []], ["SoundCloudAlbumCoverAndBandCamp", "png", 1400.0, 1400.0, [["logo", "lowr"], ["dream", "lowl"], ["title", "centerl"], ["composer", "centeru"]]], ["SoundCloudAvatar", "png", 800.0, 800.0, []], ["SpotifyBanner", "jpg", 2660.0, 1140.0, []], ["SpotifyHeaderMax", "jpg", 6000.0, 4000.0, []], ["DistroKid", "jpg", 3000.0, 3000.0, []], ["DistroKidWithText", "jpg", 3000.0, 3000.0, [["logo", "lowr"], ["dream", "lowl"], ["title", "centerl"], ["composer", "center"]]], ["FacebookCoverPhoto", "png", 820.0, 360.0, []], ["FacebookProfilePic", "png", 400.0, 400.0, []], ["FacebookVideo", "jpg", 1280.0, 720.0, []], ["FacebookLinkShare", "jpg", 1200.0, 630.0, []], ["InstegramPic", "jpg", 1080.0, 1350.0, []] ], "text_list_for_video": [ [tracks.Track().get_title(), "Segoe UI Bold", 85, (1.0, 1.0, 1.0), "fx_textured_glass 17.6,11.6,0,0,0.319,7.03,5,0,50,50"], [tracks.Track().get_composer(), "Segoe UI Bold", 85, (1.0, 1.0, 1.0), "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], [tracks.Track().get_banner(), "Segoe UI Light", 85, (1.0, 1.0, 1.0), "fx_gcd_crt 1.8,1.8,0,0"], # ["DUNE SPRING", "Segoe UI Light", 85, (1.0, 1.0, 1.0), # "fx_wind 20,0,0.7,20,1,0,0,0,50,50"], # ["DESERT DUNE", "Segoe UI Light", 85, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["SAXY PLONTER", "Segoe UI Bold", 85, (1.0, 1.0, 1.0), # "fx_wind 20,0,0.7,20,1,0,0,0,50,50"], # ["CAFE AU PLANET Z3", "Segoe UI Light", 85, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["LONELY FLOATER", "Segoe UI Light", 75, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["ELECTRIC REAGGAE", "Segoe UI Light", 65, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["LIQUID DREAMS", "Segoe UI Light", 65, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["BITOKANA", "Segoe UI Light", 65, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["BUDDHA ACID BELL", "Segoe UI Light", 65, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["DAM DAM", "Segoe UI Light", 65, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["HUNTED ROOMS", "Segoe UI Light", 65, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["QUEST TO BRASS", "Segoe UI Light", 65, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["UFO TRANSMISSION", "Segoe UI Light", 65, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["GOLEM", "Segoe UI Light", 65, (1.0, 1.0, 1.0), # "fx_gaussian_blur 3,0,0,1,0,0,0,50,50"], # ["party set 1", "Segoe UI Light", 85, (1.0, 1.0, 1.0), # "fx_gcd_crt 1.8,1.8,0,0"] ], "text_list": [ ["composer", tracks.Track().get_composer(), "Segoe UI", 88, (1.0, 1.0, 1.0), "fx_textured_glass 17.6,11.6,0,0,0.319,7.03,5,0,50,50"], ["banner_center", tracks.Track().get_banner(), "Segoe UI Bold", 128, (1.0, 1.0, 1.0), "fx_textured_glass 17.6,11.6,0,0,0.319,7.03,5,0,50,50"], ["title", tracks.Track().get_title(), "Segoe UI Bold", 88, (1.0, 1.0, 1.0), "fx_textured_glass 17.6,11.6,0,0,0.319,7.03,5,0,50,50"], ["title_small", tracks.Track().get_title(), "Segoe UI Semi-Light", 44, (1.0, 1.0, 1.0), "fx_textured_glass 17.6,11.6,0,0,0.319,7.03,5,0,50,50"], ["dream", tracks.Track().get_painter(), "Segoe UI Light", 84, (1.0, 1.0, 1.0), "fx_textured_glass 17.6,11.6,0,0,0.319,7.03,5,0,50,50"], ["composer_small", tracks.Track().get_composer(), "Segoe UI Semi-Light", 48, (1.0, 1.0, 1.0), "fx_textured_glass 17.6,11.6,0,0,0.319,7.03,5,0,50,50"], ["dream_small", tracks.Track().get_painter(), "Segoe UI", 36, (1.0, 1.0, 1.0), "fx_textured_glass 17.6,11.6,0,0,0.319,7.03,5,0,50,50"] ] }
def main(): #database record_switch = False text_rank = [] textpos_rank = [] #start music pygame.mixer.music.load('./media/background.wav') pygame.mixer.music.play(-1) #initialize objects. clock = pygame.time.Clock() running = True font = pygame.font.Font(None, 32) car = player.Player() cam = camera.Camera() target = gamemode.Finish() item = [] traffics = [] bound_alert = bounds.Alert() time_alert = timeout.Alert() info = menu.Alert() pointer = direction.Tracker(int(CENTER_W * 2), int(CENTER_H * 2)) #create sprite groups. map_s = pygame.sprite.Group() player_s = pygame.sprite.Group() traffic_s = pygame.sprite.Group() tracks_s = pygame.sprite.Group() target_s = pygame.sprite.Group() item_s = pygame.sprite.Group() pointer_s = pygame.sprite.Group() timer_alert_s = pygame.sprite.Group() bound_alert_s = pygame.sprite.Group() menu_alert_s = pygame.sprite.Group() #generate tiles 기본 맵 초원 for tile_num in range(0, len(maps.map_tile[0])): maps.map_files.append(load_image(maps.map_tile[0][tile_num], False)) for x in range(0, 10): for y in range(0, 10): map_s.add( maps.Map(maps.map_1[x][y], x * 1000, y * 1000, maps.map_1_rot[x][y])) #load tracks tracks.initialize() #load finish target_s.add(target) #load items items.initialize() for count in range(0, ITEM_COUNT): item.append(items.Items()) item_s.add(item[count]) #load direction pointer_s.add(pointer) #load alerts timer_alert_s.add(time_alert) bound_alert_s.add(bound_alert) menu_alert_s.add(info) #load traffic traffic.initialize(CENTER_W, CENTER_H) for count in range(0, TRAFFIC_COUNT): traffics.append(traffic.Traffic()) traffic_s.add(traffics[count]) player_s.add(car) cam.set_pos(car.x, car.y) while running: #Render loop. #Check for menu/reset, (keyup event - trigger ONCE) for event in pygame.event.get(): if event.type == pygame.KEYUP: if keys[K_m]: if (info.visibility == True): info.visibility = False else: info.visibility = True if info.visibility == True: if (keys[K_p]): car.reset() target.reset() for i in range(0, ITEM_COUNT): item[i].reset record_switch = False if (keys[K_q]): pygame.quit() sys.exit(0) if (keys[K_1]): change_map(map_s, maps, 0) car.reset() target.reset() for i in range(0, ITEM_COUNT): item[i].reset if (keys[K_2]): change_map(map_s, maps, 1) car.reset() target.reset() for i in range(0, ITEM_COUNT): item[i].reset if (keys[K_3]): change_map(map_s, maps, 2) car.reset() target.reset() for i in range(0, ITEM_COUNT): item[i].reset if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: running = False break #Check for key input. (KEYDOWN, trigger often) keys = pygame.key.get_pressed() if (target.timeleft > 0): if keys[K_LEFT]: car.steerleft() if keys[K_RIGHT]: car.steerright() if keys[K_UP]: car.accelerate() else: car.soften() if keys[K_DOWN]: car.deaccelerate() cam.set_pos(car.x, car.y) #Show text data. text_fps = font.render('FPS: ' + str(int(clock.get_fps())), 1, (224, 16, 16)) textpos_fps = text_fps.get_rect(centery=175, centerx=260) text_score = font.render('Score: ' + str(target.score), 1, (224, 16, 16)) textpos_score = text_fps.get_rect(centery=205, centerx=260) text_timer = font.render( 'Timer: ' + str(int((target.timeleft / 60) / 60)) + ":" + str(int((target.timeleft / 60) % 60)), 1, (224, 16, 16)) textpos_timer = text_fps.get_rect(centery=235, centerx=260) text_red_ball = font.render( 'Red Ball: ' + str(int(car.red_timer / 64)), 1, (224, 16, 16)) textpos_red_ball = text_fps.get_rect(centery=265, centerx=260) text_blue_ball = font.render( 'Blue Ball: ' + str(int(car.blue_timer / 64)), 1, (224, 16, 16)) textpos_blue_ball = text_fps.get_rect(centery=295, centerx=260) text_green_ball = font.render( 'Green Ball: ' + str(int(car.green_timer / 64)), 1, (224, 16, 16)) textpos_green_ball = text_fps.get_rect(centery=325, centerx=260) text_ranking = font.render('TOP 5 Ranking', 1, (16, 224, 16)) textpos_ranking = text_fps.get_rect(centery=CENTER_H, centerx=CENTER_W - 20) text_boundtimer = font.render( 'Game over After ' + str(int(bound_alert.timeleft / 64)) + ' Second.', 1, (224, 16, 16)) textpos_boundtimer = text_fps.get_rect(centery=CENTER_H + 30, centerx=CENTER_W - 100) #Render Scene. screen.blit(background, (0, 0)) #cam.set_pos(car.x, car.y) map_s.update(cam.x, cam.y) map_s.draw(screen) #Conditional renders/effects car.grass(screen.get_at(((int(CENTER_W - 5), int(CENTER_H - 5)))).g) if (car.tracks): tracks_s.add( tracks.Track(cam.x + CENTER_W, cam.y + CENTER_H, car.dir)) #Just render.. tracks_s.update(cam.x, cam.y) tracks_s.draw(screen) player_s.update(cam.x, cam.y) player_s.draw(screen) traffic_s.update(cam.x, cam.y) traffic_s.draw(screen) target_s.update(cam.x, cam.y) target_s.draw(screen) item_s.update(cam.x, cam.y) item_s.draw(screen) pointer_s.update(car.x + CENTER_W, car.y + CENTER_H, target.x, target.y) pointer_s.draw(screen) #Conditional renders. if (bounds.breaking(car.x + CENTER_W, car.y + CENTER_H) == True): bound_alert_s.update() bound_alert_s.draw(screen) bound_alert.update() screen.blit(text_boundtimer, textpos_boundtimer) if (bound_alert.timeleft == 0): target.timeleft = 0 else: bound_alert.timeleft = 640 if (target.timeleft == 0): timer_alert_s.draw(screen) car.speed = 0 text_score = font.render('Your Score: ' + str(target.score), 1, (224, 16, 16)) textpos_score = text_fps.get_rect(centery=CENTER_H - 56, centerx=CENTER_W - 20) if record_switch == False: cur.execute("SELECT * From rank ORDER BY Point DESC") dataList = [] dataList = cur.fetchall() rank = 0 if len(dataList) == 0: cur.execute("INSERT INTO rank VALUES(?,?)", (1, target.score)) elif len(dataList) < 5: for i in dataList: if i[1] < target.score: rank = i[0] break if rank != 0: cur.execute( "UPDATE rank SET Rank=Rank+1 WHERE Point < %d" % (target.score)) cur.execute("INSERT INTO rank VALUES(?,?)", (rank, target.score)) else: cur.execute("INSERT INTO rank VALUES(?,?)", (len(dataList) + 1, target.score)) elif len(dataList) >= 5: for i in dataList: if i[1] < target.score: rank = i[0] break if rank != 0: cur.execute( "UPDATE rank SET Rank=Rank+1 WHERE Point<%d" % (target.score)) cur.execute("INSERT INTO rank VALUES(?,?)", (rank, target.score)) cur.execute("DELETE FROM rank WHERE Rank > 5") con.commit() cur.execute("SELECT * From rank ORDER BY Rank ASC") dataList = cur.fetchall() cnt = 0 text_rank.clear() textpos_rank.clear() for i in dataList: cnt = cnt + 1 text_rank.append( font.render( str(i[0]) + '. ' + str(i[1]), 1, (16, 224, 16))) textpos_rank.append( text_fps.get_rect(centery=CENTER_H + 25 + cnt * 25, centerx=CENTER_W - 20)) record_switch = True if (info.visibility == True): menu_alert_s.draw(screen) #Blit Blit.. screen.blit(text_fps, textpos_fps) screen.blit(text_score, textpos_score) screen.blit(text_timer, textpos_timer) screen.blit(text_red_ball, textpos_red_ball) screen.blit(text_blue_ball, textpos_blue_ball) screen.blit(text_green_ball, textpos_green_ball) if record_switch == True: screen.blit(text_ranking, textpos_ranking) for i in range(0, cnt): screen.blit(text_rank[i], textpos_rank[i]) pygame.display.flip() #Check collision!!! #traffic 과의 충돌 확인. 블루볼 먹었을 시에는 충돌 없음 for i in range(0, TRAFFIC_COUNT): if traffics[i].collision_check(car) == True: if car.blue_ball == True: pygame.mixer.Sound.play(point_sound) traffics[i].respawn() else: car.impact() target.car_crash() if pygame.sprite.spritecollide(car, target_s, True): pygame.mixer.Sound.play(point_sound) target.claim_flag() target.generate_finish() target_s.add(target) for i in range(0, ITEM_COUNT): if item[i].collision_check(car) == True: pygame.mixer.Sound.play(point_sound) car.get_item(item[i].color) item[i].generate_items() item_s.add(item[i]) clock.tick(64)