コード例 #1
0
 def __init__(self, pos, images, flaks, GOs, player, mission):
     super().__init__(pos, images, flaks, GOs, player, mission)
     self.name = "jupiter_alien"
     self.maxPhase = 15
     self.till_drop = (0, 0)
     self.health = 1.5
     self.start_health = 1.5
     self.acc = 1
     self.till_reg_drop = (0, 4)
     self.exp_names = ["jupiter_alien_boom", "jupiter_alien_boom_simple"]
     self.firesLaser = True
     self.death_sound = Sound(fixPath("audio/alienDie3.wav"))
     self.explode_sound = Sound(fixPath("audio/alienExplode3.wav"))
     self.drop_sound = Sound(fixPath("audio/alienLaser.wav"))
コード例 #2
0
 def __init__(self, pos, images, flaks, GOs, player, mission):
     super().__init__(pos, images, flaks, GOs, player, mission)
     self.name = "greenAlien"
     self.death_amount = [125, 75, 75, 125]
     self.speed = random.uniform(200, 450)
     self.velocity = Vector2([self.speed, 0])
     self.drop_from = "center"
     self.till_drop = .5
     self.till_reg_drop = 2
     self.acc = 4
     self.drops_mines = True
     self.health = 2
     self.start_health = 2
     self.maxPhase = 15
     self.exp_names = ["green_boom", "green_boom_simple"]
     self.impact_damage = [.5, 1]
     self.death_sound = Sound(fixPath("audio/alienDie2.wav"))
     self.explode_sound = Sound(fixPath("audio/alienExplode2.wav"))
コード例 #3
0
 def __init__(self, pos, images, flaks, GOs, player, mission):
     self.GOs = GOs
     self.flaks = flaks
     self.images = images
     self.pos = list(pos)
     self.phase = 1
     self.phase_rate = .5
     self.phase_time = 0
     self.next_fire = -1
     self.fire_time = 0
     self.time_passed = 0
     self.speed = random.uniform(475, 600)
     self.downshift = 100
     self.direction = 1      # Direction 1 is right, direction -1 is left
     self.health = 1
     self.dead = False
     self.kill = False
     self.maxPhase = 9
     self.velocity = Vector2([self.speed, 0])
     self.grounded = False
     self.player = player
     self.jackpot = False
     self.hitBy = None
     self.mission = mission
     self.firesLaser = False
     self.min_drop = -.01
     self.till_reg_drop = (self.min_drop, 2)
     self.till_drop = (.05, .4)
     self.acc = 1.2
     self.drop_from = "LR"
     self.name = "alien"
     self.exp_names = ["exp", "Exp"]
     self.attack_range = (0, 30)
     self.size, self.exp_size = (64, 64), (256, 256)
     self.death_amount = [30, 15, 50, 75]
     self.life_bar = False
     self.start_health = self.health
     self.death_sound = Sound(fixPath("audio/alienDie.wav"))
     self.explode_sound = Sound(fixPath("audio/alienExplode.wav"))
     self.drop_sound = Sound(fixPath("audio/alienDrop1.wav"))
     self.impact_damage = [.2, .4]
     self.drops_bombs = False
     self.isBoss = False
     self.drops_mines = False
コード例 #4
0
 def purchase(self):
     cat = self.catagories[self.rect_sel]
     if not cat:
         Sound(fixPath("audio/donk.wav")).play()
         return
     selected = list(cat.keys())[self.sel_num[self.rect_sel]]
     selected.planet = self.profile["planet"].name
     if self.profile["money"] >= selected.cost:
         Sound(fixPath("audio/purchase.wav")).play()
         cat[selected] -= 1
         if not cat[selected]:
             self.catagories[self.rect_sel].pop(selected)
         if self.sel_num[self.rect_sel] >= len(cat):
             self.sel_num[self.rect_sel] = len(cat) - 1
         if selected in self.profile["inventory"][self.rect_sel]:
             self.profile["inventory"][self.rect_sel][selected] += 1
         else:
             self.profile["inventory"][self.rect_sel][selected] = 1
         if selected.type == "Vehicle":
             self.profile["inventory"][
                 self.rect_sel][selected] = self.profile["planet"].name
         self.profile["money"] -= selected.cost
     else:
         Sound(fixPath("audio/donk.wav")).play()
