def main(self): # defaults pygame pygame.init() pygame.display.init() self.screen = pygame.display.set_mode((800, 600)) pygame.key.set_repeat(200,50) self.cursor_state = True pygame.time.set_timer(USEREVENT_BLINK_CURSOR, 500) self.loadconf(True) self.loadwhitelist() while True: # escutar eventos pygame self.events = pygame.event.get() for event in self.events: if event.type == QUIT: return 0 elif event.type == USEREVENT_CUSTOM_QUIT: # usado para objetivos return int(event.code) elif event.type == USEREVENT_BLINK_CURSOR: # cursor piscante self.terminal.cursor = '_' if self.cursor_state else ' ' self.cursor_state = not self.cursor_state self.terminal.updateinput(self.events) # processo de blitting da imagem # clear the image to black self.screen.fill((0,0,0)) # show it on the screen self.stdout.display(self.screen) pygame.display.flip()
def on_init(self): pygame.init() self._display_surf = pygame.display.set_mode( (self.windowWidth, self.windowHeight), pygame.HWSURFACE) pygame.display.set_caption('MiniGame') self._running = True self._image_surf = self.load_image('Block.png') self._apple_surf = self.load_image('Chilli.png')
def main(winstyle=0): pygame.init() if store._preferences.fullscreen: winstyle = FULLSCREEN else: winstyle = 0 bestdepth = pygame.display.mode_ok(SCREENRECT.size, winstyle, 32) screen = pygame.display.set_mode(SCREENRECT.size, winstyle, bestdepth) theApp = App() theApp.on_execute() return gameCounter()
def __init__(self, basedir='sabesp', mode=''): # pasta base (root) da fase, default para sabesp self.gamedir = os.path.abspath(os.path.join(renpy.config.basedir, 'complex')) self.basedir = os.path.abspath(os.path.join(self.gamedir, basedir)) # pasta virtual, subdiretório da base self.curdir = '' self.events = '' self.mode = mode self.users = [] self.objectives = [] self.filecheck = [] self.nfilecheck = [] self.whitelist = [] pygame.init() self.font = pygame.font.SysFont('monospace', 24) # modulos sys.stdout = self.stdout = pygtext.Pygfile(self.font, parent=self) self.terminal = cli.Cli(self)
def main(winstyle=0): # Initialize pygame pygame.init() if pygame.mixer and not pygame.mixer.get_init(): print 'Warning, no sound' pygame.mixer = None # Set the display mode if store._preferences.fullscreen: winstyle = FULLSCREEN else: winstyle = 0 bestdepth = pygame.display.mode_ok(SCREENRECT.size, winstyle, 32) screen = pygame.display.set_mode(SCREENRECT.size, winstyle, bestdepth) #Load images, assign to sprite classes #(do this before the classes are used, after screen setup) horizontal = load_image('horizontal.png') #0 vertical = load_image('vertical.png') #1 ende = load_image('ende.png') #2 endn = load_image('endn.png') #3 ends = load_image('ends.png') #4 endw = load_image('endw.png') #5 bendes = load_image('bendes.png') #6 bendne = load_image('bendne.png') #7 bendsw = load_image('bendsw.png') #8 bendwn = load_image('bendwn.png') #9 threewaye = load_image('threewaye.png') #10 threewayn = load_image('threewayn.png') #11 threeways = load_image('threeways.png') #12 threewayw = load_image('threewayw.png') #13 fourway = load_image('fourway.png') #14 empty = load_image('empty.png') #15 left = load_image('playerleft.gif') up = load_image('playerup.gif') down = load_image('playerdown.gif') Player.images = [left, pygame.transform.flip(left, 1, 0), up, down] Tile.images = [ horizontal, vertical, ende, endn, ends, endw, bendes, bendne, bendsw, bendwn, threewaye, threewayn, threeways, threewayw, fourway, empty ] Hat.images = [load_image('hat.gif')] #decorate the game window #icon = pygame.transform.scale(Alien.images[0], (32, 32)) #pygame.display.set_icon(icon) #pygame.display.set_caption('MAZE') pygame.mouse.set_visible(1) #create the background, tile the bgd image bgdtile = load_image('empty.png') background = pygame.Surface(SCREENRECT.size) for x in range(0, SCREENRECT.width, bgdtile.get_width()): background.blit(bgdtile, (x, 0)) screen.blit(background, (0, 0)) #myfont = pygame.font.SysFont("monospace", 15) #label = myfont.render("Time left: 80", 1, (255,255,0)) #screen.blit(label, (100, 100)) pygame.display.flip() #load the sound effects #boom_sound = load_sound('boom.wav') #shoot_sound = load_sound('car_door.wav') #if pygame.mixer: # music = os_path_join('data', 'house_lo.wav') # pygame.mixer.music.load(music) # pygame.mixer.music.play(-1) # Initialize Game Groups tiles = pygame.sprite.Group() all = pygame.sprite.OrderedUpdates() #assign default groups to each sprite class Timer.containers = all Player.containers = all Hat.containers = all Tile.containers = all #Create Some Starting Values #global# score clock = pygame.time.Clock() global timeleft timeleft = 120 #initialize our starting sprites #Tile() #note, this 'lives' because it goes into a sprite group #add tiles to world for x in range(0, WORLDWIDTH): for y in range(0, WORLDHEIGHT): Tile([x, y]) Hat() player = Player() #timer = Timer() if pygame.font: all.add(Timer()) while timeleft > 0: milliseconds = clock.tick(40) # milliseconds passed since last frame seconds = milliseconds / 1000.0 # seconds passed since last frame (float) timeleft = timeleft - seconds #get input for event in pygame.event.get(): if event.type == QUIT or \ (event.type == KEYDOWN and event.key == K_ESCAPE): return -1 keystate = pygame.key.get_pressed() # clear/erase the last drawn sprites all.clear(screen, background) #update all the sprites all.update() #handle player input player.move(getInputDirectionX(), getInputDirectionY()) if player.pos == HATLOC: return 1 #draw the scene dirty = all.draw(screen) pygame.display.update(dirty) if pygame.mixer: pygame.mixer.music.fadeout(1000) pygame.time.wait(1000) return 0
def main(winstyle = 0): # Initialize pygame pygame.init() if pygame.mixer and not pygame.mixer.get_init(): print 'Warning, no sound' pygame.mixer = None # Set the display mode if store._preferences.fullscreen: winstyle = FULLSCREEN else: winstyle = 0 bestdepth = pygame.display.mode_ok(SCREENRECT.size, winstyle, 32) screen = pygame.display.set_mode(SCREENRECT.size, winstyle, bestdepth) #Load images, assign to sprite classes #(do this before the classes are used, after screen setup) img = load_image('player1.gif') Player.images = [img, pygame.transform.flip(img, 1, 0)] img = load_image('explosion1.gif') Explosion.images = [img, pygame.transform.flip(img, 1, 1)] Alien.images = load_images('alien1.gif', 'alien2.gif', 'alien3.gif') Bomb.images = [load_image('bomb.gif')] Shot.images = [load_image('shot.gif')] #decorate the game window icon = pygame.transform.scale(Alien.images[0], (32, 32)) pygame.display.set_icon(icon) pygame.display.set_caption('Pygame Aliens') pygame.mouse.set_visible(0) #create the background, tile the bgd image bgdtile = load_image('background.gif') background = pygame.Surface(SCREENRECT.size) for x in range(0, SCREENRECT.width, bgdtile.get_width()): background.blit(bgdtile, (x, 0)) screen.blit(background, (0,0)) pygame.display.flip() #load the sound effects boom_sound = load_sound('boom.wav') shoot_sound = load_sound('car_door.wav') if pygame.mixer: music = os_path_join('data', 'house_lo.wav') pygame.mixer.music.load(music) pygame.mixer.music.play(-1) # Initialize Game Groups aliens = pygame.sprite.Group() shots = pygame.sprite.Group() bombs = pygame.sprite.Group() all = pygame.sprite.RenderUpdates() lastalien = pygame.sprite.GroupSingle() #assign default groups to each sprite class Player.containers = all Alien.containers = aliens, all, lastalien Shot.containers = shots, all Bomb.containers = bombs, all Explosion.containers = all Score.containers = all #Create Some Starting Values global score alienreload = ALIEN_RELOAD kills = 0 clock = pygame.time.Clock() global SCORE SCORE = 0 #initialize our starting sprites player = Player() Alien() #note, this 'lives' because it goes into a sprite group #if pygame.font: #all.add(Score()) while player.alive(): #get input for event in pygame.event.get(): if event.type == QUIT or \ (event.type == KEYDOWN and event.key == K_ESCAPE): return SCORE keystate = pygame.key.get_pressed() # clear/erase the last drawn sprites all.clear(screen, background) #update all the sprites all.update() #handle player input direction = keystate[K_RIGHT] - keystate[K_LEFT] player.move(direction) firing = keystate[K_SPACE] if not player.reloading and firing and len(shots) < MAX_SHOTS: Shot(player.gunpos()) shoot_sound.play() player.reloading = firing # Create new alien if alienreload: alienreload = alienreload - 1 elif not int(random.random() * ALIEN_ODDS): Alien() alienreload = ALIEN_RELOAD # Drop bombs if lastalien and not int(random.random() * BOMB_ODDS): Bomb(lastalien.sprite) # Detect collisions for alien in pygame.sprite.spritecollide(player, aliens, 1): boom_sound.play() Explosion(alien) Explosion(player) SCORE = SCORE + 1 player.kill() for alien in pygame.sprite.groupcollide(shots, aliens, 1, 1).keys(): boom_sound.play() Explosion(alien) SCORE = SCORE + 1 for bomb in pygame.sprite.spritecollide(player, bombs, 1): boom_sound.play() Explosion(player) Explosion(bomb) player.kill() #draw the scene dirty = all.draw(screen) pygame.display.update(dirty) #cap the framerate clock.tick(40) if pygame.mixer: pygame.mixer.music.fadeout(1000) pygame.time.wait(1000) return SCORE
def main(winstyle = 0): # Initialize pygame pygame.init() if pygame.mixer and not pygame.mixer.get_init(): print 'Warning, no sound' pygame.mixer = None # Set the display mode if store._preferences.fullscreen: winstyle = FULLSCREEN else: winstyle = 0 bestdepth = pygame.display.mode_ok(SCREENRECT.size, winstyle, 32) screen = pygame.display.set_mode(SCREENRECT.size, winstyle, bestdepth) #Load images, assign to sprite classes #(do this before the classes are used, after screen setup) img = load_image('player1.gif') Player.images = [img, pygame.transform.flip(img, 1, 0)] img = load_image('explosion1.gif') Explosion.images = [img, pygame.transform.flip(img, 1, 1)] Alien.images = load_images('alien1.gif', 'alien2.gif', 'alien3.gif') Bomb.images = [load_image('bomb.gif')] Shot.images = [load_image('shot.gif')] #decorate the game window icon = pygame.transform.scale(Alien.images[0], (32, 32)) pygame.display.set_icon(icon) pygame.display.set_caption('Pygame Aliens') pygame.mouse.set_visible(0) #create the background, tile the bgd image bgdtile = load_image('background.gif') background = pygame.Surface(SCREENRECT.size) for x in range(0, SCREENRECT.width, bgdtile.get_width()): background.blit(bgdtile, (x, 0)) screen.blit(background, (0,0)) pygame.display.flip() #load the sound effects boom_sound = load_sound('boom.wav') shoot_sound = load_sound('car_door.wav') if pygame.mixer: music = os_path_join('data', 'house_lo.wav') pygame.mixer.music.load(music) pygame.mixer.music.play(-1) # Initialize Game Groups aliens = pygame.sprite.Group() shots = pygame.sprite.Group() bombs = pygame.sprite.Group() all = pygame.sprite.RenderUpdates() lastalien = pygame.sprite.GroupSingle() #assign default groups to each sprite class Player.containers = all Alien.containers = aliens, all, lastalien Shot.containers = shots, all Bomb.containers = bombs, all Explosion.containers = all Score.containers = all #Create Some Starting Values global score alienreload = ALIEN_RELOAD kills = 0 clock = pygame.time.Clock() global SCORE SCORE = 0 #initialize our starting sprites player = Player() Alien() #note, this 'lives' because it goes into a sprite group if pygame.font: all.add(Score()) while player.alive(): #get input for event in pygame.event.get(): if event.type == QUIT or \ (event.type == KEYDOWN and event.key == K_ESCAPE): return SCORE keystate = pygame.key.get_pressed() # clear/erase the last drawn sprites all.clear(screen, background) #update all the sprites all.update() #handle player input direction = keystate[K_RIGHT] - keystate[K_LEFT] player.move(direction) firing = keystate[K_SPACE] if not player.reloading and firing and len(shots) < MAX_SHOTS: Shot(player.gunpos()) shoot_sound.play() player.reloading = firing # Create new alien if alienreload: alienreload = alienreload - 1 elif not int(random.random() * ALIEN_ODDS): Alien() alienreload = ALIEN_RELOAD # Drop bombs if lastalien and not int(random.random() * BOMB_ODDS): Bomb(lastalien.sprite) # Detect collisions for alien in pygame.sprite.spritecollide(player, aliens, 1): boom_sound.play() Explosion(alien) Explosion(player) SCORE = SCORE + 1 player.kill() for alien in pygame.sprite.groupcollide(shots, aliens, 1, 1).keys(): boom_sound.play() Explosion(alien) SCORE = SCORE + 1 for bomb in pygame.sprite.spritecollide(player, bombs, 1): boom_sound.play() Explosion(player) Explosion(bomb) player.kill() #draw the scene dirty = all.draw(screen) pygame.display.update(dirty) #cap the framerate clock.tick(40) if pygame.mixer: pygame.mixer.music.fadeout(1000) pygame.time.wait(1000) return SCORE
def main(): #create initial objects pygame.init() pygame.mixer.init() screen = pygame.display.set_mode((1408, 960), pygame.FULLSCREEN) screen_rect = screen.get_rect() timer = pygame.time.get_ticks() elapsed = 0 level_complete = False asena = Asena( pygame.image.load("Asena Sprite sheet with jump.png").convert_alpha()) background = pygame.image.load("Stone BG.png").convert_alpha() background_rect = background.get_rect() platform = Sprite(pygame.image.load("Stone Platform.png").convert_alpha()) platform_rect = platform.rect spikes = Sprite(pygame.image.load("Spikes.png").convert_alpha()) fire = Sprite(pygame.image.load("lava.png").convert_alpha()) key = Key(pygame.image.load("Key.png").convert_alpha()) door = Door(pygame.image.load("Door.png").convert_alpha()) arrow_surf = pygame.image.load("Arrow.png").convert_alpha() arrow2_surf = pygame.image.load("Arrow2.png").convert_alpha() level3_file = open("Asena's Quest/game/level_data/level_3.txt") level3 = level3_file.readlines() level3 = [line.strip() for line in level3] master_clock = pygame.time.Clock() arrow_list = [] arrow2_list = [] delta_time = 0 arrow_threshold = 1500 arrow_timer = 0 platform_list = [] spike_list = [] fire_list = [] music = pygame.mixer.music.load("Okami - Battle of Ninetails.ogg") pygame.mixer.music.play(-1) for row in range(len(level3)): for column in range(len(level3[row])): if level3[row][column] == '@': arrow_list.append( Arrow(arrow_surf, pygame.Rect(column * 64, row * 64, 64, 64))) if level3[row][column] == 'a': arrow2_list.append( Arrow2(arrow2_surf, pygame.Rect(column * 64, row * 64, 64, 64))) elif level3[row][column] == 'p': platform_list.append(pygame.Rect(column * 64, row * 64, 64, 64)) elif level3[row][column] == 's': spike_list.append(pygame.Rect(column * 64, row * 64, 64, 64)) elif level3[row][column] == 'f': fire_list.append(pygame.Rect(column * 64, row * 64, 64, 64)) screen.blit(asena.surf, asena.rect) while (asena.hp > 0) and (level_complete == False): #tick the clock master_clock.tick(100) elapsed = pygame.time.get_ticks() - timer timer = pygame.time.get_ticks() #process input for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return False elif (event.key == pygame.K_w): asena.is_moving[2] = True elif event.key == pygame.K_s and key.rect.colliderect( asena.rect) == True: asena.has_key = True elif event.key == pygame.K_s and (asena.has_key == True) and ( door.rect.colliderect(asena.rect) == True): level_complete = True elif event.key == pygame.K_a: asena.is_moving[0] = True elif event.key == pygame.K_d: asena.is_moving[1] = True else: asena.level_complete = False if event.type == pygame.KEYUP: asena.is_moving = [False, False, False] #draw screen.fill((0, 0, 0)) screen.blit(background, background_rect) for row in range(len(level3)): for column in range(len(level3[row])): if level3[row][column] == 'p': screen.blit(platform.surf, pygame.Rect(column * 64, row * 64, 64, 64)) elif level3[row][column] == 's': screen.blit(spikes.surf, pygame.Rect(column * 64, row * 64, 64, 64)) elif level3[row][column] == 'f': screen.blit(fire.surf, pygame.Rect(column * 64, row * 64, 64, 64)) elif level3[row][column] == 'k': if asena.has_key == False: key.draw(screen) elif level3[row][column] == 'd': door.draw(screen) #shoot arrows arrow_timer += elapsed if arrow_timer >= arrow_threshold: arrow_timer = 0 for arrow2 in arrow2_list: arrow2.rect.right = 1408 for arrow2 in arrow2_list: arrow2.update(screen, elapsed) arrow2.draw(screen) arrow_timer += elapsed if arrow_timer >= arrow_threshold: arrow_timer = 0 for arrow in arrow_list: arrow.rect.left = 0 for arrow in arrow_list: arrow.update(screen, elapsed) arrow.draw(screen) asena.update(platform_list, elapsed, screen_rect, arrow_list, platform_list, spike_list, fire_list) asena.draw(screen) asena.health(screen) new = asena.rect timer = pygame.time.get_ticks() #flip buffers pygame.display.flip() return level_complete
def dancingguy () : # On définit la durée de la présentation # Le jeu commence à 32 secondes et 440 milisecondes # debutJeu = 32440 debutJeu = 500 # valeur de test # On initialise la SDL pygame.init() # On initialise SDL_mixer # - frequency # - size : nb de bits par échantillon # - channels : 1 pour mono, 2 pour stereo, # - buffer : nombre de samples dans le mixer : # diminuer ce nombre réduit la latence (mais des arrêts de son peuvent se produire) # l'augmenter empêche l'arrêt, mais augmente la latence pygame.mixer.init(frequency=44100, size=-16, channels=2, buffer=128) # On initialise SDL_ttf # pygame.font.init() # On charge la musique en mémoire # pygame.mixer.music.load("nico-20150823.mp3") # On créé les objets pour le texte # maFont = pygame.font.Font("FRGROT.TTF", 16) # maFont2 = pygame.font.Font("FRGROT.TTF", 14) # couleur = 255, 0, 0 # texte = maFont.render("Bienvenue dans le jeu \"Dancing Guy\"", True, (255,0,0)) # texte2 = maFont.render("Bienvenue dans le jeu \"Dancing Guy\"", True, (0,0,0)) # On créé une liste pour enregistrer la position du texte positionTexte = 0, 0 positionTexte2 = 1, 1 # On créé une horloge horloge = pygame.time.Clock() # On créé un entier pour retenir la durée (en miliseconde) écoulée depuis le début du jeu duree = 0 # On joue la musique pygame.mixer.music.play() # On créé une variable booléenne # pour enregistrer le statut de la musique (en pause ou pas) musiqueEnPause = False # On définit la taille de notre fenêtre tailleFenetre = 800, 600 # On créé la fenêtre : # charger les images après cette ligne # initialiser le mixer avant cette ligne fenetre = pygame.display.set_mode(tailleFenetre) # Avec convert() on charge en mémoire l'image du fond fond = pygame.image.load("dancefloor.jpg").convert() # On définit les coordonnées (x, y)) de la position où sera collé le fond positionFond = 0, 0 # On définit une variable mode mode = 0 # Une boucle infinie pour l'affichage while mode == 0: # Une boucle pour la gestion des évènements for event in pygame.event.get(): # Si le joueur clique sur la croix, on ferme la fenêtre if event.type == pygame.QUIT: sys.exit() # L'utilisateur presse une touche du clavier elif event.type == pygame.KEYDOWN: # Si l'utilisateur appuie sur Echap if event.key == K_ESCAPE: # on ferme la fenêtre sys.exit() # Si l'utilisateur appuie sur la touche "espace" elif event.key == K_SPACE: # Si la musique joue if not musiqueEnPause : # on arrête la musique pygame.mixer.music.pause() # Si elle ne joue pas else: # on la relance depuis le début pygame.mixer.music.unpause() # on inverse la valeur du booléen musiqueEnPause = not musiqueEnPause # On colle le fond sur la fenêtre fenetre.blit(fond, positionFond) # On colle le texte sur la fenêtre # fenetre.blit(texte2, positionTexte2) # fenetre.blit(texte, positionTexte) # On met le programme en pause pendant quelques secondes pour économiser du CPU pygame.time.wait(5) # On met à jour l'horloge duree += horloge.tick(60) # On affiche l'horloge if duree < debutJeu : decompte = debutJeu - duree # if decompte > 4000 : # texte4 = "Votre jeu va démarrer dans " + str((debutJeu - duree)/1000) + " secondes" # else : # texte4 = "Votre jeu va démarrer dans " + str(debutJeu - duree) + " milisecondes" # texte3 = maFont2.render(texte4, True, (255,0,0)) # fenetre.blit(texte3, (0, 18)) elif duree >= debutJeu : mode = 1 # On rafraichit l'affichage pygame.display.flip() if mode == 1 : jeu(fenetre, tailleFenetre)