예제 #1
0
 def begin(self, x, y):
     
     # Initialise some things
     self.x = x
     self.y = y
     # Z order. The lower the Z the "closer" they are to the player.
     # Guy has a lower Z than Other_guy so will appear on top.
     self.z = -300
     self.graph = Program.load_png(os.path.join("gfx", "guy.png"))
     speed = 0
     
     other = Other_guy(320, 240)
     
     font = Program.load_fnt("gfx/font.ttf", 10)
     distance_text = Program.write(font, 0, 0)
     angle_text = Program.write(font, 0, 15)
     collision_text = Program.write(font, 0, 30)
     
     # In-game loop
     while True:
         
         # Do input
         if Program.key(K_LEFT):
             self.angle += 10000
         if Program.key(K_RIGHT):
             self.angle -= 10000
         if Program.key(K_UP):
             speed += 2.0
         if Program.key(K_DOWN):
             speed -= 2.0
             
         # normalise speed
         if speed < -10.0:
             speed = -10.0
         if speed > 10.0:
             speed = 10.0
             
         speed *= 0.9
            
         # send the player forwards or backwards depending on speed 
         self.advance(int(speed))                
         
         # Get distance from other guy
         distance_text.text = "Distance: "+ str(self.get_dist(other))
         angle_text.text = "Angle to: "+ str(int(self.get_angle(other)/1000))
         collision_text.text = "Colliding: "+ ("True" if self.collision(other) else "False")
         
         # leave frame
         yield
예제 #2
0
	def begin(self, game):

		# loading resources
		self.menu_font = Program.load_fnt(Config.menu_font, game.screen_size[1]/self.menu_size)
		self.game = game
		self.state = game.state
		self.last_active_menu = self.game.active_song
		self.calculate_page(0)

		self.game.encoder.led_red(False);
		self.game.encoder.led_green(True);

		Bg(game, Config.menu_bg_color)

		# creating menu items
		for i in range(0, len(self.game.playlist.list)):
			item = game.playlist.list[i]
			MenuItem(self, i, item.name.upper())

		while True:

			if (self.game.encoder.serial_connected == True and self.game.encoder.encoder != self.game.active_song):
				self.calculate_page(self.game.encoder.encoder - self.game.active_song)

			if (Program.key_released(K_UP)):
				self.calculate_page(-1);

			if (Program.key_released(K_DOWN)):
				self.calculate_page(1);

			if (Program.key_released(K_LEFT)):
				self.calculate_page(-self.menu_size);

			if (Program.key_released(K_RIGHT)):
				self.calculate_page(self.menu_size);

			yield
예제 #3
0
	def begin(self, main):

		self.main = main

		font = Program.load_fnt(Config.menu_font_bold, self.main.game.screen_size[1]/5)
		clock = Program.write(font, self.main.game.screen_size[0]/2, self.main.game.screen_size[1]/4, 4, '')
		clock.colour = Config.clock_color

		while True:

			dt = datetime.datetime.now()
			hours = dt.strftime('%H')
			minutes = dt.strftime('%M')
			if (self.main.game.millis() - self.last_blinked >= 500):
				self.last_blinked = self.main.game.millis()
				self.blinked = not self.blinked
			if (self.blinked):
				blink = ':'
			else:
				blink = ' '

			clock.text = hours + blink + minutes

			yield
예제 #4
0
파일: text.py 프로젝트: Fiona/pygame-fenix
    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
예제 #5
0
	def load_fnt(self, filename, size):
		dirname, current_filename = os.path.split(os.path.abspath(__file__))
		filename = os.path.join(dirname, 'gfx', filename)
		return Program.load_fnt(filename, size)