コード例 #5
0
 def fire(self):
     self.completeness = 0
     center = Vector2(self.get_rect().topleft)
     if self.fire_from != "center":
         center += Vector2((self.fire_from))
     else:
         center += (Vector2(self.size) / 2)
     obj = self.fireObject(center, self.images, self.rotation)
     if self.whimp:
         obj.damage /= 10
     self.lasers.append(obj)
     if not self.whimp:
         sound = "audio/laser.wav"
         if self.current_items:
             if "Green Laser" in self.current_items:
                 sound = "audio/greenlaser.wav"
         Sound(sound).play()
     return obj
コード例 #6
0
 def __init__(self, pos, images, mission, dry=False):
     super().__init__(pos, images, mission, dry)
     self.title = "Jupiter Hovercraft"
     self.name = "jupiter_hover"
     self.death_frames = 21
     self.size = (32, 32)
     self.boom_size = (256, 256)
     self.fire_from = (24, 5)
     self.health = .75
     self.max_health = .75
     self.shield = 0
     self.max_shield = 2
     self.rect = self.get_rect()
     self.hover = True
     self.rotate = True
     self.send_to_ground()
     self.mass = .75
     self.max_temp = 500
     self.frame_rate = 1 / 35
     self.death_sound = Sound(fixPath("audio/jupiter_hover_explode.wav"))
コード例 #7
0
 def __init__(self,
              center,
              images,
              mission,
              type="moneyBag",
              velocity=Vector2([0, 0]),
              amount=None,
              value=None):
     self.images = images
     self.type = type
     self.size = (24, 24)
     self.physics = True
     self.gotShot = False
     if self.type == "moneyBag":
         self.size = (12, 16)
     if self.type == "rock":
         self.size = (20, 20)
     if self.type == "aircraft":
         self.physics = False
         self.size = (48, 48)
     if self.type == "mine":
         self.size = (32, 32)
     self.rect_size = self.size
     if self.type == "laser":
         self.size = (32, 32)
         self.rect_size = (16, 32)
     rect = pygame.Rect((0, 0), self.size)
     rect.center = center
     self.pos = list(rect.topleft)
     self.rect = rect
     self.time_passed = 0
     self.frame = 1
     self.frame_rate = 1 / 25
     self.frame_time = 0
     self.max_frame = 185
     self.velocity = copy.copy(velocity)
     self.dead = False
     self.kill = False
     self.amount = amount
     self.jackpot = False
     self.mission = mission
     self.health = .1
     self.kaboom = False
     if self.type == "block":
         self.max_frame = 30
     if self.type == "moneyBag":
         self.health = 1
         self.ser_num = shared["money_ser_num"]
         shared["money_ser_num"] += 1
     if self.type == "aircraft":
         self.depart = random.randint(0, 1)
         self.direction = random.randint(0, 1)
         if self.direction == 0:
             self.direction = -1
         if self.depart == 0:
             self.depart = -1
         self.frame_rate = 1
         self.max_frame = 3
         x = 0
         y = 0
         if self.direction == -1:
             x = SIZE[0]
         if self.depart == -1:
             y = self.mission.ground
         rect = self.get_rect()
         rect.center = (x, y)
         self.pos = list(rect.topleft)
         self.velocity = Vector2([1 * self.direction, .5 * self.depart
                                  ]) * 300 * random.uniform(.9, 1.1)
         self.jet_sound = Sound(fixPath("audio/jet.wav"))
         self.jet_sound.play(-1)
     if self.type == "mine":
         self.frame_rate = .5
         self.max_frame = 3
         self.health = 1
     if self.type == "laser":
         self.max_frame = 5
         self.frame_rate = 0.01
         self.physics = False
         self.velocity = Vector2([0, 1200])
     self.value = value
     self.start_health = self.health
     self.life_bar = True
     self.hitBy = []
     self.lifetime = 0
