示例#1
0
    def update_and_draw(self, draw_layer, game):

        if not game.paused:
            self.x += int(self.speed * math.cos(math.radians(self.angle / 1000.0)))
            self.y -= int(self.speed * math.sin(math.radians(self.angle / 1000.0)))

        draw_x = self.x - Program.scroll[0].x0
        draw_y = self.y - Program.scroll[0].y0

        if self.graph != None:

            if not game.paused:
                if self.spin > 0:
                    self.spin_angle += self.spin
                else:
                    self.spin_angle = self.angle
                self.size -= 7
            Program.map_xput(draw_layer, self.graph, draw_x, draw_y, self.spin_angle, self.size)
        else:
            Program.map_put_pixel(draw_layer, draw_x, draw_y, self.particle_col)

        if not game.paused:
            self.speed *= 0.99

            self.life_count += 1
            if self.graph == None and (self.life_count > self.life or self.speed < 1):
                self.handler.particles.remove(self)
            elif self.graph != None and self.size <= 0:
                self.handler.particles.remove(self)
示例#2
0
	def begin(self, game):

		self.game = game
		self.lives = 0
		self.bullets = 0
		self.music = None
		self.next_level = Main
	
		txt_message = Program.write(self.game.big_font, self.game.screen_size[0]/2, self.game.screen_size[1]/2, 4, 'You Won!')
		txt_message.colour = (0, 255, 0)

		if (game.joystick is not None):
			help = 'Press "Start" to continue'
		else:
			help = 'Press "Enter" to continue'

		txt_help = Program.write(self.game.font, self.game.screen_size[0]/2, self.game.screen_size[1]/2 + 50, 4, help)
		txt_help.colour = (255,255,255)		

		while True:

			if Program.key_released(K_RETURN) or (K_RETURN in game.read_joystick()):
				self.signal(S_KILL, True)
				self.game.scene = Main(self.game)
				self.game.scene.lives = Config.lives
				self.game.scene.bullets = Config.bullets 
				return

			yield
示例#3
0
 def begin(self, x, y):
     
     # Initialise some things
     self.x = x
     self.y = y
     self.graph = Program.load_png(os.path.join("gfx", "guy.png"))
     
     speed = 0.0
     
     # 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))                
         
         # leave frame
         yield
示例#4
0
    def begin(self):
        
        # Initialise some things
        self.x = randrange(50, 600)
        self.y = randrange(50, 450)

        self.alpha = 120
        self.size = randrange(10, 250)
        
        self.graph = Program.new_map(100,100)
        Program.map_clear(self.graph, (randrange(50, 200), randrange(50, 200), randrange(50, 200)))
                 
        direction = randrange(0, 2)
        size_to = 0 if direction else 250
        
        # In-game loop
        while True:
            
            # Spin these dudes
            self.angle += 5000 if direction else -5000 
            
            # Size them around
            if size_to == 250:
                self.size += 5
                if self.size >= size_to:
                    size_to = 0
            if size_to == 0:
                self.size -= 5
                if self.size <= size_to:
                    size_to = 250
                    
            # leave frame
            yield
示例#5
0
	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
示例#6
0
	def begin(self, game, color):

		self.x = game.screen_size[0]/2
		self.y = game.screen_size[1]/2
		self.size = 100
		self.graph = Program.new_map(game.screen_size[0], game.screen_size[1])
		Program.map_clear(self.graph, color)

		while True:

			yield
示例#7
0
	def init_stat(self):
		self.txt_level = Program.write(self.game.font, 0, 0, 0, '')
		self.txt_level.colour = (255,255,255)

		self.txt_lives = Program.write(self.game.font, 200, 0, 0, '')
		self.txt_lives.colour = (127,255,127)

		self.txt_health = Program.write(self.game.font, 400, 0, 0, '')
		self.txt_health.colour = (255,127,127)

		self.txt_bullets = Program.write(self.game.font, 600, 0, 0, '')
		self.txt_bullets.colour = (127,127,255)

		self.txt_message = Program.write(self.game.big_font, self.game.screen_size[0]/2, self.game.screen_size[1]/2, 4, '')
示例#8
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
示例#9
0
 def begin(self, x, y):
     
     # Initialise some things
     self.x = x
     self.y = y
     self.z = -200
     self.graph = Program.load_png(os.path.join("gfx", "guy.png"))
     
     while True:
         yield
