def __init__(self, display, images, money=[1, 1, 1, 1, [], 0, 0], mode="won"): self.display = display self.images = images self.mode = mode self.frame = 1 self.frame_time = 0 self.frame_rate = 1 / 25 self.time_passed = 0 self.anim_done = False self.done = False self.text = ["Save + Continue", "Save + Exit"] self.top_selected = True self.money_old, self.money_new, self.bonus, self.bonus1, self.acc, self.lost, self.maxcombo = money try: self.acc_per = self.acc.count(True) / len(self.acc) self.acc_per2 = round(self.acc_per * 100, 3) except ZeroDivisionError: self.acc_per = 0 self.acc_per2 = 0 self.money_new += round(self.bonus) self.money_new += round(self.bonus1 * self.acc_per) self.money_sound = Sound(fix_path("audio/money.wav")) self.register_sound = Sound(fix_path("audio/cashRegister.wav")) if mode == "won": self.money_sound.play(-1) self.exit = False self.stopped = False
def __init__(self, pos, images, mission, dry=False): super().__init__(pos, images, mission, dry) self.title = "Jupiter Hovercraft" self.name = "jupiter_hover" self.fire_per_sec = 6.5 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.mass = .75 self.max_temp = 500 self.hover_alt = 430 self.frame_rate = 1 / 35 self.extra_dip = 10 self.speed *= .8 self.friction = .5 self.send_to_ground() self.weapon_power = .75 self.death_sound = Sound(fix_path("audio/jupiter_hover_explode.wav"), True)
def __init__(self, center, images, rotation=0): super().__init__(center, images, rotation) self.damage = 5 self.laserType = "greenlaser" self.green = True self.impactAnimationName = "GreenImpact" self.fire_sound = Sound("audio/greenlaser.wav", True)
def __init__(self, center, images, rotation=0): self.images = images testSurf = pygame.Surface((10, 16)) self.size = pygame.transform.rotate(testSurf, -rotation).get_size() rect = pygame.Rect((0, 0), self.size) rect.center = center self.pos = list(rect.topleft) self.phase = random.randint(1, 5) self._phase_speed = 0.01 self.phase_time = 0 self.time_passed = 0 self.speed = 1200 # Speed in pixels per second self.dead = False self.kill = False self.damage = 1 self.laserType = "laser" self.impactAnimationName = "RedImpact" self.impactAnimationLength = 6 self.impactAnimationFrame = 1 self.impactAnimationTime = 0 self.impactAnimationRate = 1 / 35 self.hits = 0 self.rotation = rotation self.green = False self.fire_sound = Sound("audio/laser.wav", True)
def purchase(self): cat = self.catagories[self.rect_sel] if not cat: Sound(fix_path("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(fix_path("audio/cashRegister.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(fix_path("audio/donk.wav")).play()
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) obj.damage *= self.weapon_power 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, True).play() return obj
def __init__(self, center, images, mission, type="moneyBag", velocity=Vector2([0, 0]), amount=None, value=None, player=None, nobounce=False): self.images = images self.type = type self.size = (24, 24) self.physics = True self.player = player self.gotShot = False self.nobounce = nobounce self.max_lifetime = -1 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 = (10, 32) self.rect_size = (10, 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 / 30 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.has_touched_ground = False self.kaboom = False self.immune_to = None self.tracking = True self.update_attraction() if self.type == "block": self.max_frame = 30 if self.type == "moneyBag": self.max_frame = 13 self.frame_rate = 1 / 8 self.frame = random.randint(1, 13) self.frame_time = random.uniform(0, self.frame_rate) self.health = 1 global MoneySerialNumber self.ser_num = MoneySerialNumber MoneySerialNumber += 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(fix_path("audio/jet.wav")) self.jet_sound.play(-1) if self.type == "mine": self.frame_rate = .5 self.max_frame = 3 self.health = 1 self.tracking = True self.max_lifetime = random.uniform(2.3, 2.8) 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 self.time_on_ground = 0
class GameObject: def __init__(self, center, images, mission, type="moneyBag", velocity=Vector2([0, 0]), amount=None, value=None, player=None, nobounce=False): self.images = images self.type = type self.size = (24, 24) self.physics = True self.player = player self.gotShot = False self.nobounce = nobounce self.max_lifetime = -1 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 = (10, 32) self.rect_size = (10, 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 / 30 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.has_touched_ground = False self.kaboom = False self.immune_to = None self.tracking = True self.update_attraction() if self.type == "block": self.max_frame = 30 if self.type == "moneyBag": self.max_frame = 13 self.frame_rate = 1 / 8 self.frame = random.randint(1, 13) self.frame_time = random.uniform(0, self.frame_rate) self.health = 1 global MoneySerialNumber self.ser_num = MoneySerialNumber MoneySerialNumber += 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(fix_path("audio/jet.wav")) self.jet_sound.play(-1) if self.type == "mine": self.frame_rate = .5 self.max_frame = 3 self.health = 1 self.tracking = True self.max_lifetime = random.uniform(2.3, 2.8) 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 self.time_on_ground = 0 # Bounce equation: # V = (V - GF) * (C + C2) def update_attraction(self): if self.player: if "Magnet" in self.player.current_items: self.tracking_speed = constants.ATTRACTION_WITH_MAGNET.get( self.type, 0 ) * self.mission.magnet_power # tracing velocity change in m/s if self.type == "heart" and self.player.health == self.player.max_health: self.tracking_speed = 0 if self.type == "shield" and self.player.shield == self.player.max_shield: self.tracking_speed = 0 else: self.tracking_speed = constants.ATTRACTION.get(self.type, 0) 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 calculate_ground_impact(self): """Calculates the point on the ground where this will impact""" if self.has_touched_ground or not self.physics: return self.get_rect().center SIM_SPEED = 0.1 # Seconds / Simulation Tick rect = copy.copy(self.get_rect()) pos = Vector2(rect.center) vel = Vector2(copy.copy(self.velocity)) while rect.bottom < self.mission.ground: vel[1] += (self.mission.planet.gravity * G) * SIM_SPEED / METER pos += vel * SIM_SPEED rect.center = pos return pos def draw(self, surf): if self.type in ("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 self.frame_rate = 1 / 25 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", "moneyBag") and not self.dead: t = self.type size = (32, 32) if t == "laser": t = "bluelaser" size = self.size if t == "moneyBag": size = self.size surf.blit( pygame.transform.scale(self.images[f"{t}{self.frame}"], size), 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.frame_rate = 1 / 25 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): """Update physics and animations of this GameObject""" self.lifetime += time_passed if self.type == None: return if self.tracking and self.player and not self.dead and self.physics and not self.has_touched_ground and self.tracking_speed: impact = self.calculate_ground_impact() dest = self.player.get_rect().center if impact[0] > dest[0]: # Need to move LEFT self.velocity[0] -= self.tracking_speed * time_passed / METER if impact[0] < dest[0]: # Need to move RIGHT self.velocity[0] += self.tracking_speed * time_passed / METER 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 self.time_on_ground > 4 and self.mission.is_bottomless( ) and self.type in CRUSHABLE: self.kill = True self.frame = 1 self.frame_rate = 1 / 30 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: self.has_touched_ground = True if self.mission.is_bottomless() and self.type in CRUSHABLE: self.physics = False self.velocity[0] = 0 self.velocity[1] = 15 if self.type == "rock" and not self.dead: self.dead = True self.frame = 1 if self.type == "laser": self.kill = True if self.type == "mine": self.phyiscs = False rect.bottom = self.mission.ground self.pos = list(rect.topleft) if self.physics and not self.mission.is_bottomless(): 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 self.has_touched_ground: self.time_on_ground += self.time_passed if rect.bottom == self.mission.ground: try: if self.mission.planet.gravity * G > 1: self.velocity[0] /= self.mission.planet.gravity * G except ZeroDivisionError: pass if not (self.type in ("moneyBag", "aircraft") and self.dead): centerx = rect.centerx if (centerx < 0 or centerx > 800) and not self.nobounce: self.velocity[0] *= -1 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: 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
def __init__(self, pos, images, mission, dry=False): self.dry = dry self.pos = pos self.images = images self.speed = 1 # Acceleration multiplier self.acceleration = 1 self.fire_per_sec = 4.5 self.completeness = 1 self.title = "Alien Zapper 1" self.name = "zapper" self.time_passed = 0 self.lasers = [] self.size = (64, 64) self.boom_size = (200, 200) self.rect = self.get_rect() self.health = 1 self.shield = 0 self.max_health = 1 self.max_shield = 1 self.hover_alt = 0 self.min_alt = 0 self.target_alt = 0 self.standard_alt = 0 self.alt_change_speed = 5 self.hitBy = [] self.items = [] self.current_items = {} self.fireObject = Laser self.dead = False self.kill = False self.frame = 1 self.frame_rate = 1 / 25 self.frame_time = 0 self.friction = 1 self.velocity = pygame.Vector2((0, 0)) self.max_velocity = 6 self.target_x_velocity = 0 self.mission = mission self.mass = 1.5 # Mass in kilograms self.death_frames = 25 self.max_temp = 300 # Works up to 300 deg. F self.canFire = True self.fire_from = "center" self.beam = False self.rotation = 0 self.rotation_speed = 90 self.max_rotation = 60 self.add_temp = 0 self.rotate = False self.whimp = False self.regen = False self.hover = False self.extra_dip = 0 self.send_to_ground() self.regen_time = 0 self.just_fired = False self.death_sound = None self.weapon_power = 1 self.always_beam = False self.general_acc = 20 self.im_back = False self.invincible = False self.invincible_time = 0 self.even_frame = True self.damage_sound = Sound("audio/takeDamage.wav", True) self.fire_sound_pitches = (.95, 1, 1.05)
class Zapper: """Zapper (Player) class""" def __init__(self, pos, images, mission, dry=False): self.dry = dry self.pos = pos self.images = images self.speed = 1 # Acceleration multiplier self.acceleration = 1 self.fire_per_sec = 4.5 self.completeness = 1 self.title = "Alien Zapper 1" self.name = "zapper" self.time_passed = 0 self.lasers = [] self.size = (64, 64) self.boom_size = (200, 200) self.rect = self.get_rect() self.health = 1 self.shield = 0 self.max_health = 1 self.max_shield = 1 self.hover_alt = 0 self.min_alt = 0 self.target_alt = 0 self.standard_alt = 0 self.alt_change_speed = 5 self.hitBy = [] self.items = [] self.current_items = {} self.fireObject = Laser self.dead = False self.kill = False self.frame = 1 self.frame_rate = 1 / 25 self.frame_time = 0 self.friction = 1 self.velocity = pygame.Vector2((0, 0)) self.max_velocity = 6 self.target_x_velocity = 0 self.mission = mission self.mass = 1.5 # Mass in kilograms self.death_frames = 25 self.max_temp = 300 # Works up to 300 deg. F self.canFire = True self.fire_from = "center" self.beam = False self.rotation = 0 self.rotation_speed = 90 self.max_rotation = 60 self.add_temp = 0 self.rotate = False self.whimp = False self.regen = False self.hover = False self.extra_dip = 0 self.send_to_ground() self.regen_time = 0 self.just_fired = False self.death_sound = None self.weapon_power = 1 self.always_beam = False self.general_acc = 20 self.im_back = False self.invincible = False self.invincible_time = 0 self.even_frame = True self.damage_sound = Sound("audio/takeDamage.wav", True) self.fire_sound_pitches = (.95, 1, 1.05) def send_to_ground(self): if self.dry: return rect = self.get_rect() if not self.hover: rect.bottom = self.mission.ground else: rect.bottom = self.hover_alt self.standard_alt = rect.bottom self.target_alt = self.standard_alt self.min_alt = self.mission.ground self.pos[1] = rect.top if not self.hover and self.mission.is_bottomless(): self.dead = True self.health = 0 self.shield = 0 if self.hover and self.mission.is_bottomless(): self.min_alt += self.extra_dip def get_rect(self): """Returns a pygame.Rect object representing the player""" rect = pygame.Rect((0, 0), self.size) rect.topleft = self.pos return rect def make_invincible(self, no_sound=False): if self.dead: return self.invincible = True self.invincible_time = .75 if not no_sound: self.damage_sound.play() def draw(self, surf): """Render the Zapper""" if not self.dead: if self.invincible and not self.even_frame: return if self.rotate: line_len = 50 start_pos = Vector2(self.fire_from) + self.pos end_pos = start_pos - Vector2( cos(radians(self.rotation + 90)) * line_len, sin(radians(self.rotation + 90)) * line_len) pygame.draw.line(surf, (255, 0, 0), start_pos, end_pos, 1) name = f"{self.name}{int(6 * (self.completeness / 1))}" if name in self.images: self.image = pygame.transform.scale(self.images[name], self.size) if self.rotate and self.completeness == 1 or not name in self.images: lr = "" if self.rotation >= 45: lr = "R" if self.rotation <= -45: lr = "L" surf.blit( pygame.transform.scale(self.images[self.name + lr], self.size), self.pos) else: surf.blit(self.image, self.pos) if self.dead: rect = self.get_rect() rect.size = self.boom_size rect.center = self.get_rect().center surf.blit( pygame.transform.scale( self.images[f"{self.name}Die{self.frame}"], self.boom_size), rect) 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) obj.damage *= self.weapon_power if self.whimp: obj.damage /= 10 self.lasers.append(obj) if not self.whimp: pitch = random.choice(self.fire_sound_pitches) obj.fire_sound.__init__(obj.fire_sound.original_filename, pitch=pitch) obj.fire_sound.play() return obj def events(self, event): """Handle user events for Zapper""" if (event.type == pygame.KEYDOWN or joystick.WasEvent()) and not self.dead: if (event.key in (pygame.K_SPACE, pygame.K_UP, pygame.K_w) or joystick.JustPressedX() ) and self.completeness == 1 and self.canFire: obj = self.fire() self.just_fired = obj def update(self, time_passed): """Update Zapper""" self.even_frame = not self.even_frame if self.invincible: self.invincible_time -= time_passed if self.invincible_time < 0: self.invincible = False for item in self.current_items: self.current_items[item].total_time += time_passed self.just_fired = False if self.dead and self.health > 0: self.im_back = True self.dead = False self.frame = 1 if self.regen: self.regen_time += time_passed t = 1 if self.shield == 0: t = 2 if self.regen_time >= t: self.regen_time = 0 self.shield += .1 if self.shield > self.max_shield: self.shield = self.max_shield pressed = pygame.key.get_pressed() if ( pressed[pygame.K_SPACE] or pressed[pygame.K_w] or pressed[pygame.K_UP] or joystick.CurrentState.X ) and self.completeness == 1 and self.canFire and self.beam and not self.dead: obj = self.fire() if not self.whimp: self.just_fired = obj if pressed[pygame.K_q] and self.rotate: self.rotation -= self.rotation_speed * time_passed if joystick.CurrentState.LT_val >= .05 and self.rotate: self.rotation -= self.rotation_speed * time_passed * joystick.CurrentState.LT_val if pressed[pygame.K_e] and self.rotate: self.rotation += self.rotation_speed * time_passed if joystick.CurrentState.RT_val >= .05 and self.rotate: self.rotation += self.rotation_speed * time_passed * joystick.CurrentState.RT_val if self.rotation < -self.max_rotation: self.rotation = -self.max_rotation if self.rotation > self.max_rotation: self.rotation = self.max_rotation if self.dead: if self.frame_rate <= self.frame_time: self.frame += 1 self.frame_time = 0 if self.frame > self.death_frames: self.kill = True self.frame = 25 self.frame_time += time_passed self.time_passed = time_passed if self.completeness < 1: self.completeness += time_passed * self.fire_per_sec if self.completeness > 1: self.completeness = 1 if not self.beam: self.image = pygame.transform.scale(self.images[\ f"{self.name}{int(6 * (self.completeness / 1))}"], self.size) acc = True if (pressed[pygame.K_LEFT] or pressed[pygame.K_a] or joystick.CurrentState.joystick_left) and not self.dead: self.target_x_velocity = -self.max_velocity elif (pressed[pygame.K_RIGHT] or pressed[pygame.K_d] or joystick.CurrentState.joystick_right) and not self.dead: self.target_x_velocity = self.max_velocity else: acc = False self.target_x_velocity = 0 if acc: self.velocity.x -= ( self.velocity.x - self.target_x_velocity) * self.speed * self.friction * ( 1 if self.hover else self.mission.friction * self.mission.traction ) * self.acceleration * self.general_acc * self.time_passed if not acc: self.velocity.x -= (self.velocity.x - self.target_x_velocity) * self.friction * ( 1 if self.hover else self.mission.friction ) * self.general_acc * self.time_passed if self.velocity.x > self.max_velocity: self.velocity.x = self.max_velocity if self.velocity.x < -self.max_velocity: self.velocity.x = -self.max_velocity if abs(self.velocity.x) < .01 and not acc: self.velocity.x = 0 if self.pos[0] <= 0 and self.velocity.x < 0: self.velocity.x = abs(self.velocity.x) * .2 if self.rect.right >= 800 and self.velocity.x > 0: self.velocity.x = -abs(self.velocity.x) * .2 # if self.pos[0] < 0: # self.pos[0] = 0 # self.velocity[0] = 0 # if self.pos[0] > 736: # self.pos[0] = 736 # self.velocity[0] = 0 if self.mission.temperature + self.add_temp > self.max_temp and not self.dead: remove = ( (self.mission.temperature + self.add_temp - self.max_temp) / 1000) * self.time_passed if self.shield > 0: self.shield -= remove else: self.health -= remove if self.shield < 0: self.shield = 0 self.pos[0] += self.velocity[0] self.pos[1] += self.velocity[1] self.rect = self.get_rect() if not self.dead: self.rect.bottom -= ((self.rect.bottom - self.target_alt) * self.alt_change_speed * self.time_passed) self.pos[1] = self.rect.top self.rect = self.get_rect() def goToGround(self): self.target_alt = self.min_alt def goBackUp(self): self.target_alt = self.standard_alt
def congrats(display, images, mode, data, profile=None): """Display a screen for awarding achievements / unlocking planets""" done = False pf = 1 pt = 0 pfr = 1 / 25 time_passed = 0 total_time_passed = 0 clock = pygame.time.Clock() if profile and mode == "ach": Sound(fix_path("audio/cashRegister.wav")).play() profile["money"] += data[2] profile["achievements"].append(data[0]) while not done: for event in pygame.event.get(): joystick.Update(event) if not hasattr(event, "key"): event.key = None if event.type == pygame.KEYDOWN or joystick.WasEvent(): if event.key in (pygame.K_RETURN, pygame.K_ESCAPE) or joystick.GoEvent( ) or joystick.BackEvent(): done = True if event.key == pygame.K_F2 or joystick.JustPressedLB(): screenshot.capture("_congrats", display) display.blit(images["background"], (0, 0)) if not mode == "store": retro_text((400, 100), display, 24, "Congratulations!", font="impact", anchor="center") stuff_rect = pygame.Rect(0, 0, 450, 350) if mode == "ach": stuff_rect.w *= 1.5 stuff_rect.midtop = (400, 90) stuff_surf = pygame.Surface(stuff_rect.size) stuff_surf.fill((255, 0, 255)) stuff_surf.set_alpha(50) display.blit(stuff_surf, stuff_rect) if mode == "planet" or mode == "store": rgba = "" if data.rgba: rgba = "RGBA" name = f"spinning{data.name}{rgba}{pf}" if not name in images: name = f"still_{data.name.lower()}" image = images[name] rect = pygame.Rect(0, 0, 100, 100) rect.center = (400, 200) display.blit(pygame.transform.scale(image, (100, 100)), rect) text = "" if not mode == "store": retro_text((400, 300), display, 14, f"You have unlocked Planet {data.name}", anchor="center") else: retro_text((400, 300), display, 14, f"Restocked Store on {data.name}", anchor="center") pt += time_passed if pt >= pfr: pf += 1 pt = 0 if pf > 25: pf = 1 if mode == "ach": # Short for achievement retro_text((400, 250), display, 17, f"{data[0]} Achievement Unlocked!", anchor="center", font="Sans") retro_text((400, 280), display, 15, data[1], anchor="center", bold=True, font="Sans") retro_text((400, 300), display, 15, f"Money Earned: {data[2]}", bold=True, font="Sans", anchor="center") if total_time_passed >= 15: done = True pygame.display.update() time_passed = clock.tick(60) / 1000 total_time_passed += time_passed
def events(self): for event in pygame.event.get(): click = False joystick.Update(event) if not hasattr(event, "key"): event.key = None if event.type == pygame.MOUSEBUTTONDOWN: if self.button_rect.collidepoint(pygame.mouse.get_pos()): click = True if event.type == pygame.KEYUP or joystick.WasEvent(): if event.key == pygame.K_y or joystick.JustPressedY(): 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 or joystick.WasEvent(): if event.key in (pygame.K_UP, pygame.K_w) or joystick.JustWentUp(): if not self.button_selected: self.selected -= 1 else: self.button_selected = False if event.key in (pygame.K_DOWN, pygame.K_s) or joystick.JustWentDown(): 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) or joystick.JustWentLeft()) and not self.button_selected: self.sel_num[self.selected] -= 1 if (event.key in (pygame.K_RIGHT, pygame.K_d) or joystick.JustWentRight()) 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 or joystick.JustPressedA()) 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]) break else: cat[lcat[sel]] -= 1 break if not didSomething: Sound(fix_path("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 or joystick.JustPressedA()) and self.button_selected: click = True if click and not self.cannotContinue(): self.done = True
class LoseWin: def __init__(self, display, images, money=[1, 1, 1, 1, [], 0, 0], mode="won"): self.display = display self.images = images self.mode = mode self.frame = 1 self.frame_time = 0 self.frame_rate = 1 / 25 self.time_passed = 0 self.anim_done = False self.done = False self.text = ["Save + Continue", "Save + Exit"] self.top_selected = True self.money_old, self.money_new, self.bonus, self.bonus1, self.acc, self.lost, self.maxcombo = money try: self.acc_per = self.acc.count(True) / len(self.acc) self.acc_per2 = round(self.acc_per * 100, 3) except ZeroDivisionError: self.acc_per = 0 self.acc_per2 = 0 self.money_new += round(self.bonus) self.money_new += round(self.bonus1 * self.acc_per) self.money_sound = Sound(fix_path("audio/money.wav")) self.register_sound = Sound(fix_path("audio/cashRegister.wav")) if mode == "won": self.money_sound.play(-1) self.exit = False self.stopped = False def main(self): while not self.done: self.events() self.draw() self.update() return self.exit def events(self): for event in pygame.event.get(): joystick.Update(event) if not hasattr(event, "key"): event.key = None if event.type == pygame.KEYUP or joystick.WasEvent(): if event.key == pygame.K_F2 or joystick.JustPressedLB(): screenshot.capture("WL", self.display) if event.key == pygame.K_ESCAPE or joystick.BackEvent(): self.money_old = self.money_new if event.key == pygame.K_TAB: self.top_selected = not self.top_selected if event.key == pygame.K_UP or joystick.JustWentUp(): self.top_selected = True if event.key == pygame.K_DOWN or joystick.JustWentDown(): self.top_selected = False if event.key == pygame.K_y or joystick.JustPressedY(): self.info() if event.key == pygame.K_RETURN or joystick.JustPressedA(): self.stopped = True if self.mode == "won": self.register_sound.play() self.money_sound.stop() if self.top_selected: self.done = True else: self.done = True self.exit = True def info(self): display = self.display.copy() done = False rect = pygame.Rect(0, 0, 600, 400) rect.center = self.display.get_rect().center data = f""" Shots fired: {len(self.acc)} Shots hit: {self.acc.count(True)} Shots missed: {self.acc.count(False)} Accuracy: {self.acc_per2}% Total attempts to beat this level:{self.lost} Max Combo: {self.maxcombo}""" while not done: for event in pygame.event.get(): joystick.Update(event) if not hasattr(event, "key"): event.key = None if event.type == pygame.QUIT: done = True if event.type == pygame.KEYUP or joystick.WasEvent(): if event.key == pygame.K_F2 or joystick.JustPressedLB(): screenshot.capture("WL_info", self.display) if event.key in (pygame.K_q, pygame.K_ESCAPE, pygame.K_RETURN, pygame.K_SPACE, pygame.K_y) or joystick.BackEvent( ) or joystick.GoEvent(): done = True self.display.blit(display, (0, 0)) pygame.draw.rect(self.display, (40, 40, 40), rect) pygame.draw.rect(self.display, (255, 255, 0), rect, 1) for index, line in enumerate(data.split("\n")): retro_text((121, 142 + index * 14), self.display, 14, line, color=(0, 0, 0)) retro_text((120, 140 + index * 14), self.display, 14, line) pygame.display.update() joystick.Reset() def draw(self): self.display.blit(self.images["background"], (0, 0)) rect = pygame.Rect(0, 0, 400, 200) rect.center = self.display.get_rect().center self.display.blit( pygame.transform.scale(self.images[f"you_{self.mode}{self.frame}"], (400, 200)), rect) rect.move_ip(50, 0) pos = rect.left - 20, rect.bottom colors = [(255, 255, 175), (255, 255, 255)] if not self.top_selected: pos = rect.left - 20, rect.bottom + 20 colors.reverse() self.display.blit(self.images["bullet"], pos) retro_text(rect.bottomleft, self.display, 14, self.text[0], anchor="topleft", color=colors[0]) retro_text((rect.left, rect.bottom + 20), self.display, 14, self.text[1], anchor="topleft", color=colors[1]) if self.mode == "won": retro_text((400, 25), self.display, 14, "Loot:", anchor="center") retro_text((400, 50), self.display, 14, round(self.money_old), anchor="center") retro_text((400, 75), self.display, 14, "Fast Victory Bonus", anchor="center") retro_text((400, 100), self.display, 14, round(self.bonus), anchor="center") retro_text((400, 125), self.display, 14, "Accuracy Bonus", anchor="center") retro_text((400, 150), self.display, 14, round(self.bonus1 * self.acc_per), anchor="center") retro_text((400, 165), self.display, 14, "Press <Y> for more info", anchor="center") def update(self): self.frame_time += self.time_passed if self.frame_time >= self.frame_rate and not self.anim_done: self.frame += 1 self.frame_time = 0 if self.frame > 50 and self.mode == "won": self.frame = 50 self.anim_done = True if self.frame > 50 and self.mode == "lost": self.frame = 1 if self.mode == "won": self.money_old -= (self.money_old - self.money_new) / 25 if round(self.money_old) == round( self.money_new) and not self.stopped and self.mode == "won": self.money_sound.stop() self.register_sound.play() self.stopped = True pygame.display.update() self.time_passed = clock.tick(60) / 1000
import os import pygame import time import copy from interplanetary_invaders.scripts.retro_text import retro_text from interplanetary_invaders.scripts.sound import Sound from interplanetary_invaders.scripts.utils import fix_path, colorize from interplanetary_invaders.scripts.get_file import get_file from interplanetary_invaders.scripts import saves directory = get_file(fix_path("data/screenshots")) pygame.init() sound = Sound(fix_path("audio/click.wav")) options = saves.load_options() save_for_later = {} FirstScreenshot = True def capture(profile_num, surf, ingame=False): global FirstScreenshot if FirstScreenshot: print(colorize(f"Saving screenshots at: {directory}", "bold")) FirstScreenshot = False surf = copy.copy(surf) data = time.localtime() if not os.path.exists(directory): print(colorize("Screenshot directory missing.", "warning")) os.mkdir(directory)