def __init__(self):
        self.next = self
        self.images = [
            get_image('backgrounds/story1.png'), None,
            get_image('backgrounds/story2.png'),
            get_image('backgrounds/story2.png'),
            get_image('backgrounds/story3.png')
        ]

        self.pos = [(10, 10), (10, 10), (50, 140), (10, 10), (10, 10)]
        self.page = 0
Exemplo n.º 2
0
	def render(self, screen, looker=None):
		looker = looker or camera
		f = 1. * self.t / self.lifetime
		alpha = max(int(255 - 200 * f), 0)
		img = images.get_image("effects/boom.png")
		img.set_alpha(alpha)
		x, y = looker.screenpos(self.x, self.y, self.z)
		screen.blit(img, (x-5, y-5))
	def __init__(self):
		self.next = self
		self.images = [
			get_image('backgrounds/story1.png'),
			None,
			get_image('backgrounds/story2.png'),
			get_image('backgrounds/story2.png'),
			get_image('backgrounds/story3.png')]
		
		self.pos = [
			(10, 10),
			(10, 10),
			(50, 140),
			(10, 10),
			(10, 10)
		]
		self.page = 0
Exemplo n.º 4
0
 def render(self, screen, looker=None):
     looker = looker or camera
     f = 1. * self.t / self.lifetime
     alpha = max(int(255 - 200 * f), 0)
     img = images.get_image("effects/boom.png")
     img.set_alpha(alpha)
     x, y = looker.screenpos(self.x, self.y, self.z)
     screen.blit(img, (x - 5, y - 5))