示例#10
0
文件: media.py 项目: Fiona/scavenger
	def load_tile_map(self, tilemap_sur, start_height = 0, end_height = None, size = 16, height = None):

		if height == None:
			height = size
			
		w = tilemap_sur.get_width()
		h = tilemap_sur.get_height()

		tiles = {}
		num = 0

		for a in range(start_height, h/height):
			for b in range(w/size):
				tiles[num] = Program.new_map(size,height)
				Program.map_block_copy(tiles[num], 0, 0, tilemap_sur, b*size, a*height, size, height)
				num+=1
			if end_height != None and end_height == a:
				return tiles

		return tiles
示例#11
0
	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
示例#12
0
	def begin(self, game):
		self.x, self.y = 400, 500
		self.graph = game.g_player

		while True:

			# Processes have many member variables, one of the most common is x and y which
			# directly map to the process' coordinates on the screen. They, like all member
			# variables, can be altered at any time.
			# Here we check if the ship should move left/right and change the x (horisontal)
			# coordinate appropriately.
			if Program.key(K_LEFT):
				self.x -= 4
			if Program.key(K_RIGHT):
				self.x += 4
			# The final bit of input is shooting. Again we pass in the game object so we can
			# access graphics and honour the convention set for ourselves when creating the
			# player and enemies.
			if Program.key_released(K_SPACE):
				Bullet(game, self)
				
			yield
示例#13
0
	def begin(self, bars, idx):

		self.bars = bars

		bar_width = round((self.bars.main.game.screen_size[0] / self.bars.bars_count))
		bar_height = round(self.bars.main.game.screen_size[1] / 2)

		self.x = ((bar_width) * idx) + round(bar_width/2)
		self.size = 100

		while True:

			if (self.bars.values[idx] != self.bars.prev_values[idx]):
				self.bars.prev_values[idx] = self.bars.values[idx]
				self.y = bar_height - round(((bar_height/2) * self.bars.values[idx]) / 100)
				self.graph = Program.new_map(bar_width-4, round(bar_height * self.bars.values[idx] / 100) )
				cl = self.bars.values[idx] * 255 / 100
				self.alpha = cl
				color = (0, 0, 255)
				Program.map_clear(self.graph, color)

			yield
示例#14
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
示例#15
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
示例#16
0
	def begin(self, menu, idx, name):

		self.idx = idx
		self.menu = menu
		self.name = name

		item = Program.write(menu.menu_font, self.get_x(), self.get_y(), 0, '')

		while True:

			item.colour = self.get_color()
			item.text   = self.get_name()
			item.y = self.get_y()
				
			yield
示例#17
0
 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
示例#18
0
    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
示例#19
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
示例#20
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
示例#21
0
	def begin(self, level, x = None, y = None):

		if (x != None and y != None):
			self.x = x
			self.y = y
		else:
			self.x = 200
			self.y = 200
		self.graph = level.g_ship1
		self.level = level
		animate = False

		while True:

			if (animate):
				self.graph = level.g_ship2
			else:
				self.graph = level.g_ship1

			animate = not animate

			if (x == None and y == None):

				if Program.key(K_UP) or (K_UP in level.game.read_joystick()):
					self.y -= self.speed
				if Program.key(K_DOWN) or (K_DOWN in level.game.read_joystick()):
					self.y += self.speed
				if Program.key(K_LEFT) or (K_LEFT in level.game.read_joystick()):
					self.x -= self.speed
				if Program.key(K_RIGHT) or (K_RIGHT in level.game.read_joystick()):
					self.x += self.speed

				# bounds
				if (self.y < self.graph.get_height()/2):
					self.y = self.graph.get_height()/2
				if (self.x < self.graph.get_width()/2):
					self.x = self.graph.get_width()/2
				if (self.x > self.level.game.screen_size[0] - self.graph.get_width()/2):
					self.x = self.level.game.screen_size[0] - self.graph.get_width()/2
				if (self.y > self.level.game.screen_size[1] - self.graph.get_height()/2):
					self.y = self.level.game.screen_size[1] - self.graph.get_height()/2

			e = self.collision("Enemy1")
			if e and level.game.millis() - self.last_enemy_collision > 500:
				self.last_enemy_collision = level.game.millis()
				level.sound(level.s_ship_collision)
				self.health -= 10

			e = self.collision("Enemy2")
			if e and level.game.millis() - self.last_enemy_collision > 500:
				self.last_enemy_collision = level.game.millis()
				level.sound(level.s_ship_collision)
				self.health -= 20

			e = self.collision("Enemy3")
			if e and level.game.millis() - self.last_enemy_collision > 500:
				self.last_enemy_collision = level.game.millis()
				level.sound(level.s_ship_collision)
				self.health -= 30

			e = self.collision("Enemy4")
			if e and level.game.millis() - self.last_enemy_collision > 500:
				self.last_enemy_collision = level.game.millis()
				level.sound(level.s_ship_collision)
				self.health -= 50

			e = self.collision("Enemy5")
			if e and level.game.millis() - self.last_enemy_collision > 500:
				self.last_enemy_collision = level.game.millis()
				level.sound(level.s_ship_collision)
				self.health -= 10

			e = self.collision("Enemy6")
			if e and level.game.millis() - self.last_enemy_collision > 500:
				self.last_enemy_collision = level.game.millis()
				level.sound(level.s_ship_collision)
				self.health -= 50

			e = self.collision("Enemy7")
			if e and level.game.millis() - self.last_enemy_collision > 500:
				self.last_enemy_collision = level.game.millis()
				level.sound(level.s_ship_collision)
				self.health -= 20

			e = self.collision("Enemy8")
			if e and level.game.millis() - self.last_enemy_collision > 500:
				self.last_enemy_collision = level.game.millis()
				level.sound(level.s_ship_collision)
				self.health -= 20

			if Program.key_released(K_SPACE) or (K_SPACE in level.game.read_joystick() and level.game.millis() - level.game.last_joystick_btn > Config.joystick_button_delay):
				level.game.last_joystick_btn = level.game.millis()
				self.fire()

			yield