コード例 #8
0
class GameObject:
    def __init__(self,
                 center,
                 images,
                 mission,
                 type="moneyBag",
                 velocity=Vector2([0, 0]),
                 amount=None,
                 value=None):
        self.images = images
        self.type = type
        self.size = (24, 24)
        self.physics = True
        self.gotShot = False
        if self.type == "moneyBag":
            self.size = (12, 16)
        if self.type == "rock":
            self.size = (20, 20)
        if self.type == "aircraft":
            self.physics = False
            self.size = (48, 48)
        if self.type == "mine":
            self.size = (32, 32)
        self.rect_size = self.size
        if self.type == "laser":
            self.size = (32, 32)
            self.rect_size = (16, 32)
        rect = pygame.Rect((0, 0), self.size)
        rect.center = center
        self.pos = list(rect.topleft)
        self.rect = rect
        self.time_passed = 0
        self.frame = 1
        self.frame_rate = 1 / 25
        self.frame_time = 0
        self.max_frame = 185
        self.velocity = copy.copy(velocity)
        self.dead = False
        self.kill = False
        self.amount = amount
        self.jackpot = False
        self.mission = mission
        self.health = .1
        self.kaboom = False
        if self.type == "block":
            self.max_frame = 30
        if self.type == "moneyBag":
            self.health = 1
            self.ser_num = shared["money_ser_num"]
            shared["money_ser_num"] += 1
        if self.type == "aircraft":
            self.depart = random.randint(0, 1)
            self.direction = random.randint(0, 1)
            if self.direction == 0:
                self.direction = -1
            if self.depart == 0:
                self.depart = -1
            self.frame_rate = 1
            self.max_frame = 3
            x = 0
            y = 0
            if self.direction == -1:
                x = SIZE[0]
            if self.depart == -1:
                y = self.mission.ground
            rect = self.get_rect()
            rect.center = (x, y)
            self.pos = list(rect.topleft)
            self.velocity = Vector2([1 * self.direction, .5 * self.depart
                                     ]) * 300 * random.uniform(.9, 1.1)
            self.jet_sound = Sound(fixPath("audio/jet.wav"))
            self.jet_sound.play(-1)
        if self.type == "mine":
            self.frame_rate = .5
            self.max_frame = 3
            self.health = 1
        if self.type == "laser":
            self.max_frame = 5
            self.frame_rate = 0.01
            self.physics = False
            self.velocity = Vector2([0, 1200])
        self.value = value
        self.start_health = self.health
        self.life_bar = True
        self.hitBy = []
        self.lifetime = 0
        # Bounce equation:
