예제 #1
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
예제 #2
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, '')
예제 #3
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
예제 #4
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
예제 #5
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
예제 #6
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
예제 #7
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
예제 #8
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