示例#22
0
	def load_wav(self, filename):
		dirname, current_filename = os.path.split(os.path.abspath(__file__))
		filename = os.path.join(dirname, 'sounds', filename)
		return Program.load_wav(filename)
示例#23
0
	def load_png(self, filename):
		dirname, current_filename = os.path.split(os.path.abspath(__file__))
		filename = os.path.join(dirname, 'gfx', filename)
		return Program.load_png(filename)
示例#24
0
	def begin(self, game):

		self.game = game
		self.lives = 0
		self.bullets = 0
		self.music = "music/_music2.xm"
		self.next_level = Level1

		self.load_resources()
	
		x = self.game.screen_size[0]/2
		y = self.game.screen_size[1]/2

		txt_message = Program.write(self.game.big_font, x, y, 4, 'Aliens vs Humans')
		txt_message.colour = (255, 255, 255)

		if (game.joystick is not None):
			help1 = 'Press "Start" to run game'
			help2 = 'Press "Select" to quit'
			help3 = 'Gamepad axis to move, "Y" to fire'
		else:
			help1 = 'Press "Enter" to start'
			help2 = 'Press "ESC" to exit'
			help3 = 'Cursor keys to move, "Space" to fire'

		txt_help1 = Program.write(self.game.font, x, y + 50, 4, help1)
		txt_help1.colour = (255,255,255)

		txt_help2 = Program.write(self.game.font, x, y + 70, 4, help2)
		txt_help2.colour = (255,255,255)

		txt_help3 = Program.write(self.game.font, x, y + 90, 4, help3)
		txt_help3.colour = (255,255,255)

		txt_copy1 = Program.write(self.game.font, x, y*2 - 60, 4, 'Idea & Graphics: Nikita Karpov')
		txt_copy1.colour = (0, 255, 0)

		txt_copy2 = Program.write(self.game.font, x, y*2 - 40, 4, 'Music & Programming: Andy Karpov')
		txt_copy2.colour = (0, 255, 0)

		txt_copy3 = Program.write(self.game.font, x, y*2 - 20, 4, 'Copyright (c) 2012')
		txt_copy3.colour = (0, 255, 0)

		try:
			pygame.mixer.music.load(self.music)
			pygame.mixer.music.play(-1)
		except Exception as e:
			pass

		sky = Sky(self)
		ship = Ship(self, -200, 150)

		while True:

			ship.x += 4
			if (ship.x > self.game.screen_size[0] + 200):
				ship.x = -200

			if Program.key_released(K_RETURN) or (K_RETURN in game.read_joystick()):
				self.signal(S_KILL, True)
				self.game.scene = Level1(self.game)
				self.game.scene.lives = Config.lives
				self.game.scene.bullets = Config.bullets 
				return

			yield
示例#25
0
	def sound(self, res):
		try:
			Program.play_wav(res);
		except Exception as e:
			pass
示例#26
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"))