bignono
Nombre de messages : 1127 Age : 67 Localisation : Val de Marne Date d'inscription : 13/11/2011
| Sujet: Re: La surprise du jour Mer 13 Mai 2015 - 11:42 | |
| Bonjour Parpaiun Je te met ici les codes des labyrinthes 2D et 3D que j'avais fais il y a plus de 3 ans. - Code:
-
dim d,dtn,h,i,j,k,n,r,s,v,a(33,22),ax(32,21),ay(32,21),c(4),mur(33,22) label cpos1,cpos2,debut,jeu,lab,termine,trace label r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11 full_space 0
debut: h=31:v=20:n=h*v-1:h=h+1:v=v+1:d=1 for i=1 to h:for j=1 to v:ax(i,j)=(i*50)-85:ay(i,j)=850-(j*40):next j:next i gosub lab:gosub trace i=17:j=2:gosub cpos1:2d_line 765,810,815,810:2d_line 765,10,815,10
jeu: dtn=scancode select dtn case 37: ' gauche gosub cpos2:if odd(a(i,j))=0 then i=i-1 case 38: ' haut gosub cpos2:if a(i,j)=1 or a(i,j)=1 or a(i,j)=4 or a(i,j)=5 or a(i,j)=8 or a(i,j)=9 or a(i,j)=12 or a(i,j)=13 then j=j+1 case 39: ' droit gosub cpos2:if a(i,j)>0 and a(i,j)<4 or a(i,j)>7 and a(i,j)<12 then i=i+1 case 40: ' bas gosub cpos2:if a(i,j)<8 then j=j-1 case 27:goto termine end_select gosub cpos1:wait 100 if i=17 and j=21 then goto termine goto jeu end
cpos1: 2d_pen_color 255,0,0:2d_circle ax(i,j)+25,ay(i,j)+20,5 return cpos2: 2d_pen_color 240,240,240:2d_circle ax(i,j)+25,ay(i,j)+20,5 return
trace: 2d_pen_color 0,0,192:2d_pen_width 3 for j=2 to v:for i=2 to h select a(i,j) case 1:2d_line ax(i,j),ay(i,j),ax(i,j),ay(i,j)+40 case 2:2d_line ax(i,j),ay(i,j),ax(i,j)+50,ay(i,j) case 3:2d_line ax(i,j),ay(i,j)+40,ax(i,j),ay(i,j):2d_line ax(i,j),ay(i,j),ax(i,j)+50,ay(i,j) case 4:2d_line ax(i,j)+50,ay(i,j),ax(i,j)+50,ay(i,j)+40 case 5:2d_line ax(i,j),ay(i,j),ax(i,j),ay(i,j)+40:2d_line ax(i,j)+50,ay(i,j),ax(i,j)+50,ay(i,j)+40 case 6:2d_line ax(i,j),ay(i,j),ax(i,j)+50,ay(i,j):2d_line ax(i,j)+50,ay(i,j),ax(i,j)+50,ay(i,j)+40 case 7:2d_line ax(i,j),ay(i,j)+40,ax(i,j),ay(i,j):2d_line ax(i,j),ay(i,j),ax(i,j)+50,ay(i,j):2d_line ax(i,j)+50,ay(i,j),ax(i,j)+50,ay(i,j)+40 case 8:2d_line ax(i,j),ay(i,j)+40,ax(i,j)+50,ay(i,j)+40 case 9:2d_line ax(i,j),ay(i,j),ax(i,j),ay(i,j)+40:2d_line ax(i,j),ay(i,j)+40,ax(i,j)+50,ay(i,j)+40 case 10:2d_line ax(i,j),ay(i,j),ax(i,j)+50,ay(i,j):2d_line ax(i,j),ay(i,j)+40,ax(i,j)+50,ay(i,j)+40 case 11:2d_line ax(i,j),ay(i,j)+40,ax(i,j)+50,ay(i,j)+40:2d_line ax(i,j),ay(i,j)+40,ax(i,j),ay(i,j):2d_line ax(i,j),ay(i,j),ax(i,j)+50,ay(i,j) case 12:2d_line ax(i,j),ay(i,j)+40,ax(i,j)+50,ay(i,j)+40:2d_line ax(i,j)+50,ay(i,j),ax(i,j)+50,ay(i,j)+40 case 13:2d_line ax(i,j),ay(i,j),ax(i,j),ay(i,j)+40:2d_line ax(i,j),ay(i,j)+40,ax(i,j)+50,ay(i,j)+40:2d_line ax(i,j)+50,ay(i,j),ax(i,j)+50,ay(i,j)+40 case 14:2d_line ax(i,j),ay(i,j),ax(i,j)+50,ay(i,j):2d_line ax(i,j)+50,ay(i,j),ax(i,j)+50,ay(i,j)+40:2d_line ax(i,j),ay(i,j)+40,ax(i,j)+50,ay(i,j)+40 end_select next i:next j return
lab: for j=1 to v+1:a(1,j)=4:a(h+1,j)=1:next j for i=2 to h:a(i,v+1)=8:a(i,1)=2:for j=2 to v:a(i,j)=15:next j:next i r=int(h/2+1):s=int(v/2+1):a(r,s)=15 for k=1 to n r1: i=0 if a(r-1,s)<15 then goto r2 i=i+1:c(i)=1 r2: if a(r,s-1)<15 then goto r3 i=i+1:c(i)=2 r3: if a(r+1,s)<15 then goto r4 i=i+1:c(i)=3 r4: if a(r,s+1)<15 then goto r5 i=i+1:c(i)=4 r5: if i=0 then goto r6 if i<>1 then i=int(rnd(i)+1) select c(i) case 1 a(r,s)=a(r,s)-(int(a(r,s))-int(int(a(r,s))/2)*2):r=r-1:a(r,s)=a(r,s)-(int(a(r,s)/4)-int(int(a(r,s)/4)/2)*2)*4 goto r11 case 2 a(r,s)=a(r,s)-(int(a(r,s)/8)-int(int(a(r,s)/8)/2)*2)*8:s=s-1:a(r,s)=a(r,s)-(int(a(r,s)/2)-int(int(a(r,s)/2)/2)*2)*2 goto r11 case 3 a(r,s)=a(r,s)-(int(a(r,s)/4)-int(int(a(r,s)/4)/2)*2)*4:r=r+1:a(r,s)=a(r,s)-(int(a(r,s))-int(int(a(r,s))/2)*2) goto r11 case 4 a(r,s)=a(r,s)-(int(a(r,s)/2)-int(int(a(r,s)/2)/2)*2)*2:s=s+1:a(r,s)=a(r,s)-(int(a(r,s)/8)-int(int(a(r,s)/8)/2)*2)*8 end_select goto r11 r6: if d=-1 then goto r7 if r<>h then goto r9 if s<>v then goto r8 r=2:s=2:goto r10 r7: if r<>2 then goto r9 if s<>v then goto r8 r=h:s=2: goto r10 r8: s=s+1:d=-1*d:goto r10 r9: r=r+d r10: if a(r,s)=15 then goto r6 goto r1 r11: mur(r,s)=int(rnd(6)+1) if mur(r,s)=mur(r-1,s) or mur(r,s)=mur(r+1,s) or mur(r,s)=mur(r,s-1) or mur(r,s)=mur(r,s+1) then goto r11 next k return
termine: terminate - Code:
-
' ****************************************************************************** ' ****************************************************************************** ' ************************* LABYRINTHE 3D version 12 *************************** ' ********************** CRÉÉ PAR bignono le 24/11/2011 ************************ ' **************************** EN BASIC PANORAMIC ****************************** ' ****************************************************************************** ' ******************************************************************************
dim c_gauche,c_droite,c_avant dim ang,d,dtn,espace,f,g,gd,glouton,h,i,j,k,n,pas,pasv,r,s,sd,v,pt,rot,w, c(4),mpt,mgd label affiche,droite,gauche,glouton,lab,moteur,pan1,pan2,pan4,pan8,pivot label r1,r2,r3,r4,r5,r6,r7,termine,trace
scene3d 1:full_space 0:full_space 1:light_position 0,1500,0 3d_skybox 1:' ---> Si vous voulez définir un "SKYBOX 1" ici sur cette ligne ' N'oubliez pas d'habiller votre skybox avec les commandes 3d_load_texture_back, bottom, front, left, right et top 3d_plane 2:3d_scale 2,500,500,1:3d_x_rotate 2,90:3d_y_position 2,0:3d_color 2,0,0,32: ' ---> CHANGEZ LE 3D_COLOR 2 PAR 3D_LOAD_TEXTURE 2,"FICHIER BMP OU JPG" ET N'OUBLIEZ PAS LES COMMANDES 3D_U_TILES & 3D_v_TILES 3d_cube 3,1:3d_cube 4,1:3d_hide 3:3d_hide 4: ' CRÉATION DES VÉHICULES MOTEUR ET CAMÉRA 3d_sphere 5,1:3d_color 5,0,96,0:' CRÉATION DU GLOUTON VERT MANGEUR D'ORANGES
' ****************************************************************************** ' ************************ INITIALISATION DES VARIABLES ************************ ' ****************************************************************************** ' ** h et v représentent les dimensions du labyrinthe (vous pouvez les modifier, ' mais plus le labyrinthe est grand, plus le programme ralentit!) ************** ' ****** pas : sert à règler la vitesse de déplacement dans le labyrinthe ****** ' ****** pasv: sert à règler la vitesse du zoom vertical *********************** h=20:v=15:n=h*v-1:h=h+1:v=v+1:d=1:w=4:espace=0:c_gauche=0:c_droite=0:c_avant=0 pas=0.25:pasv=1:glouton=0 dim a(h+1,v+1),mur(h+1,v+1),trc(h,v),trn(h,v),gln(h,v),vrobj gosub lab
' ****************************************************************************** ' ******************************************************************************
' ****************************************************************************** ' **************** CONSTRUCTION DU LABYRINTHE ************************ ' ****************************************************************************** 3d_text 6,"ENTRÉE":3d_color 6,0,0,255:3d_y_rotate 6,180 3d_position 6,((h/2)*8)-(2*odd(h)-2*even(h)),4,12 3d_text 7,"SORTIE":3d_color 7,0,0,255:3d_y_rotate 7,180 3d_position 7,((h/2)*8)-(2*odd(h)-2*even(h)),4,(v*8)+4
' CAS 1 = MUR GAUCHE, CAS 2 = MUR ARRIÈRE, CAS 4 = MUR DROIT, CAS 8 = MUR FACE ' LES AUTRES CAS, C'EST UNE ADDITION; EX: CAS 3 = CAS 1 + CAS 2 for j=2 to v for i=2 to h gln(i,j)=a(i,j):trc(i,j)=0:trn(i,j)=0 if (j<>2 or i<> int(h/2)) and (j<>v or i<> int(h/2)) select a(i,j) case 1: gosub pan1 : ' mur de gauche (G) case 2: gosub pan2 : ' mur du bas (B) case 3: gosub pan1:gosub pan2 : ' G+B case 4: gosub pan4 : ' mur de droite (D) case 5: gosub pan1:gosub pan4 : ' G+D case 6: gosub pan2:gosub pan4 : ' B+D case 7: gosub pan1:gosub pan2:gosub pan4: ' G+B+D (cul de sac en u) case 8: gosub pan8 : ' mur du haut (H) case 9: gosub pan1:gosub pan8 : ' G+H case 10: gosub pan2:gosub pan8 : ' B+H case 11: gosub pan1:gosub pan2:gosub pan8: ' G+B+H (cul de sac en [) case 12: gosub pan4:gosub pan8 : ' D+H case 13: gosub pan1:gosub pan4:gosub pan8: ' G+D+H (cul de sac en n) case 14: gosub pan2:gosub pan4:gosub pan8: ' B+D+H (cul de sac en ]) end_select end_if next i next j ' ****************************************************************************** ' ******************************************************************************
' ****************************************************************************** ' ** Initialisation position de départ et création d'un timer pour gérer les ** ' * déplacements. Si le programme plante augmentez la valeur du timer_interval * ' ****************************************************************************** i=int(h/2):j=1:dtn=1:a(i,j)=a(i,j)-2:a(i,v)=a(i,v)-2:vrobj=number_3d_objects f=i:g=j:sd=1:' f et g position départ du glouton vert, sd son sens de déplacement 3d_position 5,((h/2)*8)-(3*odd(h)),4,g*8 3d_position 3,((h/2)*8)-(3*odd(h)),4,j*8:gosub affiche timer 2:timer_interval 2,10:on_timer 2,moteur end
' ****************************************************************************** ' ***************** LE PROGRAMME PRINCIPAL ****************************** ' ****************************************************************************** moteur: timer_off 2 if espace=1 then goto trace if c_gauche=1 then gosub gauche if c_droite=1 then gosub droite if c_avant=1 if dtn=1 and j < v+1 if a(i,j)=0 or a(i,j)=1 or a(i,j)=4 or a(i,j)=5 or a(i,j)=8 or a(i,j)=9 or a(i,j)=12 or a(i,j)=13 pt=j*8:j=j+1:gd=j*8 repeat pt=pt+pas:3d_move 3,pas:gosub affiche until pt>=gd end_if end_if
if dtn=2 and i < h and j > 1 if a(i,j)<4 or a(i,j)>7 and a(i,j)<12 pt=i*8:i=i+1:gd=i*8 repeat pt=pt+pas:3d_move 3,pas:gosub affiche until pt>=gd end_if end_if
if dtn=3 and j > 2 if a(i,j)<8 pt=j*8:j=j-1:gd=j*8 repeat gd=gd+pas:3d_move 3,pas:gosub affiche until gd>=pt end_if end_if
if dtn=4 and i > 2 and j > 1 if odd(a(i,j))=0 pt=i*8:i=i-1:gd=i*8 repeat gd=gd+pas:3d_move 3,pas:gosub affiche until gd>=pt end_if end_if c_avant=0 end_if
select scancode case 27:goto termine: ' SORTIE PROGRAMME case 32:espace=1: ' AFFICHAGE DU PLAN DU LABYRINTHE case 37:c_gauche=1: ' FLECHE GAUCHE = ROTATION A GAUCHE case 39:c_droite=1: ' FLECHE DROITE = ROTATION A DROITE case 38:c_avant=1: ' FLECHE HAUT = DTN DEFINIT LA DIRECTION NORD, OUEST, SUD OU EST end_select
3d_position 3, i*8,4,j*8
' TEST DE SORTIE DU LABYRINTHE if j=v+1 beep_exclamation:message "BRAVO, VOUS ETES SORTI DU LABYRINTHE!":goto termine end_if
glouton=glouton+1:if glouton=5 then gosub glouton
' MÉMORISATION DE SON PASSAGE PAR DES SPHÈRES ORANGES if trc(i,j)=0 and trn(i,j)=0 vrobj=vrobj+1 3d_sphere vrobj,0.25 3d_position vrobj,i*8,1,j*8 3d_color vrobj,224,128,32 trc(i,j)=vrobj:trn(i,j)=trc(i,j) end_if
if trc(i,j)=0 and trn(i,j)<>0 3d_sphere trn(i,j),0.25 3d_position trn(i,j),i*8,1,j*8 3d_color trn(i,j),224,128,32 trc(i,j)=trn(i,j) end_if
timer_on 2 return
' ****************************************************************************** ' ******************************************************************************
' Gestion déplacement du glouton vert (le monstre) qui mange vos oranges glouton: select sd
case 1 mpt=g*8:g=g+1:mgd=g*8 repeat mpt=mpt+pas:3d_position 5,f*8,4,mpt until mpt>=mgd if gln(f,g)= 2 or gln(f,g)=4 or gln(f,g)=6 or gln(f,g)=10 then sd=2 if gln(f,g)= 3 then sd=4 if gln(f,g)= 7 then sd=3
case 2 mgd=f*8:f=f-1:mpt=f*8 repeat mgd=mgd-pas:3d_position 5,mgd,4,g*8 until mgd<=mpt if gln(f,g)= 1 or gln(f,g)=2 or gln(f,g)=3 then sd=3 if gln(f,g)= 9 then sd=1 if gln(f,g)=11 then sd=4
case 3 mgd=g*8:g=g-1:mpt=g*8 repeat mgd=mgd-pas::3d_position 5,f*8,4,mgd until mgd<=mpt if gln(f,g)= 1 or gln(f,g)=8 or gln(f,g)=9 then sd=4 if gln(f,g)=12 then sd=2 if gln(f,g)=13 then sd=1
case 4 mpt=f*8:f=f+1:mgd=f*8 repeat mpt=mpt+pas:3d_position 5,mpt,4,g*8 until mpt>=mgd if gln(f,g)= 4 or gln(f,g)=8 or gln(f,g)=12 then sd=1 if gln(f,g)= 6 then sd=3 if gln(f,g)=14 then sd=2
end_select
if trc(f,g)<>0 then 3d_delete trc(f,g):trc(f,g)=0
glouton=0 return
' ****************************************************************************** ' ********************* LES ROUTINES *********************************** ' ******************************************************************************
' CALCUL DES POSITIONS DES VÉHICULES MOTEUR ET CAMÉRA affiche: 3d_position 4,o3d_x_position(3),o3d_y_position(3),o3d_z_position(3):3d_rotate 4,o3d_x_rotate(3),o3d_y_rotate(3),o3d_z_rotate(3) 3d_move 4,1:cam_position o3d_x_position(3),w,o3d_z_position(3):point_position o3d_x_position(4),4,o3d_z_position(4) return
' CRÉATION DES MURS DU LABYRINTHE : Vous pouvez supprimer les 3d_color et mettre ' à la place un 3d_load_texture si vous voulez habillez les murs!!! pan1: 3d_box number_3d_objects+1,8.9,8.9,1:3d_position number_3d_objects,(i*8)-4,4,(j*8) 3d_y_rotate number_3d_objects,90:3d_color number_3d_objects,96,0,0 return pan2: 3d_box number_3d_objects+1,8.9,8.9,1:3d_position number_3d_objects,(i*8),4,(j*8)+4 return pan4: 3d_box number_3d_objects+1,8.9,8.9,1:3d_position number_3d_objects,(i*8)+4,4,(j*8) 3d_y_rotate number_3d_objects,90:3d_color number_3d_objects,96,0,0 return pan8: 3d_box number_3d_objects+1,8.9,8.9,1:3d_position number_3d_objects,(i*8),4,(j*8)-4 return
' VISION DE HAUT DU LABYRINTHE EN 3D trace: repeat w=w+pasv:cam_position o3d_x_position(3),w,o3d_z_position(3):display until w=70
repeat if scancode=27 then goto termine if scancode=37 then gosub gauche if scancode=39 then gosub droite glouton=glouton+1:if glouton=4 then gosub glouton wait 100 until scancode=32
repeat w=w-pasv:cam_position o3d_x_position(3),w,o3d_z_position(3):display until w=4 espace=0 goto moteur
' ROTATION A GAUCHE gauche: ang=rot+90:dtn=dtn+1:if dtn>4 then dtn=1 repeat rot=rot+6*pas:3d_y_rotate 3,rot:if w>4 then gosub pivot gosub affiche until rot>=ang c_gauche=0 return
' ROTATION A DROITE droite: ang=rot-90:dtn=dtn-1:if dtn<1 then dtn=4 repeat rot=rot-6*pas:3d_y_rotate 3,rot:if w>4 then gosub pivot gosub affiche until rot<=ang c_droite=0 return
' ROTATION DE LA CAMÉRA LORS DE LA VISION DE HAUT pivot: cam_position o3d_x_position(3),o3d_y_position(3)+w,o3d_z_position(3) return
' GÉNÉRATION DU LABYRINTHE lab: for j=1 to v+1:a(1,j)=4:a(h+1,j)=1:next j for i=2 to h:a(i,v+1)=8:a(i,1)=2:for j=2 to v:a(i,j)=15:next j:next i r=int(h/2+1):s=int(v/2+1):a(r,s)=15 for k=1 to n r1: i=0 if a(r-1,s)=15 then i=i+1 :c(i)=1 if a(r,s-1)=15 then i=i+1 :c(i)=2 if a(r+1,s)=15 then i=i+1 :c(i)=3 if a(r,s+1)=15 then i=i+1 :c(i)=4 if i=0 then goto r2 if i<>1 then i=int(rnd(i)+1) select c(i) case 1 :a(r,s)=a(r,s)-(int(a(r,s))-int(int(a(r,s))/2)*2):r=r-1:a(r,s)=a(r,s)-(int(a(r,s)/4)-int(int(a(r,s)/4)/2)*2)*4 case 2 :a(r,s)=a(r,s)-(int(a(r,s)/8)-int(int(a(r,s)/8)/2)*2)*8:s=s-1:a(r,s)=a(r,s)-(int(a(r,s)/2)-int(int(a(r,s)/2)/2)*2)*2 case 3 :a(r,s)=a(r,s)-(int(a(r,s)/4)-int(int(a(r,s)/4)/2)*2)*4:r=r+1:a(r,s)=a(r,s)-(int(a(r,s))-int(int(a(r,s))/2)*2) case 4 :a(r,s)=a(r,s)-(int(a(r,s)/2)-int(int(a(r,s)/2)/2)*2)*2:s=s+1:a(r,s)=a(r,s)-(int(a(r,s)/8)-int(int(a(r,s)/8)/2)*2)*8 end_select goto r7 r2: if d=-1 then goto r3 if r<>h then goto r5 if s<>v then goto r4 r=2:s=2:goto r6 r3: if r<>2 then goto r5 if s<>v then goto r4 r=h:s=2: goto r6 r4: s=s+1:d=-1*d:goto r6 r5: r=r+d r6: if a(r,s)=15 then goto r2 goto r1 r7: mur(r,s)=int(rnd(6)+1) if mur(r,s)=mur(r-1,s) or mur(r,s)=mur(r+1,s) or mur(r,s)=mur(r,s-1) or mur(r,s)=mur(r,s+1) then goto r7 next k return
' SORTIE DU PROGRAMME termine: timer_off 2 terminate Même si je suis à l'origine de ces codes, ils ont pu être mis au point et améliorés avec l'esprit d'entre aide de tous les panoramiciens de l'époque. Tu peux décortiquer et te servir des codes, les modifier à ta guise. A+ | |
|