Ajout d'un systeme de Hover, savoir si la souris est au dessu du truc, de la texture, non ? #18
51
src/engine/plugins/hover.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
"""
|
||||
Definit un plugin qui verifie si la souris est sur un element (qui a une texture).
|
||||
"""
|
||||
|
||||
from engine import *
|
||||
from engine.plugins.pygame import Mouse
|
||||
from engine.plugins.render import Position, Texture, TextureManager
|
||||
|
||||
|
||||
class HoverPlugin(Plugin):
|
||||
"""
|
||||
Plugin qui verifie si la souris est sur un element (qui a une texture).
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def _update(world: World) -> None:
|
||||
entities = world.query(Hoverable, Texture, Position)
|
||||
textures = world[TextureManager]
|
||||
mouse_pos = world[Mouse].position
|
||||
for entity in entities:
|
||||
entity_pos = entity[Position]
|
||||
if (
|
||||
entity_pos.x >= mouse_pos.x
|
||||
and mouse_pos.x >= textures[entity[Texture]].get_width() + entity_pos.x
|
||||
and entity_pos.y >= mouse_pos.y
|
||||
and mouse_pos.y >= textures[entity[Texture]].get_height() + entity_pos.y
|
||||
):
|
||||
entity.set(Hover())
|
||||
else:
|
||||
entity.remove(Hover)
|
||||
|
||||
def apply(self, game: Game) -> None:
|
||||
"""
|
||||
Applique le plugin a un jeu.
|
||||
|
||||
Paramètres:
|
||||
game: Le jeu auquel appliquer le plugin.
|
||||
"""
|
||||
game.add_update_tasks(self._update)
|
||||
|
||||
|
||||
class Hoverable:
|
||||
"""
|
||||
Un composant qui marque une entitée comme pouvant etre survolée.
|
||||
"""
|
||||
|
||||
|
||||
class Hover:
|
||||
"""
|
||||
Un composant qui marque une entitée comme etant survolée.
|
||||
"""
|
|
@ -5,6 +5,7 @@ Ceci est un exemple de comment l'on peut utiliser le moteur du jeu.
|
|||
|
||||
from engine import *
|
||||
from engine.math import Vec2
|
||||
from engine.plugins.hover import HoverPlugin
|
||||
from engine.plugins.render import (
|
||||
Order,
|
||||
RenderPlugin,
|
||||
|
@ -19,7 +20,9 @@ from random import random
|
|||
|
||||
|
||||
# Initialisation
|
||||
game = Game(TimePlugin(), PygamePlugin("Guess The Number"), RenderPlugin())
|
||||
game = Game(
|
||||
TimePlugin(), PygamePlugin("Guess The Number"), RenderPlugin(), HoverPlugin()
|
||||
)
|
||||
|
||||
|
||||
# On créer une tache pour afficher des sprites
|
||||
|
|
BIN
textures/anim/edmond_serch_directory/0000.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0001.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0002.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
textures/anim/edmond_serch_directory/0003.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
textures/anim/edmond_serch_directory/0004.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0005.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0006.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0007.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0008.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0009.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0010.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0011.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0012.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0013.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0014.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0015.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0016.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
textures/anim/edmond_serch_directory/0017.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0018.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0019.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0020.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0021.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0022.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
textures/anim/edmond_serch_directory/0023.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
textures/anim/edmond_serch_directory/0024.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
textures/anim/edmond_serch_directory/0025.png
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
textures/anim/edmond_serch_directory/0026.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0027.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0028.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0029.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0030.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0031.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0032.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
textures/anim/edmond_serch_directory/0033.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
textures/anim/edmond_serch_directory/0034.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
textures/anim/edmond_serch_directory/0035.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
textures/anim/edmond_serch_directory/0036.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
textures/anim/edmond_serch_directory/0037.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
textures/anim/edmond_serch_directory/0038.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
textures/anim/edmond_serch_directory/0039.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
textures/anim/edmond_serch_directory/0040.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
textures/anim/edmond_serch_directory/0041.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0042.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0043.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0044.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0045.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0046.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0047.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0048.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0049.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0050.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0051.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0052.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0053.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0054.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0055.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0056.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0057.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0058.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0059.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0060.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0061.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0062.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0063.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0064.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0065.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
textures/anim/edmond_serch_directory/0066.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0067.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
textures/anim/edmond_serch_directory/0068.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0069.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0070.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0071.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0072.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0073.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0074.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0075.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0076.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0077.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0078.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0079.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0080.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0081.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0082.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0083.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0084.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0085.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0086.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0087.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0088.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0089.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0090.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0091.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0092.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0093.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
textures/anim/edmond_serch_directory/0094.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0095.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0096.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
textures/anim/edmond_serch_directory/0097.png
Normal file
After Width: | Height: | Size: 18 KiB |