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"""Gestion de l'arrière-plan.""" 

12import random 

13import rollnjump.utilities as ut 

14import rollnjump.conf as cf 

15import rollnjump.sprites as spt 

16 

17 

18class Cloud(ut.GameObject): 

19 """Nuages en arrière-plan.""" 

20 

21 def __init__(self, position, i): 

22 """ 

23 Initialisation. 

24 

25 Parameters 

26 ---------- 

27 position : int * int 

28 Position du nuage 

29 i : int 

30 Type de nuage 

31 """ 

32 scroll = 0.2 * random.random() + 0.1 

33 img = spt.img_dict["cloud_img"][i] 

34 super().__init__(position, scroll, img) 

35 ut.add_to_group(self, spt.clouds) 

36 

37 def update(self): 

38 """Mise à jour du nuage.""" 

39 super().update() 

40 if self.rect.right < cf.SCREEN_WIDTH * 0.8 and self.FLAG_creation: 

41 i = random.randint(0, spt.img_dict["n_cloud"] - 1) 

42 pos = (random.randint(cf.SCREEN_WIDTH, int(cf.SCREEN_WIDTH * 2)), 

43 random.randint(0, cf.SCREEN_HEIGHT // 2)) 

44 Cloud(pos, i) 

45 self.FLAG_creation = False # On en met un nouveau juste après 

46 

47 

48class Tree(ut.GameObject): 

49 """Arbres en arrière-plan.""" 

50 

51 def __init__(self, pos_x, i): 

52 """ 

53 Initialisation. 

54 

55 Parameters 

56 ---------- 

57 pos_x : int 

58 Abscisse de l'arbre 

59 i : int 

60 Type d'arbre 

61 """ 

62 img = spt.img_dict["tree_img"][i] 

63 _, height = img.get_rect().size 

64 scroll = 0.6 

65 super().__init__((pos_x, cf.SCREEN_HEIGHT - height), scroll, img) 

66 ut.add_to_group(self, spt.trees) 

67 

68 def update(self): 

69 """Mise à jour de l'arbre.""" 

70 super().update() 

71 if self.rect.right < cf.SCREEN_WIDTH * 0.8 and self.FLAG_creation: 

72 i = random.randint(0, spt.img_dict["n_tree"] - 1) 

73 pos_x = random.randint(cf.SCREEN_WIDTH, int(cf.SCREEN_WIDTH * 2)) 

74 Tree(pos_x, i) 

75 self.FLAG_creation = False # On en met un nouveau juste après