
drei Sachen noch:
-Sieg wenn Gegner vernichtet.
-Man sollte Einheiten per entf löschen können,
(Dann muss man nicht immer eine Invasion vorbereiten,
bloß weil sich eine Einheit in einer Ecke verhangen hat

-Wozu braucht man Energie?
Code: Alles auswählen
;***DLL-Freak´s Pathfinding-AI v2.0***
InitSprite()
InitKeyboard()
OpenScreen(1280,1024,32,"DLL-Freak´s Pathfinding-AI v2.0")
#FieldX = 32
#FieldY = 32
#Complex =128
#Size = 32
#Range = 256
Dim maintype.b(#FieldX - 1, #FieldY - 1)
Dim type.l(#FieldX - 1, #FieldY - 1)
NewList pathx.l()
NewList pathy.l()
NewList tempax.l()
NewList tempay.l()
NewList tempbx.l()
NewList tempby.l()
For x = 0 To #Complex
maintype(Random(#FieldX - 1), Random(#FieldY - 1)) = 1
Next
maintype(0,0) = 0
Global playerx.l, playery.l, olposx.l, olposy.l, aix.l, aiy.l, newpath.b, takt.l, tmpsel.b, begin.b, tmpcount.l, time.l, ptx.l, pty.l
aix = Random(12)
aiy = Random(12)
Repeat
SetFrameRate(60)
ExamineKeyboard()
;-Grafik ausgeben
;Hier wird der ganze Kram sichtbar gemacht
StartDrawing(ScreenOutput())
DrawingMode(1)
For x = 0 To #FieldX - 1
For y= 0 To #FieldY - 1
If maintype(x,y) = 0
Box(x * #Size , y * #Size,#Size,#Size, RGB(50,50,50))
Box(x * #Size + 2, y * #Size +2,#Size - 4,#Size - 4, RGB(100,100,100))
If #Size => 32
FrontColor(120,120,130)
Locate(x * #Size + #Size/4, y * #Size + #Size/4)
DrawText(Str(type(x,y)))
EndIf
Else
Box(x * #Size , y * #Size,#Size,#Size, RGB(200,250,10))
Box(x * #Size + 2, y * #Size +2,#Size - 4,#Size - 4, RGB(250,10,10))
EndIf
Next
Next
Circle(playerx * #Size + #Size/2 , playery * #Size + #Size/2 , #Size/2.5,RGB(120,255,0) )
Circle(aix * #Size + #Size/2 , aiy * #Size + #Size/2 , #Size/4,RGB(255,255,255) )
StopDrawing()
;-Spieler bewegen
;Hier wird der Spieler bewegt und damit das Ziel des Computers vorgegeben
olposx = playerx
olposy = playery
If KeyboardPushed(#PB_Key_Up)
playery - 1
If playery < 0
playery = 0
EndIf
EndIf
If KeyboardPushed(#PB_Key_Down)
playery + 1
If playery > #FieldY - 1
playery = #FieldY - 1
EndIf
EndIf
If KeyboardPushed(#PB_Key_Left)
playerx - 1
If playerx < 0
playerx = 0
EndIf
EndIf
If KeyboardPushed(#PB_Key_Right)
playerx + 1
If playerx > #FieldX - 1
playerx = #FieldX - 1
EndIf
EndIf
If playerx <> olposx Or playery <> olposy
newpath = 1
EndIf
If maintype(playerx,playery) = 1
playerx = olposx
playery = olposy
EndIf
takt + 1
If CountList(pathx()) > 0 And takt > 2
takt = 0
FirstElement(pathx())
FirstElement(pathy())
aix = pathx()
aiy = pathy()
DeleteElement(pathx())
DeleteElement(pathy())
;-ArrayListe löschen
If CountList(pathx()) = 0
For x = 0 To #FieldX - 1
For y = 0 To #FieldY - 1
type(x,y) = 0
Next
Next
EndIf
EndIf
If KeyboardPushed(#PB_Key_Space) And (aix <> playerx Or aiy <> playery)
;-Listen und arrays Leeren
tmpsel = 0
begin = 0
ClearList(tempax())
ClearList(tempay())
ClearList(tempbx())
ClearList(tempby())
For x = 0 To #FieldX - 1
For y = 0 To #FieldY - 1
type(x,y) = 0
Next
Next
;Erste Pfadpunkte eintragen:
;Hier werden die direkt am Startpunkt liegenden Pfadpunkte ermittelt
;und in die Erste Liste eingetragen
;-Start
For z = 0 To #Range
If begin = 0
begin = 1
time = 1
If aix - 1 => 0
If maintype(aix -1, aiy) = 0
type(aix - 1, aiy) = 1
AddElement(tempax())
AddElement(tempay())
tempax() = aix - 1
tempay() = aiy
If tempax() = playerx And tempay() = playery
Goto Ifound
EndIf
EndIf
EndIf
If aix + 1 < #FieldX
If maintype(aix +1, aiy) = 0
type(aix +1, aiy) = 1
AddElement(tempax())
AddElement(tempay())
tempax() = aix + 1
tempay() = aiy
If tempax() = playerx And tempay() = playery
Goto Ifound
EndIf
EndIf
EndIf
If aiy - 1 => 0
If maintype(aix, aiy - 1) = 0
type(aix, aiy -1) = 1
AddElement(tempax())
AddElement(tempay())
tempax() = aix
tempay() = aiy - 1
If tempax() = playerx And tempay() = playery
Goto Ifound
EndIf
EndIf
EndIf
If aiy + 1 < #FieldY
If maintype(aix, aiy + 1) = 0
type(aix, aiy + 1) = 1
AddElement(tempax())
AddElement(tempay())
tempax() = aix
tempay() = aiy + 1
If tempax() = playerx And tempay() = playery
Goto Ifound
EndIf
EndIf
EndIf
Else
;Weitere Pfadfindung:
;Ab hier werden die einzelnen Listen abwechselnd mit den Koordinaten gefüttert
;Das ganze läuft dann bis ein Pfad gefunden wurde oder eine der Listen 0 ist
;-A
time + 1
If tmpsel = 0
tmpsel = 1
tmpcount = CountList(tempax())
If tmpcount > 0
ClearList(tempbx())
ClearList(tempby())
FirstElement(tempax())
FirstElement(tempay())
For x = 1 To tmpcount
If tempax() - 1 => 0 And (tempax() - 1 <> aix Or tempay() <> aiy)
If maintype(tempax() -1, tempay()) = 0 And type(tempax() - 1, tempay()) = 0
type(tempax() - 1, tempay()) = time
AddElement(tempbx())
AddElement(tempby())
tempbx() = tempax() - 1
tempby() = tempay()
If tempbx() = playerx And tempby() = playery
Goto Ifound
EndIf
EndIf
EndIf
If tempax() + 1 < #FieldX And (tempax() +1 <> aix Or tempay() <> aiy)
If maintype(tempax() + 1, tempay()) = 0 And type(tempax() + 1, tempay()) = 0
type(tempax() + 1, tempay()) = time
AddElement(tempbx())
AddElement(tempby())
tempbx() = tempax() + 1
tempby() = tempay()
If tempbx() = playerx And tempby() = playery
Goto Ifound
EndIf
EndIf
EndIf
If tempay() - 1 => 0 And (tempax() <> aix Or tempay() - 1 <> aiy)
If maintype(tempax() , tempay() - 1) = 0 And type(tempax(), tempay() - 1) = 0
type(tempax(), tempay() - 1) = time
AddElement(tempbx())
AddElement(tempby())
tempbx() = tempax()
tempby() = tempay() - 1
If tempbx() = playerx And tempby() = playery
Goto Ifound
EndIf
EndIf
EndIf
If tempay() + 1 < #FieldY And (tempax() <> aix Or tempay() +1 <> aiy)
If maintype(tempax(), tempay() + 1) = 0 And type(tempax(), tempay() + 1) = 0
type(tempax(), tempay() + 1) = time
AddElement(tempbx())
AddElement(tempby())
tempbx() = tempax()
tempby() = tempay() + 1
If tempbx() = playerx And tempby() = playery
Goto Ifound
EndIf
EndIf
EndIf
NextElement(tempax())
NextElement(tempay())
Next
Else
Goto LetStop
EndIf
Else
;-B
tmpsel = 0
tmpcount = CountList(tempbx())
If tmpcount > 0
ClearList(tempax())
ClearList(tempay())
FirstElement(tempbx())
FirstElement(tempby())
For x = 1 To tmpcount
If tempbx() - 1 => 0 And (tempbx() - 1 <> aix Or tempby() <> aiy)
If maintype(tempbx() -1, tempby()) = 0 And type(tempbx() - 1, tempby()) = 0
type(tempbx() - 1, tempby()) = time
AddElement(tempax())
AddElement(tempay())
tempax() = tempbx() - 1
tempay() = tempby()
If tempax() = playerx And tempay() = playery
Goto Ifound
EndIf
EndIf
EndIf
If tempbx() + 1 < #FieldX And (tempbx() +1 <> aix Or tempby() <> aiy)
If maintype(tempbx() + 1, tempby()) = 0 And type(tempbx() + 1, tempby()) = 0
type(tempbx() + 1, tempby()) = time
AddElement(tempax())
AddElement(tempay())
tempax() = tempbx() + 1
tempay() = tempby()
If tempax() = playerx And tempay() = playery
Goto Ifound
EndIf
EndIf
EndIf
If tempby() - 1 => 0 And (tempbx() <> aix Or tempby() - 1 <> aiy)
If maintype(tempbx() , tempby() - 1) = 0 And type(tempbx(), tempby() - 1) = 0
type(tempbx(), tempby() - 1) = time
AddElement(tempax())
AddElement(tempay())
tempax() = tempbx()
tempay() = tempby() - 1
If tempax() = playerx And tempay() = playery
Goto Ifound
EndIf
EndIf
EndIf
If tempby() + 1 < #FieldY And (tempbx() <> aix Or tempby() +1 <> aiy)
If maintype(tempbx(), tempby() + 1) = 0 And type(tempbx(), tempby() + 1) = 0
type(tempbx(), tempby() + 1) = time
AddElement(tempax())
AddElement(tempay())
tempax() = tempbx()
tempay() = tempby() + 1
If tempax() = playerx And tempay() = playery
Goto Ifound
EndIf
EndIf
EndIf
NextElement(tempbx())
NextElement(tempby())
Next
Else
Goto LetStop
EndIf
EndIf
EndIf
Next
;-Pfad erzeugen
;Hier wird hingesprungen wenn ein Punkt aus der Pfadroutine mit der Spielerposition übereinstimmt
Ifound:
ClearList(pathx())
ClearList(pathy())
For x = 1 To time
If x = 1
ptx = playerx
pty = playery
Else
If ptx - 1 => 0
If type(ptx - 1, pty) = time - (x-1)
ptx - 1
EndIf
EndIf
If ptx +1 < #FieldX
If type(ptx + 1, pty) = time - (x-1)
ptx + 1
EndIf
EndIf
If pty - 1 => 0
If type(ptx, pty - 1) = time - (x-1)
pty - 1
EndIf
EndIf
If pty +1 < #FieldY
If type(ptx, pty + 1) = time - (x-1)
pty + 1
EndIf
EndIf
EndIf
FirstElement(pathx())
FirstElement(pathy())
InsertElement(pathx())
InsertElement(pathy())
pathx() = ptx
pathy() = pty
Next
EndIf
;Hier wird hingesprungen wenn kein Weg gefunden wurde
LetStop:
FlipBuffers()
ClearScreen(0,0,0)
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
End
Nur: Wozu?STARGÅTE hat geschrieben:Ich habe noch eine Frage :
Was haltet ihr davon wenn ich das Spiel jetzt "Desert Planet" nenne
OpenNetworkConnection() hat geschrieben:Versucht eine Verbindung mit dem angegebenen Server aufzubauen. 'ServerName$' kann eine IP-Adresse oder ein voller Name sein (z.B.: "127.0.0.1" oder "ftp.home.net").
php-freak hat geschrieben:Ich hab die IP von google auch ned rausgefunden!