Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Roll 'n' Jump 

2# Written in 2020, 2021 by Samuel Arsac, Hugo Buscemi, 

3# Matteo Chencerel, Rida Lali 

4# To the extent possible under law, the author(s) have dedicated all 

5# copyright and related and neighboring rights to this software to the 

6# public domain worldwide. This software is distributed without any warranty. 

7# You should have received a copy of the CC0 Public Domain Dedication along 

8# with this software. If not, see 

9# <http://creativecommons.org/publicdomain/zero/1.0/>. 

10 

11"""Génération des sprites.""" 

12 

13import os 

14import rollnjump.conf as cf 

15import rollnjump.utilities as ut 

16 

17 

18def listdir(path): 

19 """ 

20 os.listdir sans les fichiers cachés. 

21 

22 Parameters 

23 ---------- 

24 path : str 

25 Chemin de fichier 

26 

27 Returns 

28 ------- 

29 str list 

30 La liste des fichiers visibles de `path` 

31 """ 

32 return [f for f in os.listdir(path) if not f.startswith('.')] 

33 

34 

35# IMAGES 

36Names = ["cloud", "tree", "item"] 

37"""Liste des noms des différents éléments de décor.""" 

38for color in cf.COLORS: 

39 Names.append('mono' + color) 

40 

41img_dict = {} 

42""" 

43Dictionnaire associant, pour chaque élément de `Nom` : 

44un facteur de taille, 

45un nombre d'images 

46et la liste de ces images. 

47""" 

48for color in cf.COLORS: 

49 img_dict['mono' + color + '_factor'] = 1 

50img_dict["cloud_factor"] = 4 

51img_dict["tree_factor"] = 8 

52img_dict["item_factor"] = 2 

53 

54for name in Names: 

55 img_dict['n_' + name] = len(listdir(os.path.join(cf.ASSETS, "img", name))) 

56 img_dict[name + '_img'] = [] 

57 for i in range(img_dict['n_' + name]): 

58 img = ut.load_image(os.path.join(cf.ASSETS, "img", 

59 name, name + str(i) + ".png")) 

60 w, h = img.get_rect().size 

61 img = ut.resize(img, (img_dict[name + '_factor'] * w, 

62 img_dict[name + '_factor'] * h)) 

63 img_dict[name + '_img'].append(img) 

64 

65GROUND_IMG = ut.load_image(os.path.join(cf.ASSETS, "img", "ground.png")) 

66"""Image pour le sol""" 

67PLTFRM_IMG = ut.load_image(os.path.join(cf.ASSETS, "img", "pltfrm.png")) 

68"""Image pour une plateforme métallique""" 

69BAT_IMG = ut.load_image(os.path.join(cf.ASSETS, "img", "bat.png")) 

70"""Image pour un bâtiment""" 

71 

72# Dimensions 

73for color in cf.COLORS: 

74 w, h = img_dict["mono" + color + "_img"][0].get_rect().size 

75 for key in cf.SIZE: 

76 cf.SIZE[key] = (w * cf.SIZE_FACTOR[key], h * cf.SIZE_FACTOR[key]) 

77 ut.resize_list(img_dict['mono' + color + '_img'], cf.SIZE['normal']) 

78 

79w, h = GROUND_IMG.get_rect().size 

80GROUND_HEIGHT = (cf.SCREEN_HEIGHT - h) 

81"""Hauteur du sol""" 

82GROUND_WIDTH = w 

83"""Longueur d'un bloc de sol""" 

84 

85# Groupes 

86ground = ut.group_sprite_define() 

87"""Groupe des éléments du sol""" 

88clouds = ut.group_sprite_define() 

89"""Groupe des nuages""" 

90trees = ut.group_sprite_define() 

91"""Groupe des arbres""" 

92items = ut.group_sprite_define() 

93"""Groupe des objets"""