mirror of
https://github.com/BreizhHardware/project_sanic.git
synced 2026-01-18 16:47:25 +01:00
Feat(Level Design) - Update platform and enemy positions in JSON; add movement behavior to platform and adjust exit coordinates for improved gameplay dynamics
This commit is contained in:
9
main.py
9
main.py
@@ -64,11 +64,8 @@ def main():
|
||||
joystick = pygame.joystick.Joystick(i)
|
||||
joystick.init()
|
||||
joysticks.append(joystick)
|
||||
print(f"Manette détectée: {joystick.get_name()}")
|
||||
print(f"Nombre de boutons: {joystick.get_numbuttons()}")
|
||||
print(f"Nombre d'axes: {joystick.get_numaxes()}")
|
||||
except pygame.error:
|
||||
print("Erreur lors de l'initialisation des manettes")
|
||||
print("Error while initializing joysticks")
|
||||
|
||||
# Main game loop
|
||||
running = True
|
||||
@@ -78,7 +75,7 @@ def main():
|
||||
try:
|
||||
events = pygame.event.get()
|
||||
except Exception as e:
|
||||
print(f"Erreur lors de la récupération des événements: {e}")
|
||||
print(f"Error while getting events: {e}")
|
||||
pygame.joystick.quit()
|
||||
pygame.joystick.init()
|
||||
continue
|
||||
@@ -202,7 +199,7 @@ def main():
|
||||
if result == "back_to_levels":
|
||||
current_state = "editor_select"
|
||||
except Exception as e:
|
||||
print(f"Erreur lors du traitement de l'événement: {e}")
|
||||
print(f"Error while processing events: {e}")
|
||||
continue
|
||||
|
||||
# Clear screen
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
"platforms": [
|
||||
{
|
||||
"id": "platform1",
|
||||
"x": 240,
|
||||
"y": 340,
|
||||
"x": 220,
|
||||
"y": 280,
|
||||
"width": 540,
|
||||
"height": 160,
|
||||
"texture": "assets/map/platform/grass_texture.jpg",
|
||||
@@ -27,31 +27,46 @@
|
||||
{
|
||||
"id": "platform2",
|
||||
"x": 320,
|
||||
"y": 160,
|
||||
"y": 140,
|
||||
"width": 200,
|
||||
"height": 20,
|
||||
"texture": "assets/map/platform/grass_texture.jpg",
|
||||
"is_moving": false
|
||||
"is_moving": true,
|
||||
"movement": {
|
||||
"type": "linear",
|
||||
"points": [
|
||||
{
|
||||
"x": 320,
|
||||
"y": 140
|
||||
},
|
||||
{
|
||||
"x": 420,
|
||||
"y": 140
|
||||
}
|
||||
],
|
||||
"speed": 2,
|
||||
"wait_time": 1.0
|
||||
}
|
||||
}
|
||||
],
|
||||
"enemies": [
|
||||
{
|
||||
"id": "enemy1",
|
||||
"type": "walker",
|
||||
"x": 420,
|
||||
"y": 260,
|
||||
"x": 380,
|
||||
"y": 220,
|
||||
"health": 1,
|
||||
"damage": 1,
|
||||
"sprite_sheet": "assets/map/enemy/walker_enemy.png",
|
||||
"behavior": "patrol",
|
||||
"patrol_points": [
|
||||
{
|
||||
"x": 320,
|
||||
"y": 260
|
||||
"x": 280,
|
||||
"y": 220
|
||||
},
|
||||
{
|
||||
"x": 520,
|
||||
"y": 260
|
||||
"x": 480,
|
||||
"y": 220
|
||||
}
|
||||
],
|
||||
"speed": 1.5
|
||||
@@ -60,8 +75,8 @@
|
||||
"checkpoints": [],
|
||||
"exits": [
|
||||
{
|
||||
"x": 720,
|
||||
"y": 260,
|
||||
"x": 680,
|
||||
"y": 200,
|
||||
"width": 50,
|
||||
"height": 80,
|
||||
"next_level": "map/levels/1.json",
|
||||
|
||||
@@ -491,27 +491,13 @@ class LevelEditor:
|
||||
|
||||
# Handle keyboard controls for platform properties
|
||||
if event.type == KEYDOWN:
|
||||
print(f"Touche pressée: {pygame.key.name(event.key)}")
|
||||
print(
|
||||
f"Objet sélectionné: {type(self.selected_object).__name__ if self.selected_object else 'Aucun'}"
|
||||
)
|
||||
if event.key == K_BACKSPACE and self.selected_object:
|
||||
print(
|
||||
f"Tentative de suppression de {type(self.selected_object).__name__}"
|
||||
)
|
||||
# Vérifier que l'objet est bien dans les groupes avant de le supprimer
|
||||
if self.selected_object in self.all_sprites:
|
||||
self.all_sprites.remove(self.selected_object)
|
||||
print("Supprimé de all_sprites")
|
||||
else:
|
||||
print("L'objet n'est pas dans all_sprites")
|
||||
if isinstance(self.selected_object, EditorPlatform):
|
||||
print("Objet sélectionné est une plateforme")
|
||||
if self.selected_object in self.platforms:
|
||||
self.platforms.remove(self.selected_object)
|
||||
print("Supprimé de platforms")
|
||||
else:
|
||||
print("L'objet n'est pas dans platforms")
|
||||
elif isinstance(self.selected_object, EditorCheckpoint):
|
||||
self.checkpoints.remove(self.selected_object)
|
||||
elif isinstance(self.selected_object, EditorEnemy):
|
||||
@@ -521,7 +507,6 @@ class LevelEditor:
|
||||
elif self.selected_object == self.exit_point:
|
||||
self.exit_point = None
|
||||
self.selected_object = None
|
||||
print("Objet sélectionné réinitialisé")
|
||||
|
||||
if self.selected_object and isinstance(
|
||||
self.selected_object, EditorPlatform
|
||||
@@ -606,7 +591,7 @@ class LevelEditor:
|
||||
|
||||
elif self.selected_object and isinstance(self.selected_object, EditorExit):
|
||||
if event.key == K_n:
|
||||
# Cycle de navigation entre les niveaux
|
||||
# Navigation beetween levels
|
||||
level_dir = "map/levels/"
|
||||
levels = [f for f in os.listdir(level_dir) if f.endswith(".json")]
|
||||
|
||||
@@ -700,12 +685,13 @@ class LevelEditor:
|
||||
else:
|
||||
info_text.append("Moving: No")
|
||||
|
||||
y_offset = 120
|
||||
y_offset = 20
|
||||
for text in info_text:
|
||||
text_surf = self.game_resources.font.render(
|
||||
text, True, (255, 255, 255)
|
||||
)
|
||||
surface.blit(text_surf, (10, y_offset))
|
||||
x_pos = self.game_resources.WIDTH - text_surf.get_width() - 10
|
||||
surface.blit(text_surf, (x_pos, y_offset))
|
||||
y_offset += 25
|
||||
|
||||
# Draw platform being created
|
||||
|
||||
@@ -53,14 +53,6 @@ def initialize_game(game_resources, map_file="map/levels/1.json"):
|
||||
for exit_obj in exits:
|
||||
exit_obj.set_player(map_objects["player"])
|
||||
|
||||
with open(map_file, "r") as f:
|
||||
level_data = json.load(f)
|
||||
print(f"Chargement du niveau: {map_file}")
|
||||
if "enemies" in level_data:
|
||||
print(f"Ennemis trouvés dans le JSON: {len(level_data['enemies'])}")
|
||||
else:
|
||||
print("Aucun ennemi trouvé dans le JSON")
|
||||
|
||||
return (
|
||||
map_objects["player"],
|
||||
None,
|
||||
|
||||
Reference in New Issue
Block a user