コード例 #1
0
ファイル: aliens.py プロジェクト: andykarpov/AliensVsHumans
	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
コード例 #2
0
ファイル: invaders.py プロジェクト: Fiona/pygame-fenix
	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
コード例 #3
0
	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