Waypoints
Übersicht

OrbitBetreff: Waypoints |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hallo,
ich wollte fragen, wie ich einen Punkt von a(z.B. x=5,y=10) nach b(z.B. x=200,y=300) in der repeat-Schleife bewege. Bestimmt macht man das mit Sinus oder Kosinus oder so, aber wie? Code: [AUSKLAPPEN] Rem Ein kleiner Test zum erstellen von Waypoints End Rem Strict 'Für das Anzeigen von nicht deklarieten Variablen Graphics 640,480,0,100 Local WPAnfang[2] Local WPEnde[2] Local x:Float 'Variable für die x-Position des Punktes Local y:Float 'Variable für die y-Position des Punktes Repeat Plot x,y Until KeyHit(1) End fg, Orbit |
||
![]() |
nX^ |
![]() Antworten mit Zitat ![]() |
---|---|---|
Am besten ist es wenn ein Waypoint ein TypenEintrag ist. Du rechnest aus welcher Waypoint am nächsten zum Spieler liegt und berechnest einfach per Atan2 den Winkel zum Waypoint und dann berechnest du denn Weg mit Sinus und Cosinus zum WayPoint. | ||
![]() |
Justus |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hier ein kleiner Beispielcode:
Code: [AUSKLAPPEN] SetGraphicsDriver(D3D7Max2DDriver())
Graphics 800,600,0,60 SeedRnd MilliSecs() Global p:TPlayer = TPlayer.create(100,100) Global w:TWaypoint = TWaypoint.create(700,500) 'Hat man mehr als einen Wegpunkt, würden sich TypeListen sehr anbieten. 'Bei Spielern/Bots ebenso. Type TPlayer Field x:Float Field y:Float Function create:TPlayer(x:Int,y:Int) Local p:TPlayer = New TPlayer p.x = x p.y = y Return p EndFunction EndType Type TWaypoint Field x:Int Field y:Int Function create:TWaypoint(x:Int,y:Int) Local w:TWaypoint = New TWayPoint w.x = x w.y = y Return w EndFunction EndType Repeat Cls Local angle:Float = (ATan2(w.y-p.y,w.x-p.x)+360) Mod 360 p.x:+Cos(angle) p.y:+Sin(angle) SetColor 255,0,0 DrawOval p.x,p.y,10,10 SetColor 0,0,255 DrawOval w.x,w.y,10,10 'Linksklick versetzt den Spieler, Rechtsklick den Wegpunkt If MouseHit(1) Then p.x = MouseX() ; p.y = MouseY() If MouseHit(2) Then w.x = MouseX() ; w.y = MouseY() Flip Until KeyHit(KEY_ESCAPE) |
||
- Zuletzt bearbeitet von Justus am Mo, Jul 24, 2006 17:42, insgesamt einmal bearbeitet
![]() |
nX^ |
![]() Antworten mit Zitat ![]() |
---|---|---|
Auch hier noch ein schönes Beispiel von Vincent das ich umgeschrieben habe:
Code: [AUSKLAPPEN] SuperStrict
Const Xres:Float = 800 Const Yres:Float = 600 Apptitle = "WayPoint" Graphics Xres,Yres,0,60 SeedRnd MilliSecs() ' Spieler Global SpielerX:Float = 400 Global SpielerY:Float = 300 ' WayPoint Global WPX:Float = Rand(20,780) Global WPY:Float = Rand(20,580) ' Winkel Global Alpha:Float Global Beta:Float Global Rot:Float = .05 Global IX:Float Global IY:Float SetColor 255,0,0 DrawRect WPX-10,WPY-10,20,20 SetColor 0,255,0 Repeat DrawRect SpielerX-2,SpielerY-2,4,4 ' Spieler bewegen SpielerX:+Cos(Alpha) SpielerY:+Sin(Alpha) Beta = ATan2((WPY-SpielerY),(WPX-SpielerX)) IX = Sin(Alpha) IY = Cos(Alpha) Alpha = ATan2(IX-(IX-Sin(Beta))*Rot,IY-(IY-Cos(Beta))*Rot) If SpielerX > WPX - 10 And SpielerX < WPX +10 And SpielerY > WPY - 10 And SpielerY < WPY + 10 Then WPX = Rand(20,780) WPY = Rand(20,580) SetColor 255,0,0 DrawRect WPX-10,WPY-10,20,20 SetColor 0,255,0 EndIf Flip Until KeyHit(KEY_ESCAPE) End |
||
Orbit |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hallo,
wie kann ich mehrere Waypoints erstellen? fg, Orbit |
||
Dreamora |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Justus Beispiel nehmen und die Waypoints in eine Liste einfügen und Punkt um Punkt anlaufen. | ||
Ihr findet die aktuellen Projekte unter Gayasoft und könnt mich unter @gayasoft auf Twitter erreichen. |
Skulk |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
und zum verständnis:
wenn du den ersten wegpunkt erreicht hast, tausche ihn gegen den nächsten wegpunkt aus. überleg dir einfach wie du im richtigen leben vorgehen würdest wenn du zum bäcker gehst. du setzt auf deine liste (im gehirn) z.b. 3 wegpunkte. - haustür - ampel - eingangstür natürlich wirst du zu erst den wegpunkt eins ansteuern und die haustür öffnen. dann streichst du diesen wegpunkt aus deinem kopf und steuerst die ampel an. wenn du dort angekommen bist, wirst du als nächstes die eingangstür er bäckerei suchen wollen... |
||
War doesn't determine who's right,
war determines who's left... |
Orbit |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hallo,
das mit der Liste habe ich auch schon ausprobiert, kriege das Problem aber nur umständlich gelöst. Code: [AUSKLAPPEN] Strict SetGraphicsDriver(D3D7Max2DDriver()) Graphics 800,600,16,100 SeedRnd MilliSecs() Type TWaypoint Field x:Float Field y:Float EndType Global APunkt1X:Float = 10 Global APunkt1Y:Float = 20 Global APunkt2X:Float = 200 Global APunkt2Y:Float = 500 Global APunkt3X:Float = 700 Global APunkt3Y:Float = 550 Global w1:TWaypoint = New TWayPoint Global w2:TWaypoint = New TWayPoint Global w3:TWaypoint = New TWayPoint Global x:Float Global y:Float w1.x = APunkt1X w1.y = APunkt1Y w2.x = APunkt2X w2.y = APunkt2Y w3.x = APunkt3X w3.y = APunkt3Y Repeat Cls If w1.x < w2.x And w1.y < w2.y Then Local angle:Float = (ATan2(w2.y-w1.y,w2.x-w1.x)+360) Mod 360 w1.x:+Cos(angle) w1.y:+Sin(angle) x = w1.x y = w1.y EndIf If w1.x > 200 And w1.y > 500 Then Local angle:Float = (ATan2(w3.y-w2.y,w3.x-w2.x)+360) Mod 360 w2.x:+Cos(angle) w2.y:+Sin(angle) x = w2.x y = w2.y EndIf SetColor 255,255,255 DrawOval APunkt1X,APunkt1Y,10,10 DrawOval APunkt2X,APunkt2Y,10,10 DrawOval APunkt3X,APunkt3Y,10,10 SetColor 255,0,0 DrawOval x,y,10,10 Flip Until KeyHit(KEY_ESCAPE) fg, Orbit |
||
![]() |
FOODy |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ich weiß nicht ob es dir hilft, aber ich hab aus eigener Interesse ebend diesen Code geschrieben:
Code: [AUSKLAPPEN] SuperStrict
Framework BRL.D3D7Max2D Import BRL.Blitz Type TWaypoint Field x:Int Field y:Int Function Create:TWaypoint(x:Int,y:Int) Local waypoint:TWaypoint = New TWaypoint waypoint.x = x waypoint.y = y Return waypoint EndFunction EndType Type TBody Field x:Float Field y:Float Field speed:Float = 3.5 Field waypoints:TList = CreateList() Field curwaypoint:TWaypoint Method AddWaypoint(waypoint:TWaypoint) waypoints.addlast waypoint EndMethod Method PushWaypoint() waypoints.removefirst EndMethod Method MoveToWaypoint() If curwaypoint = Null And CountList(waypoints) Then curwaypoint = TWaypoint(waypoints.ValueAtIndex(0)) If curwaypoint = Null Then Return Local _x:Int = curwaypoint.x Local _y:Int = curwaypoint.y If x-speed<_x And x+speed>_x And y-speed<_y And y+speed>_y PushWaypoint() x = curwaypoint.x y = curwaypoint.y curwaypoint = Null Return EndIf Local _angle:Float = GetDirection(x,y,_x,_y) x:+Cos(_angle)*Speed y:+Sin(_angle)*Speed EndMethod EndType Local player:TBody = New TBody player.x = 20 player.y = 20 Graphics 800,600,0 Repeat HideMouse() Cls SetBlend ALPHABLEND SetColor 0,0,200 SetAlpha 0.7 DrawOval MouseX()-5,MouseY()-5,10,10 SetAlpha 1 SetColor 255,255,255 player.MoveToWaypoint() DrawOval player.x-4,player.y-4,8,8 For Local wp:TWaypoint=EachIn player.waypoints SetColor 0,255,0 DrawOval wp.x-2,wp.y-2,4,4 Next If(MouseHit(MOUSE_LEFT)) Then player.AddWaypoint(TWaypoint.Create(MouseX(),MouseY())) Flip Until AppTerminate() Or KeyDown(KEY_ESCAPE) Function GetDirection:Float(x1:Int,y1:Int,x2:Int,y2:Int) Return ATan2((y2-y1),(x2-x1)) EndFunction |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group