#        V = (V - GF) * (C + C2)

    def get_rect(self):
        """Returns a pygame.Rect object representing this GameObject"""
        rect = pygame.Rect((0, 0), self.rect_size)
        rect.topleft = self.pos
        return rect

    def draw(self, surf):
        if self.type in ("moneyBag", "rock") and not self.dead:
            surf.blit(self.images[self.type], self.pos)
        if self.type in "moneyBag" and self.dead:
            self.max_frame = 75
            rect = self.get_rect()
            rect2 = pygame.Rect((0, 0), (256, 256))
            rect2.center = rect.center
            if self.frame > self.max_frame:
                self.kill = True
                return
            surf.blit(
                self.images[
                    f"money_explosion_t{(self.ser_num % 5) + 1}_{self.frame}"],
                rect2)
        if self.type in ("shield", "block", "heart", "mine",
                         "laser") and not self.dead:
            t = self.type
            if t == "laser":
                t = "bluelaser"
            surf.blit(
                pygame.transform.scale(self.images[f"{t}{self.frame}"],
                                       (32, 32)), self.pos)
        if self.type == "aircraft" and not self.dead:
            surf.blit(
                pygame.transform.flip(
                    pygame.transform.scale(
                        self.images[
                            f"aircraft{'Down' if self.depart == 1 else ''}{self.frame}"],
                        self.size), self.direction == -1, 0), self.pos)
        if self.type in ("rock", "block", "heart", "shield") and self.dead:
            self.max_frame = 10
            if self.type in ("block", "heart", "shield"):
                self.max_frame = 29
            rect = self.get_rect()
            rect2 = pygame.Rect((0, 0), (50, 50))
            if self.type in ("block", "heart", "shield"):
                rect2 = pygame.Rect((0, 0), (96, 96))
            rect2.center = rect.center
            if self.frame > self.max_frame - 1:
                self.kill = True
                return
            if self.type in ("block", "heart", "shield"):
                t = self.type
                if t == "block":
                    t = "item"
                surf.blit(self.images[f"{t}_boom{self.frame}"], rect2)
            else:
                surf.blit(self.images[f"rockCrush{self.frame}"], rect2)
        if self.type == "aircraft" and self.dead:
            self.max_frame = 58
            rect = self.get_rect()
            rect2 = pygame.Rect((0, 0), (128, 128))
            rect2.center = rect.center
            if self.frame > 58:
                self.kill = True
                return
            surf.blit(self.images[f"aircraft_explode{self.frame}"], rect2)
        if self.type == "mine" and self.dead:
            self.max_frame = 15
            rect = self.get_rect()
            rect2 = pygame.Rect((0, 0), (128, 128))
            rect2.center = rect.center
            if self.frame > 58:
                self.kill = True
                return
            surf.blit(self.images[f"mine_boom{self.frame}"], rect2)

    def update(self, time_passed):
        self.lifetime += time_passed
        if self.type == None:
            return
        rect = self.get_rect()
        if self.type == "aircraft":
            if not pygame.Rect(0, 0, 800, 600).colliderect(rect):
                self.jet_sound.stop()
                self.kill = True
        if rect.bottom < self.mission.ground and self.physics:
            self.velocity[1] += (self.mission.planet.gravity *
                                 G) * time_passed / METER
        if rect.bottom > self.mission.ground and self.physics:
            if self.type == "rock":
                self.dead = True
                self.frame = 1
            if self.type == "laser":
                self.kill = True
            if self.type in ("block", "moneyBag", "heart",
                             "shield") and self.mission.planet.gasgiant:
                self.dead = True
                self.frame = 1
                self.physics = False
                self.velocity[0] = 0
                self.velocity[1] = 0
                self.frame_rate = 1 / 30
            rect.bottom = self.mission.ground
            self.pos = list(rect.topleft)
            self.velocity[1] = -(
                (self.velocity[1] -
                 (self.mission.planet.gravity * G) * time_passed / METER) /
                (constants.BOUNCE[self.type] + self.mission.bounce))
            if round(self.velocity[1], 1) == 0:
                self.velocity[0] = 0
                self.velocity[1] = 0
        if not (self.type in ("moneyBag", "aircraft") and self.dead):
            self.pos[0] += self.velocity[0] * self.time_passed
            self.pos[1] += self.velocity[1] * self.time_passed
        self.frame_time += time_passed
        if self.frame_time >= self.frame_rate and not (self.type == "moneyBag"
                                                       and not self.dead):
            self.frame += 1
            self.frame_time = 0
        if self.frame >= self.max_frame:
            if self.dead and self.type in ("rock", "moneyBag", "aircraft",
                                           "mine", "block", "shield", "heart"):
                self.kill = True
            self.frame = 1
        if self.kill:
            if self.type == "aircraft":
                self.jet_sound.stop()
        self.time_passed = time_passed
コード例 #9
0
import os
import pygame
import time
import copy
from ii_game.scripts.retro_text import retro_text
from ii_game.scripts.sound import Sound
from ii_game.scripts.utils import fixPath, colorize
from ii_game.scripts.get_file import get_file

from ii_game.scripts import saves
directory = get_file(fixPath("data/screenshots"))

pygame.init()

