Coverage for rollnjump/platforms.py : 100%

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/>.
11"""Création et déplacement des plateformes."""
12import rollnjump.conf as cf
13import rollnjump.utilities as ut
14import rollnjump.sprites as spt
17class Ground(ut.GameObject):
18 """Plateforme initiale (dans le menu)."""
20 def __init__(self, position_x):
21 """
22 Initialisation.
24 Parameters
25 ----------
26 position_x : int
27 Abscisse du début de la plateforme
28 """
29 super().__init__((position_x, spt.GROUND_HEIGHT), 1, spt.GROUND_IMG)
31 def update(self):
32 """Met à jour la position des plateformes du sol."""
33 super().update()
34 if self.rect.right < cf.SCREEN_WIDTH and self.FLAG_creation:
35 # si le dernier ne couvre plus tout sur la droite,
36 # il faut ajouter un nouveau
37 plat = Ground(self.rect.right)
38 ut.add_to_group(plat, spt.ground)
39 self.stop_creation()
41 def stop_creation(self):
42 """Arrête la génération du sol."""
43 self.FLAG_creation = False
46class Platform(ut.GameObject):
47 """
48 Plateformes pendant le jeu.
50 Attributes
51 ----------
52 dim : int * int
53 Dimensions de la plateforme
54 """
56 def __init__(self, pos=(1, 1), dim=(8, 3), img=spt.PLTFRM_IMG):
57 """
58 Initialisation.
60 Parameters
61 ----------
62 pos : int * int, optionnel
63 Position de la plateforme
64 dim : int * int, optionnel
65 Largeur et hauteur de la plateforme
66 img : Surface, optionnel
67 Apparence de la plateforme
68 """
69 self.dim = dim
70 img = ut.resize(img, dim)
71 super().__init__(pos, 1, img)