def capture(profile_num, surf, ingame = False):
    surf = copy.copy(surf)
    data = time.localtime()
    if not os.path.exists(directory):
        print(colorize("Screenshot directory missing.", "warning"))
        os.mkdir(directory)
    name = f"ii{profile_num}_{data.tm_year}{data.tm_mon}{data.tm_mday}{data.tm_hour}{data.tm_min}{data.tm_sec}"
    done_this = False
    p = fixPath(directory+"/"+name+".png")
    while os.path.exists(p) or name in save_for_later:
        if not done_this:
            name += "_2"
            done_this = True
        else:
            name = name[:-1] + str(int(name[-1]) + 1)
        p = fixPath(directory+"/"+name+".png")
    sound.play()
    if ingame and options["cache_screen_shots"]:
        print(colorize(f"Caching screenshot {name}", "blue"))
        save_for_later[name] = surf
    else:
        save(surf, name)
Esempio n. 2
0
 def __init__(self):
     self.options = saves.load_options()
     fullscreen = 0
     if self.options["fullscreen"]:
         fullscreen = pygame.FULLSCREEN
     self.Display = pygame.display.set_mode(
         (800, 600),
         fullscreen | pygame.HWSURFACE | pygame.HWACCEL | pygame.DOUBLEBUF)
     self.display = pygame.Surface((800, 600))
     pygame.display.set_caption("Interplanetary Invaders")
     pygame.display.set_icon(pygame.image.load(get_file("icon.png")))
     t1 = time.time()
     self.images, num = auto_load.fetch_images()
     t2 = time.time()
     print(
         colorize(f"Loaded {num} images in {round(t2-t1, 2)} seconds",
                  "green"))
     self.menu()
     self.cat = []
Esempio n. 3
0
def fetch_images():
    """Collect images from the IMAGE_PATH and return dictionary
with pygame.Surface objects as values and their names as keys"""
    names = []
    images = []
    num = 0
    print("Loading... \n")
    mx = 0
    for data in os.walk(IMAGE_PATH):
        for collect_file in data[2]:
            if not collect_file.startswith("."):
                mx += 1
    for data in os.walk(IMAGE_PATH):
        root = data[0]
        files = data[2]
        for collect_file in files:
            if not collect_file.startswith("."):
                num += 1
                name = remove_extension(collect_file)
                names.append(name)
                img = pygame.image.load(root + os.sep + collect_file)
                if (name.startswith("spinning") and not "RGBA" in name):
                    img = img.convert()
                    img.set_colorkey((0, 0, 0))
                else:
                    if not "animation" in root:
                        if name.startswith("map_"):
                            img = img.convert()
                        else:
                            img = img.convert_alpha()
                images.append(img)
                print(
                    f"\rLoaded {colorize(num, 'blue' if num!=mx else 'green')} / {colorize(mx, 'green')} images   %s"
                    % colorize(collect_file +
                               (" " * (40 - len(collect_file))), 'bold'),
                    flush=True,
                    end="")
    print()
    return dict(zip(names, images)), num
Esempio n. 4
0
 def keepGoing(self, lw):
     try:
         lw.main()
     except KeyboardInterrupt:
         print(colorize("Nope. Answer the questions", "fail"))
         self.keepGoing(lw)
Esempio n. 5
0
from ii_game.scripts import saves
from ii_game.scripts.saves import load_options

saves.debugMode = debugMode
from ii_game.scripts import map_menus as maps
from ii_game.scripts import lose_win
from ii_game.scripts.congrats import congrats
from ii_game.scripts.planets import *
from ii_game.scripts import stores
from ii_game.scripts.achievements import ACHIEVEMENTS
from ii_game.scripts.get_file import get_file
from ii_game.scripts.utils import colorize
import os
import time

print(colorize(f"Your \"data\" directory is: {get_file('data')}", "bold"))

pygame.init()

SIZE = (800, 600)
from ii_game.scripts import game