sound = Sound(fixPath("audio/click.wav"))
options = saves.load_options()
save_for_later = {}

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
コード例 #10
0
 def events(self):
     for event in pygame.event.get():
         click = False
         if event.type == pygame.MOUSEBUTTONDOWN:
             if self.button_rect.collidepoint(pygame.mouse.get_pos()):
                 click = True
         if event.type == pygame.KEYUP:
             if event.key == pygame.K_i:
                 cat = self.catagories[self.selected]
                 sel = self.sel_num[self.selected]
                 if self.selected != 2:
                     item = list(cat.keys())[sel]
                 else:
                     item = cat[sel][1]
                 if item:
                     display_info(self.display, self.images, item)
         if event.type == pygame.KEYDOWN:
             if event.key in (pygame.K_UP, pygame.K_w):
                 if not self.button_selected:
                     self.selected -= 1
                 else:
                     self.button_selected = False
             if event.key in (pygame.K_DOWN, pygame.K_s):
                 self.selected += 1
             if self.selected < 0:
                 self.selected = 0
             if self.selected == len(self.rects):
                 self.selected = len(self.rects) - 1
                 self.button_selected = True
             if event.key in (pygame.K_LEFT, pygame.K_a) and not self.button_selected:
                 self.sel_num[self.selected] -= 1
             if event.key in (pygame.K_RIGHT, pygame.K_d) and not self.button_selected:
                 self.sel_num[self.selected] += 1
             if self.sel_num[self.selected] < 0:
                 self.sel_num[self.selected] = 0
             if self.sel_num[self.selected] == len(self.catagories[self.selected]):
                 self.sel_num[self.selected] = len(self.catagories[self.selected]) - 1
             if event.key == pygame.K_RETURN and not self.button_selected:
                 cat = self.catagories[self.selected]
                 lcat = list(cat)
                 sel = self.sel_num[self.selected]
                 didSomething = False
                 if self.selected == 1:
                     for x in self.catagories[2]:
                         if x[1] == None:
                             if not lcat:
                                 return
                             didSomething = True
                             x[1] = lcat[sel]
                             if cat[lcat[sel]] == 1:
                                 cat.pop(lcat[sel])
                             else:
                                 cat[lcat[sel]] -= 1
                             break
                 if not didSomething:
                     Sound(fixPath("audio/donk.wav")).play()
                 if self.selected == 2 and cat[sel][1] != None:
                     done = False
                     for x in self.catagories[1]:
                         if x == cat[sel][1]:
                             self.catagories[1][x] += 1
                             done = True
                     if not done:
                         self.catagories[1][cat[sel][1]] = 1
                     cat[sel][1] = None
             if event.key == pygame.K_RETURN and self.button_selected:
                 click = True
         if click and not self.cannotContinue():
             self.done = True
