Пример #1
0
 def update(self, left, right, up, platforms, animations):
     if left:
         self.image = flip_image(
             scale_image(load_image(r"player.png"),
                         (self.rect.width, self.rect.height)), 1, 0)
         self.x_vel -= MOVE_SPEED
     elif right:
         self.image = scale_image(load_image(r"player.png"),
                                  (self.rect.width, self.rect.height))
         self.x_vel += MOVE_SPEED
     else:
         if self.x_vel > 0:
             self.x_vel -= MOVE_SPEED
         if self.x_vel < 0:
             self.x_vel += MOVE_SPEED
     if up:
         if self.on_ground or self.jump_count == 1:
             self.jump_sound.play()
             self.y_vel = JUMP_POWER * -1
             self.jump_count += 1
     if not self.on_ground:
         self.y_vel += GRAVITY
     self.on_ground = False
     self.scroll[0] = self.x_vel // 3
     self.scroll[1] = self.y_vel // 3
     self.move(platforms, animations)
Пример #2
0
def load_resource(basepath):
    # TODO: all the resizing functions are just for testing. remaster all the imgs with photoshop.
    """
    Load the files from the given path.
    Maybe can be used for loading a custom theme
    """

    ### Loading Images ###
    print("\nLoading Images...\n")
    imgpath = join(basepath, "res", "image")
    img = {}

    for file in scandir(imgpath):
        # load it as a list/dict if it's a folder, else just load it as a single image
        filename = file.name.split(".")[0]
        print("Loading " + filename  + "... ", end = "")
        if file.is_dir():
            folderpath = file.path
            for name in [x.name.split(".")[0] for x in scandir(folderpath)]:
                # check if every file name is a number
                try:
                    int(name)
                except:
                    break
            else:
                img[filename] = [load_image(x.path).convert_alpha() for x in scandir(folderpath)]
                print("Done.")
                continue
            # if not, load it as a dict
            img[filename] = dict([(x.name.split(".")[0], load_image(x.path).convert_alpha()) for x in scandir(folderpath)])
        else:
            img[filename] = load_image(file.path).convert_alpha()
        print("Done.")
    img['logo'] = resize_width(img['logo'], 1500)
    img['logo'] = resize(img['logo'], 0.8)

    ### Loading sound ###
    print("\nLoading Sound files...\n")
    soundpath = join(basepath, "res", "sound")
    
    sound = {}
    
    # Loading files as a dict based on its filename, but also printing all the files that are loaded
    for x in listdir(soundpath):
        print("Loading " + x.split('.')[0] + " sound... ", end = "")
        sound[x.split(".")[0]] = load_sound(join(soundpath, x))
        print("Done.")
    
    ### Loading fonts ###
    print("\nLoading Fonts...", end = "")
    fontpath = join(basepath, "res", "fonts")
    
    # Loading files as a dict based on its filename
    font = dict([[x.split(".")[0], pygame.font.Font(join(fontpath, x), 70)] for x in listdir(fontpath) if x.split(".")[-1] == "ttf"])
    print("Done.\n")
    print("Finished loading.")

    return (img, sound, font)
Пример #3
0
 def __init__(self, x, y):
     self.image = scale_image(load_image("player.png"), (6 * 3, 13 * 3))
     self.x_vel = 0
     self.y_vel = 0
     self.rect = self.image.get_rect()
     self.rect.x = x
     self.rect.y = y
     self.on_ground = False
     self.jump_sound = mixer.Sound("jump.wav")
     self.jump_count = 0
     self.scroll = [0, 0]
Пример #4
0
	def __init__(self, x, y):
		self.image = scale_image(load_image("dirt.png"), (40, 40))
		self.rect = self.image.get_rect()
		self.rect.x = x
		self.rect.y = y
Пример #5
0
    def __init__(self, name):
        super(Scene, self).__init__((S_WIDTH, S_HEIGHT))

        self.background = load_image(scenefile('background.bmp'))
        self.suscribed_events = {}
        self.director = None