Exemplo n.º 5
0
	def render(self, screen, looker=None):
		looker = looker or camera
		f = self.t * 1. / self.lifetime
		h = f * (1-f) * 40
		s = int(4 + 10 * f)
		img = pygame.transform.scale(images.get_image("effects/alienblood.png"), (2*s, s))
		x, y = looker.screenpos(self.x, self.y, self.z + h)
		screen.blit(img, (x-s, y-s//2))
Exemplo n.º 6
0
 def render(self, screen, looker=None):
     looker = looker or camera
     f = self.t * 1. / self.lifetime
     h = f * (1 - f) * 40
     s = int(4 + 10 * f)
     img = pygame.transform.scale(
         images.get_image("effects/alienblood.png"), (2 * s, s))
     x, y = looker.screenpos(self.x, self.y, self.z + h)
     screen.blit(img, (x - s, y - s // 2))
	def __init__(self, skippable=True):
		scenefactory.add_builder('story', lambda:CreditsScene())
		self.next = self
		self.skippable = skippable
		self.counter = 0
		self.credits = [
			["", "Credits", None, None],
			["Programming", "Blake O'Hare & Christopher Night", get_image('people/blake.png'), get_image('people/cosmo.png')],
			["Sprite & Building Art", "Angel McLaughlin", get_image('people/spears.png'), None],
			["Story & Title Art", "\"infinip\"", None, get_image('people/infinip.png')],
			["Music", "Adrian Cline", get_image('people/ikanreed.png'), None],
			["Writing & Voice", "Laura Freer", None, get_image('people/satyrane.png')]
		]
		
		i = 0
		while i < len(self.credits):
			img = self.credits[i][3]
			if img != None:
				self.credits[i][3] = pygame.transform.flip(img, True, False)
			i += 1
	def render(self, screen, looker=None):
		looker = looker or camera
		if self.rocket_y_offset is None:
			return Structure.render(self, screen, looker)
		else:
			self.fnumber += 1
			frame = "rocket.png" if self.rocket_y_offset == 0 else ["rocket1.png", "rocket2.png"][self.fnumber % 2]
			Structure.render(self, screen, looker)
			px, py = looker.screenpos(self.x, self.y, self.z)
			img = images.get_image("rocket.png")
			screen.blit(img, (px-img.get_width()//2 + 8, py-self.rocket_y_offset-img.get_height()+20))
Exemplo n.º 9
0
 def __init__(self):
     UiScene.__init__(self)
     self.username = TextBox(20, 200, 100, "Username")
     self.add_element(Image(0, 0, get_image("backgrounds/title.png")))
     self.add_element(self.username)
     self.button = Button(20, 230, "Login", self.login_pressed, False)
     self.add_element(self.button)
     yo = 30
     self.add_element(Button(300, 200 - yo, "Story", self.story_pressed, True))
     self.add_element(Button(300, 230 - yo, "Tutorial Mode", self.tutorial_pressed, True))
     self.add_element(Button(300, 260 - yo, "Credits", self.credits_pressed, True))
     self.auth_request = None
Exemplo n.º 10
0
    def __init__(self, skippable=True):
        scenefactory.add_builder('story', lambda: CreditsScene())
        self.next = self
        self.skippable = skippable
        self.counter = 0
        self.credits = [["", "Credits", None, None],
                        [
                            "Programming", "Blake O'Hare & Christopher Night",
                            get_image('people/blake.png'),
                            get_image('people/cosmo.png')
                        ],
                        [
                            "Sprite & Building Art", "Angel McLaughlin",
                            get_image('people/spears.png'), None
                        ],
                        [
                            "Story & Title Art", "\"infinip\"", None,
                            get_image('people/infinip.png')
                        ],
                        [
                            "Music", "Adrian Cline",
                            get_image('people/ikanreed.png'), None
                        ],
                        [
                            "Writing & Voice", "Laura Freer", None,
                            get_image('people/satyrane.png')
                        ]]

        i = 0
        while i < len(self.credits):
            img = self.credits[i][3]
            if img != None:
                self.credits[i][3] = pygame.transform.flip(img, True, False)
            i += 1
Exemplo n.º 11
0
 def render(self, screen, looker=None):
     looker = looker or camera
     if self.rocket_y_offset is None:
         return Structure.render(self, screen, looker)
     else:
         self.fnumber += 1
         frame = "rocket.png" if self.rocket_y_offset == 0 else [
             "rocket1.png", "rocket2.png"
         ][self.fnumber % 2]
         Structure.render(self, screen, looker)
         px, py = looker.screenpos(self.x, self.y, self.z)
         img = images.get_image("rocket.png")
         screen.blit(img,
                     (px - img.get_width() // 2 + 8,
                      py - self.rocket_y_offset - img.get_height() + 20))
Exemplo n.º 12
0
 def __init__(self):
     UiScene.__init__(self)
     self.username = TextBox(20, 200, 100, "Username")
     self.add_element(Image(0, 0, get_image('backgrounds/title.png')))
     self.add_element(self.username)
     self.button = Button(20, 230, "Login", self.login_pressed, False)
     self.add_element(self.button)
     yo = 30
     self.add_element(
         Button(300, 200 - yo, "Story", self.story_pressed, True))
     self.add_element(
         Button(300, 230 - yo, "Tutorial Mode", self.tutorial_pressed,
                True))
     self.add_element(
         Button(300, 260 - yo, "Credits", self.credits_pressed, True))
     self.auth_request = None
Exemplo n.º 13
0
def get_resource_icon(key):
	img = _resource_icons.get(key, None)
	if img == None:
		t = get_image('resources.png')
		offset = {
			'water': 0,
			'oil': 1,
			'food': 2,
			'aluminum': 3,
			'copper': 4,
			'silicon': 5,
			'research': 6
		}
		
		img = pygame.Surface((12, 12))
		img.blit(t, (offset[key] * -12, 0))
		_resource_icons[key] = img
	return img
Exemplo n.º 14
0
	def render_skycrane(self, screen):
		path = ('lander1.png', 'lander2.png')[(self.counter // 3) % 2]
		lander = get_image(path)
		y = 10
		if self.counter < 100:
			y = self.counter // 10
			
		x = screen.get_width() // 2 - lander.get_width() // 2 + 16
		
		if self.counter > 100 and self.counter < 230:
			y1 = y + 20
			y2 = self.hq.last_render_y
			if y2 != None:
				pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(screen.get_width() // 2 + 16, y1, 1, y2 - y1))
		
		if self.counter > 230:
			d = self.counter - 230
			x += d * 4
			y += d * 2
		
		screen.blit(lander, (x, y))
Exemplo n.º 15
0
 def render(self, screen, looker=None):
     looker = looker or camera
     px, py = looker.screenpos(self.x, self.y, self.z)
     if not looker.isvisible(px, py, 100):
         return
     self.renderplatform(screen, looker)
     if self.destroyed:
         return
     path = "buildings/selection/%s.png" if self.selected else "buildings/%s.png"
     if self.flashdamage:
         if self.flashdamage % 2:
             path = "buildings/damage/%s.png"
         self.flashdamage -= 1
     elif self.hp <= 0:
         path = "buildings/disabled/%s.png"
     img = images.get_image(path % self.imagename())
     ix, iy = img.get_size()
     y = py - iy + ix // 4
     screen.blit(img, (px - ix // 2, y))
     self.last_render_y = y
     if self.hp < self.hp0:
         self.renderhealthbar(screen, looker)
Exemplo n.º 16
0
	def render(self, screen, looker=None):
		looker = looker or camera
		px, py = looker.screenpos(self.x, self.y, self.z)
		if not looker.isvisible(px, py, 100):
			return
		self.renderplatform(screen, looker)
		if self.destroyed:
			return
		path = "buildings/selection/%s.png" if self.selected else "buildings/%s.png"
		if self.flashdamage:
			if self.flashdamage % 2:
				path = "buildings/damage/%s.png"
			self.flashdamage -= 1
		elif self.hp <= 0:
			path = "buildings/disabled/%s.png"
		img = images.get_image(path % self.imagename())
		ix, iy = img.get_size()
		y = py-iy+ix//4
		screen.blit(img, (px-ix//2, y))
		self.last_render_y = y
		if self.hp < self.hp0:
			self.renderhealthbar(screen, looker)
Exemplo n.º 17
0
def get_tiny_text(text):
	text = str(text)
	img = _tiny_cache.get(text, None)
	if img == None:
		if len(_letters) == 0:
			from src import images
			tf = images.get_image('tinyletters2.png')
			
			_letters['A'] = makenblit(0, 0, tf)
			_letters['B'] = makenblit(1, 0, tf)
			_letters['C'] = makenblit(2, 0, tf)
			_letters['D'] = makenblit(3, 0, tf)
			_letters['E'] = makenblit(4, 0, tf)
			_letters['F'] = makenblit(5, 0, tf)
			_letters['G'] = makenblit(6, 0, tf)
			_letters['H'] = makenblit(7, 0, tf)
			_letters['I'] = makenblit(8, 0, tf)
			_letters['J'] = makenblit(9, 0, tf)
			_letters['K'] = makenblit(10, 0, tf)
			_letters['L'] = makenblit(11, 0, tf)
			_letters['M'] = makenblit(12, 0, tf)
			_letters['N'] = makenblit(0, 1, tf)
			_letters['O'] = makenblit(1, 1, tf)
			_letters['P'] = makenblit(2, 1, tf)
			_letters['Q'] = makenblit(3, 1, tf)
			_letters['R'] = makenblit(4, 1, tf)
			_letters['S'] = makenblit(5, 1, tf)
			_letters['T'] = makenblit(6, 1, tf)
			_letters['U'] = makenblit(7, 1, tf)
			_letters['V'] = makenblit(8, 1, tf)
			_letters['W'] = makenblit(9, 1, tf)
			_letters['X'] = makenblit(10, 1, tf)
			_letters['Y'] = makenblit(11, 1, tf)
			_letters['Z'] = makenblit(12, 1, tf)
			_letters['a'] = makenblit(0, 2, tf)
			_letters['b'] = makenblit(1, 2, tf)
			_letters['c'] = makenblit(2, 2, tf)
			_letters['d'] = makenblit(3, 2, tf)
			_letters['e'] = makenblit(4, 2, tf)
			_letters['f'] = makenblit(5, 2, tf)
			_letters['g'] = makenblit(6, 2, tf)
			_letters['h'] = makenblit(7, 2, tf)
			_letters['i'] = makenblit(8, 2, tf)
			_letters['j'] = makenblit(9, 2, tf)
			_letters['k'] = makenblit(10, 2, tf)
			_letters['l'] = makenblit(11, 2, tf)
			_letters['m'] = makenblit(12, 2, tf)
			_letters['n'] = makenblit(0, 3, tf)
			_letters['o'] = makenblit(1, 3, tf)
			_letters['p'] = makenblit(2, 3, tf)
			_letters['q'] = makenblit(3, 3, tf)
			_letters['r'] = makenblit(4, 3, tf)
			_letters['s'] = makenblit(5, 3, tf)
			_letters['t'] = makenblit(6, 3, tf)
			_letters['u'] = makenblit(7, 3, tf)
			_letters['v'] = makenblit(8, 3, tf)
			_letters['w'] = makenblit(9, 3, tf)
			_letters['x'] = makenblit(10, 3, tf)
			_letters['y'] = makenblit(11, 3, tf)
			_letters['z'] = makenblit(12, 3, tf)
			_letters['1'] = makenblit(0, 4, tf)
			_letters['2'] = makenblit(1, 4, tf)
			_letters['3'] = makenblit(2, 4, tf)
			_letters['4'] = makenblit(3, 4, tf)
			_letters['5'] = makenblit(4, 4, tf)
			_letters['6'] = makenblit(5, 4, tf)
			_letters['7'] = makenblit(6, 4, tf)
			_letters['8'] = makenblit(7, 4, tf)
			_letters['9'] = makenblit(8, 4, tf)
			_letters['0'] = makenblit(9, 4, tf)
			_letters['!'] = makenblit(10, 4, tf)
			_letters['?'] = makenblit(11, 4, tf)
			_letters['.'] = makenblit(12, 4, tf)
			_letters['('] = makenblit(0, 5, tf)
			_letters[')'] = makenblit(1, 5, tf)
			_letters['/'] = makenblit(2, 5, tf)
			_letters[','] = makenblit(3, 5, tf)
			_letters['-'] = makenblit(4, 5, tf)
			_letters["'"] = makenblit(5, 5, tf)
			_letters['"'] = makenblit(6, 5, tf)
			_letters[':'] = makenblit(7, 5, tf)
			_letters['%'] = makenblit(8, 5, tf)
			_letters['&'] = makenblit(9, 5, tf)
			
		output = pygame.Surface((5 * len(text), 8)).convert_alpha()
		output.fill((0, 0, 0, 0))
		x = 0
		for char in text:
			img = _letters.get(char, None)
			if img != None:
				output.blit(img, (x, 0))
			x += 5
		img = output
		_tiny_cache[text] = img
	return img
Exemplo n.º 18
0
    def __init__(self):
        self.next = self
        self.pages = [
            get_image('backgrounds/ending1.png'),
            get_image('backgrounds/ending1.png'),
            get_image('backgrounds/ending1.png'),
            get_image('backgrounds/ending1.png'),
            get_image('backgrounds/ending2.png'),
            get_image('backgrounds/ending2.png')
        ]
        self.text = [
            util.trim("""
			Despite the fact that you can still see hordes of the
			alien monsters on the horizon, you begin the launch
			sequence for your homemade spaceship, hoping for the best.
			Amazingly enough, the patchwork rocket engine ignites.
			The hastily constructed frame groans as the fuel burns;
			this is a one-way trip, so you better hope your""").split('\n'),
            util.trim("""
			destination isn't too far. You've used the computer to
			calculate where your home world is, hoping you'll be able
			to hide among your family and friends, counting on the fact
			that no one has escaped the prison planet before to mean
			they won't be looking for you. It's a desperate gamble, but
			it's better than being trapped for the rest of your life.
		""").split('\n'),
            util.trim("""
				You're not sure how long you spend traveling through
				the blackness of space, but finally you think you
				have arrived at the location the computer indicated
				your home would be. It's not a moment too soon; your
				fuel supply is nearly depleted. You buckle in and
				start the landing sequence; hoping to survive.""").split('\n'),
            util.trim("""

			Your arrival was more on the "crash" side of landing,
			but you're in one piece! You open the hatch to your rocket,
			ready to make your way home.""").split('\n'),
            util.trim("""
				Except something is wrong; where are the houses,
				the architecture, the parks and fountains? Even
				in the most uninhabited areas, it didn't look
				like this: barren, almost lifeless. You cautiously
				approach the small crowd gathered around your craft;
				they're a motley bunch, looking shifty and suspicious. """).split('\n'),
            util.trim("""
			"Where am I? Isn't this Earth?"
			
			They look at each other, and an older man with one eye
			and a lot of tattoos answers, "Sure was, stranger, but
			it ain't much of anythin' no more."
			
			"What do you mean? This is my home!"
			
			"Ain't no one's home; they moved the locals out of here
			when they made this a prison planet. You must be crazy
			to come here, cause everyone knows there ain't no way out!"
		""").split('\n')
        ]
        self.current = 0
        self.counter = 0
Exemplo n.º 19
0
def main():
	
	pygame.init()
	
	icon = get_image('icon.png')
	pygame.display.set_icon(icon)
	pygame.display.set_caption("Shunned Survivor")
	
	rscreen, vscreen = get_screen()
	
	last_fps = 30
	
	scene = title.TitleScene()  # can be set to None to quit
	pressed_keys = defaultdict(bool)
	for ea in event_actions:
		pressed_keys[ea] = False
	while scene:
		start = time.time()
		
		events = []
		pressed = pygame.key.get_pressed()
		shift = pressed[pygame.K_LSHIFT] or pressed[pygame.K_RSHIFT]
		ctrl = pressed[pygame.K_LCTRL] or pressed[pygame.K_RCTRL]
		alt = pressed[pygame.K_LALT] or pressed[pygame.K_RALT]
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				scene = None
			elif event.type == pygame.USEREVENT:
				jukebox.song_ended()
			elif event.type == pygame.KEYDOWN and event.key == pygame.K_F7:
				if 'PlayScene' in str(scene):
					scene.give_resources()
			elif event.type in (pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP, pygame.MOUSEMOTION):
				x = vscreen.get_width() * event.pos[0] // rscreen.get_width()
				y = vscreen.get_height() * event.pos[1] // rscreen.get_height()
				if event.type == pygame.MOUSEMOTION:
					events.append(MyEvent('mousemove', None, False, x, y))
				else:
					down = event.type == pygame.MOUSEBUTTONDOWN
					left = event.button == 1
					events.append(MyEvent('mouseleft' if left else 'mouseright', None, down, x, y))
			elif event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
				down = event.type == pygame.KEYDOWN
				if event.key in (pygame.K_ESCAPE, pygame.K_BACKSPACE):
					events.append(MyEvent('key', 'back', down, 0, 0))
				elif event.key == pygame.K_F4 and alt:
					scene = None
				elif event.key == pygame.K_F1:
					events.append(MyEvent('key', 'debug', down, 0, 0))
				elif event.key == pygame.K_F9:
					events.append(MyEvent('key', 'f9', down, 0, 0))
				elif event.key == pygame.K_F11 and down:
					rscreen, vscreen = toggle_full_screen()
				elif event.key == pygame.K_LEFT:
					events.append(MyEvent('key', 'left', down, 0, 0))
				elif event.key == pygame.K_RIGHT:
					events.append(MyEvent('key', 'right', down, 0, 0))
				elif event.key == pygame.K_UP:
					events.append(MyEvent('key', 'up', down, 0, 0))
				elif event.key == pygame.K_DOWN:
					events.append(MyEvent('key', 'down', down, 0, 0))
				elif event.key == pygame.K_SPACE:
					events.append(MyEvent('key', 'build', down, 0, 0))
				elif event.key == pygame.K_1:
					events.append(MyEvent('key', 'b1', down, 0, 0))
				elif event.key == pygame.K_2:
					events.append(MyEvent('key', 'b2', down, 0, 0))
				elif event.key == pygame.K_3:
					events.append(MyEvent('key', 'b3', down, 0, 0))
				elif event.key == pygame.K_RETURN:
					events.append(MyEvent('key', 'action', down, 0, 0))
				elif event.key in (pygame.K_z, pygame.K_SEMICOLON):
					events.append(MyEvent('key', 'shoot', down, 0, 0))
				
				if len(events) > 0 and events[-1].type == 'key':
					pressed_keys[events[-1].action] = events[-1].down
				
				typed = letters.get(event.key, None)
				if typed != None:
					if down:
						letter = typed[shift]
						events.append(MyEvent('type', letter, True, 0, 0))
						_type_delay[0] = letter
						_type_delay[1] = 0
					else:
						_type_delay[0] = None
				
				# TODO: mouse events
		if not scene: break
		
		if _type_delay[0] != None:
			_type_delay[1] += 1
			k = _type_delay[0]
			d = _type_delay[1]
			if d > 20 and d % 3 == 0:
				events.append(MyEvent('type', k, True, 0, 0))
		
		scene.process_input(events, pressed_keys)
		scene.update()
		scene.render(vscreen)
		if settings.sz == 1:
			rscreen.blit(vscreen, (0,0))
		else:
			pygame.transform.scale(vscreen, rscreen.get_size(), rscreen)
		
		length = time.time() - start
		if length > 0:
			pass # rscreen.blit(get_text("FPS: %.1f" % (1.0 / length), (255, 0, 0), 18), (4, 4))
		
		pygame.display.flip()
		end = time.time()
		
		fps = settings.fps
		if "Credits" in str(scene):
			fps = 60
		diff = end - start
		delay = 1.0 / fps - diff
		if delay > 0:
			time.sleep(delay)
		else:
			last_fps = 1.0 / diff
			
		scene = scene.next
	if settings.dumpmap:
		worldmap.dumpmap()
Exemplo n.º 20
0
def main(s3_bucket_name, s3_object_key):
    image = get_image(s3_bucket_name, s3_object_key)
    image_features = extract_features(image)
    print(image_features)
Exemplo n.º 21
0
	def __init__(self):
		self.next = self
		self.pages = [
			get_image('backgrounds/ending1.png'),
			get_image('backgrounds/ending1.png'),
			get_image('backgrounds/ending1.png'),
			get_image('backgrounds/ending1.png'),
			get_image('backgrounds/ending2.png'),
			get_image('backgrounds/ending2.png')]
		self.text = [
		util.trim("""
			Despite the fact that you can still see hordes of the
			alien monsters on the horizon, you begin the launch
			sequence for your homemade spaceship, hoping for the best.
			Amazingly enough, the patchwork rocket engine ignites.
			The hastily constructed frame groans as the fuel burns;
			this is a one-way trip, so you better hope your""").split('\n'),
			
		util.trim("""
			destination isn't too far. You've used the computer to
			calculate where your home world is, hoping you'll be able
			to hide among your family and friends, counting on the fact
			that no one has escaped the prison planet before to mean
			they won't be looking for you. It's a desperate gamble, but
			it's better than being trapped for the rest of your life.
		""").split('\n'),

			util.trim("""
				You're not sure how long you spend traveling through
				the blackness of space, but finally you think you
				have arrived at the location the computer indicated
				your home would be. It's not a moment too soon; your
				fuel supply is nearly depleted. You buckle in and
				start the landing sequence; hoping to survive.""").split('\n'),
				
				util.trim("""

			Your arrival was more on the "crash" side of landing,
			but you're in one piece! You open the hatch to your rocket,
			ready to make your way home.""").split('\n'),
			
			util.trim("""
				Except something is wrong; where are the houses,
				the architecture, the parks and fountains? Even
				in the most uninhabited areas, it didn't look
				like this: barren, almost lifeless. You cautiously
				approach the small crowd gathered around your craft;
				they're a motley bunch, looking shifty and suspicious. """).split('\n'),
				
				util.trim("""
			"Where am I? Isn't this Earth?"
			
			They look at each other, and an older man with one eye
			and a lot of tattoos answers, "Sure was, stranger, but
			it ain't much of anythin' no more."
			
			"What do you mean? This is my home!"
			
			"Ain't no one's home; they moved the locals out of here
			when they made this a prison planet. You must be crazy
			to come here, cause everyone knows there ain't no way out!"
		""").split('\n')
		
		]
		self.current = 0
		self.counter = 0
Exemplo n.º 22
0
	def __init__(self, playscene):
		self.playscene = playscene
		self.bg = None
		self.mode = 'main'
		self.hovering = -1
		buttons = {}
		self.buttons = buttons
		
		ex = {
			'build_turret': (0, 8),
			'build_farm': (0, -8),
			'build_watertreatment': (0, -11)
		}
		
		bg = get_image('toolbar/button_background.png')
		
		buttons['main_build'] = get_image('toolbar/main_build.png')
		buttons['main_demolish'] = get_image('toolbar/main_demolish.png')
		buttons['main_bots'] = get_image('toolbar/main_bots.png')
		buttons['main_fight'] = get_image('toolbar/main_fight.png')
		buttons['main_exit'] = get_image('toolbar/main_exit.png')
		buttons['back'] = get_image('toolbar/back.png')
		
		
		# Caption, icon key, resulting mode, resulting lambda
		self.menu = {
			'main' : {
				'b': (1, "Build (b)", 'main_build', 'build', None),
				'd': (2, "Demolish (d)", 'main_demolish', 'demolish', None),
				'e': (3, "Deploy Bots (e)", 'main_bots', 'main', self.summon_bots),
				'f': (4, "Fire Ray Gun (f)", 'main_fight', 'fight', None)
			},
			
			'build' : {
				'r': (1, "Resource Generating (r)", 'era_landing', 'era_landing', None),
				'd': (2, "Defensive Structures (d)", 'era_lowtech', 'era_lowtech', None),
				'f': (3, "Offensive Structures (f)", 'era_medtech', 'era_medtech', None),
				's': (4, "Miscellaneous (s)", 'era_hightech', 'era_hightech', None)
			},
			
			# Landing == Resources
			'era_landing' : {
				'g': (1, "Build Green House (g)", 'build_greenhouse', 'build_greenhouse', None),
				'f': (2, "Build Farm (f)", 'build_farm', 'build_farm', None),
				'd': (3, "Build Drill (d)", 'build_drill', 'build_drill', None),
				'r': (4, "Build Resevoir (r)", 'build_resevoir', 'build_resevoir', None),
				'q': (5, "Build Quarry (q)", 'build_quarry', 'build_quarry', None)
			},
			
			# LowTech == Defense
			'era_lowtech' : {
				'b': (1, "Build Shield (b)", 'build_beacon', 'build_beacon', None),
				't': (2, "Build Basic Turret (t)", 'build_turret', 'build_turret', None),
				'f': (3, "Build Tractor Turret (f)", 'build_fireturret', 'build_fireturret', None),
				's': (4, "Build Tesla Turret (s)", 'build_teslaturret', 'build_teslaturret', None),
				'a': (5, "Build Laz0r Turret (a)", 'build_lazorturret', 'build_lazorturret', None)
			},
			
			# Med Tech == Offense
			'era_medtech' : {
				'a': (1, "Build Machinery Lab (a)", 'build_machinerylab', 'build_machinerylab', None),
				's': (2, "Build Science Lab (s)", 'build_sciencelab', 'build_sciencelab', None),
				'f': (3, "Build Foundry (f)", 'build_foundry', 'build_foundry', None)
			},
			
			# High Tech == Misc
			'era_hightech' : {
				'e': (1, "Build Medical Tent (e)", 'build_medicaltent', 'build_medicaltent', None),
				'r': (2, "Build Radar (r)", 'build_radar', 'build_radar', None),
				's': (3, "Build Launch Site (s)", 'build_launchsite', 'build_launchsite', None)
			},
			
			'era_space' : {
			}
		}
		
		self.tiny_captions = {
			'era_landing': "Resource",
			'era_lowtech': "Defensive",
			'era_medtech': "Offensive",
			'era_hightech': "Misc.",
			'era_space': "Launch Site",
			'main_build': "Build",
			'main_demolish': "Demolish",
			'main_bots': "Infiltrate",
			'main_fight': "Fire Ray Gun",
			'main_exit': "Main Menu",
			'build_greenhouse': "Greenhouse",
			'build_medicaltent': "Med. Tent",
			'build_turret': "Turret",
			'build_beacon': "Shield",
			'build_farm': "Farm",
			'build_resevoir': "Resevoir",
			'build_fireturret': "Tract.Tur.",
			'build_drill': "Drill",
			'build_quarry': "Quarry",
			'build_foundry': "Foundry",
			'build_radar': "Radar",
			'build_teslaturret': "Tesla Tur.",
			'build_machinerylab': "Mach. Lab",
			'build_lazorturret': "Lazor Tur.",
			'build_sciencelab': "Science Lab",
			'build_launchsite': "Launch Site"
		}
		
		eras = structure.get_eras()
		for era in self.menu.keys():
			if era.startswith('era_'):
				for building in eras[era.split('_')[1]]:
					img = pygame.Surface(bg.get_size())
					img.blit(bg, (0, 0))
					b = get_image('buildings/' + building[0] + '.png')
					e = ex.get('build_' + building[0], (0, 0))
					img.blit(b, (img.get_width() // 2 - b.get_width() // 2 + e[0], e[1] + img.get_height() // 2 - b.get_height() // 2))
					buttons['build_' + building[0]] = img
		
		buttons['era_landing'] = get_image('toolbar/build_resource.png')
		buttons['era_lowtech'] = get_image('toolbar/build_defensive.png')
		buttons['era_medtech'] = get_image('toolbar/build_offensive.png')
		buttons['era_hightech']= get_image('toolbar/build_misc.png')
		buttons['era_space']   = buttons['build_launchsite']
		buttons['locked'] = get_image('toolbar/locked.png')
		self.details_bg = None
		self.caption_bg = None
Exemplo n.º 23
0
def main():

    pygame.init()

    icon = get_image('icon.png')
    pygame.display.set_icon(icon)
    pygame.display.set_caption("Shunned Survivor")

    rscreen, vscreen = get_screen()

    last_fps = 30

    scene = title.TitleScene()  # can be set to None to quit
    pressed_keys = defaultdict(bool)
    for ea in event_actions:
        pressed_keys[ea] = False
    while scene:
        start = time.time()

        events = []
        pressed = pygame.key.get_pressed()
        shift = pressed[pygame.K_LSHIFT] or pressed[pygame.K_RSHIFT]
        ctrl = pressed[pygame.K_LCTRL] or pressed[pygame.K_RCTRL]
        alt = pressed[pygame.K_LALT] or pressed[pygame.K_RALT]
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                scene = None
            elif event.type == pygame.USEREVENT:
                jukebox.song_ended()
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_F7:
                if 'PlayScene' in str(scene):
                    scene.give_resources()
            elif event.type in (pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP,
                                pygame.MOUSEMOTION):
                x = vscreen.get_width() * event.pos[0] // rscreen.get_width()
                y = vscreen.get_height() * event.pos[1] // rscreen.get_height()
                if event.type == pygame.MOUSEMOTION:
                    events.append(MyEvent('mousemove', None, False, x, y))
                else:
                    down = event.type == pygame.MOUSEBUTTONDOWN
                    left = event.button == 1
                    events.append(
                        MyEvent('mouseleft' if left else 'mouseright', None,
                                down, x, y))
            elif event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
                down = event.type == pygame.KEYDOWN
                if event.key in (pygame.K_ESCAPE, pygame.K_BACKSPACE):
                    events.append(MyEvent('key', 'back', down, 0, 0))
                elif event.key == pygame.K_F4 and alt:
                    scene = None
                elif event.key == pygame.K_F1:
                    events.append(MyEvent('key', 'debug', down, 0, 0))
                elif event.key == pygame.K_F9:
                    events.append(MyEvent('key', 'f9', down, 0, 0))
                elif event.key == pygame.K_F11 and down:
                    rscreen, vscreen = toggle_full_screen()
                elif event.key == pygame.K_LEFT:
                    events.append(MyEvent('key', 'left', down, 0, 0))
                elif event.key == pygame.K_RIGHT:
                    events.append(MyEvent('key', 'right', down, 0, 0))
                elif event.key == pygame.K_UP:
                    events.append(MyEvent('key', 'up', down, 0, 0))
                elif event.key == pygame.K_DOWN:
                    events.append(MyEvent('key', 'down', down, 0, 0))
                elif event.key == pygame.K_SPACE:
                    events.append(MyEvent('key', 'build', down, 0, 0))
                elif event.key == pygame.K_1:
                    events.append(MyEvent('key', 'b1', down, 0, 0))
                elif event.key == pygame.K_2:
                    events.append(MyEvent('key', 'b2', down, 0, 0))
                elif event.key == pygame.K_3:
                    events.append(MyEvent('key', 'b3', down, 0, 0))
                elif event.key == pygame.K_RETURN:
                    events.append(MyEvent('key', 'action', down, 0, 0))
                elif event.key in (pygame.K_z, pygame.K_SEMICOLON):
                    events.append(MyEvent('key', 'shoot', down, 0, 0))

                if len(events) > 0 and events[-1].type == 'key':
                    pressed_keys[events[-1].action] = events[-1].down

                typed = letters.get(event.key, None)
                if typed != None:
                    if down:
                        letter = typed[shift]
                        events.append(MyEvent('type', letter, True, 0, 0))
                        _type_delay[0] = letter
                        _type_delay[1] = 0
                    else:
                        _type_delay[0] = None

                # TODO: mouse events
        if not scene: break

        if _type_delay[0] != None:
            _type_delay[1] += 1
            k = _type_delay[0]
            d = _type_delay[1]
            if d > 20 and d % 3 == 0:
                events.append(MyEvent('type', k, True, 0, 0))

        scene.process_input(events, pressed_keys)
        scene.update()
        scene.render(vscreen)
        if settings.sz == 1:
            rscreen.blit(vscreen, (0, 0))
        else:
            pygame.transform.scale(vscreen, rscreen.get_size(), rscreen)

        length = time.time() - start
        if length > 0:
            pass  # rscreen.blit(get_text("FPS: %.1f" % (1.0 / length), (255, 0, 0), 18), (4, 4))

        pygame.display.flip()
        end = time.time()

        fps = settings.fps
        if "Credits" in str(scene):
            fps = 60
        diff = end - start
        delay = 1.0 / fps - diff
        if delay > 0:
            time.sleep(delay)
        else:
            last_fps = 1.0 / diff

        scene = scene.next
    if settings.dumpmap:
        worldmap.dumpmap()