def test_change_state(): """Test pour la méthode change_state.""" main.initialization(False) player = plyr.Player() player.change_state('little') assert player.width, player.height == cf.SIZE["little"] player.change_state('big') assert player.width, player.height == cf.SIZE["big"]
def initialization(graphical, music=False): # pragma: no cover """ Initialisation des variables et des surfaces. Parameters ---------- graphical : bool Indique si le jeu doit être lancé en mode graphique ou non music : bool, optionnel Indique si on lance la musique Returns ------- Clock * Player list Une horloge pour le contrôle de la vitesse et la liste des joueurs """ # Initialisation de la fenêtre cf.DISPLAYSURF, cf.WINDOWSURF = \ ut.initialize_window(os.path.join(cf.ASSETS, "img", "monogreen", "monogreen3.png"), "Roll 'n' jump", cf.SCREEN_WIDTH, cf.SCREEN_HEIGHT, graphical) FramePerSec = ut.initialize_clock() # Initialisation des modules wrld.init_modules() # Initialisation de la langue if not os.path.isfile(lg.FILE): lg.init_lang() lg.get_lang() # Initialisation des commandes if not os.path.isfile(ky.FILE): ky.init_com() ky.get_keys() # Initialisation du joueur players = [plyr.Player(cf.COLORS[i]) for i in range(cf.NB_PLAYERS)] # Initialisation du monde wrld.initgen() # Lance la musique if music: ut.load_music(cf.MUSIC) ut.play_music() return (FramePerSec, players)
def test_collisions(pos_prev, pos_next, pos_plat, size_plat): """Test pour la fonction de vérification des collisions.""" player = plyr.Player() player.pos = ut.Vec(pos_prev) dummy_next = ut.create_rect( [pos_next[0], pos_next[1], player.width, player.height]) plat = ut.create_rect( [pos_plat[0], pos_plat[1], size_plat[0], size_plat[1]]) (vert, hor, new_pos) = ut.collide(player, ut.Vec(pos_next), plat) assert (vert or hor) == dummy_next.colliderect(plat) if new_pos is not None: dummy_next.topleft = new_pos assert not dummy_next.colliderect(plat)
def test_move(velx, vely): """Test pour la méthode move de la classe Player.""" main.initialization(False) spt.ground = ut.group_sprite_define() player = plyr.Player() xinit, yinit = player.pos.x, player.pos.y player.vel = ut.Vec(velx, vely) player.move() vely += player.acc.y assert player.pos.x <= xinit + velx + 0.5 * player.acc.x + 0.001\ and player.pos.x >= xinit + velx + 0.5 * player.acc.x - 0.001 assert player.pos.y <= yinit + vely + 0.5 * player.acc.y + 0.001\ and player.pos.y >= yinit + vely + 0.5 * player.acc.y - 0.001 player.timer = 1 player.state = "little" player.move() assert player.state == "normal" player.state = "fast" player.move() assert player.vel.x == cf.V_ITEM["fast"] player.pos.x = (3 * cf.SCREEN_WIDTH) // 4 player.move() assert player.vel.x == 0 player.state = "slow" player.move() assert player.vel.x == cf.V_ITEM["slow"] player.pos.x = -player.width // 2 player.move() assert player.vel.x == 0 player.state = "normal" item = it.Item() item.pos = player.pos item.update() ut.add_to_group(item, spt.items) player.vel = ut.Vec((0, 0)) player.acc = ut.Vec((0, 0)) player.move() assert player.state != "normal" player.state = 'delay' player.timer = 1 player.move() assert player.state == "big"
def test_update(): """Test pour la fonction update_pos_vel.""" main.initialization(False) player = plyr.Player() # collision horizontale plat = plt.Platform((50, 50), (100, 40)) ut.add_to_group(plat, spt.ground) player.pos = ut.Vec((40 - player.width, 50)) player.vel = ut.Vec((20, 0)) player.acc = ut.Vec((0, 0)) ut.update_pos_vel(player, spt.ground) assert player.pos == ut.Vec((50 - player.width, 50)) # collision verticale player.pos = ut.Vec((50, 40 - player.height)) player.vel = ut.Vec((0, 20)) player.acc = ut.Vec((0, 0)) ut.update_pos_vel(player, spt.ground) assert player.pos == ut.Vec((50, 50 - player.height))
def test_end_item(): """Test pour la méthode end_item.""" main.initialization(False) player = plyr.Player() player.vel.x = cf.V_ITEM['fast'] player.change_state('little') player.end_item() assert player.width, player.height == cf.SIZE["normal"] assert player.vel.x == 0 player.vel.x = cf.V_ITEM['slow'] player.change_state('big') player.end_item() assert player.width, player.height == cf.SIZE["normal"] assert player.vel.x == 0 # Délai en cas d'obstacle plat = plt.Platform(player.pos, (1, 1)) ut.add_to_group(plat, spt.ground) player.state = 'little' player.end_item() assert player.width, player.height == cf.SIZE["little"]