def main_loop(self): self.start_screen() self.level_setup() pg.key.set_repeat() while self.running: self.handle_events() self.check_collisions() self.draw() self.clock.tick(60) self.end_screen() pg.font.quit() pg.mixer.quit() pg.quit() sys.exit(0)
def loop(self): done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True # Fill buffer with black pixels self.screen.fill(BLACK) # Flip (push/draw) buffer to screen pygame.display.flip() # Tick according to frame rate self.__clock.tick(self.__framerate) pygame.quit()
def start_screen(self): start_surf = self.font.render("Pong.py",0,GREEN) pkey_surf = self.font.render("Press space to start",0,GREEN) start_rect = start_surf.get_rect() pkey_rect = pkey_surf.get_rect() start_rect.center = (self.size[0]/2,self.size[1]/3) pkey_rect.center = (self.size[0]/2,self.size[1]/3 + 100) while True: for event in pg.event.get(): if event.type == pg.QUIT: pg.quit() sys.exit(0) elif event.type == pg.KEYDOWN: keys = pg.key.get_pressed() if keys[pg.K_SPACE]: return if keys[pg.K_ESCAPE]: self.running = False self.screen.fill(BLACK) self.screen.blit(start_surf,start_rect) self.screen.blit(pkey_surf,pkey_rect) pg.display.update()
def processEvents(self, events): for event in events: if event.type == QUIT: pygame_sdl2.quit() sys.exit()
if damcount <= 24: batdamage = True width -= widthc2 if width < 2: width = 0 rect2 = False if width < 2: width = 0 rect2 = False batdamage = False y = 460 axe = False axe2 = False batdamage = False g = False fall = True else: batdamage = True fall = False else: batdamage = False fightl() pygame.quit()
#bliting grid lines for i in range(0,timeSignature[0]*(bar)): if i%timeSignature[0] != 0: blitGridLine(base_x+(int(i*zoom_x*hashMusic2Float[timeSignature[1]]))+bg_scroll_x*zoom_x, base_y-(290/2)+1) #bliting bar lines for i in range(0,bar): blitBarLine(base_x+(int(i*zoom_x*timeSignature[0]*hashMusic2Float[timeSignature[1]]))+bg_scroll_x*zoom_x,base_y-(290/2)) ##blit snap text #for i,letter in enumerate("Time:" + str(timeSignature) + " Snap:" + str(obj_cursor.snap) + " Duration:" + str(obj_cursor.trajanje) + " Bar:" + str(obj_cursor.pozicija/timeSignature[0]) + "/" + str(bar) + " Pos:" + str(obj_cursor.pozicija) + " Note:" + str(obj_cursor.ton) + " Zoom:" + str(zoom_factor)): #tu denes loremIpsum varijablu # blitFont((i%100)*4*3,int(i/100)*6, spriteFont.index(letter)) #blit notes for listOfNotes for note in listOfNotes: blitNote(pos2Pixel(note.pozicija)+4+bg_scroll_x*zoom_x,tone2Pixel(note.ton)-(24/2)+1, hashMusic2Float[note.trajanje], note.predikat) blitCursor(pos2Pixel(obj_cursor.pozicija)+4+bg_scroll_x*zoom_x, tone2Pixel(obj_cursor.ton)-(52/2)+1, hashMusic2Float[obj_cursor.trajanje]/zoom_factor) blitOTFFont(0, 0, ("Time:" + str(timeSignature) + " Snap:" + str(obj_cursor.snap) + " Duration:" + str(obj_cursor.trajanje) + " Bar:" + str(obj_cursor.pozicija/timeSignature[0]) + "/" + str(bar) + " Pos:" + str(obj_cursor.pozicija) + " Note:" + str(obj_cursor.ton) + " Zoom:" + str(zoom_factor)), 25) ##blit bar number for i in range(bar): blitOTFFont(base_x+2-4*len(str(i))+i*timeSignature[0]*zoom_x+bg_scroll_x*zoom_x, base_y-(290)/2-25, (str(i)), 25) pygame.display.flip() clock.tick(60) # pygame.quit() #quit()
all_sprites.add(asteroids) # gameover # nave acertou asteroide? # for asteroid in asteroids: # if ship.collision(asteroid): # ship.kill() # ship = Ship('img/ship.png', angle=0) # all_sprites.add ( ship ) if len(asteroids.sprites()) == 0: asteroids.add(Asteroid.create_asteroids()) all_sprites.add(asteroids) # colisao caption = "Angle %d FPS %d/%d Q%d" % (ship.angle, clock.get_fps(), FPS, ship.get_quadrant()) # text = font.render("by Humberto Lino", 1, Color.WHITE) text = font.render(caption, 1, Color.WHITE) screen.blit(text, (0, 0)) pg.display.set_caption(caption) touch_buttons.draw() pg.display.flip() if __name__ == "__main__": pg.init() main() pg.quit()
def start(): pg.init() main() pg.quit()
# nave acertou asteroide? # for asteroid in asteroids: # if ship.collision(asteroid): # ship.kill() # ship = Ship('img/ship.png', angle=0) # all_sprites.add ( ship ) if len(asteroids.sprites()) == 0 : asteroids.add ( Asteroid.create_asteroids() ) all_sprites.add( asteroids ) # colisao caption = "Angle %d FPS %d/%d Q%d" % (ship.angle, clock.get_fps(), FPS, ship.get_quadrant()) # text = font.render("by Humberto Lino", 1, Color.WHITE) text = font.render(caption, 1, Color.WHITE) screen.blit(text, (0,0)) pg.display.set_caption(caption) touch_buttons.draw() pg.display.flip() if __name__ == "__main__": pg.init() main() pg.quit()