コード例 #11
0
class Alien:
    difficulty = 1
    def __init__(self, pos, images, flaks, GOs, player, mission):
        self.GOs = GOs
        self.flaks = flaks
        self.images = images
        self.pos = list(pos)
        self.phase = 1
        self.phase_rate = .5
        self.phase_time = 0
        self.next_fire = -1
        self.fire_time = 0
        self.time_passed = 0
        self.speed = random.uniform(475, 600)
        self.downshift = 100
        self.direction = 1      # Direction 1 is right, direction -1 is left
        self.health = 1
        self.dead = False
        self.kill = False
        self.maxPhase = 9
        self.velocity = Vector2([self.speed, 0])
        self.grounded = False
        self.player = player
        self.jackpot = False
        self.hitBy = None
        self.mission = mission
        self.firesLaser = False
        self.min_drop = -.01
        self.till_reg_drop = (self.min_drop, 2)
        self.till_drop = (.05, .4)
        self.acc = 1.2
        self.drop_from = "LR"
        self.name = "alien"
        self.exp_names = ["exp", "Exp"]
        self.attack_range = (0, 30)
        self.size, self.exp_size = (64, 64), (256, 256)
        self.death_amount = [30, 15, 50, 75]
        self.life_bar = False
        self.start_health = self.health
        self.death_sound = Sound(fixPath("audio/alienDie.wav"))
        self.explode_sound = Sound(fixPath("audio/alienExplode.wav"))
        self.drop_sound = Sound(fixPath("audio/alienDrop1.wav"))
        self.impact_damage = [.2, .4]
        self.drops_bombs = False
        self.isBoss = False
        self.drops_mines = False

    def drop(self):
        if self.dead:
            return
        num = 30
        if not random.randint(0, 3):
            num = random.randint(*self.attack_range)
        num = num // 2
        Num = int(num)
        if not self.drops_bombs and not self.drops_mines and not self.firesLaser:
            Type = "rock"
        if self.drops_bombs:
            Type = "bomb"
        if self.drops_mines:
            Type = "mine"
        if self.firesLaser:
            Type = "laser"
        if Num == 0 or Num == 4:
            Type = "heart"
        if Num == 1:
            Type = "moneyBag"
        if Num == 2:
            Type = "shield"
        if num == 3 and not self.mission.items_dropped == self.mission.items:
            Type = "block"
            self.mission.items_dropped += 1
        rect = self.get_rect()
        pos = random.randint(rect.left, rect.right)
        if self.drop_from == "center":
            pos = rect.centerx
        if Type != "bomb":
            self.GOs.append(GameObject((pos, rect.centery), self.images, self.mission, Type))
        else:
            self.flaks.append(Bomb(self.images, (pos, rect.centery), self.mission))
        if type(self.till_reg_drop) in (type(3), type(3.5)):
            self.next_fire = self.till_reg_drop
        else:
            self.next_fire = random.uniform(*self.till_reg_drop)
        self.fire_time = 0
        self.drop_sound.play()

    def get_rect(self):
        rect = pygame.Rect((0, 0), self.size)
        rect.topleft = self.pos
        return rect

    def draw(self, surf):
        if not self.dead:
            surf.blit(pygame.transform.scale(self.images[f"{self.name}{self.phase}"], self.size), self.pos)
        if self.dead == 2 and not self.grounded:
            direction = "Right" if self.direction == 1 else "Left"
            surf.blit(pygame.transform.scale(self.images[f"{self.name}Falling{direction}"], self.size), self.pos)
        if self.dead == 1 or (self.dead == 2 and self.grounded):
            rect = self.get_rect()
            rect2 = pygame.Rect((0, 0), self.exp_size)
            rect2.center = rect.center
            exp_type = self.exp_names[0]
            if self.dead == 2:
                exp_type = self.exp_names[1]
            if self.phase > self.maxPhase:
                self.kill = True
                return
            surf.blit(pygame.transform.scale(self.images[f"{exp_type}{self.phase}"], self.exp_size), rect2)
        if self.life_bar:
            rect = self.get_rect()
            rect1 = pygame.Rect((0, 0), (50, 3))
            rect1.center = rect.midbottom
            rect2 = rect1.copy()
            if self.health < 0:
                self.health = 0
            rect2.w *= self.health / self.start_health
            pygame.draw.rect(surf, (0, 0, 0), rect1)
            pygame.draw.rect(surf, (0, 255, 0), rect2)

    def update(self, time_passed):
        if self.next_fire < 0:
            rect = self.get_rect()
            center = rect.center
            rect.w *= self.acc
            rect.h = 600
            rect.midtop = center
            if rect.contains(self.player.get_rect()):
                if type(self.till_drop) in (type(3), type(3.5)):
                    self.next_fire = self.till_drop
                else:
                    self.next_fire = random.uniform(*self.till_drop)
        self.time_passed = time_passed
        self.fire_time += time_passed
        self.phase_time += time_passed
        if self.fire_time >= self.next_fire and self.next_fire >= 0:
            self.drop()
        if self.dead:
            if self.dead == 1:
                self.phase_rate = .025
                self.velocity.x, self.velocity.y = [0, 0]
            if self.dead == 2:
                self.velocity[1] += (self.mission.planet.gravity * G) * time_passed / METER
        if self.phase_time >= self.phase_rate and not (self.dead == 2 and not self.grounded):
            self.phase += 1
            self.phase_time = 0
            if self.jackpot:
                self.GOs.append(GameObject((self.get_rect().x + self.get_rect().width / self.phase, self.get_rect().centery), self.images, self.mission, type = "moneyBag", amount = random.choice([50, 100])))
        if self.phase == 4 and not self.dead:
            self.phase = 1
        if self.phase == self.maxPhase:
            self.kill = True
        if self.dead == 2 and not self.grounded:
            if self.get_rect().bottom >= self.mission.ground:
                self.grounded = True
                self.velocity.x, self.velocity.y = [0, 0]
                self.phase = 1
        self.pos[0] += self.velocity[0] * self.direction * self.time_passed
        self.pos[1] += self.velocity[1] * self.time_passed
        if self.get_rect().left <= 0 and self.direction == -1:
            self.direction = 1
            self.pos[1] += self.downshift
        if self.get_rect().right >= 800 and self.direction == 1:
            self.direction = -1
            self.pos[1] += self.downshift