une fourmiliere (enfin le debut)
Publié : mer. 13/mai/2009 17:02
bjr (depuis le temps), voilà g repris la pure et je crois que je m'enfonce dans une impasse.
voilà, les fourmis sont marrons
la fourmilière en orange
la "bouffe" en vert
les pheromones (odeur/signal) en jaune
quand une fourmi a trouvé dla bouffe , il dépose des pheromones jusqu'au nid et quand une fourmi trouve une pheromone elle va chercher la bouffe et la ramene au nid, mais !! pour l'instant elle deviens rose pour voir si ça marche... mais ça marche pas , les sprites sont tous sur des calques differents... dois-je renoncer ?
voilà, les fourmis sont marrons
la fourmilière en orange
la "bouffe" en vert
les pheromones (odeur/signal) en jaune
quand une fourmi a trouvé dla bouffe , il dépose des pheromones jusqu'au nid et quand une fourmi trouve une pheromone elle va chercher la bouffe et la ramene au nid, mais !! pour l'instant elle deviens rose pour voir si ça marche... mais ça marche pas , les sprites sont tous sur des calques differents... dois-je renoncer ?
Code : Tout sélectionner
InitSprite()
OpenScreen(1024, 768, 32, "squelette ecran")
InitKeyboard()
InitMouse()
deb:
;determine la position de la bouffe, du nid et du nombre de phéromones
nidx=Random(992) : nidy=Random(736)
rec:
boufx=Random(992) : boufy=Random(736)
dx=Abs(boufx-nidx) : dy=Abs(boufy-nidy)
If dx<160 And dy<160 : Goto rec
EndIf
If dx>=dy : nbp=dx : Goto sui1
EndIf
nbp=dy
sui1:
nbent=52+nbp ; nb entité= (1 à 50)fourm + (51)nid + (52)bouffe + nbp (pheromones)
Structure ent
xe.w
ye.w
vie.w ;nb vie
coul.l
sensx.b
sensy.b
direction.b
dpp.b ; drapeau pose pheromones
EndStructure
Dim ent.ent(nbent)
ph=53
;{- *** CHARGE TOUTES LES DONNEES DE LA STRUCTURE + COORDONNEES PHEROMONES ***
; positionne les fourmies 1 à 50 dans le nid
ent(51)\xe=nidx : ent(51)\ye=nidy : ent(51)\coul=RGB(255,100,0)
ent(52)\xe=boufx : ent(52)\ye=boufy : ent(52)\coul=RGB(103,139,32) : ent(52)\vie=100
;Debug nidy
;Debug boufy
;CallDebugger
For i=1 To 50
ent(i)\dpp=0
ent(i)\xe=ent(51)\xe : ent(i)\ye=ent(51)\ye
ent(i)\coul=RGB(65,32,14)
Next i
For i=53 To nbent
ent(i)\xe=ent(i-1)\xe : ent(i)\ye=ent(i-1)\ye ; 51= position bouffe
If ent(51)\xe=ent(i)\xe And f=0:f=i: Goto suiy ; si le nid est aligné à la bouffe en "x" passe
EndIf
If ent(51)\xe=ent(i)\xe :Goto suiy
EndIf
If ent(51)\xe>ent(i)\xe : ent(i)\xe=ent(i)\xe+1 : Goto suiy
EndIf
ent(i)\xe=ent(i)\xe-1
suiy:
If ent(51)\ye=ent(i)\ye And f=0:f=i: Goto pass
EndIf
If ent(51)\ye=ent(i)\ye : Goto pass
EndIf
If ent(51)\ye>ent(i)\ye : ent(i)\ye=ent(i)\ye+1 : Goto pass
EndIf
ent(i)\ye=ent(i)\ye-1
pass:
If ent(51)\xe=ent(i)\xe And ent(51)\ye=ent(i)\ye : Goto cont
EndIf
Next i
Goto deb ; je m'explique pas que des fois ça passe par là (?)
;}
cont:
;{ *** CREATION DES ENTITES (sprites) ***
; nid
CreateSprite( 51,32,32)
StartDrawing(SpriteOutput(51))
Circle(16, 16, 16, ent(51)\coul)
StopDrawing()
; bouf
CreateSprite( 52,32,32)
StartDrawing(SpriteOutput(52))
Circle(16, 16, 16, ent(52)\coul)
StopDrawing()
; fourmies
For i=1 To 50
CreateSprite( i,16,16)
StartDrawing(SpriteOutput(i))
Circle(8, 8, 8, ent(i)\coul)
StopDrawing()
Next i
; pheromones
For i=53 To nbent
ent(i)\coul=RGB(247,250,4)
CreateSprite( i,2,2)
StartDrawing(SpriteOutput(i))
Circle(1, 1, 1, ent(i)\coul)
StopDrawing()
Next i
;}
up=si : tt=0 : undp=0 : r=0
;-boucle principale
Repeat
ExamineKeyboard()
ExamineMouse()
;Delay(30)
;-determine la direction et avance
;{
For i=1 To 50
temp=Random(50)
If temp=25
ent(i)\direction=Random(7)+1; choix de la direction
EndIf
If ent(i)\direction=1
ent(i)\sensx=0
ent(i)\sensy=-1
EndIf ; nord
If ent(i)\direction=2
ent(i)\sensx=1
ent(i)\sensy=-1
EndIf ; nord/est
If ent(i)\direction=3
ent(i)\sensx=1
ent(i)\sensy=0
EndIf ; est
If ent(i)\direction=4
ent(i)\sensx=1
ent(i)\sensy=1
EndIf ; sud/est
If ent(i)\direction=5
ent(i)\sensx=0
ent(i)\sensy=1
EndIf ; sud
If ent(i)\direction=6
ent(i)\sensx=-1
ent(i)\sensy=1
EndIf ; sud/ouest
If ent(i)\direction=7
ent(i)\sensx=-1
ent(i)\sensy=0
EndIf ; ouest
If ent(i)\direction=8
ent(i)\sensx=-1
ent(i)\sensy=-1
EndIf ; nord/ouest
If ent(i)\xe<0
ent(i)\xe=0;1024
EndIf
If ent(i)\xe>1024
ent(i)\xe=1024;0
EndIf
If ent(i)\ye<0
ent(i)\ye=0;768
EndIf
If ent(i)\ye>768
ent(i)\ye=768;0
EndIf
;}
ent(i)\xe=ent(i)\xe+ent(i)\sensx
ent(i)\ye=ent(i)\ye+ent(i)\sensy
StartDrawing(ScreenOutput())
cp=Point(ent(i)\xe,ent(i)\ye)
StopDrawing()
If undp=1 And cp=326391
ent(i)\coul=RGB(255,125,100)
CreateSprite( i,16,16)
StartDrawing(SpriteOutput(i))
Circle(8, 8, 8, ent(i)\coul)
StopDrawing()
EndIf
; trace diagonale
If tt=1 And ent(52)\vie>0
dtx=ttx+2 : dty=tty+2 : atx=ent(52)\xe+4 : aty=ent(52)\ye+4
Gosub trace
EndIf
; trace droite
If undp=3 And ent(52)\vie>0
dtx=ttx : dty=tty
atx=ent(51)\xe+4 : aty=ent(51)\ye+4
Gosub trace
EndIf
If tt=1 And si=i And undp=1
If s=0 : dtx= ent(i)\xe+4 : dty=ent(i)\ye+4 :s=1
EndIf
atx= ent(i)\xe+4 : aty=ent(i)\ye+4
Gosub trace
ent(i)\xe=ent(ph)\xe : ent(i)\ye=ent(ph)\ye
ph=ph+1
If ph=nbent : undp=3
EndIf
EndIf
; fourmie à touché l'angle
If tt=0 And si=i And undp=1 And f=ph
dtx=ent(ph)\xe+16 : dty=ent(ph)\ye+16
atx=ent(52)\xe+16 : aty=ent(52)\ye+16
tt=1
Gosub trace
ttx=dtx : tty=dty
EndIf
;fourmie à touché bouffe
If tt=0 And si=i And undp=1; si > si c la meme fourmie alors depose les pheromones / undp > si y a deja eu colision
dtx=ent(ph)\xe+4 : dty=ent(ph)\ye+4 ; depart trait
atx=ent(52)\xe+16 : aty=ent(52)\ye+16 ; arrivée trait
Gosub trace
ent(i)\xe=ent(ph)\xe : ent(i)\ye=ent(ph)\ye
ph=ph+1
If ph=nbent : undp=3
EndIf
EndIf
; undp=drapo de collision / si=sauve le no fourmie ki a trouvé la bouffe
If undp=0 And SpritePixelCollision ( i , ent(i)\xe,ent(i)\ye , 52, ent(52)\xe, ent(52)\ye)
undp=1: si=i: ent(i)\xe=ent(52)\xe+8 : ent(i)\ye=ent(52)\ye+8
EndIf
DisplayTransparentSprite(i,ent(i)\xe,ent(i)\ye) ; aff fourmies
DisplayTransparentSprite(51,ent(51)\xe,ent(51)\ye) ; aff nid
DisplayTransparentSprite(52,ent(52)\xe,ent(52)\ye) ; aff bouffe
Next i
FlipBuffers() ; affiche le resultat a l'ecran !
ClearScreen(RGB(0, 0,0)) ; nettoie l'ecran apres affichage
Until KeyboardPushed(#PB_Key_Escape) Or MouseButton(2)
End
trace:
StartDrawing(ScreenOutput())
LineXY(dtx,dty,atx,aty,RGB(247,250,4))
StopDrawing()
Return