예제 #6
0
	def begin(self, game):

		self.game = game

		self.game.encoder.led_red(True);
		self.game.encoder.led_green(True);

		Bg(game, Config.main_bg_color);

		# Bars(self)
		Clock(self)

		font = Program.load_fnt(Config.menu_font, self.game.screen_size[1]/18)
		font2 = Program.load_fnt(Config.menu_font, self.game.screen_size[1]/20)
		font3 = Program.load_fnt(Config.menu_font, self.game.screen_size[1]/24)

		station_name = Program.write(font, self.get_x(), self.get_y(0), 0, '')
		station_name.colour = Config.title_color

		playlist_pos = Program.write(font2, self.get_x(), self.get_y(1), 0, '')
		playlist_pos.colour = Config.station_color

		artist_name1 = Program.write(font3, self.get_x(), self.get_y(2), 0, '')
		artist_name1.colour = Config.song_color
		artist_name2 = Program.write(font3, self.get_x(), self.get_y(2.5), 0, '')
		artist_name2.colour = Config.song_color

		scroll_width = 0
		scroll_count = 0
		scroll_total_count = 0

		while True:

			# fetch current song from mpd every 500ms
			if (self.game.millis() - self.last_current_song > 500):
				current_song = self.game.mpd.currentsong();
				#print current_song
				if 'title' in current_song:
					title = current_song['title'].strip()
					try:
						title = title.decode('utf8')
					except Exception as e:
						pass

					if (title != self.current_song):
						scroll_width = 0
						scroll_count = 0
						scroll_total_count = 0
						self.current_song = title.upper()
						for l in self.current_song:
							scroll_width += font3.size(l)[0]
							scroll_total_count = scroll_total_count+1
							if (scroll_width <= self.game.screen_size[0] - self.get_x()):
								scroll_count = scroll_count+1
				else:
					self.current_song = ''
					scroll_width = 0
					scroll_count = 0
					scroll_total_count = 0
				self.last_current_song = self.game.millis()

				#if ('pos' in current_song and int(current_song['pos']) != self.game.active_song):
				#	self.game.active_song = int(current_song['pos'])
				#	self.game.last_active_song = int(current_song['pos'])


			# pring station, pos and song title
			station = self.game.playlist.list[self.game.active_song]
			station_name.text = station.name.upper()
			playlist_pos.text = u'STATION ' + str(self.game.active_song+1) + u' / ' + str(len(self.game.playlist.list))

			if (scroll_total_count > scroll_count):
				part = textwrap.wrap(self.current_song, scroll_count)
				if(len(part)>=2):
					artist_name1.text = part[0]
					artist_name2.text = part[1]
				else:
					artist_name1.text = ''
					artist_name2.text = self.current_song
			else:
				artist_name1.text = ''
				artist_name2.text = self.current_song

			if (self.game.encoder.serial_connected == True and self.game.encoder.encoder != self.game.active_song):
				self.calculate_page(self.game.encoder.encoder - self.game.active_song)

			if (Program.key_released(K_UP)):
				self.calculate_page(-1);

			if (Program.key_released(K_DOWN)):
				self.calculate_page(1);

			yield
