Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Code/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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)
16 changes: 13 additions & 3 deletions Code/main.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion Code/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Loading