class Main:
    def __init__(self):
        self.options = saves.load_options()
        fullscreen = 0
        if self.options["fullscreen"]:
            fullscreen = pygame.FULLSCREEN
        self.Display = pygame.display.set_mode(
            (800, 600),
Esempio n. 6
0
 def events(self):
     for event in pygame.event.get():
         if event.type == pygame.QUIT:
             self.exit()
         if event.type == pygame.MOUSEBUTTONDOWN:
             if not self.finished:
                 self.finished = True
                 print(self.text)
                 self.text = ""
         if event.type == pygame.KEYDOWN:
             if event.key == pygame.K_F2:
                 screenshot.capture("M", self.display)
             if not self.finished:
                 self.finished = True
                 print(self.text)
                 self.text = ""
             else:
                 item = self.item_selected
                 items = self.items
                 if self.options_mode:
                     item = self.option_selected
                     items = self.options
                 if self.play_mode:
                     item = self.profile_selected
                     items = self.profiles
                 if event.key == pygame.K_ESCAPE:
                     self.exit()
                 if event.key == pygame.K_UP:
                     item -= 1
                 if event.key == pygame.K_DOWN:
                     item += 1
                 if item < 0:
                     item = 0
                 if item >= len(items):
                     item = len(items) - 1
                 if self.options_mode:
                     self.option_selected = item
                 if self.play_mode:
                     self.profile_selected = item
                 elif self.play_mode:
                     pass
                 else:
                     self.item_selected = item
                 if self.options_mode:
                     op = self.options[self.option_selected]
                     if op == "Volume":
                         vol = self.options_dict["volume"]
                         if event.key == pygame.K_LEFT:
                             vol -= .1
                         if event.key == pygame.K_RIGHT:
                             vol += .1
                         if vol < 0:
                             vol = 0
                         if vol > 1:
                             vol = 1
                         self.options_dict["volume"] = vol
                     if op == "Cache Screenshots":
                         if event.key == pygame.K_RETURN:
                             self.options_dict[
                                 "cache_screen_shots"] = not self.options_dict[
                                     "cache_screen_shots"]
                     if op == "Stretch to Fullscreen":
                         if event.key == pygame.K_RETURN:
                             self.options_dict[
                                 "fullscreen"] = not self.options_dict[
                                     "fullscreen"]
                     if op == self.DEL:
                         if event.key == pygame.K_RETURN:
                             try:
                                 for e, x in enumerate(
                                         os.listdir(
                                             fixPath(
                                                 get_file(
                                                     "data/screenshots")))):
                                     os.remove(
                                         fixPath(
                                             get_file("data/screenshots/"))
                                         + x)
                                 print(
                                     colorize(f"Deleted screenshots: {e+1}",
                                              "green"))
                                 self.options[self.options.index(
                                     self.DEL)] = "Deleted screenshots"
                                 self.DEL = "Deleted screenshots"
                             except FileNotFoundError:
                                 print(
                                     colorize(
                                         "Failed to delete screenshots!",
                                         "fail"))
                                 print(
                                     colorize("File not found error.",
                                              "fail"))
                 if event.key == pygame.K_x:
                     if self.play_mode:
                         if self.profile_selected < 5 and not self.profiles[
                                 self.profile_selected].startswith("New"):
                             self.confirm_delete()
                 if event.key == pygame.K_RETURN:
                     if self.options_mode:
                         sel = self.option_selected
                         if self.options[sel] == "Cancel":
                             self.options_mode = False
                             self.options_dict = saves.load_options()
                         if self.options[sel] == "Save":
                             self.options_mode = False
                             saves.save_data("options", self.options_dict)
                         if not self.options_mode and self.options_lock:
                             self.done = True
                     elif self.play_mode:
                         if self.profiles[self.profile_selected] == "Back":
                             self.play_mode = False
                         else:
                             profile = saves.load_profile(
                                 self.profile_selected)
                             profile["new"] = False
                             saves.save_data(self.profile_selected, profile)
                             self.done = True
                     else:
                         sel = self.item_selected
                         if self.items[sel] == "Play":
                             self.play_mode = True
                         if self.items[sel] == "Options":
                             self.options_mode = True
                         if self.items[sel] == "Quit":
                             self.exit()
                         if self.items[sel] == "Credits":
                             run_credits(self.display, self.images)
def save(surf, name):
    print(colorize("Saving screenshot...", "blue"))
    t1 = time.time()
    pygame.image.save(surf, fixPath(f"{directory}/{name}.png"))
    t2 = time.time()
    print(colorize(f"Saved screenshot \"{name}\" in {round(t2-t1, 2)} seconds", "green"))
 def __init__(self,
              images,
              display,
              profile,
              profile_number,
              focus="theSun"):
     self.images = images
     self.Display = display
     self.display = pygame.Surface((800, 600))
     self.done = False
     self.time_passed = 0
     self.planets1 = [
         Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune
     ]
     for planet in Moons:
         for moon in Moons[planet]:
             self.planets1.append(moon)
     self.planets1.reverse()
     self.planets = []
     for p in self.planets1:
         self.planets.append(p())
     self.sunRect = pygame.Rect(0, 0, 20, 20)
     self.sunRect.center = self.Display.get_rect().center
     self.real_world_time = 0
     self.offset = [0, 0]
     self.target_offset = [0, 0]
     self.zoom = 1
     self.target_zoom = 1
     self.scroll_speed = 300
     self.scroll_range = 10
     self.zoom_amount = .1
     self.focused = None
     self.sun_frame = 1
     self.next_sun_frame = 0
     self.sun_frame_len = 1 / 25
     self.overlay_pos = None
     self.moving_start = 0
     self.moving = False
     if focus in planetByName:
         focus = self.planets1.index(planetByName[focus])
     self.focused = focus
     self.mouse_on = False
     self.profile = profile
     self.profile_number = profile_number
     self.money = self.profile["money"]
     self.text_yellow = False
     self.text_rate = 1 / 5
     self.text_time = 0
     self.start_click = None
     self.last_sample = None
     self.unlocked_planets = []
     for planet in self.profile["finished_planets"]:
         for p in self.planets:
             if p.name == planet:
                 self.unlocked_planets.append(p)
                 for u in p.unlocks:
                     for p2 in self.planets:
                         if p2.name == u:
                             self.unlocked_planets.append(p2)
     self.missions_left = {}
     for planet in self.unlocked_planets:
         self.missions_left[planet.name] = 0
         try:
             for p in self.profile["map"][planet.name]:
                 if p.alien_flag:
                     self.missions_left[planet.name] += 1
         except KeyError:
             print(colorize(f"No map for {planet.name} found!", "fail"))
     self.speed = 1
     pygame.mixer.music.load(fixPath(get_file("AmbientSpace.mp3")))
     pygame.mixer.music.play(-1)