wegpunkte problem, punkt bewegt sich falsch
Übersicht

MadMentalBetreff: wegpunkte problem, punkt bewegt sich falsch |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
hi,
also ich habe folgendes problem und zwar: da ich jetzt bald ein autospiel projekt anfangen werde, muss ich natürlich wissen, wie man gescheid wegpunkt macht. Ich habe auch schon ein programm geschrieben, nur dazu da, ob ich weis, wie man wegpunkte macht, aber der Punkt bewegt sich immer falsch .... hier der code: Code: [AUSKLAPPEN] ; ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ; Wegpunkte test von MadMental ; 30.9.2006 ; ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Graphics 640,480 SetBuffer BackBuffer() Global nummer = 1 Global gehe_nummer = 0 Global winkel = 0 Type wegpunkt Field x Field y Field nr End Type While Not KeyHit(1) Cls neu() wegpunkte_setzten() wegpunkte_gehen() Flip Wend Function wegpunkte_setzten() While Not KeyHit(28) Or KeyHit(1) Cls Mx = MouseX() My = MouseY() If MouseHit(1) Then weg.wegpunkt = New wegpunkt weg\x = Mx weg\y = My weg\nr = nummer nummer = nummer + 1 EndIf For weg.wegpunkt = Each wegpunkt Oval weg\x - 1, weg\y - 1, 3, 3 Text weg\x + 5, weg\y, weg\nr Next Text 10,10, "Setzte wegpunkte mit der Maus und starte Programm mit Enter" Flip Wend End Function Function wegpunkte_gehen() x = 320: y = 240 For weg.wegpunkt = Each wegpunkt x_ziel = weg\x: y_ziel = weg\y winkel_ausrechnen(x,y,x_ziel,y_ziel) While Not x=x_ziel And y=y_ziel Cls If KeyHit(28) Or KeyHit(1) Then End x = x + Cos(winkel) * 2 y = y + Sin(winkel) * 2 Color 255,255,255 For weg.wegpunkt = Each wegpunkt Oval weg\x - 1, weg\y - 1, 3, 3 Text weg\x + 5, weg\y, weg\nr Next Color 100,100,100 Oval x-3,y-3,7,7 Color 200,200,200 Text 10,10, "Zum beenden Esc oder Enter drücken" Flip Wend Next End Function Function winkel_ausrechnen(x1,y1,x2,y2) winkel = ATan2(x1-x2,y1-y2) End Function Function neu() Delete Each wegpunkt nummer = 1 gehe_nummer = 1 winkel = 0 End Function ich denke es ist ihrgendetwas falsch bei zeile 68/69 ... Hoffe ihr könnt mir helfen. (Der code ist net ganz sauber geschrieben ![]() mfg MM |
||
![]() |
BlitzcoderNewsposter |
![]() Antworten mit Zitat ![]() |
---|---|---|
hab mal ein BSP gemacht:
Code: [AUSKLAPPEN] Graphics 800,600,0,2
Dim punkte(10,2) SeedRnd MilliSecs() Global x#, y# Global punkt=1 Global xspeed#, yspeed# For i=1 To 10 punkte(i,1)=rand(10,700) punkte(i,2)=rand(10,500) Next x=punkte(1,1) y=punkte(1,2) xspeed=(punkte(punkt,1)-x)/50 yspeed=(punkte(punkt,2)-y)/50 SetBuffer BackBuffer() Repeat If a=50 then punkt=punkt+1 If punkt=11 Then Print "Fertig!" : Flip: WaitKey : End xspeed=(punkte(punkt,1)-x)/50 yspeed=(punkte(punkt,2)-y)/50 a=0 EndIf a=a+1 Color 255,0,0 For i=1 To 10 Oval punkte(i,1), punkte(i,2),5,5 Text punkte(i,1)+5, punkte(i,2),i Next Color 255,255,255 Oval x,y,5,5 x=x+xspeed y=y+yspeed Flip Cls Until KeyDown(1) End MfG Blitzcoder |
||
P4 3 Ghz@3,55Ghz|GF 6600GT 256MB|Samsung 80GB | 2x Samsung 160GB|2048MB DDR-400 RAM|6 Mbit Flatrate | Logitech G15 | Samsung 225BW-TFT | Ubuntu Gutsy Linux | Windows Vista | Desktop | Blog | CollIDE | Worklog
________________ |°°°°°°°°°°°°°°||'""|""\__,_ |______________ ||__ |__|__ |) |(@) |(@)"""**|(@)(@)****|(@) |
MadMental |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
thx Blitzcoder, aber ich wollte iegtentlich wissen, wieso der winkel immer falsch ist.
Ich glaube da ist ihrgendetwas bei: Code: [AUSKLAPPEN] x = x + Cos(winkel) * 2 y = y + Sin(winkel) * 2 falsch oder bei Code: [AUSKLAPPEN] Function winkel_ausrechnen(x1,y1,x2,y2) winkel = ATan2(x1-x2,y1-y2) End Function ..... ich sehe einfach keinen fehler, aber das programm hat einen! Könnt ihr euch nicht nochmal das programm anschauen, und sagen, wenn euch was auffällt? mfg MM |
||
![]() |
Iguan |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ich hab deinen code ein wenig abgeändert... ich hoffe, das ist das was du brauchst
mfg Iguan Code: [AUSKLAPPEN] ; ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ; Wegpunkte test von MadMental ; 30.9.2006 ; ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Graphics 640,480 SetBuffer BackBuffer() Global nummer = 1 Global gehe_nummer = 0 Global winkel# = 0 Type wegpunkt Field x Field y Field nr End Type wegpunkte_setzten() Function wegpunkte_setzten() While Not KeyHit(28) Or KeyHit(1) Cls Mx = MouseX() My = MouseY() If MouseHit(1) Then weg.wegpunkt = New wegpunkt weg\x = Mx weg\y = My weg\nr = nummer nummer = nummer + 1 EndIf For weg.wegpunkt = Each wegpunkt Oval weg\x - 1, weg\y - 1, 3, 3 Text weg\x + 5, weg\y, weg\nr Next Text 10,10, "Setzte wegpunkte mit der Maus und starte Programm mit Enter" Flip Wend End Function x# = 240 y# = 200 PunktNr = 1 For weg.wegpunkt = Each wegpunkt X_Ziel = weg\x Y_Ziel = weg\y Exit Next While Not KeyHit(1) Cls If RectsOverlap(x-2,y-2,4,4,x_ziel-2,y_ziel-2,4,4) Then PunktNr = PunktNr + 1 For weg.wegpunkt = Each wegpunkt If PunktNr = Weg\Nr Then X_Ziel = weg\x Y_Ziel = weg\y Exit End If Next EndIf winkel_ausrechnen(x#,y#,x_ziel,y_ziel) x# = x# + Sin(winkel#) * 2 y# = y# + Cos(winkel#) * 2 Color 255,255,255 For weg.wegpunkt = Each wegpunkt Oval weg\x - 1, weg\y - 1, 3, 3 Text weg\x + 5, weg\y, weg\nr Next Color 100,100,100 Oval x#-3,y#-3,7,7 Color 200,200,200 Text 10,10, "Zum beenden Esc oder Enter drücken" Flip Wend End Function winkel_ausrechnen(x1#,y1#,x2,y2) winkel# = (ATan2#(x2-x1#,y2-y1#)+360) Mod 360 End Function Function neu() Delete Each wegpunkt nummer = 1 gehe_nummer = 1 winkel = 0 End Function |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group