class SparkleWhite(MomentaryEffect): sheet = spritesheet.Spritesheet(8, 4, filename=image_folder + "sparkle.png") all_frames = sheet.get_frames() frames = all_frames[4:8] + all_frames[12:16] + \ all_frames[20:24] + all_frames[28:32]
class SparkleYellow(MomentaryEffect): sheet = spritesheet.Spritesheet(8, 4, filename=image_folder + "sparkle.png") all_frames = sheet.get_frames() frames = all_frames[0:4] + all_frames[8:12] + \ all_frames[16:20] + all_frames[24:28]
class PurplePeopleEater(Monster): sheet = spritesheet.Spritesheet( 4, 1, filename=image_folder+"PurplePeopleEater-02.png") frames = sheet.get_frames() radius = 20 speed = 1.3
class GreenZombie(Monster): sheet = spritesheet.Spritesheet( 3, 1, filename=image_folder+"Zombie.png") frames = sheet.get_frames() radius = 12 speed = 0.5
class GemDiamond(Gemstone): sheet = spritesheet.Spritesheet(7, 6, filename=image_folder + "diamondspinning.png") image_list = sheet.get_frames(end_frame=38) sound = soundeffects.pickup_4
class FireballRed(DirectedSprite): sheet = spritesheet.Spritesheet(3, 2, filename=image_folder + "fireball-red.png") image_list = sheet.get_frames() sheet.create_angled_image_lists(image_list, 32) radius = 16
class BlueGhost(Monster): sheet = spritesheet.Spritesheet( 28, 1, filename=image_folder+"sGhost_strip28.png") frames = sheet.get_frames() radius = 10 speed = 1.8 frame_change_trigger = 3
class Grue(Monster): sheet = spritesheet.Spritesheet( 2, 2, filename=image_folder+"GrueBloodyGrinHorns.png") frames = sheet.get_frames() radius = 16 speed = 1.0 start_health = 40
def __init__(self, sokoban): self.window = sokoban.window self.set_window = sokoban.set_window self.clock = pygame.time.Clock() self.sprites = spritesheet.Spritesheet("sprites.png") self.tiles = dict(zip(("#", "-", "_", ".", "$"), self.sprites.load_strip((0, 0, 32, 32), 5))) self.player_frames = [self.sprites.load_strip((0, i*32, 32, 32), 3, colorkey=(255, 0, 0)) for i in range(1, 5)] self.player_direction = 0 self.player_frame = 1
def __init__(self, filename, rect, count, colorkey=None, loop=False, frames=1): """construct a SpriteStripAnim filename, rect, count, and colorkey are the same arguments used by spritesheet.load_strip. loop is a boolean that, when True, causes the next() method to loop. If False, the terminal case raises StopIteration. frames is the number of ticks to return the same image before the iterator advances to the next image. """ self.filename = filename ss = spritesheet.Spritesheet(filename) self.images = ss.load_strip(rect, count, colorkey) self.i = 0 self.loop = loop self.frames = frames self.f = frames
def __init__(self): self.enemy_choices = EnemyChoice() self.sc_width = SCREEN_WIDTH self.sc_height = SCREEN_HEIGHT self.all_cards = cards.load_cards( os.path.join(ASSETS_PATH, CARD_PATH, 'cards.json')) self.class_cards = self.all_cards['fighter'] self.neutral_cards = self.all_cards['neutral'] ec = cards.load_cards( os.path.join(ASSETS_PATH, CARD_PATH, 'enemy_cards.json'))['enemy'] self.enemy_cards = {e.name: e for e in ec} self.coin = pygame.image.load(os.path.join(ICON_PATH, "metal-disc.png")) laser_beams = spritesheet.Spritesheet( os.path.join(ASSETS_PATH, 'Misc', 'beams.png')) self.laser_img = laser_beams.image_at((210, 310, 50, 90)) self.laser_img = pygame.transform.rotate(self.laser_img, 90) self.laser_rect = self.laser_img.get_rect() self.shield_effect = pygame.transform.scale( pygame.image.load( os.path.join(ASSETS_PATH, 'Misc', 'spr_shield.png')), (80, 80))
def __init__(self, game): super(Rocket, self).__init__() self.game = game # we need to rotate this baseimage baseimage = pygame.image.load(data.filepath('smallrocket.png')).\ convert_alpha() # height and width of base image height, width = baseimage.get_width(), baseimage.get_height() self.baseimage = baseimage # initial image is the upright image self.image = self.baseimage self.rect = self.image.get_rect() # mask used for checking collision with moon self.mask = pygame.mask.from_surface(self.image) # orientation angle to vertical (clockwise in degrees) self.oangle = 0.0 # blank image for when we hit moon self.blankimage = pygame.Surface((self.rect.width, self.rect.height), pygame.SRCALPHA, 32).convert_alpha() # images for explosion animation - only use last 9! self.explodeimages = spritesheet.Spritesheet('explode.png').\ all_images(4, 4, 100, 100)[:9] self.numexplode = len(self.explodeimages) # add states to the statemachine onlaunchpad_state = RocketOnLaunchpadState(self) fired_state = RocketFiredState(self) hitmoon_state = RocketHitMoonState(self) hitasteroid_state = RocketHitAsteroidState(self) self.brain.add_state(onlaunchpad_state) self.brain.add_state(fired_state) self.brain.add_state(hitmoon_state) self.brain.add_state(hitasteroid_state)
class Player(pygame.sprite.Sprite): sheet = spritesheet.Spritesheet(13, 21, filename=image_folder + "Player-01.png") frames_walk_up = sheet.get_frames_in_row(8, end_frame=8) frames_walk_left = sheet.get_frames_in_row(9, end_frame=8) frames_walk_down = sheet.get_frames_in_row(10, end_frame=8) frames_walk_right = sheet.get_frames_in_row(11, end_frame=8) walking_speed_normal = 120.0 / common.frames_per_second walking_speed_fast = 210.0 / common.frames_per_second walking_speed = walking_speed_normal radius = 16 # Collsion radius items_set = set() def __init__(self, position): super().__init__() self.action = "STOP" self.frame_list = self.frames_walk_down self.frame_curr = 0 self.image = self.frame_list[self.frame_curr] self.rect = self.image.get_rect() self.rect.center = position self.frame_change = int(common.frames_per_second / 10) self.frame_change_counter = 0 # Track position as float values for better accuracy self.position_x = float(position[0]) self.position_y = float(position[1]) self.delta_x = 0 self.delta_y = 0 def update(self): if self.action != "STOP": self.frame_change_counter += 1 if self.frame_change_counter >= self.frame_change: self.frame_change_counter = 0 self.frame_curr += 1 # Change frame if self.frame_curr >= len(self.frame_list): self.frame_curr = 0 # Update float postion values for better accuracy self.position_x += self.delta_x self.position_y += self.delta_y self.rect.center = [int(self.position_x), int(self.position_y)] # self.rect.x += self.delta_x # self.rect.y += self.delta_y self.image = self.frame_list[self.frame_curr] def speed_normal(self): if self.walking_speed != self.walking_speed_normal: self.walking_speed = self.walking_speed_normal # Adjust the current speed deltas ratio = self.walking_speed_fast / self.walking_speed_normal self.delta_x /= ratio self.delta_y /= ratio def speed_fast(self): if self.walking_speed != self.walking_speed_fast: self.walking_speed = self.walking_speed_fast # Adjust the current speed deltas ratio = self.walking_speed_fast / self.walking_speed_normal self.delta_x *= ratio self.delta_y *= ratio def walk(self, angle): self.action = "WALK" self.delta_x = math.cos(angle) * self.walking_speed self.delta_y = math.sin(angle) * self.walking_speed # Determine the best frame set self.frame_curr = 0 if abs(self.delta_x) > abs(self.delta_y): if self.delta_x > 0: self.frame_list = self.frames_walk_right else: self.frame_list = self.frames_walk_left else: if self.delta_y > 0: self.frame_list = self.frames_walk_down else: self.frame_list = self.frames_walk_up def do_action(self, action_name): if self.action == action_name: action_name = "STOP" self.action = action_name if self.action == "STOP": self.frame_curr = 0 self.delta_x = 0 self.delta_y = 0 elif self.action == "RIGHT": self.frame_list = self.frames_walk_right self.frame_curr = 0 self.delta_x = self.walking_speed self.delta_y = 0 elif self.action == "LEFT": self.frame_list = self.frames_walk_left self.frame_curr = 0 self.delta_x = -self.walking_speed self.delta_y = 0 elif self.action == "DOWN": self.frame_list = self.frames_walk_down self.frame_curr = 0 self.delta_x = 0 self.delta_y = self.walking_speed elif self.action == "UP": self.frame_list = self.frames_walk_up self.frame_curr = 0 self.delta_x = 0 self.delta_y = -self.walking_speed else: # Any unknown action forces a STOP self.action = "STOP" self.frame_curr = 0 self.delta_x = 0 self.delta_y = 0 def has_item(self, name): return name in self.items_set def add_item(self, name): if name in self.items_set: return self.items_set.add(name) if name == "BOOTS": self.speed_fast() def remove_item(self, name): if name not in self.items_set: return self.items_set.discard(name) if name == "BOOTS": self.speed_fast() def set_position(self, position): self.position_x = position[0] self.position_y = position[1] self.rect.center = [int(self.position_x), int(self.position_y)] def scroll_position(self, dx, dy): self.position_x += dx self.position_y += dy self.rect.center = [int(self.position_x), int(self.position_y)]
class GemPink(Gemstone): sheet = spritesheet.Spritesheet( 32, 1, filename=image_folder + "gem-pink.png") image_list = sheet.get_frames() sound = soundeffects.pickup_3
# Dungeon Tiles import random import pygame import common import clientserver import spritesheet # Load the dungeon tiles spritesheets frames = [] ss_names = "hyptosis_tile-art-batch-{}.png" for number in range(1, 5): ss = spritesheet.Spritesheet(30, 30, filename=common.image_folder + ss_names.format(number)) frames.append(ss.get_frames()) def get_tile_image(sheet, row, col): frame_list = frames[sheet - 1] image = frame_list[row * 30 + col] return image # determine tile size from first tile tile_size = get_tile_image(1, 0, 0).get_rect().width wall_images = [] wall_images.append(get_tile_image(1, 7, 0)) wall_images.append(get_tile_image(1, 7, 1))
def __init__(self, x, y): ss = spritesheet.Spritesheet('sprites/sprites.gif') #add images self.downImages = ss.images_at( ((328, 50, 30, 50), (386, 50, 30, 50), (430, 50, 30, 50), (478, 50, 30, 50), (523, 50, 30, 50)), colorkey=(255, 255, 255)) self.upImages = ss.images_at( ((328, 130, 30, 50), (386, 130, 30, 50), (430, 130, 30, 50), (478, 130, 30, 50), (523, 130, 30, 50)), colorkey=(255, 255, 255)) self.rightImages = ss.images_at( ((328, 210, 30, 48), (386, 210, 30, 48), (430, 210, 30, 48), (478, 210, 27, 48), (523, 210, 27, 48)), colorkey=(255, 255, 255)) self.leftImages = [] #scale images down for index in range(len(self.downImages)): temp = pygame.transform.scale(self.downImages[index], (15, 25)) self.downImages[index] = temp for index in range(len(self.upImages)): temp = pygame.transform.scale(self.upImages[index], (15, 25)) self.upImages[index] = temp for index in range(len(self.rightImages)): temp = pygame.transform.scale(self.rightImages[index], (15, 25)) self.rightImages[index] = temp #add left images for image in self.rightImages: self.leftImages.append(pygame.transform.flip(image, True, False)) ssA = spritesheet.Spritesheet('sprites/sprite_attack.gif') self.downAttackImages = ssA.images_at( ((338, 42, 55, 65), (390, 42, 55, 65), (445, 42, 55, 65), (504, 42, 55, 65), (555, 42, 55, 65)), colorkey=(255, 255, 255)) self.upAttackImages = ssA.images_at( ((346, 120, 50, 65), (398, 120, 50, 65), (450, 120, 50, 65), (500, 120, 50, 65), (555, 120, 50, 65)), colorkey=(255, 255, 255)) self.rightAttackImages = ssA.images_at( ((331, 210, 65, 65), (387, 210, 65, 65), (445, 210, 65, 65), (508, 210, 65, 65), (515, 210, 65, 65)), colorkey=(255, 255, 255)) self.leftAttackImages = [] #scale images down for index in range(len(self.downAttackImages)): temp = pygame.transform.scale(self.downAttackImages[index], (20, 30)) self.downAttackImages[index] = temp for index in range(len(self.upAttackImages)): temp = pygame.transform.scale(self.upAttackImages[index], (20, 30)) self.upAttackImages[index] = temp for index in range(len(self.rightAttackImages)): temp = pygame.transform.scale(self.rightAttackImages[index], (20, 30)) self.rightAttackImages[index] = temp #add left images for image in self.rightAttackImages: self.leftAttackImages.append( pygame.transform.flip(image, True, False)) self.index = 0 self.image = self.downImages[self.index] self.isAttacking = False self.health = 100 self.keys = 0 self.arrows = 0 super().__init__(x, y, self.image, 10)
class BloodHit(MomentaryEffect): sheet = spritesheet.Spritesheet( 4, 4, filename=image_folder+"BloodHit-1-small.png") frames = sheet.get_frames() frame_change_trigger = 2
class BloodKill(MomentaryEffect): sheet = spritesheet.Spritesheet( 15, 1, filename=image_folder+"bloodsplat3_strip15-small.png") frames = sheet.get_frames() frame_change_trigger = 2
class FireCircle(ContinuousEffect): sheet = spritesheet.Spritesheet( 8, 8, filename=image_folder+"FireCircle.png", scale=1.5) frames = sheet.get_frames() frames = frames[:31]
class SparkleBlue(MomentaryEffect): sheet = spritesheet.Spritesheet(35, 1, filename=image_folder + "Sparkle-Blue.png") frames = sheet.get_frames()
class Vanish(MomentaryEffect): sheet = spritesheet.Spritesheet(4, 4, filename=image_folder + "Effect95.png") frames = sheet.get_frames()
class ExplosionBlue(MomentaryEffect): sheet = spritesheet.Spritesheet(4, 4, filename=image_folder + "Explosion-Blue.png") frames = sheet.get_frames()
def __init__(self, ai_settings, screen, maze): """Initialize the ship and set its starting position.""" super(Pacman, self).__init__() self.screen = screen self.ai_settings = ai_settings self.maze = maze self.size = 30 self.ghosts = Ghosts(self.ai_settings, self.screen, self.maze, self) # Get ship from sprite sheet and load its image and rect. self.ss = spritesheet.Spritesheet('images/pacman.png') self.s1 = spritesheet.Spritesheet('images/pacmandeath.png') self.image = self.ss.image_at((0, 0, 16, 16), -1) self.image = pygame.transform.scale(self.image, (self.size, self.size)) self.rect = self.image.get_rect() # Initilize all pacman assets self.image4 = self.s1.image_at((0, 0, 16, 16), -1) self.image4 = pygame.transform.scale(self.image4, (self.size, self.size)) self.image5 = self.s1.image_at((16, 0, 16, 16), -1) self.image5 = pygame.transform.scale(self.image5, (self.size, self.size)) self.imageright1 = self.ss.image_at((0, 0, 16, 16), -1) self.imageright1 = pygame.transform.scale(self.imageright1, (self.size, self.size)) self.imageright2 = self.ss.image_at((16, 0, 16, 16), -1) self.imageright2 = pygame.transform.scale(self.imageright2, (self.size, self.size)) self.imageleft1 = self.ss.image_at((0, 16, 16, 16), -1) self.imageleft1 = pygame.transform.scale(self.imageleft1, (self.size, self.size)) self.imageleft2 = self.ss.image_at((16, 16, 16, 16), -1) self.imageleft2 = pygame.transform.scale(self.imageleft2, (self.size, self.size)) self.imageup1 = self.ss.image_at((0, 32, 16, 16), -1) self.imageup1 = pygame.transform.scale(self.imageup1, (self.size, self.size)) self.imageup2 = self.ss.image_at((16, 32, 16, 16), -1) self.imageup2 = pygame.transform.scale(self.imageup2, (self.size, self.size)) self.imagedown1 = self.ss.image_at((0, 48, 16, 16), -1) self.imagedown1 = pygame.transform.scale(self.imagedown1, (self.size, self.size)) self.imagedown2 = self.ss.image_at((16, 48, 16, 16), -1) self.imagedown2 = pygame.transform.scale(self.imagedown2, (self.size, self.size)) self.image3 = self.ss.image_at((32, 0, 16, 16), -1) self.image3 = pygame.transform.scale(self.image3, (self.size, self.size)) self.screen = screen self.screen_rect = screen.get_rect() self.rect.center = self.screen_rect.center self.waka = pygame.mixer.Sound('sounds/waka.wav') self.intromus = pygame.mixer.Sound('sounds/intro.wav') self.dsound = pygame.mixer.Sound('sounds/death.wav') self.esound = pygame.mixer.Sound('sounds/eatghost.wav') self.dead = 0 # Load the ship image and get its rect. # self.image = pygame.image.load('images/ship.bmp') # self.rect = self.image.get_rect() # Start each new ship at the bottom center of the screen. # self.rect.centerx = self.screen_rect.centerx # self.rect.bottom = self.screen_rect.bottom # Store a decimal value for the ship's center self.centerx = float(self.rect.centerx) self.centery = float(self.rect.centery) # Movement flags self.moving_right = False self.moving_left = False self.moving_up = False self.moving_down = False self.tick = 0 self.i = 0
def __init__(self, loadmap=0): self.spritesheet = spritesheet.Spritesheet(SPRITESHEET_PATH) self.spritesheet2 = spritesheet.Spritesheet(SPRITESHEET_PATH2) self.player = player.Player(self.spritesheet) self.player.pos = (6 * stg.GRID_SIZE, 6 * stg.GRID_SIZE) self.map = muhmap.Map(self.spritesheet2)
def __init__(self, ai_settings, screen, maze, pacman): """Initialize the ship and set its starting position.""" super(Ghosts, self).__init__() self.screen = screen self.ai_settings = ai_settings self.maze = maze self.size = 30 self.pacman = pacman # Get ship from sprite sheet and load its image and rect. self.bl = spritesheet.Spritesheet('images/blinky.png') self.cl = spritesheet.Spritesheet('images/clyde.png') self.pi = spritesheet.Spritesheet('images/pinky.png') self.ink = spritesheet.Spritesheet('images/inky.png') # Blinky setup self.blinky1a = self.bl.image_at((0, 0, 16, 16), -1) self.blinky1a = pygame.transform.scale(self.blinky1a, (self.size, self.size)) self.blinky1b = self.bl.image_at((16, 0, 16, 16), -1) self.blinky1b = pygame.transform.scale(self.blinky1b, (self.size, self.size)) self.blinky2a = self.bl.image_at((0, 16, 16, 16), -1) self.blinky2a = pygame.transform.scale(self.blinky2a, (self.size, self.size)) self.blinky2b = self.bl.image_at((16, 16, 16, 16), -1) self.blinky2b = pygame.transform.scale(self.blinky2b, (self.size, self.size)) self.blinky3a = self.bl.image_at((0, 32, 16, 16), -1) self.blinky3a = pygame.transform.scale(self.blinky3a, (self.size, self.size)) self.blinky3b = self.bl.image_at((16, 32, 16, 16), -1) self.blinky3b = pygame.transform.scale(self.blinky3b, (self.size, self.size)) self.blinky4a = self.bl.image_at((0, 48, 16, 16), -1) self.blinky4a = pygame.transform.scale(self.blinky4a, (self.size, self.size)) self.blinky4b = self.bl.image_at((16, 48, 16, 16), -1) self.blinky4b = pygame.transform.scale(self.blinky4b, (self.size, self.size)) # inky setup self.inky1a = self.ink.image_at((0, 0, 16, 16), -1) self.inky1a = pygame.transform.scale(self.inky1a, (self.size, self.size)) self.inky1b = self.ink.image_at((16, 0, 16, 16), -1) self.inky1b = pygame.transform.scale(self.inky1b, (self.size, self.size)) self.inky2a = self.ink.image_at((0, 16, 16, 16), -1) self.inky2a = pygame.transform.scale(self.inky2a, (self.size, self.size)) self.inky2b = self.ink.image_at((16, 16, 16, 16), -1) self.inky2b = pygame.transform.scale(self.inky2b, (self.size, self.size)) self.inky3a = self.ink.image_at((0, 32, 16, 16), -1) self.inky3a = pygame.transform.scale(self.inky3a, (self.size, self.size)) self.inky3b = self.ink.image_at((16, 32, 16, 16), -1) self.inky3b = pygame.transform.scale(self.inky3b, (self.size, self.size)) self.inky4a = self.ink.image_at((0, 48, 16, 16), -1) self.inky4a = pygame.transform.scale(self.inky4a, (self.size, self.size)) self.inky4b = self.ink.image_at((16, 48, 16, 16), -1) self.inky4b = pygame.transform.scale(self.inky4b, (self.size, self.size)) # pinky setup self.pinky1a = self.pi.image_at((0, 0, 16, 16), -1) self.pinky1a = pygame.transform.scale(self.pinky1a, (self.size, self.size)) self.pinky1b = self.pi.image_at((16, 0, 16, 16), -1) self.pinky1b = pygame.transform.scale(self.pinky1b, (self.size, self.size)) self.pinky2a = self.pi.image_at((0, 16, 16, 16), -1) self.pinky2a = pygame.transform.scale(self.pinky2a, (self.size, self.size)) self.pinky2b = self.pi.image_at((16, 16, 16, 16), -1) self.pinky2b = pygame.transform.scale(self.pinky2b, (self.size, self.size)) self.pinky3a = self.pi.image_at((0, 32, 16, 16), -1) self.pinky3a = pygame.transform.scale(self.pinky3a, (self.size, self.size)) self.pinky3b = self.pi.image_at((16, 32, 16, 16), -1) self.pinky3b = pygame.transform.scale(self.pinky3b, (self.size, self.size)) self.pinky4a = self.pi.image_at((0, 48, 16, 16), -1) self.pinky4a = pygame.transform.scale(self.pinky4a, (self.size, self.size)) self.pinky4b = self.pi.image_at((16, 48, 16, 16), -1) self.pinky4b = pygame.transform.scale(self.pinky4b, (self.size, self.size)) # clyde setup self.clyde1a = self.cl.image_at((0, 0, 16, 16), -1) self.clyde1a = pygame.transform.scale(self.clyde1a, (self.size, self.size)) self.clyde1b = self.cl.image_at((16, 0, 16, 16), -1) self.clyde1b = pygame.transform.scale(self.clyde1b, (self.size, self.size)) self.clyde2a = self.cl.image_at((0, 16, 16, 16), -1) self.clyde2a = pygame.transform.scale(self.clyde2a, (self.size, self.size)) self.clyde2b = self.cl.image_at((16, 16, 16, 16), -1) self.clyde2b = pygame.transform.scale(self.clyde2b, (self.size, self.size)) self.clyde3a = self.cl.image_at((0, 32, 16, 16), -1) self.clyde3a = pygame.transform.scale(self.clyde3a, (self.size, self.size)) self.clyde3b = self.cl.image_at((16, 32, 16, 16), -1) self.clyde3b = pygame.transform.scale(self.clyde3b, (self.size, self.size)) self.clyde4a = self.cl.image_at((0, 48, 16, 16), -1) self.clyde4a = pygame.transform.scale(self.clyde4a, (self.size, self.size)) self.clyde4b = self.cl.image_at((16, 48, 16, 16), -1) self.clyde4b = pygame.transform.scale(self.clyde4b, (self.size, self.size)) # Death setup self.eye = spritesheet.Spritesheet('images/eyes.png') self.eyes1 = self.eye.image_at((0, 0, 16, 16), -1) self.eyes1 = pygame.transform.scale(self.eyes1, (self.size, self.size)) self.eyes2 = self.eye.image_at((0, 16, 16, 16), -1) self.eyes2 = pygame.transform.scale(self.eyes2, (self.size, self.size)) self.eyes3 = self.eye.image_at((0, 32, 16, 16), -1) self.eyes3 = pygame.transform.scale(self.eyes3, (self.size, self.size)) self.eyes4 = self.eye.image_at((0, 48, 16, 16), -1) self.eyes4 = pygame.transform.scale(self.eyes4, (self.size, self.size)) self.blueghost = pygame.image.load('images/blueghost.png') self.blueghost = pygame.transform.scale(self.blueghost, (self.size, self.size)) self.powerpill = pygame.image.load('images/powerpill.png') self.powerpill_rect = self.powerpill.get_rect() self.blimage = self.blinky1a self.inkimage = self.inky1a self.piimage = self.pinky1a self.climage = self.clyde1a self.blrect = self.blimage.get_rect() self.inkrect = self.inkimage.get_rect() self.pirect = self.piimage.get_rect() self.clrect = self.climage.get_rect() # Initilize all pacman assets self.screen = screen self.screen_rect = screen.get_rect() # self.rect.center = self.screen_rect.center self.blrect.center = (280, 312) self.inkrect.center = (250, 312) self.pirect.center = (310, 312) self.clrect.center = (340, 312) self.bldead = 0 self.pidead = 0 self.inkdead = 0 self.cldead = 0 # Load the ship image and get its rect. # self.image = pygame.image.load('images/ship.bmp') # self.rect = self.image.get_rect() # Start each new ship at the bottom center of the screen. # self.rect.centerx = self.screen_rect.centerx # self.rect.bottom = self.screen_rect.bottom # Store a decimal value for the ship's center self.blcenterx = float(self.blrect.centerx) self.blcentery = float(self.blrect.centery) self.inkcenterx = float(self.inkrect.centerx) self.inkcentery = float(self.inkrect.centery) self.picenterx = float(self.pirect.centerx) self.picentery = float(self.pirect.centery) self.clcenterx = float(self.clrect.centerx) self.clcentery = float(self.clrect.centery) self.tick = 0 self.blbutton = None
from scipy.sparse.csgraph import connected_components from scipy.sparse import csr_matrix from json import load, dumps import numpy as np from constants import * import spritesheet import engine import pygame Game = engine.Game(BACKGROUND, fullscreen=False) GameSpritesheet = spritesheet.Spritesheet(GAME_SPRITESHEET) game_sprites = GameSpritesheet.images_datafile(SPRITES_DATAFILE) NameSpritesheet = spritesheet.Spritesheet(NAME_SPRITESHEET) name_sprites = NameSpritesheet.images_datafile(CITIES_DATAFILE) city_sprites = [] names = [] for city in load(open(CITY_POS_DATAFILE, "r")): names.append(city[SPRITE_ID]) sprite_id = city[SPRITE_ID] x, y = city[POSITION] cityspace_c = engine.Point(x + CITYTEXT_WIDTH // 2, y + CITYSPACE_SIZE // 2) cityspace_size = (CITYSPACE_SIZE, CITYSPACE_SIZE) citytext_size = (CITYTEXT_WIDTH, CITYTEXT_HEIGHT) a = pygame.transform.scale(game_sprites[city[SPRITE_ICON]], cityspace_size) b = pygame.transform.scale(name_sprites[city[SPRITE_ID]], citytext_size) s = (CITYTEXT_WIDTH, CITYSPACE_SIZE + CITYTEXT_HEIGHT - CITYTEXT_UPSHIFT) image = pygame.Surface(s, pygame.SRCALPHA)