예제 #7
0
파일: media.py 프로젝트: Fiona/scavenger
	def __init__(self):
		
		# FONTS
		self.fonts['system'] = Program.load_fnt(os.path.join("fnt","system_font.ttf"), 10)
		self.fonts['vera'] = Program.load_fnt(os.path.join("fnt","vera.ttf"), 12)
		self.fonts['mini_vera'] = Program.load_fnt(os.path.join("fnt","vera.ttf"), 11)

		# GRAPHICS
		self.player_gfx['ship'] = Program.load_png(os.path.join("gfx", "player.png"))
		self.player_gfx['crosshair'] = Program.load_png(os.path.join("gfx", "crosshair.png"))
		self.player_gfx['laser'] = Program.load_png(os.path.join("gfx", "lazor.png"))
		self.player_gfx['tractor'] = Program.load_png(os.path.join("gfx", "tractor.png"))
		self.player_gfx['wormhole'] = Program.load_png(os.path.join("gfx", "wormhole.png"))
		self.player_gfx['hub_arrow'] = Program.load_png(os.path.join("gfx", "hub_arrow.png"))

		self.gfx_landmarks['spacestation'] = Program.load_png(os.path.join("gfx", "landmark-spacestation.png"))
		self.gfx_landmarks['cruiser'] = Program.load_png(os.path.join("gfx", "landmark-cruiser.png"))

		self.gfx_exp = Program.load_png(os.path.join("gfx", "exp.png"))

		self.gfx_mine = Program.load_png(os.path.join("gfx", "mine.png"))
		self.gfx_turret = Program.load_png(os.path.join("gfx", "turret.png"))
		self.gfx_turret_laser = Program.load_png(os.path.join("gfx", "enemylazor.png"))
		self.gfx_title = Program.load_png(os.path.join("gfx", "title.png"))

		self.gfx_hud['hold'] = Program.load_png(os.path.join("gfx", "holdhud.png"))
		self.gfx_hud['hull'] = Program.load_png(os.path.join("gfx", "hullhud.png"))
		self.gfx_hud['invenbutton'] = self.load_tile_map(Program.load_png(os.path.join("gfx", "hudinvenbutton.png")), size = 105, height = 24)
		self.gfx_hud['inventory'] = Program.load_png(os.path.join("gfx", "hudinven.png"))
		self.gfx_hud['hub'] = Program.load_png(os.path.join("gfx", "hudhub.png"))
		self.gfx_hud['hub_launch'] = self.load_tile_map(Program.load_png(os.path.join("gfx", "hudhub_launch.png")), size = 105, height = 24)
		self.gfx_hud['hub_repair'] = self.load_tile_map(Program.load_png(os.path.join("gfx", "hudhub_repair.png")), size = 105, height = 24)
		self.gfx_hud['hub_upgradehull'] = self.load_tile_map(Program.load_png(os.path.join("gfx", "hudhub_upgradehull.png")), size = 156, height = 24)
		self.gfx_hud['hub_upgradehold'] = self.load_tile_map(Program.load_png(os.path.join("gfx", "hudhub_upgradehold.png")), size = 156, height = 24)
		self.gfx_hud['hub_upgradetractor'] = self.load_tile_map(Program.load_png(os.path.join("gfx", "hudhub_upgradetractor.png")), size = 174, height = 24)
		self.gfx_hud['hub_upgradeengine'] = self.load_tile_map(Program.load_png(os.path.join("gfx", "hudhub_upgradeengine.png")), size = 174, height = 24)
		self.gfx_hud['hub_sellstuff'] = self.load_tile_map(Program.load_png(os.path.join("gfx", "hudhub_sell.png")), size = 105, height = 24)
		self.gfx_hud['hub_sell'] = Program.load_png(os.path.join("gfx", "hudsell.png"))
		self.gfx_hud['hub_sell_cancel'] = self.load_tile_map(Program.load_png(os.path.join("gfx", "hudhub_cancel.png")), size = 60, height = 17)
		self.gfx_hud['hub_sell_sell'] = self.load_tile_map(Program.load_png(os.path.join("gfx", "hudhub_sellall.png")), size = 60, height = 17)

		self.gfx_debris_inventory = Program.load_png(os.path.join("gfx", "debris", "debris_inventory.png"))
		
		for a in xrange(1, DEBRIS_GFX_NUM+1):
			self.gfx_debris.append(
				Program.load_png(os.path.join("gfx", "debris", "debris" + str(a) + ".png"))
				)

		self.gfx_debris_particles = self.load_tile_map(
			Program.load_png(os.path.join("gfx", "debris", "debris_particles.png")),
			size = 10
			)

		for a in xrange(1, 6):
			self.gfx_valuable_debris['tier'+str(a)] = self.load_tile_map(
				Program.load_png(os.path.join("gfx", "debris", "tier"+str(a)+"_valuables.png")),
				size = 30
				)

		self.player_gfx['indicator'] = self.load_tile_map(
			Program.load_png(os.path.join("gfx", "indicator.png")),
			size = 4
			)

		self.gfx_particles_trail = self.load_tile_map(
			Program.load_png(os.path.join("gfx", "particles", "trail.png")),
			size = 6
			)

		for a in xrange(1, 7):
			self.gfx_tutorial_messages[a] = Program.load_png(os.path.join("gfx", "tut"+str(a)+".png"))
			
		# SOUNDS
		self.sounds['collision'] = pygame.mixer.Sound(os.path.join("sounds", "collision.wav"))
		self.sounds['wormhole'] = pygame.mixer.Sound(os.path.join("sounds", "wormholeout.wav"))
		self.sounds['tractor'] = pygame.mixer.Sound(os.path.join("sounds", "tractor.wav"))
		self.sounds['pickup'] = pygame.mixer.Sound(os.path.join("sounds", "pickup.wav"))
		self.sounds['laser'] = pygame.mixer.Sound(os.path.join("sounds", "laser.wav"))
		self.sounds['explosion'] = pygame.mixer.Sound(os.path.join("sounds", "explosion.wav"))
		self.sounds['beep'] = pygame.mixer.Sound(os.path.join("sounds", "beep.wav"))
		self.sounds['moneyout'] = pygame.mixer.Sound(os.path.join("sounds", "moneyout.wav"))
		self.sounds['startfly'] = pygame.mixer.Sound(os.path.join("sounds", "startfly.wav"))
		self.sounds['flyloop'] = pygame.mixer.Sound(os.path.join("sounds", "flyloop.wav"))