Coverage for rollnjump/item.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"""Gère la génération d'items."""
13import random as rd
14import rollnjump.conf as cf
15import rollnjump.utilities as ut
16import rollnjump.sprites as spt
19ITEMS = ["fast", "slow", "little", "big"]
20"""
21fast : fait accélérer le joueur (sauf après les 2/3 de l'écran)
22slow : fait ralentir le joueur (sauf s'il sort presque de l'écran)
23little : fait rapetisser le joueur
24big : fait grossir le joueur
25"""
28class Item(ut.GameObject):
29 """
30 Gestion des objets.
32 Attributes
33 ----------
34 type : str
35 Type de l'objet
36 width : float
37 Largeur de l'objet
38 height : float
39 Hauteur de l'objet
40 vel : float
41 Vitesse de l'objet
42 acc : float
43 Accélération de l'objet
44 """
46 def __init__(self):
47 """Initialisation de l'objet."""
48 cf.FLAG_ITEM = True
49 i = rd.randint(0, spt.img_dict["n_item"] - 1)
50 self.type = ITEMS[i]
51 img = spt.img_dict["item_img"][i]
53 self.width, self.height = img.get_rect().size
54 x = cf.SCREEN_WIDTH - self.width
55 y = 0
57 # Au début il tombe du ciel
58 self.vel = ut.Vec(-cf.SPEED, 0)
59 self.acc = ut.Vec(0, cf.G)
61 super().__init__((x, y), 1, img)
63 def update(self):
64 """Met à jour l'item."""
65 self.vel.x = -cf.SPEED
67 ut.update_pos_vel(self, spt.ground)
69 cf.DISPLAYSURF.blit(self.image, self.rect) # affichage
70 # Si on sort de l'écran, on annule le FLAG,
71 # on programme un nouvel item et on kill celui-là.
72 if (self.pos.y > cf.SCREEN_HEIGHT) or (self.rect.right < 0):
73 cf.FLAG_ITEM = False
74 cf.NEW_ITEM_TIME = cf.SECONDS + rd.randint(cf.ITEM_PROBA_MIN,
75 cf.ITEM_PROBA_MAX)
76 self.kill()