Coverage for rollnjump/main.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"""Module principal du jeu."""
13import os
14os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
15# pylint: disable=wrong-import-position
16import rollnjump.utilities as ut # noqa: E402
17import rollnjump.conf as cf # noqa: E402
18import rollnjump.lang as lg # noqa: E402
19import rollnjump.worldgen as wrld # noqa: E402
20import rollnjump.player as plyr # noqa: E402
21import rollnjump.key as ky # noqa: E402
22import rollnjump.gameloop as gml # noqa: E402
23# pylint: enable=wrong-import-position
26def initialization(graphical, music=False): # pragma: no cover
27 """
28 Initialisation des variables et des surfaces.
30 Parameters
31 ----------
32 graphical : bool
33 Indique si le jeu doit être lancé en mode graphique ou non
34 music : bool, optionnel
35 Indique si on lance la musique
37 Returns
38 -------
39 Clock * Player list
40 Une horloge pour le contrôle de la vitesse et la liste des joueurs
41 """
42 # Initialisation de la fenêtre
43 cf.DISPLAYSURF, cf.WINDOWSURF = \
44 ut.initialize_window(os.path.join(cf.ASSETS, "img",
45 "monogreen", "monogreen3.png"),
46 "Roll 'n' jump",
47 cf.SCREEN_WIDTH,
48 cf.SCREEN_HEIGHT,
49 graphical)
51 FramePerSec = ut.initialize_clock()
53 # Initialisation des modules
54 wrld.init_modules()
56 # Initialisation de la langue
57 if not os.path.isfile(lg.FILE):
58 lg.init_lang()
59 lg.get_lang()
61 # Initialisation des commandes
62 if not os.path.isfile(ky.FILE):
63 ky.init_com()
64 ky.get_keys()
66 # Initialisation du joueur
67 players = [plyr.Player(cf.COLORS[i]) for i in range(cf.NB_PLAYERS)]
69 # Initialisation du monde
70 wrld.initgen()
72 # Lance la musique
73 if music:
74 ut.load_music(cf.MUSIC)
75 ut.play_music()
77 return(FramePerSec, players)
80def main(): # pragma: no cover
81 """Fonction principale du jeu."""
82 FramePerSec, players = initialization(True, True)
84 while True: # Boucle du jeu
86 for event in ut.get_events(): # Gestion des événements
87 players = gml.event_handling(players, event)
89 wrld.update() # Mise à jour de l'environnement
91 players = gml.main_loop(players) # Mise à jour du jeu
93 # Gestion de l'affichage
94 dim = ut.get_screen_size()
95 ut.resize(cf.DISPLAYSURF, dim, cf.WINDOWSURF)
96 ut.update_screen()
97 FramePerSec.tick(cf.FPS)
100if __name__ == "__main__": # pragma: no cover
101 main()