diff --git a/Code/entities.py b/Code/entities.py
index 03f4021..337ea6c 100644
--- a/Code/entities.py
+++ b/Code/entities.py
@@ -16,6 +16,7 @@ def __init__(self, pos, frames, groups, regard):
# Mouvemenent :
self.direction = vector()
self.speed = 1000
+ self.blocked = False
# sprite setup
self.image = self.frames['down'][self.frames_indice]
@@ -36,10 +37,20 @@ def get_etat(self):
self.regard = 'down' if self.direction.y > 0 else 'up'
return f"{self.regard}{'' if moving else '_idle'}"
+
+
+ def block(self):
+ self.blocked = True
+ self.direction = vector(0,0)
+
+ def unblock(self):
+ self.blocked = False
+
class Dresseur(Entity):
def __init__(self, pos, frames, groups, regard):
super().__init__(pos, frames,groups, regard)
+
class Player(Entity):
def __init__(self, pos, frames, groups, regard, collision_sprites):
super().__init__(pos, frames, groups, regard)
@@ -56,7 +67,7 @@ def input(self):
input_vector.x -= 1
if keys[pygame.K_RIGHT]:
input_vector.x += 1
- self.direction = input_vector
+ self.direction = input_vector.normalize() if input_vector else input_vector
def mouvement(self, dt):
@@ -86,6 +97,7 @@ def collisions(self, axis):
def update(self, dt):
self.y_sort = self.rect.centery
- self.input()
- self.mouvement(dt)
+ if not self.blocked:
+ self.input()
+ self.mouvement(dt)
self.animation(dt)
diff --git a/Code/main.py b/Code/main.py
index 20d5d27..79ab870 100644
--- a/Code/main.py
+++ b/Code/main.py
@@ -1,4 +1,4 @@
-from Code.sprites import Waremon_patch_Sprite
+from sprites import Waremon_patch_Sprite
from settings import *
from pytmx.util_pygame import load_pygame
from os.path import join
@@ -17,6 +17,7 @@ def __init__(self):
#groupes :
self.all_sprites = AllSprites()
self.collision_sprites = pygame.sprite.Group()
+ self.character_sprites = pygame.sprite.Group()
self.import_assets()
self.setup(self.tmx_maps['map3'], 'house')
@@ -71,11 +72,19 @@ def setup(self, tmx_map, player_start_pos):
Dresseur(
pos=(obj.x, obj.y),
frames=self.overwolrd_frames['characters'][obj.properties['graphic']],
- groups=( self.all_sprites, self.collision_sprites),
+ groups=( self.all_sprites, self.collision_sprites,self.character_sprites),
regard = obj.properties['direction']
)
-
+ def input(self):
+ keys = pygame.key.get_just_pressed()
+ if keys[pygame.K_SPACE]:
+ for character in self.character_sprites:
+ if check_connection(100, self.player, character):
+ self.player.block()
+
+ #crée les dialogue
+ print('dialog')
def run(self):
while True:
@@ -90,6 +99,7 @@ def run(self):
#game logique
+ self.input()
self.all_sprites.update(dt)
self.display_surface.fill('Black')
self.all_sprites.draw(self.player.rect.center)
diff --git a/Code/support.py b/Code/support.py
index 1a88713..7a07973 100644
--- a/Code/support.py
+++ b/Code/support.py
@@ -95,4 +95,14 @@ def cote_importer(cols, rows, *path):
new_dict[terrain] = {}
for key, pos in sides.items():
new_dict[terrain][key] = [frame_dict[(pos[0] + index * 3, pos[1]+ row)] for row in range(0, rows, 3)]
- return new_dict
\ No newline at end of file
+ return new_dict
+
+#fonction jeu
+def check_connection(radius, entité, cible, tolerance = 30):
+ relation = vector(cible.rect.center) - vector(entité.rect.center)
+ if relation.length() < radius:
+ if entité.regard == 'left' and relation.x <0 and abs(relation.y) < tolerance or\
+ entité.regard == 'right' and relation.x > 0 and abs(relation.y) < tolerance or \
+ entité.regard == 'up' and relation.y < 0 and abs(relation.x) < tolerance or \
+ entité.regard == 'down' and relation.y > 0 and abs(relation.x) < tolerance:
+ return True
\ No newline at end of file
diff --git a/data/maps/map3.tmx b/data/maps/map3.tmx
index b600874..8596426 100644
--- a/data/maps/map3.tmx
+++ b/data/maps/map3.tmx
@@ -1,1188 +1,1199 @@
-
-
+
+