Browse files

initial commit

  • Loading branch information...
0 parents commit 0425157f6b72fe9b46d0cd72cf88abdc2b8b5ee0 @Fiona committed Feb 27, 2013
Showing with 5,456 additions and 0 deletions.
  1. +143 −0 __main__.py
  2. BIN audio/ambient.ogg
  3. BIN audio/galaxy_travel.wav
  4. BIN audio/mine.wav
  5. BIN audio/survey.wav
  6. BIN audio/system_travel.wav
  7. +63 −0 consts.py
  8. BIN fnt/aurulent.ttf
  9. BIN fnt/bitmap.ttf
  10. BIN fnt/hanzel.ttf
  11. +778 −0 galaxy.py
  12. +148 −0 game_galaxy.py
  13. BIN gfx/cursor.png
  14. BIN gfx/gui/button_generic_background.png
  15. BIN gfx/gui/crew_count.png
  16. BIN gfx/gui/cursor.png
  17. BIN gfx/gui/fuel_meter.png
  18. BIN gfx/gui/money_meter.png
  19. BIN gfx/gui/solar_system_nameplate.png
  20. BIN gfx/space/planet_earth.png
  21. BIN gfx/space/planet_gas_giant.png
  22. BIN gfx/space/planet_rocky.png
  23. BIN gfx/space/planet_rocky2.png
  24. BIN gfx/space/player_ship.png
  25. BIN gfx/space/solar_system.png
  26. BIN gfx/space/starfield.png
  27. +818 −0 gui.py
  28. +507 −0 gui_elements.py
  29. +6 −0 helpers.py
  30. +7 −0 license.txt
  31. +55 −0 media.py
  32. 0 myrmidon/__init__.py
  33. +189 −0 myrmidon/backend_dummy.py
  34. +44 −0 myrmidon/consts.py
  35. 0 myrmidon/engine/__init__.py
  36. 0 myrmidon/engine/audio/__init__.py
  37. 0 myrmidon/engine/audio/pygame/__init__.py
  38. +41 −0 myrmidon/engine/audio/pygame/engine.py
  39. 0 myrmidon/engine/gfx/__init__.py
  40. 0 myrmidon/engine/gfx/modern_opengl/__init__.py
  41. +638 −0 myrmidon/engine/gfx/modern_opengl/engine.py
  42. 0 myrmidon/engine/gfx/modern_opengl/plugins/__init__.py
  43. +206 −0 myrmidon/engine/gfx/modern_opengl/plugins/lighting.py
  44. 0 myrmidon/engine/gfx/opengl/__init__.py
  45. +704 −0 myrmidon/engine/gfx/opengl/engine.py
  46. 0 myrmidon/engine/input/__init__.py
  47. 0 myrmidon/engine/input/pygame/__init__.py
  48. +161 −0 myrmidon/engine/input/pygame/engine.py
  49. 0 myrmidon/engine/window/__init__.py
  50. 0 myrmidon/engine/window/pygame/__init__.py
  51. +123 −0 myrmidon/engine/window/pygame/engine.py
  52. BIN myrmidon/examples/simple_engine_test/profile
  53. BIN myrmidon/examples/simple_engine_test/ship.png
  54. BIN myrmidon/examples/simple_engine_test/shot.png
  55. +132 −0 myrmidon/examples/simple_engine_test/test.py
  56. +675 −0 myrmidon/myrmidon.py
  57. +18 −0 readme.md
