def __init__(self, screen: pygame.Surface): global current_game current_game = self self.screen = screen spritesheet = SpriteSheet('./assets/sprites.png') self.life_image = pygame.transform.scale( spritesheet.image_at((423, 345, 16, 8), color_key=-1), (64, 32)) self.checkpoint_image = pygame.transform.scale( spritesheet.image_at((389, 335, 8, 8), color_key=-1), (32, 32)) self.simplex = OpenSimplex() self.font = pygame.font.Font('freesansbold.ttf', 24) self.next_hole = self.screen.get_width( ) + random.random() * HOLE_SPACE_VAR self.holes = [] self.checkpoint = 0 self.checkpoint_score = 0 self.lives = 3 self.score = 0 self.highest_score = 0 self.terrain = Terrain(screen, MARTIAN_BROWN, self.terrain_point) self.all_sprites = pygame.sprite.Group() self.player = Player(START_LOCATION, 0) self.all_sprites.add(self.player)
def __init__(self): pygame.sprite.Sprite.__init__(self) screen = pygame.display.get_surface() # self.rect = pygame.Rect(self.x, self.y, 15, 30) # Each sprite is 16x21 pixels starting at location 0,6 in the file main_dir = os.path.split(os.path.abspath(__file__))[0] character_ss = SpriteSheet(main_dir + '/graphics/character.png') self.image_front = character_ss.image_at((0, 6, 16, 21)) self.image_front = pygame.transform.scale(self.image_front, (48, 63)) self.image_back = character_ss.image_at((0, 69, 16, 21)) self.image_back = pygame.transform.scale(self.image_back, (48, 63)) self.image_left = character_ss.image_at((0, 101, 16, 21)) self.image_left = pygame.transform.scale(self.image_left, (48, 63)) self.image_right = character_ss.image_at((0, 38, 16, 21)) self.image_right = pygame.transform.scale(self.image_right, (48, 63)) self.image = self.image_front self.rect = self.image.get_rect()
class HealthBar(): def __init__(self): self.sheet = SpriteSheet( pygame.transform.scale2x(utils.load_png("gui.png"))) self.health = 100 def draw(self, surface, level): surface.blit(self.sheet.image_at((32, 0, 32, 16)), (0, 0)) surface.blit(self.sheet.image_at((64, 0, 32, 2)), (0, 18)) for bar_lvl in range(1, 81, 2): y_val = bar_lvl + 19 if self.health >= (40 - bar_lvl / 2) * 2.5: surface.blit(self.sheet.image_at((64, 2, 32, 2)), (0, y_val)) else: surface.blit(self.sheet.image_at((64, 4, 32, 2)), (0, y_val)) surface.blit(self.sheet.image_at((64, 0, 32, 2)), (0, 100)) utils.text_format(surface, 'LVL', 12, (0, 129), (255, 255, 255), 3) if level.levelNumber < 10: utils.text_format(surface, str(level.levelNumber), 18, (8, 145), (255, 255, 255), 1) elif level.levelNumber < 100: utils.text_format(surface, str(level.levelNumber), 18, (2, 145), (255, 255, 255), 2) else: utils.text_format(surface, str(level.levelNumber), 13, (0, 145), (255, 255, 255), 3) utils.text_format(surface, "MSTR LEFT", 9, (0, 223), (255, 255, 255), 4) if level.num_monsters > 9: utils.text_format(surface, str(level.num_monsters), 18, (2, 255), (255, 255, 255), 2) else: utils.text_format(surface, str(level.num_monsters), 18, (8, 255), (255, 255, 255), 1) utils.text_format(surface, "RGN", 12, (0, 333), (255, 255, 255), 3) if level.health > 9: utils.text_format(surface, str(int(level.health)), 18, (2, 349), (255, 255, 255), 2) else: utils.text_format(surface, str(int(level.health)), 18, (8, 349), (255, 255, 255), 1)
def __init__(self, max_hp, cur_hp, hb_img, img_dim): pygame.sprite.Sprite.__init__(self) self.max_hp = max_hp self.cur_hp = cur_hp self.images = [] self.barcount = 15 sp = SpriteSheet(hb_img) for i in range(self.barcount): self.images.append(sp.image_at((0, -img_dim[1] * (self.barcount - i - 1), img_dim[0], img_dim[1]), -1)) self.image, self.rect = self.images[self.hp_to_bar_value(self.cur_hp)]
def __init__(self, center=None): pygame.sprite.Sprite.__init__(self) img = SpriteSheet(os.path.join(env.img_folder, 'flower.png')) self.image = pygame.transform.scale(img.image_at( (5 * 32, 0, 32, 32)), (self.width, self.height)).convert_alpha() self.rect = self.image.get_rect() if center is None: center = (random.randint(self.width // 2, env.WIDTH - self.width // 2), random.randint(self.height // 2, env.HEIGHT - self.height // 2)) self.rect.center = center
class Ship: def __init__(self): current_path = os.path.dirname(__file__) self._image_path = os.path.join(current_path, 'images') self._sprite_sheet = SpriteSheet(os.path.join(self._image_path, "sprites.png"), color_key=-1) self._ship = self._sprite_sheet.image_at((66, 14, 35, 32)) self._ship_rect = self._ship.get_rect() def move(self, speed): self._ship_rect = self._ship_rect.move(speed) def draw(self, screen): screen.blit(self._ship, self._ship_rect)
def __init__(self): pygame.sprite.Sprite.__init__(self) img = pygame.Surface((env.WIDTH, env.HEIGHT)).convert_alpha() self.image = img self.rect = self.image.get_rect(left=0, top=0) sheet = SpriteSheet(os.path.join(env.img_folder, 'basictiles.png')) bit = pygame.transform.scale(sheet.image_at((1 * 16, 8 * 16, 16, 16)), self.bit_size) for x in range(self.map_size[0]): for y in range(self.map_size[1]): img.blit( bit, bit.get_rect(left=x * self.bit_size[0], top=y * self.bit_size[1]))
def __init__(self, color, width, height): """ Constructor, accepts the color and dimensions of the block """ super().__init__() sprite_sheet = SpriteSheet('lol.png') #Create an image of the block picture = sprite_sheet.image_at([0, 0, 20, 20]) picture = pygame.transform.scale(picture, (width, height)) self.image = picture # Fetch the rectangle object that has the dimensions of the image # Update the position by setting the values of # rect.x and rect.y self.rect = self.image.get_rect()
def __init__(self, x, y, remove_self): super().__init__() spritesheet = SpriteSheet('./assets/sprites.png') large_explosion_rects = [(2 + 2 * 50 * i, 36, 48, 32) for i in range(3)] small_explosion_rects = [(302 + 2 * 34 * i, 52, 32, 16) for i in range(2)] last_explosion_rect = (438, 52, 16, 16) self.large_explosion_images = [pygame.transform.scale(img, (WIDE_TILE_SIZE, ROVER_SIZE)) for img in spritesheet.images_at(*large_explosion_rects, color_key=-1)] self.small_explosion_images = [pygame.transform.scale(img, (ROVER_SIZE, WHEEL_SIZE)) for img in spritesheet.images_at(*small_explosion_rects, color_key=-1)] self.last_explosion_image = pygame.transform.scale(spritesheet.image_at(last_explosion_rect, color_key=-1), (WHEEL_SIZE, WHEEL_SIZE)) self.x_pos, self.y_pos = x, y self.image = self.large_explosion_images[0] self.rect = (x, y, ROVER_SIZE, WIDE_TILE_SIZE) self.frame_timer = 0 self.skip_frames = 8 self.remove_self = remove_self
def load_pieces(square_size): # Loading sprite sheet ss = SpriteSheet('Sprites/Pieces_trans.png') # Storing each image in directory # Kings w_king = pygame.transform.scale(ss.image_at((0,0,200,200)),(square_size,square_size)) w_king.set_colorkey(TRANS) b_king = pygame.transform.scale(ss.image_at((0,200,200,200)),(square_size,square_size)) b_king.set_colorkey(TRANS) # Queens w_queen = pygame.transform.scale(ss.image_at((200,0,200,200)),(square_size,square_size)) w_queen.set_colorkey(TRANS) b_queen = pygame.transform.scale(ss.image_at((200,200,200,200)),(square_size,square_size)) b_queen.set_colorkey(TRANS) # Bishops w_bishop = pygame.transform.scale(ss.image_at((400,0,200,200)),(square_size,square_size)) w_bishop.set_colorkey(TRANS) b_bishop = pygame.transform.scale(ss.image_at((400,200,200,200)),(square_size,square_size)) b_bishop.set_colorkey(TRANS) # Knights w_knight = pygame.transform.scale(ss.image_at((600,0,200,200)),(square_size,square_size)) w_knight.set_colorkey(TRANS) b_knight = pygame.transform.scale(ss.image_at((600,200,200,200)),(square_size,square_size)) b_knight.set_colorkey(TRANS) # Rook w_rook = pygame.transform.scale(ss.image_at((800,0,200,200)),(square_size,square_size)) w_rook.set_colorkey(TRANS) b_rook = pygame.transform.scale(ss.image_at((800,200,200,200)),(square_size,square_size)) b_rook.set_colorkey(TRANS) # Pawn w_pawn = pygame.transform.scale(ss.image_at((1000,0,200,200)),(square_size,square_size)) w_pawn.set_colorkey(TRANS) b_pawn = pygame.transform.scale(ss.image_at((1000,200,200,200)),(square_size,square_size)) b_pawn.set_colorkey(TRANS) pieces = { "w_king" : w_king, "b_king" : b_king, "w_queen" : w_queen, "b_queen" : b_queen, "w_bishop" : w_bishop, "b_bishop" : b_bishop, "w_knight" : w_knight, "b_knight" : b_knight, "w_rook" : w_rook, "b_rook" : b_rook, "w_pawn" : w_pawn, "b_pawn" : b_pawn } return pieces
def intro(): gameExit = False frame_counter = 0 phase = 0 summoning = 0 summoned = False chest = 'closed' show_key = False show_bear = False show_cake = False done_hoot = False did_fade = False cake_x = 290 cake_y = 5 key_pressed = False hoot_sound = pygame.mixer.Sound("sound/hoot.wav") ufo_sound = pygame.mixer.Sound("sound/ufo.wav") pop_sound = pygame.mixer.Sound("sound/pop.wav") open_sound = pygame.mixer.Sound("sound/unlock.wav") happy_birthday = pygame.mixer.Sound("sound/happybirthday.wav") pygame.mixer.init() pygame.mixer.music.load('sound/music.wav') pygame.mixer.music.set_volume(0.3) scan = pygame.image.load('pictures/scan.jpg') spritesheet = SpriteSheet('tiles/sheet.png') pumpkin = spritesheet.image_at((ts * 6, ts * 20, ts, ts), -1) seedling = spritesheet.image_at((ts * 7, ts * 19, ts, ts), -1) stone1 = spritesheet.image_at((ts * 1, ts * 57, ts, ts)) stone2 = spritesheet.image_at((ts * 2, ts * 57, ts, ts)) stone3 = spritesheet.image_at((0, ts * 57, ts, ts)) ground1 = spritesheet.image_at((0, 0, ts, ts)) ground2 = spritesheet.image_at((ts, 0, ts, ts)) ground3 = spritesheet.image_at((ts * 2, 0, ts, ts)) fence = spritesheet.image_at((0, ts * 22, ts, ts), -1) path1 = spritesheet.image_at((ts * 5, 0, ts, ts)) tree2 = spritesheet.image_at((ts * 2, ts, ts * 2, ts * 2), -1) log = spritesheet.image_at((ts * 6, ts * 5, ts * 2, ts), -1) skull = spritesheet.image_at((ts * 6, ts * 131, ts, ts), -1) fountain = spritesheet.image_at((0, ts * 116, ts * 3, ts * 3), -1) statue = spritesheet.image_at((ts * 4, ts * 113, ts, ts * 2), -1) statue2 = spritesheet.image_at((ts * 3, ts * 115, ts, ts * 2), -1) statue3 = spritesheet.image_at((ts * 4, ts * 115, ts, ts * 2), -1) grave = spritesheet.image_at((ts * 3, ts * 8, ts, ts), -1) key = spritesheet.image_at((ts * 7, ts * 131, ts, ts), -1) bear = spritesheet.image_at((ts * 3, ts * 128, ts, ts), -1) heart = pygame.image.load('tiles/heart.png') cake_hover = pygame.image.load('tiles/cake.png') cake_hover.set_colorkey(cake_hover.get_at((0, 0)), pygame.RLEACCEL) cake_hover = pygame.transform.scale(cake_hover, (scalesize * 4, scalesize * 4)) cat1 = Character('cat2', -100, 20) cat2 = Character('cat2', 900, 40) cat3 = Character('cat3', -100, 60) morgan = Character('morgan', -64, 50) zander = Character('zander', -64, 70) ghost = Character('ghost', -120, 70) ace = Character('alex', 575, 188) geoff = Character('geoff', 450, -80) martin = Character('martin', 800 + 64 + 20, 50) chest_closed = spritesheet.image_at((ts * 6, ts * 107, ts, ts), -1) chest_open = spritesheet.image_at((ts * 6, ts * 108, ts, ts), -1) # scale things.. chest_closed = pygame.transform.scale(chest_closed, (scalesize, scalesize)) chest_open = pygame.transform.scale(chest_open, (scalesize, scalesize)) pumpkin = pygame.transform.scale(pumpkin, (scalesize, scalesize)) seedling = pygame.transform.scale(seedling, (scalesize, scalesize)) ground1 = pygame.transform.scale(ground1, (scalesize, scalesize)) ground2 = pygame.transform.scale(ground2, (scalesize, scalesize)) ground3 = pygame.transform.scale(ground3, (scalesize, scalesize)) grave = pygame.transform.scale(grave, (scalesize, scalesize)) key = pygame.transform.scale(key, (scalesize, scalesize)) bear = pygame.transform.scale(bear, (scalesize * 2, scalesize * 2)) stone1 = pygame.transform.scale(stone1, (scalesize, scalesize)) stone2 = pygame.transform.scale(stone2, (scalesize, scalesize)) stone3 = pygame.transform.scale(stone3, (scalesize, scalesize)) path1 = pygame.transform.scale(path1, (scalesize, scalesize)) tree2 = pygame.transform.scale(tree2, (scalesize * 2, scalesize * 2)) fence = pygame.transform.scale(fence, (scalesize, scalesize)) log = pygame.transform.scale(log, (scalesize * 2, scalesize)) skull = pygame.transform.scale(skull, (scalesize, scalesize)) statue = pygame.transform.scale(statue, (scalesize, scalesize * 2)) fountain = pygame.transform.scale(fountain, (scalesize * 3, scalesize * 3)) statue2 = pygame.transform.scale(statue2, (scalesize, scalesize * 2)) statue3 = pygame.transform.scale(statue3, (scalesize, scalesize * 2)) background = ( ("S1", "S1", "S1", "S1", "S2", "P1", "P1", "P1", "S3", "S1", "S1", "S1", "S1"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "P1", "P1", "P1", "P1", "P1", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "P1", "P1", "P1", "P1", "P1", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "P1", "P1", "P1", "P1", "P1", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "P1", "P1", "P1", "P1", "P1", "P1", "P1", "G2", "G2", "G2"), ("G2", "G2", "G2", "P1", "P1", "P1", "P1", "P1", "P1", "P1", "G2", "G2", "G2"), ) foreground = ( (" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "), (" ", "PD", "PD", " ", " ", " ", " ", " ", " ", " ", "PD", " ", " "), ("F1", " ", "T2", " ", " ", " ", " ", " ", " ", "A1", " ", "A2", " "), ("F1", "GR", " ", "T2", " ", " ", " ", " ", " ", " ", "PD", "T2", " "), ("F1", "SK", " ", " ", " ", " ", " ", " ", " ", " ", "PU", " ", " "), ("F1", "T2", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "), ("F1", " ", "A3", " ", " ", " ", " ", " ", " ", " ", "L1", " ", " "), ("F1", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "T2", " "), ("T2", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "), ) drawn = 0 is_shaking = 0 while not gameExit: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() # For the sake of video capture, this will require # a hit of the space bar to start the whole thing.. key_input = pygame.key.get_pressed() if key_pressed != True: if key_input[pygame.K_SPACE]: key_pressed = True font_heading = 'EightBitDragon-anqx.ttf' font_heading = pygame.font.Font(font_heading, 30) gameDisplay.blit( font_heading.render('INSERT COIN', 1, (255, 255, 255)), (325, 280)) pygame.display.update() continue #debug #print(event) loc_x = 0 loc_y = 0 if did_fade == False: for map_y in background: for map_x in map_y: if map_x == 'S1': gameDisplay.blit(stone1, (loc_x, loc_y)) if map_x == 'S2': gameDisplay.blit(stone2, (loc_x, loc_y)) if map_x == 'S3': gameDisplay.blit(stone3, (loc_x, loc_y)) if map_x == 'G1': gameDisplay.blit(ground1, (loc_x, loc_y)) if map_x == 'G2': gameDisplay.blit(ground2, (loc_x, loc_y)) if map_x == 'G3': gameDisplay.blit(ground3, (loc_x, loc_y)) if map_x == 'P1': gameDisplay.blit(path1, (loc_x, loc_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 loc_x = 0 loc_y = 0 if did_fade == False: for map_y in foreground: for map_x in map_y: if map_x == 'GR': gameDisplay.blit(grave, (loc_x, loc_y)) if map_x == 'SK': gameDisplay.blit(skull, (loc_x, loc_y)) if map_x == 'PD': gameDisplay.blit(seedling, (loc_x, loc_y)) if map_x == 'PU': gameDisplay.blit(pumpkin, (loc_x, loc_y)) if map_x == 'T2': gameDisplay.blit(tree2, (loc_x, loc_y)) if map_x == 'F1': gameDisplay.blit(fence, (loc_x, loc_y)) if map_x == 'L1': gameDisplay.blit(log, (loc_x, loc_y)) if map_x == 'A2': gameDisplay.blit(statue2, (loc_x, loc_y)) if map_x == 'A3': gameDisplay.blit(statue3, (loc_x, loc_y)) if map_x == 'A1': if not summoned: statue_x = loc_x statue_y = loc_y if summoning > 0: if summoning == 1: pygame.mixer.Sound.play(ufo_sound) summoning = summoning + 1 statue_x = statue_x + random.randint(-5, 5) statue_y = statue_y + random.randint(-5, 5) if summoning > 80: # ugh python - ?? dim = statue.get_size() lst = list(dim) lst[0] = lst[0] + 100 lst[1] = lst[1] + 100 dim = tuple(lst) statue_x = statue_x - 50 * (summoning - 80) statue_y = statue_y - 50 * (summoning - 80) statue = pygame.transform.scale( statue, dim) if summoning == 117: pygame.mixer.Sound.play(pop_sound) if summoning > 120: summoned = True gameDisplay.blit(statue, (statue_x, statue_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 # Foreground tiles that don't fit into my tile engine if chest != 'hidden': if chest == 'open': gameDisplay.blit(chest_open, (390, 380)) else: gameDisplay.blit(chest_closed, (390, 380)) if show_key: gameDisplay.blit(key, (390, 350)) if show_bear: gameDisplay.blit(bear, (358, 353)) if show_cake: gameDisplay.blit(cake_hover, (cake_x, cake_y)) if did_fade != True: gameDisplay.blit(fountain, (327, 490)) gameDisplay.blit(morgan.get_image(), morgan.get_location()) gameDisplay.blit(martin.get_image(), martin.get_location()) gameDisplay.blit(zander.get_image(), zander.get_location()) gameDisplay.blit(ghost.get_image(), ghost.get_location()) gameDisplay.blit(geoff.get_image(), geoff.get_location()) if summoned: gameDisplay.blit(ace.get_image(), ace.get_location()) gameDisplay.blit(cat1.get_image(), cat1.get_location()) gameDisplay.blit(cat2.get_image(), cat2.get_location()) gameDisplay.blit(cat3.get_image(), cat3.get_location()) # This is the non-interactive .. thing. Each phase is an 'act' of the animation. # I'm sure there are better ways of doing this.. this is what I came up with, # while drinking a cup of tea. # Morgan walks in to the right if phase == 0: if done_hoot != True: pygame.mixer.Sound.play(hoot_sound) done_hoot = True t1 = cat1.move_right(900) t2 = cat2.move_left(-100) t3 = cat3.move_right(900) font = 'EightBitDragon-anqx.ttf' font = pygame.font.Font(font, 30) gameDisplay.blit(font.render('England', 1, (255, 255, 255)), (350, 140)) gameDisplay.blit(font.render('2020', 1, (255, 255, 255)), (378, 185)) if t1 and t2 and t3: frame_counter = frame_counter + 1 if frame_counter > 50: frame_counter = 0 phase = 1 pygame.mixer.music.play(1) if phase == 1: if morgan.move_right(360): phase = 2 # Martin walks in from the left if phase == 2: if martin.move_left(420): phase = 3 # A heart appears above us for a few frames if phase == 3: frame_counter = frame_counter + 1 if frame_counter < 50: gameDisplay.blit(heart, (406, 30)) else: frame_counter = 0 phase = 4 # We walk down together if phase == 4: t1 = morgan.move_down(300) t2 = martin.move_down(300) if t1 and t2: phase = 5 # A speech bubble of some sort if phase == 5: dialogue(morgan, 'Hello everybody!') phase = 6 if phase == 6: dialogue(martin, 'We have brought you here today for some news...') phase = 7 if phase == 7: dialogue(martin, 'But first...') phase = 8 if phase == 8: dialogue(morgan, 'ZANDER!!!') phase = 9 if phase == 9: t1 = zander.move_right(900) t2 = ghost.move_right(890) if t1 and t2: phase = 10 if phase == 10: dialogue(martin, 'ZANDER!!!!!!') phase = 11 if phase == 11: if zander.move_left(340): phase = 12 if phase == 12: if zander.move_down(220): phase = 13 # Add some frames between z arriving and speaking. if phase == 13: frame_counter = frame_counter + 1 if frame_counter > 10: frame_counter = 0 phase = 14 if phase == 14: dialogue(zander, '???') phase = 15 if phase == 15: dialogue(martin, 'GEOFFFFFF!!!!!!') phase = 16 if phase == 16: if geoff.move_down(220): phase = 17 if phase == 17: frame_counter = frame_counter + 1 if frame_counter > 10: frame_counter = 0 phase = 18 if phase == 18: dialogue(geoff, 'Want to see my new Beano?') phase = 19 if phase == 19: dialogue(martin, 'We\'re missing one...') phase = 20 if phase == 20: dialogue(morgan, '>> SUMMON ALEX <<') phase = 21 if phase == 21: if summoning == 0: summoning = 1 if summoned: phase = 22 if phase == 22: frame_counter = frame_counter + 1 if frame_counter > 10: frame_counter = 0 phase = 23 if phase == 23: dialogue(ace, 'HERE!') phase = 24 if phase == 24: t1 = ace.move_up(120) t2 = ace.move_left(390) if t1 and t2: phase = 25 if phase == 25: if ace.move_down(215): phase = 26 if phase == 26: dialogue(martin, 'Now that everybody is here, we just want to say..') phase = 27 if phase == 27: show_cake = True frame_counter = frame_counter + 1 if frame_counter > 50: pygame.mixer.Sound.play(happy_birthday) frame_counter = 0 cake = pygame.image.load('tiles/cake.png') cake.set_colorkey(cake.get_at((0, 0)), pygame.RLEACCEL) cake = pygame.transform.scale(cake, (scalesize * 2, scalesize * 2)) dialogue_all('everybody', cake, 'HAPPY BIRTHDAY GRANDPA!') phase = 28 if phase == 28: dialogue(morgan, 'We hope you have an amazing day!') phase = 29 if phase == 29: frame_counter = frame_counter + 1 if frame_counter > 100: frame_counter = 0 phase = 30 if phase == 30: show_cake = False dialogue(zander, 'Wait, what\'s in the chest?') phase = 31 if phase == 31: dialogue(ace, 'Yeh, I was in the middle of a game!') phase = 32 if phase == 32: dialogue(morgan, 'Well let\'s open it and find out!') show_key = True phase = 33 if phase == 33: frame_counter = frame_counter + 1 if frame_counter == 90: pygame.mixer.Sound.play(open_sound) if frame_counter > 100: frame_counter = 0 phase = 34 if phase == 34: show_key = False chest = 'open' frame_counter = frame_counter + 1 if frame_counter > 100: frame_counter = 0 phase = 35 pygame.mixer.init() pygame.mixer.music.load('sound/lullaby.wav') pygame.mixer.music.set_volume(1) pygame.mixer.music.play(1) if phase == 35: chest = 'hidden' show_bear = True frame_counter = frame_counter + 1 if frame_counter == 1: pygame.mixer.music.play(1) if frame_counter > 100: frame_counter = 0 phase = 36 if phase == 36: dialogue(martin, 'That\'s interesting...') phase = 37 if phase == 37: dialogue(morgan, 'That means...') phase = 38 if phase == 38: dialogue(geoff, 'What does it mean?') phase = 39 if phase == 39: dialogue(zander, 'Oh no...') phase = 40 if phase == 40: dialogue(ace, 'Not again...') phase = 41 if phase == 41: dialogue(morgan, 'Yes, again.') phase = 42 if phase == 42: dialogue(morgan, 'Arriving April 2021! A new player!') phase = 43 if phase == 43: dialogue(geoff, 'I\'m not sharing my Lego.') phase = 44 if phase == 44: dialogue(morgan, 'Hush all of you!') phase = 45 if phase == 45: dialogue(morgan, 'Thank you for listening to our news!') phase = 46 if phase == 46: dialogue(martin, 'We hope you are excited as we are!') phase = 47 if phase == 47: frame_counter = frame_counter + 1 if frame_counter > 100: frame_counter = 0 phase = 48 if phase == 48: did_fade = True fadeout() phase = 49 if phase == 49: pygame.draw.rect(gameDisplay, (0, 0, 0), (30, 30, 740, 540)) font_heading = 'EightBitDragon-anqx.ttf' font_heading = pygame.font.Font(font_heading, 20) font_body = 'EightBitDragon-anqx.ttf' font_body = pygame.font.Font(font_body, 15) gameDisplay.blit( font_heading.render('Sound Credits', 1, (255, 255, 255)), (320, 60)) gameDisplay.blit( font_body.render( 'https://freesound.org/people/BeezleFM (unlock)', 1, (193, 193, 193)), (140, 100)) gameDisplay.blit( font_body.render( 'https://freesound.org/people/erkanozan/ (ufo)', 1, (193, 193, 193)), (140, 120)) gameDisplay.blit( font_body.render( 'https://freesound.org/people/Breviceps/ (owl)', 1, (193, 193, 193)), (140, 140)) gameDisplay.blit(font_heading.render('Music', 1, (255, 255, 255)), (370, 180)) gameDisplay.blit( font_body.render('David Vitas @davidvitas (Lullaby Music)', 1, (193, 193, 193)), (230, 240)) gameDisplay.blit( font_body.render('sawsquarenoise (Towel Defence Ending)', 1, (193, 193, 193)), (230, 220)) gameDisplay.blit(scan, (150, 280)) frame_counter = frame_counter + 1 if frame_counter > 300: frame_counter = 0 fadeout() phase = 50 if phase == 50: pygame.draw.rect(gameDisplay, (0, 0, 0), (30, 30, 740, 540)) font_heading = 'EightBitDragon-anqx.ttf' font_heading = pygame.font.Font(font_heading, 20) font_body = 'EightBitDragon-anqx.ttf' font_body = pygame.font.Font(font_body, 15) gameDisplay.blit( font_heading.render('Graphics', 1, (255, 255, 255)), (355, 60)) gameDisplay.blit( font_body.render( 'https://pipoya.itch.io/pipoya-rpg-tileset-32x32 (tiles)', 1, (193, 193, 193)), (140, 100)) gameDisplay.blit( font_body.render( 'https://pipoya.itch.io/pipoya-free-rpg-character-sprites-32x32', 1, (193, 193, 193)), (90, 120)) gameDisplay.blit( font_body.render('(character sprites)', 1, (193, 193, 193)), (320, 140)) gameDisplay.blit( font_heading.render('Thanks to all content creators!', 1, (255, 255, 255)), (220, 180)) gameDisplay.blit( font_body.render('starfighter.dev', 1, (193, 193, 193)), (330, 250)) gameDisplay.blit(scan, (150, 280)) frame_counter = frame_counter + 1 if frame_counter > 300: fadeout() frame_counter = 0 phase = 51 if phase == 51: pygame.draw.rect(gameDisplay, (0, 0, 0), (30, 30, 740, 540)) pygame.mixer.music.fadeout(5000) #cat1 = Character('cat1', -100, 20) #cat2 = Character('cat2', 900, 40) #cat3 = Character('cat3', -100, 60) pygame.display.update() clock.tick(60)
def intro(): gameExit = False spritesheet = SpriteSheet('tiles/sheet.png') ground1 = spritesheet.image_at((0, 0, ts, ts)) ground2 = spritesheet.image_at((ts, 0, ts, ts)) ground3 = spritesheet.image_at((ts * 2, 0, ts, ts)) fence = spritesheet.image_at((0, ts * 22, ts, ts), -1) path1 = spritesheet.image_at((ts * 5, 0, ts, ts)) tree2 = spritesheet.image_at((ts * 2, ts, ts * 2, ts * 2), -1) log = spritesheet.image_at((ts * 6, ts * 5, ts * 2, ts), -1) skull = spritesheet.image_at((ts * 6, ts * 131, ts, ts), -1) # scale things.. ground1 = pygame.transform.scale(ground1, (scalesize, scalesize)) ground2 = pygame.transform.scale(ground2, (scalesize, scalesize)) ground3 = pygame.transform.scale(ground3, (scalesize, scalesize)) path1 = pygame.transform.scale(path1, (scalesize, scalesize)) tree2 = pygame.transform.scale(tree2, (scalesize * 2, scalesize * 2)) fence = pygame.transform.scale(fence, (scalesize, scalesize)) log = pygame.transform.scale(log, (scalesize * 2, scalesize)) skull = pygame.transform.scale(skull, (scalesize, scalesize)) skull_x = 40 skull_y = 40 skull_direction = 'se' background = ( ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ) foreground = ( (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", "T2", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", "L1", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), ("T2", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), ) drawn = 0 is_shaking = 0 while not gameExit: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() #debug #print(event) if not drawn: loc_x = 0 loc_y = 0 for map_y in background: for map_x in map_y: if map_x == 'G1': gameDisplay.blit(ground1, (loc_x, loc_y)) if map_x == 'G2': gameDisplay.blit(ground2, (loc_x, loc_y)) if map_x == 'G3': gameDisplay.blit(ground3, (loc_x, loc_y)) if map_x == 'P1': gameDisplay.blit(path1, (loc_x, loc_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 loc_x = 0 loc_y = 0 for map_y in foreground: for map_x in map_y: if map_x == 'T2': gameDisplay.blit(tree2, (loc_x, loc_y)) if map_x == 'F1': gameDisplay.blit(fence, (loc_x, loc_y)) if map_x == 'L1': gameDisplay.blit(log, (loc_x, loc_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 drawn = 0 #force redraw, or not step = 5 key_input = pygame.key.get_pressed() if not is_shaking: if key_input[pygame.K_LEFT]: skull_x -= step if key_input[pygame.K_UP]: skull_y -= step if key_input[pygame.K_RIGHT]: skull_x += step if key_input[pygame.K_DOWN]: skull_y += step if key_input[pygame.K_SPACE]: is_shaking = 1 if is_shaking: is_shaking = is_shaking + 1 skull_x = skull_x + random.randint(-5, 5) skull_y = skull_y + random.randint(-5, 5) if is_shaking > 15: is_shaking = 0 gameDisplay.blit(skull, (skull_x, skull_y)) pygame.display.update() clock.tick(60)
def intro(): gameExit = False spritesheet = SpriteSheet('tiles/sheet.png') ground1 = spritesheet.image_at((0, 0, ts, ts)) ground2 = spritesheet.image_at((ts, 0, ts, ts)) ground3 = spritesheet.image_at((ts * 2, 0, ts, ts)) fence = spritesheet.image_at((0, ts * 22, ts, ts), -1) path1 = spritesheet.image_at((ts * 5, 0, ts, ts)) tree2 = spritesheet.image_at((ts * 2, ts, ts * 2, ts * 2), -1) log = spritesheet.image_at((ts * 6, ts * 5, ts * 2, ts), -1) skull = spritesheet.image_at((ts * 6, ts * 131, ts, ts), -1) morgan = Character('morgan', 20, 20) # scale things.. ground1 = pygame.transform.scale(ground1, (scalesize, scalesize)) ground2 = pygame.transform.scale(ground2, (scalesize, scalesize)) ground3 = pygame.transform.scale(ground3, (scalesize, scalesize)) path1 = pygame.transform.scale(path1, (scalesize, scalesize)) tree2 = pygame.transform.scale(tree2, (scalesize * 2, scalesize * 2)) fence = pygame.transform.scale(fence, (scalesize, scalesize)) log = pygame.transform.scale(log, (scalesize * 2, scalesize)) skull = pygame.transform.scale(skull, (scalesize, scalesize)) background = ( ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ) foreground = ( (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", "T2", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", "L1", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), ("T2", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), ) drawn = 0 is_shaking = 0 while not gameExit: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() #debug #print(event) if not drawn: loc_x = 0 loc_y = 0 for map_y in background: for map_x in map_y: if map_x == 'G1': gameDisplay.blit(ground1, (loc_x, loc_y)) if map_x == 'G2': gameDisplay.blit(ground2, (loc_x, loc_y)) if map_x == 'G3': gameDisplay.blit(ground3, (loc_x, loc_y)) if map_x == 'P1': gameDisplay.blit(path1, (loc_x, loc_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 loc_x = 0 loc_y = 0 for map_y in foreground: for map_x in map_y: if map_x == 'T2': gameDisplay.blit(tree2, (loc_x, loc_y)) if map_x == 'F1': gameDisplay.blit(fence, (loc_x, loc_y)) if map_x == 'L1': gameDisplay.blit(log, (loc_x, loc_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 drawn = 0 #force redraw, or not key_input = pygame.key.get_pressed() if not is_shaking: if key_input[pygame.K_LEFT]: morgan.move_left() if key_input[pygame.K_UP]: morgan.move_up() if key_input[pygame.K_RIGHT]: morgan.move_right() if key_input[pygame.K_DOWN]: morgan.move_down() gameDisplay.blit(morgan.get_image(), morgan.get_location()) pygame.display.update() clock.tick(60)
def __init__(self, width, height, rows, columns, speed=1): # default speed 1, higher = faster # initialize pygame pygame.init() # change title of the window pygame.display.set_caption("Snake Game") # WIDTH and HEIGHT of the main game window self.WIDTH = width self.HEIGHT = height # The grid for the snake self.ROWS = rows self.COLUMNS = columns # Width/height of a cell in the grid (for convenience) self.CELL_WIDTH = self.WIDTH // self.COLUMNS self.CELL_HEIGHT = self.HEIGHT // self.ROWS # The snake (a list of tuples (coordinates and direction)) head = (random.randint(0, columns - 3), random.randint(0, rows - 1), pygame.K_RIGHT) self.snake = [ head, (head[0] + 1, head[1], head[2]), (head[0] + 2, head[1], head[2]) ] # How fast is the snake (DEFAULT = 1) self.SPEED = speed self.CLOCK = pygame.time.Clock() # Snake direction self.direction = pygame.K_RIGHT # The food self.food = self.random_food() self.food_eaten = False # The main game window self.WINDOW = pygame.display.set_mode((width, height)) # Game sprites game_sprites = SpriteSheet("snakeSprite.png") self.bg = pygame.transform.scale(pygame.image.load("bg.jpeg"), (self.WIDTH, self.HEIGHT)) self.snake_head_sprite = { pygame.K_UP: pygame.transform.scale( game_sprites.image_at((3 * 64, 0 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)), # UP pygame.K_DOWN: pygame.transform.scale( game_sprites.image_at((4 * 64, 1 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)), # DOWN pygame.K_LEFT: pygame.transform.scale( game_sprites.image_at((3 * 64, 1 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)), # LEFT pygame.K_RIGHT: pygame.transform.scale( game_sprites.image_at((4 * 64, 0 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)) } # RIGHT self.snake_tail_sprite = { pygame.K_UP: pygame.transform.scale( game_sprites.image_at((3 * 64, 2 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)), # UP pygame.K_DOWN: pygame.transform.scale( game_sprites.image_at((4 * 64, 3 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)), # DOWN pygame.K_LEFT: pygame.transform.scale( game_sprites.image_at((3 * 64, 3 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)), # LEFT pygame.K_RIGHT: pygame.transform.scale( game_sprites.image_at((4 * 64, 2 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)) } # RIGHT self.snake_body_straight = ( pygame.transform.scale( game_sprites.image_at((1 * 64, 0 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)), # HORIZONTAL pygame.transform.scale( game_sprites.image_at((2 * 64, 1 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT))) # VERTICAL self.snake_body_curved = ( pygame.transform.scale( game_sprites.image_at((0 * 64, 0 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)), # UP-RIGHT / LEFT-DOWN pygame.transform.scale( game_sprites.image_at((2 * 64, 0 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)), # UP-LEFT / RIGHT-DOWN pygame.transform.scale( game_sprites.image_at((2 * 64, 2 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)), # DOWN-LEFT / RIGHT-UP pygame.transform.scale( game_sprites.image_at((0 * 64, 1 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT))) # DOWN-RIGHT / LEFT-UP self.food_sprite = pygame.transform.scale( game_sprites.image_at((0 * 64, 3 * 64, 64, 64)), (self.CELL_WIDTH, self.CELL_HEIGHT)) # Game status self.GAME_START = False self.GAME_OVER = False
def intro(): gameExit = False spritesheet = SpriteSheet('tiles/sheet.png') ground1 = spritesheet.image_at((0, 0, ts, ts)) ground2 = spritesheet.image_at((ts, 0, ts, ts)) ground3 = spritesheet.image_at((ts * 2, 0, ts, ts)) fence = spritesheet.image_at((0, ts * 22, ts, ts), -1) path1 = spritesheet.image_at((ts * 5, 0, ts, ts)) tree2 = spritesheet.image_at((ts * 2, ts, ts * 2, ts * 2), -1) log = spritesheet.image_at((ts * 6, ts * 5, ts * 2, ts), -1) skull = spritesheet.image_at((ts * 6, ts * 131, ts, ts), -1) # scale things.. ground1 = pygame.transform.scale(ground1, (scalesize, scalesize)) ground2 = pygame.transform.scale(ground2, (scalesize, scalesize)) ground3 = pygame.transform.scale(ground3, (scalesize, scalesize)) path1 = pygame.transform.scale(path1, (scalesize, scalesize)) tree2 = pygame.transform.scale(tree2, (scalesize * 2, scalesize * 2)) fence = pygame.transform.scale(fence, (scalesize, scalesize)) log = pygame.transform.scale(log, (scalesize * 2, scalesize)) skull = pygame.transform.scale(skull, (scalesize, scalesize)) skull_x = 40 skull_y = 40 skull_direction = 'se' background = ( ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ("G2", "G2", "G2", "G2", "G2", "P1", "P1", "P1", "G2", "G2", "G2", "G2", "G2"), ) foreground = ( (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", "T2", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", "L1", " ", " ", " "), (" ", " ", "T2", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), ("T2", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), (" ", " ", " ", " ", "F1", " ", " ", " ", " ", " ", " ", " ", " "), ) drawn = 0 while not gameExit: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() #debug #print(event) if not drawn: loc_x = 0 loc_y = 0 for map_y in background: for map_x in map_y: if map_x == 'G1': gameDisplay.blit(ground1, (loc_x, loc_y)) if map_x == 'G2': gameDisplay.blit(ground2, (loc_x, loc_y)) if map_x == 'G3': gameDisplay.blit(ground3, (loc_x, loc_y)) if map_x == 'P1': gameDisplay.blit(path1, (loc_x, loc_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 loc_x = 0 loc_y = 0 for map_y in foreground: for map_x in map_y: if map_x == 'T2': gameDisplay.blit(tree2, (loc_x, loc_y)) if map_x == 'F1': gameDisplay.blit(fence, (loc_x, loc_y)) if map_x == 'L1': gameDisplay.blit(log, (loc_x, loc_y)) loc_x = loc_x + scalesize loc_y = loc_y + scalesize loc_x = 0 drawn = 0 step = 10 if skull_direction == 'se': skull_x = skull_x + step skull_y = skull_y + step if skull_direction == 'sw': skull_x = skull_x - step skull_y = skull_y + step if skull_direction == 'ne': skull_x = skull_x + step skull_y = skull_y - step if skull_direction == 'nw': skull_x = skull_x - step skull_y = skull_y - step if skull_y > 600 - scalesize: if skull_direction == 'se': skull_direction = 'ne' elif skull_direction == 'sw': skull_direction = 'nw' if skull_x > 800 - scalesize: if skull_direction == 'se': skull_direction = 'sw' elif skull_direction == 'ne': skull_direction = 'nw' if skull_x < 0: if skull_direction == 'sw': skull_direction = 'se' elif skull_direction == 'nw': skull_direction = 'ne' if skull_y < 0: if skull_direction == 'ne': skull_direction = 'se' elif skull_direction == 'nw': skull_direction = 'sw' gameDisplay.blit(skull, (skull_x, skull_y)) pygame.display.update() clock.tick(60)
def __init__(self, name, start_x, start_y): self.name = name if self.name == 'zander': self.step = 15 if self.name == 'ghost': self.step = 6 if self.name == 'geoff': self.step = 15 if self.name == 'cat1': self.step = 10 if self.name == 'cat2': self.step = 7 # ^ these should be passed in to the constuctor self.x = start_x self.y = start_y spritesheet = SpriteSheet('characters/' + name + '.png') self.down = [ pygame.transform.scale(spritesheet.image_at((0, 0, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((32, 0, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((64, 0, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((32, 0, 32, 32), -1), (64, 64)), ] self.left = [ pygame.transform.scale(spritesheet.image_at((0, 32, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((32, 32, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((64, 32, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((32, 32, 32, 32), -1), (64, 64)), ] self.right = [ pygame.transform.scale(spritesheet.image_at((0, 64, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((32, 64, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((64, 64, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((32, 64, 32, 32), -1), (64, 64)), ] self.up = [ pygame.transform.scale(spritesheet.image_at((0, 96, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((32, 96, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((64, 96, 32, 32), -1), (64, 64)), pygame.transform.scale(spritesheet.image_at((32, 96, 32, 32), -1), (64, 64)), ]