Ajout de score en ligne #9
|
@ -10,9 +10,20 @@ from engine.math import Vec2
|
|||
from plugins import render
|
||||
from plugins.click import Clickable
|
||||
from plugins.hover import HoveredTexture
|
||||
from plugins.render import SpriteBundle
|
||||
from plugins.render import SpriteBundle, TextBundle
|
||||
from plugins.timing import Time
|
||||
from scenes import game, send_to_server
|
||||
from scenes import game
|
||||
import requests as rq
|
||||
|
||||
IP = "pong.cocosol.fr"
|
||||
|
||||
|
||||
def get_scores():
|
||||
try:
|
||||
return rq.get(f"https://{IP}/data").json()
|
||||
except:
|
||||
print("Error with the serveur")
|
||||
return ["", 1]
|
||||
|
||||
|
||||
def __create_button(world: World, i: int, name: str):
|
||||
|
@ -61,6 +72,23 @@ def __spawn_elements(world: World):
|
|||
for i, name in enumerate(scenes_name):
|
||||
__create_button(world, i, name)
|
||||
|
||||
__spawn_score(world)
|
||||
|
||||
|
||||
def __spawn_score(world: World):
|
||||
"""
|
||||
Ajoute le score dans le monde.
|
||||
"""
|
||||
for i, score in enumerate(get_scores()):
|
||||
world.new_entity().set(
|
||||
TextBundle(
|
||||
score[1] + " : " + str(score[0]),
|
||||
position=Vec2(render.WIDTH / 2, 350 + 50 * i),
|
||||
origin=Vec2(0.5),
|
||||
order=1,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
MENU = Scene(
|
||||
[__spawn_elements],
|
||||
|
|
Loading…
Reference in a new issue