Pathfinding mit 4 Richtungen
Übersicht

HyDr0x |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
So hoffe der Link funtzt. Ich empfehel die Highsound weil die auf mp3 basiert und daher keine Soundfehler hat ![]() https://www.blitzforum.de/foru...hp?t=25981 EDIT bin jetzt erstma wech bis morjen ciao |
||
![]() |
Baschdi |
![]() Antworten mit Zitat ![]() |
---|---|---|
wow das pathfinding von den gegner is sehr gut ...
und die gfx is au net schlecht gj |
||
The_Baschdi@
Wer in Ogame is soll sofort zum Orden wechseln (D.O.) --- Alle Macht dem Orden |
HyDr0x |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Naja and der gfx wollt ich eigentlich noch was machen, danke für das Lob ![]() |
||
![]() |
Baschdi |
![]() Antworten mit Zitat ![]() |
---|---|---|
ok ...ich kann das pathfinding jetzt schon ganz gut ...ich weiß was für eine aufgabe welche variable hat etcetcetce ...aber eine sache ist noch merkwürdig:
bei dem pathfinding das im code archiv ist, gibt es ein fahrzeig das die strecke entlangfährt per knopf druck! aber es fährt nicht exact die line nach sondern fährt an den kurven eine kurve, d.h. es macht einen schwenker nach außen bevor es wieder auf nie normale bahn kommt. wo und wi kann mna das verändern? ich vermute entweder im Spline doer in pathfinding selbst ... in der spline function gibt es nur 4 zeilen in denen das passieren könnte, die anderen hab ich bereits überprüft: Code: [AUSKLAPPEN] f1#=-0.5*u3#+1.0*u2#-0.5*u# f2#= 1.5*u3#-2.5*u2#+1.0 f3#=-1.5*u3#+2.0*u2#+0.5*u# f4#= 0.5*u3#-0.5*u2# könnt ihr mir bitte sagen was diese zeieln bewirken und woher die kurve kommt ?? |
||
The_Baschdi@
Wer in Ogame is soll sofort zum Orden wechseln (D.O.) --- Alle Macht dem Orden |
HyDr0x |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Da diese Zeilen aus dem Zusammenhang gerissen wurden und mir der Quellcode nicht bekannt ist, nein. | ||
![]() |
Baschdi |
![]() Antworten mit Zitat ![]() |
---|---|---|
stimmt ...
Code: [AUSKLAPPEN] Function spline1(x1,y1,x2,y2,x3,y3,x4,y4) ;"Standart spliner Algo" Ras=25:Rh=Ras/2 x1=x1*Ras+rh:y1=y1*Ras+rh x2=x2*Ras+rh:y2=y2*Ras+rh x3=x3*Ras+rh:y3=y3*Ras+rh x4=x4*Ras+rh:y4=y4*Ras+rh For u#=0 To 1.1 Step .1 u2#=u#*u# u3#=u#*u#*u# f1#=-0.5*u3#+1.0*u2#-0.5*u# f2#= 1.5*u3#-2.5*u2#+1.0 f3#=-1.5*u3#+2.0*u2#+0.5*u# f4#= 0.5*u3#-0.5*u2# x=x1*f1#+x2*f2#+x3*f3#+x4*f4# y=y1*f1#+y2*f2#+y3*f3#+y4*f4# If ax<>x Or ay<>y Then Pos=BankSize(PfadBank):ResizeBank(PfadBank,Pos+4) PokeShort(PfadBank,Pos,x) PokeShort(PfadBank,Pos+2,y) End If ax=X:ay=Y Next End Function das ist die ganze function ..wenn du auch das programm brauchst : Code: [AUSKLAPPEN] Graphics 800,600,32,2 Global MapUntg=CreateImage(800,600) Global PfadBank=CreateBank(2) Global mapwidth,mapheight;"Wichtig für Pfadfinding" Dim MapData$(50),Fighter(72) Dim Map(50,50) ;"----------Pfadfinding Vorbereitung----------------" Dim sqrmap(50,50),nodemap(0,0),dirx(7),diry(7),dirz(7) For i=0 To 7:Read dirx(i):Read diry(i):Read dirz(i):Next Type node Field parent.node,cost,x,y End Type Type open Field node.node End Type Type path Field node.node End Type Data 0,-1,0, -1,0,0, 1,0,0, 0,1,0 Data -1,-1,1, 1,-1,1, -1,1,1, 1,1,1 ;---------------Vorbereitung beendet---------------- MapData$(00)="11111111111111111111111111111111" MapData$(01)="10000000000000000000000000000001" MapData$(02)="10011111111111111111111111111101" MapData$(03)="10000000000100000000000000000001" MapData$(04)="10000000000100000000000000000001" MapData$(05)="10000000000100000000000000000001" MapData$(06)="10000000000100000000000000000001" MapData$(07)="10000000000111011111111111111111" MapData$(08)="10000000000100000000000000000001" MapData$(09)="10000000000100000000000000000001" MapData$(10)="10000000000100000000000000000001" MapData$(11)="10000000000100000000000000000001" MapData$(12)="10000000000100000000000000000001" MapData$(13)="10000000000100000000000000000001" MapData$(14)="10000000000100000000000000000001" MapData$(15)="10000000000100000000000000000001" MapData$(16)="10000000000100000000000000000001" MapData$(17)="10000000000100000000000000000001" MapData$(18)="10000000000100000000000000000001" MapData$(19)="10000000000100000000000000000001" MapData$(20)="10000000000100000000000000000001" MapData$(21)="10000000000100000000000000000001" MapData$(22)="10000000000100000000000000000001" MapData$(23)="11111111111111111111111111111111" ClsColor 180,180,180 CreateFighter() LoadMap() ZeigeMap() StartX=5:StartY=20 EndeX=30:EndeY=10 SetBuffer BackBuffer() ;=========MainLoop========================================= Repeat: DrawBlock MapUntg,0,0 ;---------Start/End Position--" If MouseDown(1)=1 Then StartX=MouseX()/25:StartY=MouseY()/25 If MouseDown(2)=1 Then EndeX=MouseX()/25:EndeY=MouseY()/25 Color 255,255,0:Text StartX*25+12,StartY*25+12,"S",1,1 Color 255,0,0:Text EndeX*25+12,EndeY*25+12,"E",1,1 ;"Tastertur 1,2,3 für die PfadfindingAlgos If KeyHit(2):pathfinding0(startx,starty,endex,endey) FightStep=PfadSpliner():AppTitle "Typ1":End If If KeyHit(3):pathfinding1(startx,starty,endex,endey) FightStep=PfadSpliner():AppTitle "Typ2":End If If KeyHit(4):pathfinding2(startx,starty,endex,endey) FightStep=PfadSpliner():AppTitle "Typ3":End If ;------Zeigt den Pfad an M=BankSize(PfadBank)-8:LockBuffer:For I=0 To M Step 4: WritePixelFast PeekShort(PfadBank,I),PeekShort(PfadBank,I+2),-1 Next:UnlockBuffer ;------Fighter wird bewegt wenn Ziel nicht erreicht ist 0=Ziel If FightStep>0 Then FightStep=Bewegung(FightStep) Flip:Until KeyDown(1)=1:End ;"============================================================ Function Bewegung(FightStep):M=BankSize(PfadBank) ;"X,Y Koords aus der Bank Lesen ;"Winkel aus den über über über nästen Koords berechnen" X=PeekShort(PfadBank,FightStep) Y=PeekShort(PfadBank,FightStep+2) XNext=PeekShort(PfadBank,FightStep-12) YNext=PeekShort(PfadBank,FightStep-10) Wink=Int(ATan2(XNext-X,Y-YNext)/5) If Wink<0 Then Wink=72+Wink Wink=Wink Mod 72 DrawImage Fighter(Wink),X,Y Return FightStep-4 End Function Function PfadSpliner() ;"Pfad Abrunden(Spliner) und in die PfadBank transverieren ;damit mann auf die über über über nästen Daten zugreifen kann FreeBank(PfadBank):PfadBank=CreateBank(4) For path.path=Each path If path=Last path Then Exit tmp.path=Before path If tmp=Null Then x0=path\node\x y0=path\node\y Else x0=tmp\node\x y0=tmp\node\y EndIf x1=path\node\x y1=path\node\y tmp.path=After path x2=tmp\node\x y2=tmp\node\y tmp.path=After tmp If tmp=Null Then x3=x2 y3=y2 Else x3=tmp\node\x y3=tmp\node\y EndIf spline(X0,Y0,X1,Y1,X2,Y2,X3,Y3) Next Return BankSize(PfadBank)-4 End Function Function spline(x1,y1,x2,y2,x3,y3,x4,y4) ;"Standart spliner Algo" Ras=25:Rh=Ras/2 x1=x1*Ras+rh:y1=y1*Ras+rh x2=x2*Ras+rh:y2=y2*Ras+rh x3=x3*Ras+rh:y3=y3*Ras+rh x4=x4*Ras+rh:y4=y4*Ras+rh For u#=0 To 1.1 Step .1 u2#=u#*u# u3#=u#*u#*u# f1#=-0.5*u3#+1.0*u2#-0.5*u# f2#= 1.5*u3#-2.5*u2#+1.0 f3#=-1.5*u3#+2.0*u2#+0.5*u# f4#= 0.5*u3#-0.5*u2# x=x1*f1#+x2*f2#+x3*f3#+x4*f4# y=y1*f1#+y2*f2#+y3*f3#+y4*f4# If ax<>x Or ay<>y Then Pos=BankSize(PfadBank):ResizeBank(PfadBank,Pos+4) PokeShort(PfadBank,Pos,x) PokeShort(PfadBank,Pos+2,y) End If ax=X:ay=Y Next End Function Function ZeigeMap() ;Hindernisse zeigen SetBuffer ImageBuffer(MapUntg):Cls Color 0,0,200 For ZX=0 To 49:For ZY=0 To 49 If Map(ZX,ZY)>0 Then Rect ZX*25,ZY*25,24,24 Next:Next SetBuffer BackBuffer() End Function Function CreateFighter() ;"Fighter herstellen und in 72 Winkel drehen (360/5) :Fighter(0)=CreateImage(15,21) SetBuffer ImageBuffer(Fighter(0)):MidHandle Fighter(0):Color 0,0,200 For I=0 To 7:Line 7,0,I,11:Line 8,0,14-I,11:Next:Rect 0,12,15,10:Color 255,255,0 Rect 2,17,11,5:For I=1 To 72:Fighter(I)=CopyImage(Fighter(0)) RotateImage Fighter(I),I*5:Next End Function Function LoadMap():MaxX=Len(MapData$(00))-1 ;MapDatas Lesen" Repeat:For X=0 To MaxX:Map(X,Y)=Asc(Mid(MapData$(Y),X+1,1))-48 Next:Y=Y+1:Until Len(MapData$(Y))<1: mapwidth=MaxX-1:mapheight=Y-1 End Function Function pathfinding0(startx,starty,endx,endy) Delete Each node Delete Each open Delete Each path Dim nodemap(mapwidth,mapheight) If startx=endx And starty=endy Then Return node.node=New node node\x=startx node\y=starty open.open=New open open\node=node nodemap(startx,starty)=1 .again0 node=Null cost=2147483647 For open=Each open delta=Abs(open\node\x-endx)+Abs(open\node\y-endy) If open\node\cost+delta<cost Then cost=open\node\cost+delta node=open\node tempopen.open=open EndIf Next If node=Null Then Return Delete tempopen For i=0 To 3 x=node\x+dirx(i) y=node\y+diry(i) If x=>0 And y=>0 And x<=mapwidth And y<=mapheight Then If map(x,y)=0 And nodemap(x,y)=0 Then tempnode.node=New node tempnode\parent=node tempnode\cost=node\cost+1 tempnode\x=x tempnode\y=y open.open=New open open\node=tempnode nodemap(x,y)=1 If x=endx And y=endy Then finish=1:Exit EndIf EndIf Next If finish=0 Then Goto again0 While tempnode\parent<>Null path.path=New path path\node=tempnode tempnode=tempnode\parent Wend path.path=New path path\node=tempnode End Function ;--------------------------------------------------------------------- ;A*Pathfinding 8 ;--------------------------------------------------------------------- Function pathfinding1(startx,starty,endx,endy) Delete Each node Delete Each open Delete Each path Dim nodemap(mapwidth,mapheight) If startx=endx And starty=endy Then Return node.node=New node node\x=startx node\y=starty open.open=New open open\node=node nodemap(startx,starty)=1 .again1 node=Null cost=2147483647 For open=Each open delta=Abs(open\node\x-endx)+Abs(open\node\y-endy) If open\node\cost+delta<cost Then cost=open\node\cost+delta node=open\node tempopen.open=open EndIf Next If node=Null Then Return Delete tempopen For i=0 To 7 x=node\x+dirx(i) y=node\y+diry(i) If x=>0 And y=>0 And x<=mapwidth And y<=mapheight Then If map(x,y)=0 And nodemap(x,y)=0 Then If dirz(i)=1 Then If map(x,node\y)=1 And map(node\x,y)=1 Then Goto jump1 EndIf tempnode.node=New node tempnode\parent=node tempnode\cost=node\cost+1 tempnode\x=x tempnode\y=y open.open=New open open\node=tempnode nodemap(x,y)=1 If x=endx And y=endy Then finish=1:Exit .jump1 EndIf EndIf Next If finish=0 Then Goto again1 While tempnode\parent<>Null path.path=New path path\node=tempnode tempnode=tempnode\parent Wend path.path=New path path\node=tempnode End Function ;--------------------------------------------------------------------- ;A*Pathfinding 8+ ;--------------------------------------------------------------------- Function pathfinding2(startx,starty,endx,endy) Delete Each node Delete Each open Delete Each path Dim nodemap(mapwidth,mapheight) If startx=endx And starty=endy Then Return node.node=New node node\x=startx node\y=starty open.open=New open open\node=node nodemap(startx,starty)=1 .again2 node=Null cost=2147483647 For open=Each open delta=sqrmap(Abs(open\node\x-endx),Abs(open\node\y-endy)) If open\node\cost+delta<cost Then cost=open\node\cost+delta node=open\node tempopen.open=open EndIf Next If node=Null Then Return Delete tempopen For i=0 To 7 x=node\x+dirx(i) y=node\y+diry(i) If x=>0 And y=>0 And x<=mapwidth And y<=mapheight Then If map(x,y)=0 And nodemap(x,y)=0 Then If dirz(i)=1 Then If map(x,node\y)=1 And map(node\x,y)=1 Then Goto jump2 EndIf tempnode.node=New node tempnode\parent=node tempnode\cost=node\cost+1+dirz(i) tempnode\x=x tempnode\y=y open.open=New open open\node=tempnode nodemap(x,y)=1 If x=endx And y=endy Then finish=1:Exit .jump2 EndIf EndIf Next If finish=0 Then Goto again2 While tempnode\parent<>Null path.path=New path path\node=tempnode tempnode=tempnode\parent Wend path.path=New path path\node=tempnode End Function |
||
The_Baschdi@
Wer in Ogame is soll sofort zum Orden wechseln (D.O.) --- Alle Macht dem Orden |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group