def begin(self): # Set fb device for Raspberry pi os.environ["SDL_FBDEV"] = Config.fb_dev if (Config.detect_screen_size): self.screen_size = (pygame.display.Info().current_w, pygame.display.Info().current_h) # Set the resolution and the frames per second Program.set_mode(self.screen_size, self.full_screen, False) Program.set_fps(self.fps) Program.set_title(self.window_title) # set mouse invisible pygame.mouse.set_visible(False) self.init_joystick() self.font = Game.load_fnt("c64.ttf", 16) self.big_font = Game.load_fnt("c64.ttf", 50) # run scene scene = Main(self); scene.lives = Config.lives scene.bullets = Config.bullets while True: # This is the main loop # Simple input check if Program.key(K_ESCAPE) or (K_ESCAPE in self.read_joystick()): Program.exit() yield
def begin(self): # set up the screen Program.set_mode((640,480)) Program.set_fps(30) # Create the player Guy() # game loop while True: # Check for pressing escape if Program.key(K_ESCAPE): Program.quit() # Leave frame yield
def begin(self): # Set the resolution and the frames per second Program.set_mode((800, 600)) Program.set_fps(30) # load the graphics and store a pointer to the loaded surfaces. # Assigning them to the main game object is purely a convention # and is not required for pygame-fenix. They are set as members of # the game because it is a persistant process that lasts for the # length of the game. self.g_player = Program.load_png("player.png") self.g_enemy = Program.load_png("enemy.png") self.g_bullet = Program.load_png("bullet.png") # Because it in persistent and holds references to all our graphic # surfaces, it makes sense to pass it to all of our objects. # Again this is purely a convention. A recommended convention, but # entirely optional nontheless. Player(self) # We create the invaders along the top of the screen. for x in range(100, 601, 50): Enemy(self, x) # Note that we do not save references to the processes. Simply the act # of initialising one will cause it to exist. It's internal loop will # execute immediately and it can happily act independantly of everything # else. while True: # This is the main loop # Simple input check if Program.key(K_ESCAPE): Program.exit() # The yield statement signifies that this object is finished for the # current frame, on the next frame the loop will resume here until it # hits the yield statement again. All objects are designed to act this way. yield
def begin(self): # set up the screen Program.set_mode((640, 480)) Program.set_fps(30) font = Program.load_fnt("gfx/font.ttf", 20) cheri_font = Program.load_fnt("gfx/cheri.ttf", 30) # Create the text objects text_guys = [] text_guys.append(Program.write(font, 100, 100, 4, "Texts")) text_guys.append(Program.write(font, 200, 150, 4, "Are")) text_guys.append(Program.write(font, 400, 200, 4, "Processes")) text_guys.append(Program.write(font, 550, 250, 4, "Too!")) # This is our scrolly message message = ( "This is the Fenix Pygame library! Who needs the goddamn amiga?" + " Weeee! I'm having far too much fun with this! You'll have to try out the" + " library for yourself. :D Fiona made this in the last bit of 2008. For realsies." + " OMG I think it's gonna loop now..... " + " so i herd you like mudkips..?" ) scroll_text = [] # game loop while True: # strobe the message along the top for single in text_guys: single.colour = (randrange(50, 200), randrange(50, 200), randrange(50, 200)) text_guys[3].angle += 3000 # if we don't have a scrolly message, create it if len(scroll_text) < 1: a, b = 650, 0 for x in message: a += 25 b += 20000 guy = Program.write(cheri_font, a, 420, text=x) guy.mystery_angle = b guy.init_x = a guy.colour = (randrange(50, 200), randrange(50, 200), randrange(50, 200)) scroll_text.append(guy) # loop through the scrolly characters and move them and stuff for single in scroll_text: single.x -= 5 single.y = 420 + Program.get_disty(single.mystery_angle, 30) single.mystery_angle += 20000 if single.x <= -25: scroll_text.remove(single) single.signal(S_KILL) # Check for pressing escape if Program.key(K_ESCAPE): Program.quit() # Leave frame yield
def begin(self): # Set fb device for Raspberry pi #os.environ["SDL_FBDEV"] = Config.fb_dev "Ininitializes a new pygame screen using the framebuffer" # Based on "Python GUI in Linux frame buffer" # http://www.karoltomala.com/blog/?p=679 disp_no = os.getenv("DISPLAY") if disp_no: print "I'm running under X display = {0}".format(disp_no) # Check which frame buffer drivers are available # Start with fbcon since directfb hangs with composite output drivers = ['fbcon', 'directfb', 'svgalib'] found = False for driver in drivers: # Make sure that SDL_VIDEODRIVER is set if not os.getenv('SDL_VIDEODRIVER'): os.putenv('SDL_VIDEODRIVER', driver) try: pygame.display.init() except pygame.error: print 'Driver: {0} failed.'.format(driver) continue found = True break if not found: raise Exception('No suitable video driver found!') if (Config.detect_screen_size): self.screen_size = (pygame.display.Info().current_w, pygame.display.Info().current_h) # Set the resolution and the frames per second Program.set_mode(self.screen_size, self.full_screen, False) Program.set_fps(self.fps) #Program.set_title(self.window_title) # set mouse invisible pygame.mouse.set_visible(False) # load playlist self.playlist = Playlist() self.playlist.load(Config.playlist) # init mpd self.mpd = MPDClient() self.mpd.connect(Config.mpd_host, Config.mpd_port) if (Config.mpd_password is not None): self.mpd.password(Config.mpd_password) # collect mpd playlist self.mpd.stop() self.mpd.clear() for item in self.playlist.list: self.mpd.add(item.url) # get active song from saved state self.state = State() self.active_song = self.state.load() self.last_active_song = self.active_song # init serial encoder instance self.encoder = Encoder(self.active_song, 0, len(self.playlist.list)-1) # play self.mpd.play(self.active_song) # run scene scene = Main(self); while True: # This is the main loop # Simple input check if (Program.key(K_ESCAPE)): Program.exit() change_scene_request = self.encoder.try_read() if (self.millis() - self.last_changed >= Config.save_timeout and self.last_active_song != self.active_song): self.last_active_song = self.active_song self.mpd.play(self.active_song) self.state.save(self.active_song) if (Program.key_released(K_SPACE) or Program.key_released(K_RETURN) or change_scene_request == True): change_scene_request = False if (isinstance(scene, Menu)): scene.signal(S_KILL, True) scene = Main(self) elif (isinstance(scene, Main)): scene.signal(S_KILL, True) scene = Menu(self) # The yield statement signifies that this object is finished for the # current frame, on the next frame the loop will resume here until it # hits the yield statement again. All objects are designed to act this way. yield