ropy/ropy_init.py

162 lines
5.6 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import bge # Bibliothèque Blender Game Engine (BGE)
import random
from ropy_lib import *
###############################################################################
# ropy_init.py
# @title: Initialisation du Robot Ropy
# @project: Blender-EduTech
# @lang: fr
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
# @copyright: Copyright (C) 2020-2022 Philippe Roy
# @license: GNU GPL
#
# Initialisation du Robot
#
# Ropy est destiné à la découverte de la programmation procédurale et du language Python.
# A travers plusieurs challenges, donc de manière graduée, les élèves vont apprendre à manipuler les structures algorithmiques de base et à les coder en Python.
#
###############################################################################
def main():
###############################################################################
# Récupérer les objets du moteur 3D (BGE)
###############################################################################
scene = bge.logic.getCurrentScene() # Récupérer la scène 3D
cont = bge.logic.getCurrentController() # Récupérer le contrô´leur BGE
obj = cont.owner # Récupérer le robot de la scène 3D
###############################################################################
# Initialisation
###############################################################################
# niveau = obj['level']
# print ("")
# print ("Construction du niveau ...")
# # Position initiale du robot
# rp_init_position() # zone de 10x10 -> par défaut, au centre case (X,Y) : 5,5
# rp_orientation("est") # il y a nord, sud, est, ouest
# obj['mvts'] = "" # Liste des mouvements
# obj['mvt_i'] = 0 # Liste des mouvements
# # obj.visible=False
# # Enlever les murs et les marques
# def_murs=[]
# rp_enlever_marques()
###############################################################################
# Construction du niveau
# Zone de 10x10
#
# Murs :
# Longueur des murs : fixe d' une case
# Position des murs : liste imbriquée : [[mur1_x1,mur1_y1,mur1_x2,mur1_y2],[mur2_x1,mur2_y1,mur2_x2,mur2_y2], ...]
###############################################################################
niveau = obj['level']
print ("")
print ("Construction du niveau ...")
# Enlever les murs et les marques
def_murs=[]
rp_enlever_marques()
rp_orientation("est") # il y a nord, sud, est, ouest
# niveau 0 : Vide (bac à sable élève)
if niveau==0:
def_murs=[]
obj['x_init'] = 5
obj['y_init'] = 5
# niveau 10 : Bac à sable enseignant
if niveau==10:
# Murs de test
def_murs=[[4,3, 5,3],[4,3, 4,4]]
# def_murs=[[4,3, 4,4]]
# def_murs=[[4,3, 5,3]]
rp_construire_murs(def_murs)
obj['x_init'] = 5
obj['y_init'] = 5
###############################################################################
# niveau 1 : Mission 1 : Les premiers pas de Ropy
###############################################################################
if niveau==1:
# Petite maison
def_murs=[
[4,3, 4,4],[4,4, 4,5],[4,5, 4,6],
[4,6, 5,6],[5,6, 6,6],[6,6, 7,6],
[7,5, 7,6],[7,4, 7,5],[7,3, 7,4],
[4,3, 5,3], [6,3, 7,3]]
rp_construire_murs(def_murs)
rp_marquer_objectif (7,2)
obj['x_init'] = 5
obj['y_init'] = 5
###############################################################################
# Mission 2 : Sécuriser Ropy
###############################################################################
if niveau==2:
# Petite maison
def_murs=[
[4,3, 4,4],[4,4, 4,5],[4,5, 4,6],
[4,6, 5,6],[5,6, 6,6],[6,6, 7,6],
[7,5, 7,6],[7,4, 7,5],[7,3, 7,4],
[4,3, 5,3], [6,3, 7,3]]
rp_construire_murs(def_murs)
rp_marquer_objectif (7,2)
obj['x_init'] = 5
obj['y_init'] = 5
###############################################################################
# Mission 3 : Partir au bout du monde
###############################################################################
if niveau==3:
def_murs=[]
rp_marquer_objectif (10,10)
obj['x_init'] = 5
obj['y_init'] = 4
###############################################################################
# Mission 4 : Faire face à l'inconnu
###############################################################################
if niveau==4:
def_murs=[]
rp_marquer_objectif (10,10)
obj['x_init'] = random.randint(1,10)
obj['y_init'] = random.randint(1,10)
###############################################################################
# Mission 5 : Se rendre utile
###############################################################################
if niveau==5:
for i in range (10):
rp_marquer_objectif (random.randint(1,10),random.randint(1,10)) # Position aléatoire des objectifs
def_murs=[]
obj['x_init'] = random.randint(1,10)
obj['y_init'] = random.randint(1,10)
###############################################################################
# Position initiale du robot
###############################################################################
rp_init_position()
# rp_orientation("est") # il y a nord, sud, est, ouest
obj['mvts'] = "" # Liste des mouvements
obj['mvt_i'] = 0 # Liste des mouvements
# obj.visible=False