143 __main__.py
@@ -0,0 +1,143 @@
+##########
+# LD 22
+# The theme is alone
+# it's a dumb theme
+# fiona wrote this
+##########
+
+# System and Python lib imports
+import sys
+sys.path += ['.']
+
+# Game engine imports
+from myrmidon.myrmidon import MyrmidonGame, MyrmidonProcess
+from myrmidon.consts import *
+from pygame.locals import *
+
+# Game imports
+from consts import *
+from media import Media
+from gui import GUI
+from galaxy import Galaxy
+from game_galaxy import Galaxy_background, Solar_system_star, Player_ship, Galaxy_player_ship
+
+
+class Game(MyrmidonProcess):
+
+ # Current state
+ game_state = 0
+
+ # Player state
+ money = 2000000000
+ fuel = 0
+ crew = 0
+ current_system = "Sol"
+ current_object = "Earth"
+
+ fuel_cost = 1000000000
+ crew_cost = 500000000
+ actions_done = {}
+ home_planet_result = []
+
+ first_time = True
+
+ # Self explanitory object pointers and lists
+ fps_text = None
+ gui = None
+ media = None
+ solar_system_objects = []
+
+ player_ship = None
+ background = None
+ galaxy = None
+
+
+ def execute(self):
+ # Pre launch set-up
+ MyrmidonGame.current_fps = 60
+ self.priority = PRIORITY_MAIN_GAME
+
+ # Load all media
+ self.media = Media()
+ self.media.load_fonts()
+ self.media.load_graphics()
+ self.media.load_audio()
+
+ # Debug display
+ if DEBUG_SHOW_FPS:
+ self.fps_text = MyrmidonGame.write_text(0.0, 0.0, font = self.media.fonts['basic'], text = 0)
+ self.fps_text.colour = (1, 1, 1, 1)
+ self.fps_text.z = -2000
+
+ # Set up starting game objects
+ self.galaxy = Galaxy(self)
+ self.gui = GUI(self)
+ self.switch_game_state_to(GAME_STATE_SOLAR_SYSTEM)
+
+ self.media.audio['ambient'].play(loops = -1)
+
+ while True:
+
+ # update debug display
+ if DEBUG_SHOW_FPS:
+ self.fps_text.text = "fps: " + str(MyrmidonGame.fps)
+
+ yield
+
+
+ def quit_game(self):
+ sys.exit()
+
+
+ def switch_game_state_to(self, state, gui_state = None):
+ """
+ Pass in a state and this will switch to it.
+ It will also clean up everying necessary to go out of the
+ previous game state.
+ """
+ # Undo and destroy everything in the current state
+ self.gui.destroy_current_gui_state()
+ col = (1.0, 1.0, 1.0)
+
+ if self.game_state == GAME_STATE_SOLAR_SYSTEM:
+ for x in self.solar_system_objects:
+ x.signal(S_KILL)
+ self.solar_system_objects = []
+ self.player_ship.signal(S_KILL)
+ self.background.signal(S_KILL)
+ elif self.game_state == GAME_STATE_GALAXY:
+ self.player_ship.signal(S_KILL)
+ self.background.signal(S_KILL)
+
+ # Switch to new state
+ self.game_state = state
+
+ # Create everything we require
+ if state == GAME_STATE_GALAXY:
+ self.background = Galaxy_background(self)
+ self.gui.fade_toggle()
+ self.gui.switch_gui_state_to(GUI_STATE_GALAXY if gui_state is None else gui_state)
+ self.player_ship = Galaxy_player_ship(self)
+ elif state == GAME_STATE_SOLAR_SYSTEM:
+ self.background = Galaxy_background(self)
+ self.solar_system_objects = []
+ self.solar_system_objects.append(Solar_system_star(self, self.galaxy.solar_systems[self.current_system]))
+ self.gui.fade_toggle()
+ self.gui.switch_gui_state_to(GUI_STATE_SOLAR_SYSTEM if gui_state is None else gui_state)
+ self.player_ship = Player_ship(self)
+
+
+ def do_home_planet_results(self):
+ if len(self.home_planet_result) > 0:
+ result = self.home_planet_result.pop()
+ result[0](self, *result[1])
+
+
+
+if __name__ == '__main__':
+ MyrmidonGame.screen_resolution = (1024, 768)
+ MyrmidonGame.lowest_resolution = (1024, 768)
+ MyrmidonGame.full_screen = False
+ Game()
+
+
BIN audio/ambient.ogg
Binary file not shown.
BIN audio/galaxy_travel.wav
Binary file not shown.
BIN audio/mine.wav
Binary file not shown.
BIN audio/survey.wav
Binary file not shown.
BIN audio/system_travel.wav
Binary file not shown.
63 consts.py
@@ -0,0 +1,63 @@
+# Debug values
+DEBUG_SHOW_FPS = True
+
+# States
+GAME_STATE_GALAXY = 1
+GAME_STATE_SOLAR_SYSTEM = 2
+
+# GUI states
+GUI_STATE_GALAXY = 1
+GUI_STATE_SOLAR_SYSTEM = 2
+
+# Z vals
+Z_BACKGROUND = 1000
+Z_GUI = -500
+Z_GUI_CONTAINERS = -550
+Z_GUI_OBJECT_LEVEL_1 = -560
+Z_GUI_OBJECT_LEVEL_2 = -570
+Z_PLAYER_SHIP = -575
+Z_GUI_OBJECT_LEVEL_3 = -580
+Z_GUI_OBJECT_LEVEL_4 = -590
+Z_GUI_OBJECT_LEVEL_5 = -600
+Z_GUI_OBJECT_LEVEL_6 = -610
+Z_GUI_OBJECT_LEVEL_7 = -620
+Z_GUI_OBJECT_LEVEL_8 = -630
+Z_GUI_OBJECT_LEVEL_9 = -640
+Z_GUI_OBJECT_LEVEL_10 = -650
+Z_MOUSE = -1000
+
+# Process priorities
+PRIORITY_MAIN_GAME = 1000
+PRIORITY_GUI_ELEMENTS = 900
+PRIORITY_GUI = 800
+
+# Actions
+ACTION_BUY_CREW = 1
+ACTION_BUY_FUEL = 2
+ACTION_MINE = 3
+ACTION_MINE_GAS = 4
+ACTION_SURVEY_ALPHA_CENTAURI_I = 5
+ACTION_SURVEY_ALPHA_CENTAURI_II = 6
+ACTION_SURVEY_ALPHA_CENTAURI_III = 7
+ACTION_SURVEY_BERNARD_I = 8
+ACTION_SURVEY_LALANDE_21185_II = 9
+ACTION_SURVEY_SIRIUS_I = 10
+ACTION_SURVEY_LUYTEN_726_8_I = 11
+ACTION_SURVEY_EPSILON_ERIDANI_I = 12
+ACTION_SURVEY_EZ_AQUARII_II = 13
+ACTION_SURVEY_PROCYON_II = 14
+ACTION_SURVEY_KRUGER_60_I = 15
+ACTION_SURVEY_STRUVE_2399_I = 16
+
+# Results when we go home
+RESULT_SOLD_RESOURCES = 1
+RESULT_ALPHA_CENTAURI_II = 2
+RESULT_BERNARD_I = 3
+RESULT_SIRIUS_I = 4
+RESULT_LUYTEN_726_8_I = 5
+RESULT_EZ_AQUARII_II = 6
+RESULT_STRUVE_2399_I = 7
+
+# Other consts
+MAX_CREW = 10
+FUEL_COST_TO_LAUNCH = 2
BIN fnt/aurulent.ttf
Binary file not shown.
BIN fnt/bitmap.ttf
Binary file not shown.
BIN fnt/hanzel.ttf
Binary file not shown.
778 galaxy.py
@@ -0,0 +1,778 @@
+
+# Python imports
+import random
+import locale
+
+# Engine imports
+from myrmidon.myrmidon import MyrmidonProcess, MyrmidonGame, MyrmidonError
+from myrmidon.consts import *
+from pygame.locals import *
+
+# OpenGL imports
+from OpenGL.GL import *
+
+# game imports
+from consts import *
+from helpers import *
+from gui_elements import GUI_element_dialog_box
+
+
+class Galaxy(object):
+ solar_systems = {}
+
+ def __init__(self, game):
+ self.game = game
+ locale.setlocale(locale.LC_ALL, '')
+
+ # Create systems
+ # They add themselves to the galaxy
+ Solar_system(self.game, self, "Sol", 445, 305)
+
+ Solar_system(self.game, self, "Alpha Centauri", 480, 250, chance_of_life = 20)
+ Solar_system(self.game, self, "Bernard's Star", 560, 360, chance_of_life = 10)
+ Solar_system(self.game, self, "Wolf 359", 550, 420, chance_of_life = 12)
+ Solar_system(self.game, self, "Lalande 21185", 725, 275, chance_of_life = 30)
+ Solar_system(self.game, self, "Sirius", 610, 510, chance_of_life = 67)
+
+ Solar_system(self.game, self, "Luyten 726-8", 259, 633, chance_of_life = 30)
+ Solar_system(self.game, self, "Epsilon Eridani", 710, 100, chance_of_life = 60)
+ Solar_system(self.game, self, "SCR 1845-6357", 800, 670, chance_of_life = 24)
+ Solar_system(self.game, self, "Tau Ceti", 240, 540, chance_of_life = 75)
+ Solar_system(self.game, self, "GJ 1061", 100, 300, chance_of_life = 18)
+
+ Solar_system(self.game, self, "EZ Aquarii", 820, 600, chance_of_life = 25)
+ Solar_system(self.game, self, "Procyon", 110, 210, chance_of_life = 16)
+ Solar_system(self.game, self, "Kruger 60", 270, 310, chance_of_life = 3)
+ Solar_system(self.game, self, "Struve 2399", 940, 450, chance_of_life = 25)
+
+ # Ross 154
+ # Ross 248
+ # Lacaille 9352
+
+ # Ross 128
+ # 61 Cygni
+ # Struve 2399
+
+ # Groombridge 34
+ # Epsilon Indi
+ # DX Cancri
+
+ # YZ Ceti
+ # Luyten's Star
+ # Teegarden's Star
+ # Kapteyn's Star
+
+ # Lacaille 8760
+ # Ross 614
+ # Wolf 1061
+ # Van Maanen's Star
+
+ # Gilese 1
+ # Wolf 242
+ # TZ Arteris
+ # GJ 687
+ # LHS 292
+
+ # GJ 674
+ # GJ 1245
+ # AD Leonis
+ # GJ 832
+ # LHS 288
+
+
+
+class Solar_system(object):
+ name = "Foo"
+ chance_of_life = 50
+ objects = []
+
+ def __init__(self, game, galaxy, name, x, y, chance_of_life = 50):
+ self.game = game
+ self.galaxy = galaxy
+ self.name = name
+ self.x = x
+ self.y = y
+ self.chance_of_life = chance_of_life
+ self.scale = .3
+ self.colour = (1.0, 1.0, 1.0)
+ self.objects = {}
+
+ self.galaxy.solar_systems[name] = self
+
+ if self.name == "Sol":
+ self.scale = .5
+ self.colour = (1, 1, .6)
+ Planet(
+ self.game, self, distance = 100, name="Venus", image = "rocky", scale = .1,
+ description = [
+ "Although named after the Roman godess of love,",
+ "there is little to love about a planet covered in",
+ "an atmosphere comprised of sulphuric acid."
+ ],
+ actions = {
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (0,)),
+ }
+ )
+ Planet(
+ self.game, self, distance = 150, name="Earth", image = "earth", scale = .15,
+ description = [
+ "Our home planet, as it has been for thousands of years.",
+ "A small green blue marble in the infinite sea of space.",
+ "Could it be that we are alone on our pale blue dot?"
+ ],
+ actions = {
+ "buy_fuel" : Action(self.game, "Fuel - 10 units $" + locale.format("%d", self.game.fuel_cost, grouping=True), "Purchase", ACTION_BUY_FUEL, repeat = True),
+ "buy_crew" : Action(self.game, "Hire crew member - $" + locale.format("%d", self.game.crew_cost, grouping=True), "Purchase", ACTION_BUY_CREW, repeat = True),
+ }
+ )
+ Planet(
+ self.game, self, distance = 250, name="Mars", image = "rocky", scale = .2, colour = (1.0, .3, .3),
+ description = [
+ "The red planet. Once a world covered in water,",
+ "now it is nothing but a desolate wastleland."
+ ],
+ actions = {
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (1,)),
+ }
+ )
+ Planet(
+ self.game, self, distance = 360, name="Jupiter", image = "gas_giant", scale = .4,
+ description = [
+ "The huge gas giant that dwarfs the other",
+ "planets in our solar system.",
+ "It has long served as the Earth's protector against",
+ "sellar objects that would threaten us."
+ ],
+ actions = {
+ "mine_gas" : Action(self.game, "Attempt to mine gas for fuel (DANGEROUS)", "Mine", ACTION_MINE_GAS, repeat = True),
+ }
+ )
+ elif self.name == "Alpha Centauri":
+ self.scale = .2
+ self.colour = (.6, .6, 1)
+ Planet(
+ self.game, self, distance = 75, name="Alpha Centauri I", image = "rocky2", scale = .1, colour = (.2, .2, .2),
+ description = [
+ "This charred husk of a planet is almost certainly", "worthless."
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_ALPHA_CENTAURI_I),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (0,)),
+ }
+ )
+ Planet(
+ self.game, self, distance = 200, name="Alpha Centauri II", image = "rocky", scale = .4, colour = (1.0, 1.0, .6),
+ description = [
+ "An large and completely empty desert planet.", "This planet appears to hold nothing of value."
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_ALPHA_CENTAURI_II),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (0,)),
+ }
+ )
+ Planet(
+ self.game, self, distance = 400, name="Alpha Centauri III", image = "rocky2", scale = .2,
+ description = [
+ "This little rock looks barren.", "It has no atmosphere to speak of."
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_ALPHA_CENTAURI_III),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (3,)),
+ }
+ )
+
+ elif self.name == "Bernard's Star":
+ self.scale = .4
+ self.colour = (.9, 1.0, 1.0)
+ Planet(
+ self.game, self, distance = 300, name="Bernard's Planet", image = "rocky2", scale = .8, colour = (.6, .6, 1.0),
+ description = [
+ "Incredible! This planet is completely covered in a", "deep ocean. Could it hold signs of life?"
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_BERNARD_I),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (0,)),
+ }
+ )
+
+ elif self.name == "Wolf 359":
+ self.scale = .5
+ self.colour = (.9, .8, 1.0)
+ Planet(
+ self.game, self, distance = 250, name="Wolf 359 I", image = "gas_giant", scale = .4, colour = (.5, 1.0, .5),
+ description = [
+ "One of the two gas giants in this system.",
+ "It glows a bright green."
+ ],
+ actions = {
+ "mine_gas" : Action(self.game, "Attempt to mine gas for fuel (DANGEROUS)", "Mine", ACTION_MINE_GAS, repeat = True),
+ }
+ )
+ Planet(
+ self.game, self, distance = 400, name="Wolf 359 II", image = "gas_giant", scale = .8, colour = (.2, .2, .6),
+ description = [
+ "A massive gas giant, it almost seems impossible for", "it to mantain it's orbit around Wolf 359."
+ ],
+ actions = {
+ "mine_gas" : Action(self.game, "Attempt to mine gas for fuel (DANGEROUS)", "Mine", ACTION_MINE_GAS, repeat = True),
+ }
+ )
+
+ elif self.name == "Lalande 21185":
+ self.scale = .2
+ self.colour = (.7, 1.0, 1.0)
+ Planet(
+ self.game, self, distance = 100, name="Lalande 21185 I", image = "rocky", scale = .1, colour = (1.0, 1.0, 1.0),
+ description = [
+ "An unremarkable barren planet. It may be rich in", "resources, however."
+ ],
+ actions = {
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (4,)),
+ }
+ )
+ Planet(
+ self.game, self, distance = 225, name="Lalande 21185 II", image = "rocky", scale = .2, colour = (1.0, .8, 1.0),
+ description = [
+ "A dull looking rock. It has an interesting", " atmosphere that demands further attention."
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_LALANDE_21185_II),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (0,))
+ }
+ )
+ Planet(
+ self.game, self, distance = 300, name="Lalande 21185 III", image = "rocky", scale = .1, colour = (1.0, .8, .8),
+ description = [
+ "Another empty planet."
+ ],
+ actions = {
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (0,))
+ }
+ )
+
+ elif self.name == "Sirius":
+ self.scale = .2
+ self.colour = (1.0, 1.0, 1.0)
+ Planet(
+ self.game, self, distance = 200, name="Sirius I", image = "rocky", scale = .1, colour = (1.0, .6, .9),
+ description = [
+ "An decidedly alien looking, bubble-gum pink planet"
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_SIRIUS_I),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (0,))
+ }
+ )
+ Planet(
+ self.game, self, distance = 350, name="Sirius II", image = "gas_giant", scale = .7, colour = (1.0, 1.0, 1.0),
+ description = [
+ "Yet another unremarkable gas giant."
+ ],
+ actions = {
+ "mine_gas" : Action(self.game, "Attempt to mine gas for fuel (DANGEROUS)", "Mine", ACTION_MINE_GAS, repeat = True),
+ }
+ )
+
+ elif self.name == "Luyten 726-8":
+ self.scale = .3
+ self.colour = (1.0, 1.0, 1.0)
+ Planet(
+ self.game, self, distance = 220, name="Luyten 726-8 I", image = "rocky", scale = .2, colour = (.8, 1.0, .8),
+ description = [
+ "At first we think the scanners are malfunctioning", "but we soon confirm that this planet", "is covered in a massive jungle!"
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_LUYTEN_726_8_I),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (0,))
+ }
+ )
+ Planet(
+ self.game, self, distance = 350, name="Luyten 726-8 II", image = "gas_giant", scale = .7, colour = (1.0, 1.0, 1.0),
+ description = [
+ "Yet another unremarkable gas giant."
+ ],
+ actions = {
+ "mine_gas" : Action(self.game, "Attempt to mine gas for fuel (DANGEROUS)", "Mine", ACTION_MINE_GAS, repeat = True),
+ }
+ )
+
+ elif self.name == "Epsilon Eridani":
+ self.scale = .3
+ self.colour = (1.0, 1.0, .7)
+ Planet(
+ self.game, self, distance = 220, name="Epsilon Eridani I", image = "rocky", scale = .3, colour = (.6, .2, .2),
+ description = [
+ "A very hot planet, it almost seems to be bubbling", "even from looking at the satellite images."
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_EPSILON_ERIDANI_I),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (2,))
+ }
+ )
+
+ elif self.name == "EZ Aquarii":
+ self.scale = .3
+ self.colour = (1.0, .7, .7)
+ Planet(
+ self.game, self, distance = 200, name="EZ Aquarii I", image = "rocky", scale = .3, colour = (1.0, 1.0, 1.0),
+ description = [
+ "An unremarkable barren planet. It may be rich in", "resources, however."
+ ],
+ actions = {
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (2,)),
+ }
+ )
+ Planet(
+ self.game, self, distance = 280, name="EZ Aquarii II", image = "rocky", scale = .2, colour = (.2, .2, .2),
+ description = [
+ "A dark planet. Our readings suggest a hollow crust.", "We should investigate further."
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_EZ_AQUARII_II),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (0,)),
+ }
+ )
+
+ elif self.name == "Procyon":
+ self.scale = .3
+ self.colour = (1.0, .7, .7)
+ Planet(
+ self.game, self, distance = 350, name="Procyon III", image = "gas_giant", scale = .7, colour = (1.0, 1.0, 1.0),
+ description = [
+ "Yet another unremarkable gas giant."
+ ],
+ actions = {
+ "mine_gas" : Action(self.game, "Attempt to mine gas for fuel (DANGEROUS)", "Mine", ACTION_MINE_GAS, repeat = True),
+ }
+ )
+ Planet(
+ self.game, self, distance = 100, name="Procyon I", image = "rocky", scale = .3, colour = (1.0, 1.0, 1.0),
+ description = [
+ "An unremarkable barren planet. It may be rich in", "resources, however."
+ ],
+ actions = {
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (2,)),
+ }
+ )
+ Planet(
+ self.game, self, distance = 100, name="Procyon II", image = "rocky2", scale = .3, colour = (1.0, 1.0, .2),
+ description = [
+ "This planet has a strange atmosphere."
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_PROCYON_II),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (1,)),
+ }
+ )
+
+ elif self.name == "Kruger 60":
+ self.scale = .4
+ self.colour = (.6, .7, 1.0)
+ Planet(
+ self.game, self, distance = 200, name="Kruger 60 I", image = "rocky", scale = .4, colour = (1.0, 1.0, .2),
+ description = [
+ "An unremarkable barren planet. It may be rich in", "resources, however."
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_KRUGER_60_I),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (1,)),
+ }
+ )
+ Planet(
+ self.game, self, distance = 250, name="Kruger 60 II", image = "rocky", scale = .2, colour = (1.0, 1.0, .5),
+ description = [
+ "An unremarkable barren planet. It may be rich in", "resources, however."
+ ],
+ actions = {
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (0,)),
+ }
+ )
+
+ elif self.name == "Struve 2399":
+ self.scale = .4
+ self.colour = (.6, .7, 1.0)
+ Planet(
+ self.game, self, distance = 200, name="Struve 2399 I", image = "rocky2", scale = .3, colour = (.5, .5, .8),
+ description = [
+ "An unremarkable barren planet. It may be rich in", "resources, however."
+ ],
+ actions = {
+ "survey" : Action(self.game, "Survey planet", "Survey", ACTION_SURVEY_STRUVE_2399_I),
+ "mine" : Action(self.game, "Mine planet for resources", "Mine", ACTION_MINE, args = (2,)),
+ }
+ )
+ Planet(
+ self.game, self, distance = 400, name="Struve 2399 II", image = "gas_giant", scale = .4,
+ description = [
+ "A large gas giant, appearing to", "protect the other planet in the system.", "Much like Jupiter."
+ ],
+ actions = {
+ "mine_gas" : Action(self.game, "Attempt to mine gas for fuel (DANGEROUS)", "Mine", ACTION_MINE_GAS, repeat = True),
+ }
+ )
+
+
+
+class Planet(object):
+ def __init__(self, game, solar_system, distance = 100, name = "Foo", image = "rocky", scale = .5, colour = (1, 1, 1), description = [], actions = {}):
+ self.game = game
+ self.solar_system = solar_system
+ self.distance = distance
+ self.name = name
+ self.image = image
+ self.scale = scale
+ self.colour = colour
+ self.description = description
+ self.x, self.y = MyrmidonGame.move_forward((MyrmidonGame.screen_resolution[0] / 2, MyrmidonGame.screen_resolution[1] / 2), self.distance, random.randrange(0, 360))
+ self.actions = actions
+
+ self.solar_system.objects[name] = self
+
+
+
+class Action(object):
+
+ def __init__(self, game, description, button_text, action_type, repeat = False, args = ()):
+ self.game = game
+ self.description = description
+ self.button_text = button_text
+ self.action_type = action_type
+ self.repeat = repeat
+ self.args = args
+
+
+ def do_action(self):
+ if self.game.crew == 0 and self.action_type not in (ACTION_BUY_CREW, ACTION_BUY_FUEL):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Cannot do action",
+ message = ["You require a crew to do anything."]
+ )
+ return
+
+ self.actions_to_method[self.action_type](self, *self.args)
+ if not self.game.current_system in self.game.actions_done:
+ self.game.actions_done[self.game.current_system] = {}
+ if not self.game.current_object in self.game.actions_done[self.game.current_system]:
+ self.game.actions_done[self.game.current_system][self.game.current_object] = []
+ self.game.actions_done[self.game.current_system][self.game.current_object].append(self.action_type)
+
+
+ # actions
+
+
+ def action_buy_fuel(self):
+ if self.game.money >= self.game.fuel_cost and self.game.fuel < 100:
+ self.game.money -= self.game.fuel_cost
+ self.game.fuel += 10
+ if self.game.fuel > 100:
+ self.game.fuel = 100
+
+
+ def action_buy_crew(self):
+ if self.game.money >= self.game.crew_cost and self.game.crew < MAX_CREW:
+ self.game.money -= self.game.crew_cost
+ self.game.crew += 1
+
+
+ def action_mine(self, amount_to_mine = 0):
+ if amount_to_mine == 0:
+ message = ["Attempting to mine the planet yields no useful resources."]
+ else:
+ message = ["Mining the planet yields a number of plentiful resources.", "Selling them on Earth will provide money, useful for later expeditions."]
+ self.game.home_planet_result.append((self.results_to_method[RESULT_SOLD_RESOURCES], (self.game.current_object, amount_to_mine)))
+
+ if random.random() > .80:
+ self.game.crew -= 1
+ message.append("During the mining process one of your crew members was tragically killed.")
+
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Mining result",
+ message = message
+ )
+
+ self.game.media.audio['mine'].play()
+
+
+ def action_mine_gas(self):
+ self.game.fuel += 5
+ if self.game.fuel > 100:
+ self.game.fuel = 100
+ message = ["You mine 5 units of fuel from the planet's atmosphere."]
+
+ if random.random() > .50:
+ self.game.crew -= 1
+ message.append("During the mining process one of your crew members was tragically killed.")
+
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Mining result",
+ message = message
+ )
+
+
+ def action_survey_alpha_centauri_i(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["The heat from Alpha Centauri causes the space suit of one of your", "crew to explode in flames and he burns to death.", "The survey mission is permanently called off as a result."]
+ )
+ self.game.crew -= 1
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_alpha_centauri_ii(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["As expected, the planet is devoid of anything of value.", "Some rocks are gathered to take back to Earth."]
+ )
+ self.game.home_planet_result.append( (self.results_to_method[RESULT_ALPHA_CENTAURI_II], ()) )
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_alpha_centauri_iii(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["A survey of the planet's crust yields a heavy metal content, making the planet ripe for mining."]
+ )
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_bernard_i(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["The initial excitement of discovering this planet subsided as a complete survey", "of the planet found it held no life at all.", "The temperature of the water is too warm to contain any life. It's nearly boiling!", "We have gathered some of the planet's water to take back with us."]
+ )
+ self.game.home_planet_result.append( (self.results_to_method[RESULT_BERNARD_I], ()) )
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_lalande_21185_ii(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["Indeed, the planet's atmosphere was interesting. Appearing to", "be made up of a gaseous lead-like compound.", "Not long after the planet survey started, rain began to fall.", "It was not long before it became apparent that the rain was", "infact solid lead pellets.", "While fleeing the planet, one of the survey team was struck", "by a particularly large chunk and died immediately."]
+ )
+ self.game.crew -= 1
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_sirius_i(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["Although a very pretty planet, the survey yielded no interesting results.", "Of note is that crewman Matthews has decided to dub the newly", "discovered planet 'Cassidy' in honour of his daughter back home."]
+ )
+ self.game.home_planet_result.append( (self.results_to_method[RESULT_SIRIUS_I], ()) )
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_luyten_726_8_i(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["The planet is covered in hundreds of thousands of different species", "of plant-life. Although not intelligent life, this is still an", "important and unprecedented find!", "Unfortunately, during the survey a massive Venus-flytrap-like plant swallowed", "and digested a crewman whole.", "We should get these plant samples back home to ensure his death was not in vain."]
+ )
+ self.game.home_planet_result.append( (self.results_to_method[RESULT_LUYTEN_726_8_I], ()) )
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_epsilon_eridani_i(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["This is a rocky planet covered in seas and rivers of molten lava.", "Our scans indicate huge shafts, leading down to the", "core of the planet that are open on the surface.", "The survey team witness the spectacular display of one of these shafts erupting,", "but barely escape with their lives and decide to call off the survey mission"]
+ )
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_ez_aquarii_ii(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["The survey finds that the crust of the planet is not so hollow. Infact we quickly discover,", "to our excitement and surprise, that a large portion of the structure is organic.", "It transpires that the entire undecrust of the planet is a massive species of fungii!", "Indeed, there appears to be a single organism encompassing the entire mass.", "This is the largest single organism ever discovered in history!", "We should report our findings back home."]
+ )
+ self.game.home_planet_result.append( (self.results_to_method[RESULT_EZ_AQUARII_II], ()) )
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_procyon_ii(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["Initially the survey seemed fine. Samples of the soil and atmosphere were taken and the team", "returned to the ship. After a couple of hours the members of the survey team started to act oddly.", "They exhibited symptoms of extreme paranoia and distrust.", "It was too late to help a small number of crewmen before it was discovered", "that a toxin in the atmosphere of the planet somehow infected them.", "They were found to have commited suicide."]
+ )
+ self.game.crew -= 3
+ if self.game.crew < 0:
+ self.game.crew = 0
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_kruger_60_i(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["This planet is very interesting indeed, a huge section of the crust appears to have been dug out.", "The long, winding tunnels remind of ants nests.", "Unfortunately, we have discovered that the tunnels are natural, formed by", "flowing water that has long since vanished."]
+ )
+ self.game.media.audio['survey'].play()
+
+
+ def action_survey_struve_2399_i(self):
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Survey result",
+ message = ["At first we were ready to dismiss this planet. Although it had some interesting vegitation,", "once we got to the surface we made the most incredible discovery of our lives.", "We saw beasts, the likes of which we have never seen. And hundreds of incredible insects flying", "past our heads.", "Although we were already over the moon, nothing could have prepared us for what we found next.", "", "We observed a group of intelligent extra terrestrials.", "They appeared to be in a tribal stage of development.", "We did not introduce ourselves and only watched from afar.", "That is far out of our league. Still, we MUST make it back home to report our findings."]
+ )
+ self.game.home_planet_result.append((self.results_to_method[RESULT_STRUVE_2399_I], ()))
+ self.game.media.audio['survey'].play()
+
+
+ actions_to_method = {
+ ACTION_BUY_FUEL : action_buy_fuel,
+ ACTION_BUY_CREW : action_buy_crew,
+ ACTION_MINE : action_mine,
+ ACTION_MINE_GAS : action_mine_gas,
+ ACTION_SURVEY_ALPHA_CENTAURI_I : action_survey_alpha_centauri_i,
+ ACTION_SURVEY_ALPHA_CENTAURI_II : action_survey_alpha_centauri_ii,
+ ACTION_SURVEY_ALPHA_CENTAURI_III : action_survey_alpha_centauri_iii,
+ ACTION_SURVEY_BERNARD_I : action_survey_bernard_i,
+ ACTION_SURVEY_LALANDE_21185_II : action_survey_lalande_21185_ii,
+ ACTION_SURVEY_SIRIUS_I : action_survey_sirius_i,
+ ACTION_SURVEY_LUYTEN_726_8_I : action_survey_luyten_726_8_i,
+ ACTION_SURVEY_EPSILON_ERIDANI_I : action_survey_epsilon_eridani_i,
+ ACTION_SURVEY_EZ_AQUARII_II : action_survey_ez_aquarii_ii,
+ ACTION_SURVEY_PROCYON_II : action_survey_procyon_ii,
+ ACTION_SURVEY_KRUGER_60_I : action_survey_kruger_60_i,
+ ACTION_SURVEY_STRUVE_2399_I : action_survey_struve_2399_i,
+ }
+
+
+ # Home planet results
+
+
+ def result_sold_resources(game, planet_name, amount_sold):
+ money_yield = 1500020407 * amount_sold
+ game.money += money_yield
+
+ GUI_element_dialog_box(
+ game,
+ game.gui.parent_window,
+ title = "Result",
+ message = ["Selling the resources gathered from " + planet_name, "nets $" + locale.format("%d", money_yield, grouping=True) + "."],
+ confirm_callback = game.do_home_planet_results
+ )
+
+
+ def result_alpha_centauri_ii(game):
+ money_yield = 500053031
+ game.money += money_yield
+
+ GUI_element_dialog_box(
+ game,
+ game.gui.parent_window,
+ title = "Result",
+ message = ["The rocks you brought back from Alpha Centauri II go down a", "treat with the boys back home.", "A small amount of money has been donated."],
+ confirm_callback = game.do_home_planet_results
+ )
+
+
+ def result_bernard_i(game):
+ money_yield = 2040043732
+ game.money += money_yield
+
+ GUI_element_dialog_box(
+ game,
+ game.gui.parent_window,
+ title = "Result",
+ message = ["After examination, the water you brought back from Bernard's Planet apparently exhibited", "some extraordinary properties.", "Immediately after this news was delivered to your team a group of government agents arrived.", "They sieze the water sample and offer your team a large amount of money in exchange for", "your silence on the matter.", "Naturally, you comply."],
+ confirm_callback = game.do_home_planet_results
+ )
+
+
+ def result_sirius_i(game):
+ GUI_element_dialog_box(
+ game,
+ game.gui.parent_window,
+ title = "Result",
+ message = ["After finding about the planet named after her in the Sirius system, Cassidy Matthews", "has sent the whole team a big thank you card.", "That was nice."],
+ confirm_callback = game.do_home_planet_results
+ )
+
+
+ def result_luyten_726_8_i(game):
+ money_yield = 4040043732
+ game.money += money_yield
+
+ message = ["The discovery of the jungle planet of Luyten 726-8 I has been hailed", "as one of the most important of our time.", "As a result a significant injection of funds has been pumped into the project."]
+
+ if game.crew < MAX_CREW:
+ message.append("A very influential scientist has also joined the crew on the back of this.")
+ game.crew += 1
+
+ GUI_element_dialog_box(
+ game,
+ game.gui.parent_window,
+ title = "Result",
+ message = message,
+ confirm_callback = game.do_home_planet_results
+ )
+
+
+ def result_ez_aquarii_ii(game):
+ money_yield = 1040043732
+ game.money += money_yield
+
+ message = ["Although the team attempted to explain the importance of finding", "the huge fungii organism on EZ Aquarii II, it transpires", "that fungii just doesn't excite people as much as it should.", "No amount of graphs and charts could convince your benefactors to give a", "larger budget, they instead gave you a small amount just", "to get yout out of the boardroom."]
+
+ GUI_element_dialog_box(
+ game,
+ game.gui.parent_window,
+ title = "Result",
+ message = message,
+ confirm_callback = game.do_home_planet_results
+ )
+
+
+ def result_struve_2399_i(game):
+ money_yield = 100040043732
+ game.money += money_yield
+
+ message = ["It's been a week since we returned from our discovery at Struve 2399.", "Images and videos of the lifeforms have been shown all over the world.", "Now everyone knows, WE ARE NOT ALONE.", "Untold riches are now ours from countless interviews, book deals and guest lectures.", "But, there's still a galaxy out there to explore.", "Somehow it doesn't seem right to leave it alone.", "", "", "[YOU WIN! THANKS FOR PLAYING!]"]
+
+ GUI_element_dialog_box(
+ game,
+ game.gui.parent_window,
+ title = "Result",
+ message = message,
+ confirm_callback = game.do_home_planet_results
+ )
+
+
+ results_to_method = {
+ RESULT_SOLD_RESOURCES : result_sold_resources,
+ RESULT_ALPHA_CENTAURI_II : result_alpha_centauri_ii,
+ RESULT_BERNARD_I : result_bernard_i,
+ RESULT_SIRIUS_I : result_sirius_i,
+ RESULT_LUYTEN_726_8_I : result_luyten_726_8_i,
+ RESULT_EZ_AQUARII_II : result_ez_aquarii_ii,
+ RESULT_STRUVE_2399_I : result_struve_2399_i,
+ }
148 game_galaxy.py
@@ -0,0 +1,148 @@
+
+# Engine imports
+from myrmidon.myrmidon import MyrmidonProcess, MyrmidonGame, MyrmidonError
+from myrmidon.consts import *
+from pygame.locals import *
+
+# OpenGL imports
+from OpenGL.GL import *
+
+# game imports
+from consts import *
+from helpers import *
+from gui import GUI_solar_system_landed_menu
+
+
+class Galaxy_background(MyrmidonProcess):
+ def execute(self, game):
+ self.game = game
+ self.z = Z_BACKGROUND
+ while True:
+ yield
+
+
+ def draw(self):
+ glPushMatrix()
+ glColor4f(1.0, 1.0, 1.0, 1.0)
+ glEnable(GL_TEXTURE_2D)
+ glBindTexture(GL_TEXTURE_2D, self.game.media.graphics['space']['starfield'].surfaces[0])
+ MyrmidonGame.engine['gfx'].last_image = self.game.media.graphics['space']['starfield'].surfaces[0]
+ MyrmidonGame.engine['gfx'].draw_textured_quad(MyrmidonGame.screen_resolution[0], MyrmidonGame.screen_resolution[1], repeat = self.game.media.graphics['space']['starfield'])
+ glPopMatrix()
+
+
+
+
+class Solar_system_star(MyrmidonProcess):
+ def execute(self, game, solar_system):
+ self.game = game
+ self.z = Z_GUI_OBJECT_LEVEL_1
+ self.image = self.game.media.graphics['space']['solar_system']
+ self.x = MyrmidonGame.screen_resolution[0]/2
+ self.y = MyrmidonGame.screen_resolution[1]/2
+ self.colour = solar_system.colour
+ while True:
+ yield
+
+
+ def get_screen_draw_position(self):
+ return self.x - (self.image.width/2), self.y - (self.image.height/2)
+
+
+
+class Player_ship(MyrmidonProcess):
+ do_travel_to = None
+
+ def execute(self, game):
+ self.game = game
+ if self.game.current_object is None:
+ self.x = MyrmidonGame.screen_resolution[0] / 2
+ self.y = MyrmidonGame.screen_resolution[1] - 100
+ self.rotation = -90
+ else:
+ current_object = self.game.galaxy.solar_systems[self.game.current_system].objects[self.game.current_object]
+ self.x, self.y = current_object.x, current_object.y
+ self.z = Z_PLAYER_SHIP
+ self.image = self.game.media.graphics['space']['player_ship']
+ while True:
+
+ if not self.do_travel_to is None and self.game.fuel >= 0:
+ rotation_towards_target = MyrmidonGame.angle_between_points(
+ (self.x, self.y),
+ (self.do_travel_to[1].x, self.do_travel_to[1].y)
+ )
+ self.rotation = MyrmidonGame.near_angle(
+ self.rotation,
+ rotation_towards_target,
+ 2.0
+ )
+ self.move_forward(1.0)
+ if self.get_distance((self.do_travel_to[1].x, self.do_travel_to[1].y)) < 8 :
+ self.game.current_object = self.do_travel_to[1].name
+ self.do_travel_to = None
+ GUI_solar_system_landed_menu(self.game, self.game.gui.current_visible_gui_elements[GUI_STATE_SOLAR_SYSTEM]['container'])
+ self.game.gui.block_gui_mouse_input = False
+ MyrmidonGame.engine['input'].mouse.alpha = 1.0
+
+ self.travel_time += 1
+ if self.travel_time == 360:
+ self.travel_time = 0
+ self.game.fuel -= 1
+
+ yield
+
+
+ def get_screen_draw_position(self):
+ return self.x - (self.image.width/2), self.y - (self.image.height/2)
+
+
+ def travel_to(self, solar_system_object, object_object):
+ self.travel_time = 0
+ self.do_travel_to = (solar_system_object, object_object)
+
+
+
+class Galaxy_player_ship(MyrmidonProcess):
+ do_travel_to = None
+
+ def execute(self, game):
+ self.game = game
+ current_system = self.game.galaxy.solar_systems[self.game.current_system]
+ self.x, self.y = current_system.x, current_system.y
+ self.z = Z_PLAYER_SHIP
+ self.image = self.game.media.graphics['space']['player_ship']
+ while True:
+
+ if not self.do_travel_to is None and self.game.fuel >= 0:
+ rotation_towards_target = MyrmidonGame.angle_between_points(
+ (self.x, self.y),
+ (self.do_travel_to.x, self.do_travel_to.y)
+ )
+ self.rotation = MyrmidonGame.near_angle(
+ self.rotation,
+ rotation_towards_target,
+ 1.0
+ )
+ self.move_forward(.5)
+ if self.get_distance((self.do_travel_to.x, self.do_travel_to.y)) < 8 :
+ self.game.current_system = self.do_travel_to.name
+ self.do_travel_to = None
+ self.game.gui.block_gui_mouse_input = False
+ MyrmidonGame.engine['input'].mouse.alpha = 1.0
+ self.game.gui.fade_toggle(callback = lambda: self.game.switch_game_state_to(GAME_STATE_SOLAR_SYSTEM))
+
+ self.travel_time += 1
+ if self.travel_time == 60:
+ self.travel_time = 0
+ self.game.fuel -= 1
+
+ yield
+
+
+ def get_screen_draw_position(self):
+ return self.x - (self.image.width/2), self.y - (self.image.height/2)
+
+
+ def travel_to(self, solar_system_object):
+ self.travel_time = 0
+ self.do_travel_to = solar_system_object
BIN gfx/cursor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/gui/button_generic_background.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/gui/crew_count.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/gui/cursor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/gui/fuel_meter.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/gui/money_meter.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/gui/solar_system_nameplate.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/space/planet_earth.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/space/planet_gas_giant.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/space/planet_rocky.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/space/planet_rocky2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/space/player_ship.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/space/solar_system.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN gfx/space/starfield.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
818 gui.py
@@ -0,0 +1,818 @@
+
+# Python imports
+import locale
+
+# Engine imports
+from myrmidon.myrmidon import MyrmidonProcess, MyrmidonGame, MyrmidonError
+from myrmidon.consts import *
+from pygame.locals import *
+
+# OpenGL imports
+from OpenGL.GL import *
+
+# game imports
+from consts import *
+from helpers import *
+from gui_elements import GUI_element, GUI_element_window, GUI_element_button, GUI_element_dialog_box
+
+
+class GUI(MyrmidonProcess):
+ gui_state = None
+
+ current_visible_gui_elements = {
+ GUI_STATE_GALAXY : {},
+ GUI_STATE_SOLAR_SYSTEM : {}
+ }
+
+ current_game_state_gui_ticks = 0
+
+ parent_window = None
+
+ block_gui_keyboard_input = False
+
+ block_gui_mouse_input = False
+
+ fading = None
+ fade_to = 0.0
+ fade_speed = 50
+ fading_done = False
+ fading_callback = None
+
+
+ def execute(self, game):
+ self.game = game
+ self.alpha = 1.0
+ self.fading = 1.0
+ self.fade_to = 0
+ self.fading_done = True
+ self.z = -5000
+ self.priority = PRIORITY_GUI
+ locale.setlocale(locale.LC_ALL, '')
+
+ while True:
+ self.current_game_state_gui_ticks += 1
+
+ # Specific state input
+ if self.game.game_state == GAME_STATE_GALAXY:
+ """
+ GALAXY VIEW
+ """
+ if not self.block_gui_keyboard_input:
+ # Quit on escape
+ if MyrmidonGame.engine['input'].keyboard_key_released(K_ESCAPE):
+ self.game.quit_game()
+ elif self.game.game_state == GAME_STATE_SOLAR_SYSTEM:
+ """
+ SOLAR SYSTEM VIEW
+ """
+ if not self.block_gui_keyboard_input:
+ # Quit on escape
+ if MyrmidonGame.engine['input'].keyboard_key_released(K_ESCAPE):
+ self.game.quit_game()
+
+ # Handle overall gui input
+ if not self.parent_window is None and not self.block_gui_mouse_input:
+ mouse_over = self.parent_window.handle_input((MyrmidonGame.engine['input'].mouse.x, MyrmidonGame.engine['input'].mouse.y))
+ if not mouse_over is None and not MyrmidonGame.engine['input'].disable_input:
+
+ if not mouse_over._currently_hovered:
+ mouse_over.mouse_enter()
+ mouse_over._currently_hovered = True
+
+ mouse_over.mouse_over()
+
+ if MyrmidonGame.engine['input'].mouse.left:
+ mouse_over.mouse_left_down()
+ elif MyrmidonGame.engine['input'].mouse.left_up:
+ mouse_over.mouse_left_up()
+
+ if MyrmidonGame.engine['input'].mouse.right:
+ mouse_over.mouse_right_down()
+ elif MyrmidonGame.engine['input'].mouse.right_up:
+ mouse_over.mouse_right_up()
+
+ if MyrmidonGame.engine['input'].mouse.middle:
+ mouse_over.mouse_middle_down()
+ elif MyrmidonGame.engine['input'].mouse.middle_up:
+ mouse_over.mouse_middle_up()
+
+ if MyrmidonGame.engine['input'].mouse.wheel_down:
+ mouse_over.mouse_wheel_down()
+ elif MyrmidonGame.engine['input'].mouse.wheel_up:
+ mouse_over.mouse_wheel_up()
+
+ # Handle the fading stuff
+ if not self.fading == None and self.fading_done == False:
+ for i in range(self.fade_speed):
+ self.alpha = lerp(i, self.fade_speed, self.fading, self.fade_to)
+ yield
+ self.fading = None
+ self.fading_done = True
+ if not self.fading_callback == None:
+ self.fading_callback()
+
+ yield
+
+
+ def draw(self):
+ if self.alpha > 0:
+ MyrmidonGame.engine['gfx'].draw_rectangle((0,0), (MyrmidonGame.screen_resolution[0], MyrmidonGame.screen_resolution[1]), colour = (0.0, 0.0, 0.0, self.alpha), filled = True)
+
+
+ def switch_gui_state_to(self, state):
+ self.destroy_current_gui_state()
+ self.gui_state = state
+ self.current_game_state_gui_ticks = 0
+ self.parent_window = None
+
+ MyrmidonGame.engine['input'].mouse.visible = False
+ MyrmidonGame.engine['input'].mouse.z = Z_MOUSE
+ MyrmidonGame.engine['input'].mouse.image = self.game.media.graphics['gui']['cursor']
+
+ if self.gui_state == GUI_STATE_GALAXY:
+ self.current_visible_gui_elements[GUI_STATE_GALAXY]['galaxy_container'] = GUI_galaxy_container(self.game)
+ self.parent_window = self.current_visible_gui_elements[GUI_STATE_GALAXY]['galaxy_container']
+ #self.current_visible_gui_elements[GUI_STATE_GALAXY]['fuel_meter'] = GUI_fuel_meter(self.game, self.parent_window)
+ #self.current_visible_gui_elements[GUI_STATE_GALAXY]['money_meter'] = GUI_money_meter(self.game, self.parent_window)
+ #self.current_visible_gui_elements[GUI_STATE_GALAXY]['crew_meter'] = GUI_crew_meter(self.game, self.parent_window)
+ elif self.gui_state == GUI_STATE_SOLAR_SYSTEM:
+ self.current_visible_gui_elements[GUI_STATE_SOLAR_SYSTEM]['container'] = GUI_solar_system_container(self.game)
+ self.parent_window = self.current_visible_gui_elements[GUI_STATE_SOLAR_SYSTEM]['container']
+ self.current_visible_gui_elements[GUI_STATE_SOLAR_SYSTEM]['fuel_meter'] = GUI_fuel_meter(self.game, self.parent_window)
+ self.current_visible_gui_elements[GUI_STATE_SOLAR_SYSTEM]['money_meter'] = GUI_money_meter(self.game, self.parent_window)
+ self.current_visible_gui_elements[GUI_STATE_SOLAR_SYSTEM]['crew_meter'] = GUI_crew_meter(self.game, self.parent_window)
+
+
+ def destroy_current_gui_state(self):
+ if self.gui_state is None:
+ return
+ for x in self.current_visible_gui_elements[self.gui_state]:
+ self.current_visible_gui_elements[self.gui_state][x].signal(S_KILL)
+ self.current_visible_gui_elements[self.gui_state] = {}
+
+
+ def fade_toggle(self, callback = None, speed = 15, colour = (0.0, 0.0, 0.0)):
+ if not self.fading_done:
+ return
+
+ self.fade_speed = speed
+ self.fading_callback = callback
+ self.fading = self.alpha
+ self.fade_colour = colour
+ self.fade_to = 1.0 if self.fading < 1.0 else 0.0
+ self.fading_done = False
+
+
+
+###################################################################################################
+###################################################################################################
+###################################### COMMON GUI #################################################
+###################################################################################################
+###################################################################################################
+
+
+
+class GUI_fuel_meter(GUI_element):
+ def execute(self, game, parent = None):
+ self.game = game
+ self.parent = parent
+ self.image = self.game.media.graphics['gui']['fuel_meter']
+ self.y = 5
+ self.z = Z_GUI_OBJECT_LEVEL_8
+ self.bar_width = 185.0
+ self.init()
+ while True:
+ self.update()
+ yield
+
+
+ def draw(self):
+ width = (self.bar_width / 100) * self.game.fuel
+ if width > 1:
+ MyrmidonGame.engine['gfx'].draw_rectangle(
+ (self.x + 152, self.y + 20),
+ (self.x + 152 + width, self.y + 20 + 11),
+ colour = (.6, 1.0, 0.0, .5),
+ filled = True
+ )
+
+
+
+class GUI_money_meter(GUI_element):
+ def execute(self, game, parent = None):
+ self.game = game
+ self.parent = parent
+ self.image = self.game.media.graphics['gui']['money_meter']
+ self.y = MyrmidonGame.screen_resolution[1] - 55
+ self.width = 400
+ self.height = 50
+ self.z = Z_GUI_OBJECT_LEVEL_8
+ self.text = MyrmidonGame.write_text(self.x + 200, self.y + 8, font = self.game.media.fonts['money_meter'], text = "")
+ self.text.z = self.z
+ self.text.colour = (.8, .5, 0)
+ self.init()
+ while True:
+ self.update()
+ self.text.text = "$" + locale.format("%d", self.game.money, grouping=True)
+ yield
+
+
+ def on_exit(self):
+ GUI_element.on_exit(self)
+ self.text.signal(S_KILL)
+
+
+
+class GUI_crew_meter(GUI_element):
+ def execute(self, game, parent = None):
+ self.game = game
+ self.parent = parent
+ self.x = 7
+ self.y = 60
+ self.z = Z_GUI_OBJECT_LEVEL_8
+ self.text = MyrmidonGame.write_text(self.x, self.y, font = self.game.media.fonts['crew_meter'], text = "CREW COUNT")
+ self.text.z = self.z
+ self.text.colour = (1.0, .45, 0)
+ self.init()
+ while True:
+ self.update()
+ yield
+
+
+ def draw(self):
+ if self.game.crew == 0:
+ return
+
+ glPushMatrix()
+ glColor4f(1.0, 1.0, 1.0, 1.0)
+ glEnable(GL_TEXTURE_2D)
+ glBindTexture(GL_TEXTURE_2D, self.game.media.graphics['gui']['crew_count'].surfaces[0])
+ MyrmidonGame.engine['gfx'].last_image = self.game.media.graphics['gui']['crew_count'].surfaces[0]
+ glTranslatef(220.0, 62.0, 0)
+ for x in range(self.game.crew):
+ MyrmidonGame.engine['gfx'].draw_textured_quad(self.game.media.graphics['gui']['crew_count'].width, self.game.media.graphics['gui']['crew_count'].width)
+ glTranslatef(12.0, 0, 0)
+ glPopMatrix()
+
+
+ def on_exit(self):
+ GUI_element.on_exit(self)
+ self.text.signal(S_KILL)
+
+
+
+
+###################################################################################################
+###################################################################################################
+###################################### GALAXY VIEW ################################################
+###################################################################################################
+###################################################################################################
+
+
+
+class GUI_galaxy_container(GUI_element):
+ """
+ All elements in the galaxy view live inside this thing.
+ """
+ def execute(self, game, parent = None):
+ self.game = game
+ self.parent = parent
+ self.init()
+ self.z = Z_GUI_CONTAINERS
+ self.width = MyrmidonGame.screen_resolution[0]
+ self.height = MyrmidonGame.screen_resolution[1]
+
+ # Create kids
+ for star_name in self.game.galaxy.solar_systems:
+ GUI_galaxy_solar_system(self.game, self, self.game.galaxy.solar_systems[star_name])
+
+ GUI_fuel_meter(self.game, self)
+ GUI_money_meter(self.game, self)
+ GUI_crew_meter(self.game, self)
+
+ while True:
+ self.update()
+ yield
+
+
+
+class GUI_galaxy_solar_system(GUI_element):
+ def execute(self, game, parent, solar_system):
+ self.game = game
+ self.parent = parent
+ self.solar_system = solar_system
+ self.z = Z_GUI_OBJECT_LEVEL_1
+ self.image = self.game.media.graphics['space']['solar_system']
+ self.x = self.solar_system.x
+ self.y = self.solar_system.y
+ self.scale = self.solar_system.scale
+ self.colour = self.solar_system.colour
+ self.width = self.image.width
+ self.height = self.image.height
+ self.init()
+ self.nameplate = None
+ while True:
+ self.update()
+ yield
+
+
+ def mouse_left_up(self):
+ self.game.gui.block_gui_mouse_input = True
+ MyrmidonGame.engine['input'].mouse.alpha = 0
+ self.game.player_ship.travel_to(self.solar_system)
+ self.game.media.audio['galaxy_travel'].play()
+
+
+ def mouse_not_over(self):
+ self.scale = self.solar_system.scale
+ if not self.nameplate is None:
+ self.nameplate.die()
+ self.nameplate = None
+
+
+ def mouse_over(self):
+ self.scale = self.solar_system.scale + .1
+ if self.nameplate is None:
+ self.nameplate = GUI_galaxy_solar_system_nameplate(self.game, self, self.solar_system)
+
+
+ def is_coords_in_bounds(self, coordinates):
+ x = self.x - ((self.image.width/2) * self.scale)
+ y = self.y - ((self.image.height/2) * self.scale)
+
+ return (
+ coordinates[0] > x and
+ coordinates[0] < x + (self.width * self.scale) and
+ coordinates[1] > y and
+ coordinates[1] < y + (self.height * self.scale)
+ )
+
+
+ def get_screen_draw_position(self):
+ return self.x - ((self.image.width/2) * self.scale), self.y - ((self.image.height/2) * self.scale)
+
+
+ def on_exit(self):
+ GUI_element.on_exit(self)
+ if not self.nameplate is None:
+ self.nameplate.signal(S_KILL)
+
+
+
+class GUI_galaxy_solar_system_nameplate(MyrmidonProcess):
+ def execute(self, game, parent, solar_system):
+ self.game = game
+ self.parent = parent
+ self.solar_system = solar_system
+ self.z = Z_GUI_OBJECT_LEVEL_5
+ self.image = self.game.media.graphics['gui']['solar_system_nameplate']
+ self.alpha = 0
+ self.dying = False
+
+ self.text = MyrmidonGame.write_text(0.0, 0.0, font = self.game.media.fonts['solar_system_nameplate'], text = self.solar_system.name)
+ self.text.z = self.z-1
+ self.text.colour = (1.0, 0.5, 0.0)
+
+ self.text2 = MyrmidonGame.write_text(0.0, 0.0, font = self.game.media.fonts['solar_system_nameplate'], text = "Home" if solar_system.name == "Sol" else str(self.solar_system.chance_of_life) + "% chance of life.")
+ self.text2.z = self.z-1
+ self.text2.colour = (1.0, 0.5, 0.0)
+
+ while True:
+ if self.dying:
+ if self.alpha > 0:
+ self.alpha -= .1
+ if self.alpha <= 0:
+ self.signal(S_KILL)
+ else:
+ if self.alpha < 1:
+ self.alpha += .1
+ self.x = MyrmidonGame.engine['input'].mouse.x
+ self.y = MyrmidonGame.engine['input'].mouse.y - self.image.height
+
+ self.text.x = self.x + 60
+ self.text.y = self.y - 11
+ self.text.alpha = self.alpha
+
+ self.text2.x = self.x + 65
+ self.text2.y = self.y + 7
+ self.text2.alpha = self.alpha
+
+ yield
+
+
+ def die(self):
+ self.dying = True
+
+
+ def on_exit(self):
+ self.text.signal(S_KILL)
+ self.text2.signal(S_KILL)
+
+
+
+###################################################################################################
+###################################################################################################
+################################# SOLAR SYSTEM VIEW ###############################################
+###################################################################################################
+###################################################################################################
+
+
+
+class GUI_solar_system_container(GUI_element):
+ """
+ All elements in the solar system view live inside this thing.
+ """
+ def execute(self, game, parent = None):
+ self.game = game
+ self.parent = parent
+ self.init()
+ self.z = Z_GUI_CONTAINERS
+ self.width = MyrmidonGame.screen_resolution[0]
+ self.height = MyrmidonGame.screen_resolution[1]
+
+ # Create kids
+ for object_name in self.game.galaxy.solar_systems[self.game.current_system].objects:
+ GUI_solar_system_object(self.game, self, self.game.galaxy.solar_systems[self.game.current_system], self.game.galaxy.solar_systems[self.game.current_system].objects[object_name])
+
+ if not self.game.current_object is None:
+ GUI_solar_system_landed_menu(self.game, self)
+
+ GUI_solar_system_leave_system_button(self.game, self)
+
+ while True:
+ self.update()
+ yield
+
+
+
+class GUI_solar_system_object(GUI_element):
+ def execute(self, game, parent, solar_system, object):
+ self.game = game
+ self.parent = parent
+ self.solar_system = solar_system
+ self.object = object
+ self.z = Z_GUI_OBJECT_LEVEL_2
+ self.image = self.game.media.graphics['space']['planet_' + object.image]
+ self.x = self.object.x
+ self.y = self.object.y
+ self.scale = self.object.scale
+ self.colour = self.object.colour
+ self.width = self.image.width
+ self.height = self.image.height
+ self.init()
+ self.nameplate = None
+ self.selected = False
+ while True:
+ self.update()
+ yield
+
+
+ def mouse_left_up(self):
+ self.game.gui.block_gui_mouse_input = True
+ MyrmidonGame.engine['input'].mouse.alpha = 0
+ self.game.player_ship.travel_to(self.solar_system, self.object)
+ self.game.media.audio['system_travel'].play()
+
+
+ def mouse_not_over(self):
+ self.selected = False
+ if not self.nameplate is None:
+ self.nameplate.die()
+ self.nameplate = None
+
+
+ def mouse_over(self):
+ self.selected = True
+ if self.nameplate is None:
+ self.nameplate = GUI_solar_system_object_nameplate(self.game, self, self.object)
+
+
+ def is_coords_in_bounds(self, coordinates):
+ x = self.x - ((self.image.width/2) * self.scale)
+ y = self.y - ((self.image.height/2) * self.scale)
+
+ return (
+ coordinates[0] > x and
+ coordinates[0] < x + (self.width * self.scale) and
+ coordinates[1] > y and
+ coordinates[1] < y + (self.height * self.scale)
+ )
+
+
+ def get_screen_draw_position(self):
+ return self.x - ((self.image.width/2) * self.scale), self.y - ((self.image.height/2) * self.scale)
+
+
+ def draw(self):
+ if self.selected == False or self.game.gui.block_gui_mouse_input:
+ if not self.nameplate is None:
+ self.nameplate.die()
+ self.nameplate = None
+ return
+ glPushMatrix()
+ MyrmidonGame.engine['gfx'].draw_circle((MyrmidonGame.screen_resolution[0]/2, MyrmidonGame.screen_resolution[1]/2), self.object.distance, colour = (1.0,.6,0,1.0), width = 1.0, accuracy = 32)
+ MyrmidonGame.engine['gfx'].draw_circle((self.x, self.y), 128 * self.scale, colour = (1.0,.6,0,1.0), width = 2.0)
+ glPopMatrix()
+
+
+
+class GUI_solar_system_object_nameplate(MyrmidonProcess):
+ def execute(self, game, parent, object):
+ self.game = game
+ self.parent = parent
+ self.object = object
+ self.z = Z_GUI_OBJECT_LEVEL_5
+ self.image = self.game.media.graphics['gui']['solar_system_nameplate']
+ self.alpha = 0
+ self.dying = False
+
+ self.text = MyrmidonGame.write_text(0.0, 0.0, font = self.game.media.fonts['solar_system_nameplate'], text = self.object.name)
+ self.text.z = self.z-1
+ self.text.colour = (1.0, 0.5, 0.0)
+
+ while True:
+ if self.dying:
+ if self.alpha > 0:
+ self.alpha -= .1
+ if self.alpha <= 0:
+ self.signal(S_KILL)
+ else:
+ if self.alpha < 1:
+ self.alpha += .1
+ self.x = MyrmidonGame.engine['input'].mouse.x
+ self.y = MyrmidonGame.engine['input'].mouse.y - self.image.height
+
+ self.text.x = self.x + 60
+ self.text.y = self.y - 11
+ self.text.alpha = self.alpha
+
+ yield
+
+
+ def die(self):
+ self.dying = True
+
+
+
+class GUI_solar_system_landed_menu(GUI_element):
+ def execute(self, game, parent = None):
+ self.game = game
+ self.parent = parent
+ self.width = MyrmidonGame.screen_resolution[0]
+ self.height = MyrmidonGame.screen_resolution[1]
+ self.z = Z_GUI_OBJECT_LEVEL_6
+ self.init()
+ GUI_solar_system_landed_menu_window(self.game, self)
+ while True:
+ self.update()
+ yield
+
+
+ def draw(self):
+ MyrmidonGame.engine['gfx'].draw_rectangle((0,0), (MyrmidonGame.screen_resolution[0], MyrmidonGame.screen_resolution[1]), colour = (0.0, 0.0, 0.0, .6), filled = True)
+
+
+
+class GUI_solar_system_landed_menu_window(GUI_element_window):
+ title = "Landed"
+ def execute(self, game, parent = None):
+ self.game = game
+ self.parent = parent
+ self.width = 700
+ self.x = (MyrmidonGame.screen_resolution[0]/2) - (self.width/2)
+ self.y = 100
+ self.z = Z_GUI_OBJECT_LEVEL_7
+
+ self.texts = []
+
+ current_object = self.game.galaxy.solar_systems[self.game.current_system].objects[self.game.current_object]
+
+ text = MyrmidonGame.write_text(self.x + 200, self.y + 30, font = self.game.media.fonts['landed_menu_title'], text = current_object.name)
+ text.z = self.z -1
+ text.colour = (0, 0, 0)
+ self.texts.append(text)
+
+ if len(current_object.description) > 0:
+ start_y = 60
+ for desc_line in current_object.description:
+ text = MyrmidonGame.write_text(self.x + 180, self.y + start_y, font = self.game.media.fonts['landed_menu_description'], text = desc_line)
+ text.z = self.z -1
+ text.colour = (0, 0, 0)
+ self.texts.append(text)
+ start_y += 15
+
+ self.height = 220
+
+ # Do each action
+ start_y = 170
+ for action_name in current_object.actions:
+ text = MyrmidonGame.write_text(self.x + 20, self.y + start_y, font = self.game.media.fonts['actions_description'], text = current_object.actions[action_name].description)
+ text.z = self.z -1
+ text.colour = (0, 0, 0)
+ self.texts.append(text)
+ start_y += 30
+ self.height += 30
+
+ self.height += 20
+
+ self.init()
+
+ # Do each action
+ start_y = 170
+ for action_name in current_object.actions:
+ GUI_solar_system_landed_menu_window_action_button(self.game, self, current_object.actions[action_name], start_y)
+ start_y += 30
+
+ GUI_solar_system_landed_menu_window_planet(self.game, self, current_object.image, current_object.colour)
+ self.launch_button = GUI_solar_system_landed_menu_window_launch(self.game, self)
+ self.launch_error_text = MyrmidonGame.write_text(self.x + 20, self.y + self.height - 43, font = self.game.media.fonts['landed_menu_description'], text = "")
+ self.launch_error_text.z = self.z -1
+ self.launch_error_text.colour = (.8, 0, 0)
+ self.texts.append(self.launch_error_text)
+
+ yield
+
+ # If this is our first time launching the game, we need to show the intro message
+ if self.game.first_time:
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "The journey begins!",
+ message = [
+ "This is it! The culmination of years of work.", "Finally SETI have gathered enough funding to build a space", "faring vessel of their own.",
+ "With it they will explore the nearest stars, but the ultimate ", "goal is of course the answer to the question;", "Are We Alone?"
+ ]
+ )
+ self.game.first_time = False
+ else:
+ if self.game.current_system == "Sol" and self.game.current_object == "Earth":
+ # Coming home empty handed is harsh.
+ if len(self.game.home_planet_result) == 0 and self.game.money > 500000000:
+ GUI_element_dialog_box(
+ self.game,
+ self.game.gui.parent_window,
+ title = "Funding disaster",
+ message = [
+ "You have returned to Earth empty-handed and your benefactors are not impressed.",
+ "Your funding has been slashed as a result."
+ ]
+ )
+ self.game.money /= 2
+ else:
+ # If we're on sol we need to do the results
+ self.game.do_home_planet_results()
+
+ while True:
+ self.check_can_launch()
+ self.update()
+ yield
+
+
+ def check_can_launch(self):
+ self.launch_button.disabled = True
+ if self.game.fuel < 2:
+ self.launch_error_text.text = "Require at least 2 units of fuel to launch!"
+ return
+ if self.game.crew == 0:
+ self.launch_error_text.text = "Require at least 1 crew member to launch!"
+ return
+ self.launch_error_text.text = ""
+ self.launch_button.disabled = False
+
+
+ def on_exit(self):
+ GUI_element_window.on_exit(self)
+ for x in self.texts:
+ x.signal(S_KILL)
+
+
+ def draw(self):
+ # The planet image box
+ box_pos = (self.x + 20, self.y + 25)
+ MyrmidonGame.engine['gfx'].draw_rectangle(
+ box_pos,
+ (box_pos[0] + 128, box_pos [1] + 128),
+ colour = (0.0, 0.0, 0.0, 1.0),
+ )
+ MyrmidonGame.engine['gfx'].draw_rectangle(
+ box_pos,
+ (box_pos[0] + 128, box_pos [1] + 128),
+ colour = (0.8, 0.4, 0.0, 1.0),
+ width = 1.0,
+ filled = False
+ )
+
+ # Line
+ MyrmidonGame.engine['gfx'].draw_line(
+ (self.x + 30, self.y + 160),
+ (self.x + self.width - 30, self.y + 160),
+ colour = (0.8, 0.4, 0.0, 1.0),
+ width = 1.0
+ )
+
+ MyrmidonGame.engine['gfx'].draw_line(
+ (self.x + 30, self.y + self.height - 60),
+ (self.x + self.width - 30, self.y + self.height - 60),
+ colour = (0.8, 0.4, 0.0, 1.0),
+ width = 1.0
+ )
+
+
+
+class GUI_solar_system_landed_menu_window_planet(GUI_element):
+ def execute(self, game, parent = None, image = "", colour = ()):
+ self.game = game
+ self.parent = parent
+ self.x = self.parent.x + 20 - 64
+ self.y = self.parent.y + 25 - 64
+ self.z = Z_GUI_OBJECT_LEVEL_8
+ self.init()
+ self.image = self.game.media.graphics['space']['planet_' + image]
+ self.colour = colour
+ self.scale = .3
+ self.scale_point = (self.image.width/2, self.image.height/2)
+ while True:
+ self.update()
+ yield
+
+
+
+class GUI_solar_system_landed_menu_window_launch(GUI_element_button):
+ generic_button_text = "Launch"
+
+ def execute(self, game, parent = None):
+ self.game = game
+ self.parent = parent
+ self.x = self.parent.x + self.parent.width - 90
+ self.y = self.parent.y + self.parent.height - 50
+ self.z = Z_GUI_OBJECT_LEVEL_8
+ self.init()
+ while True:
+ self.update()
+ yield
+
+ def mouse_left_up(self):
+ if self.disabled:
+ return
+ GUI_element_button.mouse_left_up(self)
+ self.game.current_object = None
+ self.game.fuel -= FUEL_COST_TO_LAUNCH
+ self.parent.parent.signal(S_KILL)
+
+
+
+class GUI_solar_system_landed_menu_window_action_button(GUI_element_button):
+ generic_button_text = ""
+
+ def execute(self, game, parent = None, action = None, y = 0):
+ self.game = game
+ self.parent = parent
+ self.action = action
+ self.y = self.parent.y + y
+ self.z = Z_GUI_OBJECT_LEVEL_9
+ self.generic_button_text = self.action.button_text
+ self.init()
+ self.x = self.parent.x + self.parent.width - self.width - 30
+ self.generic_button_text_object.x = self.parent.x + self.parent.width - self.width - 25
+
+ if not self.game.current_system in self.game.actions_done:
+ self.game.actions_done[self.game.current_system] = {}
+ if not self.game.current_object in self.game.actions_done[self.game.current_system]:
+ self.game.actions_done[self.game.current_system][self.game.current_object] = []
+
+ if self.action.action_type in self.game.actions_done[self.game.current_system][self.game.current_object] and self.action.repeat == False:
+ self.disabled = True
+
+ while True:
+ self.update()
+ yield
+
+
+ def mouse_left_up(self):
+ GUI_element_button.mouse_left_up(self)
+ if self.disabled:
+ return
+ self.action.do_action()
+ if self.action.repeat == False:
+ self.disabled = True
+
+
+
+class GUI_solar_system_leave_system_button(GUI_element_button):
+ generic_button_text = "LEAVE SOLAR SYSTEM"
+
+ def execute(self, game, parent = None):
+ self.game = game
+ self.parent = parent
+ self.x = MyrmidonGame.screen_resolution[0] - 200
+ self.y = MyrmidonGame.screen_resolution[1] - 40
+ self.z = Z_GUI_OBJECT_LEVEL_3
+ self.init()
+ while True:
+ self.update()
+ yield
+
+
+ def mouse_left_up(self):
+ GUI_element_button.mouse_left_up(self)
+ self.game.gui.fade_toggle(callback = lambda: self.game.switch_game_state_to(GAME_STATE_GALAXY))
507 gui_elements.py
@@ -0,0 +1,507 @@
+# Engine imports
+from myrmidon.myrmidon import MyrmidonProcess, MyrmidonGame, MyrmidonError
+from myrmidon.consts import *
+from pygame.locals import *
+
+# OpenGL imports
+from OpenGL.GL import *
+
+# game imports
+from consts import *
+from helpers import *
+
+
+class GUI_element(MyrmidonProcess):
+ """
+ All GUI elements extend from this template.
+ It must have a position and a width/height. This enables it to take mouse input.
+ The handle_input() method must only be directly called by the overall parent element, all
+ children will be polled and the correct response will be sent back up the chain.
+ The Z order matters for how elements will be polled.
+ """
+ parent = None
+ children = []
+ width = 0
+ height = 0
+ disable = False
+ _currently_hovered = False
+
+ def execute(self, game, parent = None):
+ """
+ Template, base all elements off this execute method.
+ """
+ self.game = game
+ self.parent = parent
+ self.init()
+ while True:
+ self.update()
+ yield
+
+
+ def init(self):
+ """
+ Must be called at the start of the execute method. Requres self.parent to be set though.
+ """
+ if not self.parent is None:
+ self.parent.children.append(self)
+ self.children = []
+ self.priority = PRIORITY_GUI_ELEMENTS
+
+
+ def update(self):
+ """
+ Stub designed to be called every frame.
+ """
+ pass
+
+
+ def mouse_over(self):
+ """
+ Override this method to respond to the mouse hovering.
+ Called AFTER mouse_enter if that method gets called.
+ """
+ pass
+
+
+ def mouse_not_over(self):
+ """
+ Override this method to respond to the mouse not being over the element.
+ Called AFTER mouse_out if that method gets called.
+ """
+ pass
+
+
+ def mouse_enter(self):
+ """
+ Override this method to respond to the mouse entering the element.
+ """
+ pass
+
+
+ def mouse_out(self):
+ """
+ Override this method if to respond to the mouse leaving the element.
+ """
+ pass
+
+
+ def mouse_left_down(self):
+ """
+ Override this method to respond to the left mouse button being held down over the element.
+ """
+ pass
+
+
+ def mouse_left_up(self):
+ """
+ Override this method to respond to the left mouse button being released on the element.
+ """
+ pass
+
+
+ def mouse_right_down(self):
+ """
+ Override this method to respond to the right mouse button being held down over the element.
+ """
+ pass
+
+
+ def mouse_right_up(self):
+ """
+ Override this method to respond to the right mouse button being released on the element.
+ """