Frage zu Types und Vista
Übersicht

MadMentalBetreff: Frage zu Types und Vista |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hi leute,
Ich habe mal wieder seit längerem versucht etwas zu programmieren. Der Minispaceklon von mir funktioniert auch soweit, nur sind mir 2 Dinge aufgefallen: 1. Ich habe 2 For-Next-Schleifen mit types gekapselt und da ist mir folgendes aufgefallen: Die Variablen der ersten For-Next-Schleife sind bei mir in der zweiten For-Next-Schleife nicht mehr gültig: Ausschnitt aus dem Code(Vollständigen Code gibt es unten) Funktioniert: Code: [AUSKLAPPEN] For s.schuss = Each schuss s\x# = s\x# + Cos(s\winkel#)*s\speed# s\y# = s\y# + Sin(s\winkel#)*s\speed# Oval s\x#-3,s\y#-3,6,6,1 If (s\x# < 0 Or s\x# > 800) Or ( s\y# < 0 Or s\y# > 600) Then Delete s.schuss as = as - 1 Goto endschuss EndIf s_x# = s\x# ;variablen neu deklarieren funktioniert s_y# = s\y# ; ----------------------------------------------- For r.rock = Each rock If abstand(r\x#,s_x#,r\y#,s_y#,r\u,3) Then score = score + 1 Delete r.rock Delete s.schuss as = as - 1 : ar = ar - 1 new_r() EndIf Next .endschuss Next Funktioniert nicht: Code: [AUSKLAPPEN] For s.schuss = Each schuss s\x# = s\x# + Cos(s\winkel#)*s\speed# s\y# = s\y# + Sin(s\winkel#)*s\speed# Oval s\x#-3,s\y#-3,6,6,1 If (s\x# < 0 Or s\x# > 800) Or ( s\y# < 0 Or s\y# > 600) Then Delete s.schuss as = as - 1 Goto endschuss EndIf ;s_x# = s\x# ;hier funktionierts nich ;s_y# = s\y# For r.rock = Each rock If abstand(r\x#,s\x#,r\y#,s\y#,r\u,3) Then score = score + 1 Delete r.rock Delete s.schuss as = as - 1 : ar = ar - 1 new_r() EndIf Next .endschuss Next Unten habe ich beide Möglichkeiten aufgelistet ( einmal funktionierenden Code und einmal Fehlerhaften Code) Wie ihr seht, habe ich bei der ersten Möglichkeit (funktionierender Code) den Type-Variablen nocheinmal extra einer Variable zuordnen müssen und im zweiten (fehlerhaften Code) diesen Schritt ausgelassen und es komtm eine Fehlermeldung bei mir. (habe s\x# und s\y# in s_x# und s_y# variabilisiert(gibt es das wort? xD) Entschuldigt mich, wenn ich mich etwas "falsch" ausgedrückt habe. Soweit ich mich erinnern kann, hat diese Möglichkeit mal soweit bei mir mal funktioniert( Entschuldigt mich, wenn ich mich irre) Hier funktionierender Code, des Space-Shooters: Code: [AUSKLAPPEN] Graphics3D 800,600,16,2 SetBuffer BackBuffer() Global x#=400:Global y#=300:Global winkel#=180:Global a_speed#: Global a# = 0.1 Global as = 0: Global ar = 0 Global lastf = MilliSecs():Global ttnr= 1000 Global huelle = 100: Global energy = 100:Global schutzschild = 100 Global schutzschild_auflad_zeit = 7000: schutzschild_auflad_ms = MilliSecs() Global nextenergy= MilliSecs():Global nextenergy_period = 500 Global schuss_period = 200:Global schuss_ms = MilliSecs() Global score = 0 Global mx# = MouseX() : Global my# = MouseY() : Global stmw# Global antialiasing_w = 1 ;Global timer = CreateTimer(60) Type schuss Field x# Field y# Field winkel# Field speed# End Type Type rock Field x# Field y# Field winkel# Field speed Field u ;radius Field stuecke End Type While Not KeyHit(1) Cls move() US() UR() new_r() UI() a_s_f() Color 255,255,255 ;das schiff Oval x#-10,y#-10,20,20,1 Line x#+Cos(winkel#+90)*10,y#+Sin(winkel#+90)*10,x#+Cos(winkel#)*30,y#+Sin(winkel#)*30 Line x#+Cos(winkel#-90)*10,y#+Sin(winkel#-90)*10,x#+Cos(winkel#)*30,y#+Sin(winkel#)*30 Line x#-Cos(winkel#+90)*10,y#-Sin(winkel#+90)*10,x#-Cos(winkel#)*30,y#-Sin(winkel#)*30 Line x#-Cos(winkel#-90)*10,y#-Sin(winkel#-90)*10,x#-Cos(winkel#)*30,y#-Sin(winkel#)*30 ;die kanonen Line x#+Cos(stmw#+90)*10,y#+Sin(stmw#+90)*10,x#+Cos(stmw#+20)*30,y#+Sin(stmw#+20)*30 Line x#+Cos(stmw#-90)*10,y#+Sin(stmw#-90)*10,x#+Cos(stmw#-20)*30,y#+Sin(stmw#-20)*30 ;das rote zeugs hinten If schutzschild >= 10 Color 0,255,0 Oval x#-15,y#-15,30,30,0 EndIf Color 255,255,255 Text 10,10,"x: "+x#+" y: "+y#+ " winkel: "+winkel# Text 10,30,"aktive Schüsse: "+as+" aktive felsbrocken: "+ar ms=MilliSecs():Text 10,50,"fps: "+fps If ms>mt mt=ms+502:fps=frame:frame=0 Else frame=frame+2 Text 10,70,"score :"+score Text 400,10,"Geschwindigkeit: "+a_speed# Text 400,30,"Antialiasing (0=Aus | 1=An) :"+antialiasing_w Text 400,50,"Schiff-Maus-Winkel = "+stmw# Flip WaitTimer(timer) Wend Function move() If KeyDown(17) a_speed# = a_speed# + a# If a_speed# > 8 Then a_speed# = 8 ;x#=x#+Cos(winkel#)*a_speed# ;y#=y#+Sin(winkel#)*a_speed# EndIf If KeyDown(31) a_speed# = a_speed# - a# If a_speed# < -6 Then a_speed# = -6 ;x#=x#-Cos(winkel#)*a_speed# ;y#=y#-Sin(winkel#)*a_speed# EndIf If KeyDown(30) winkel# = winkel# - 5 EndIf If KeyDown(32) winkel# = winkel# + 5 EndIf x#=x#+Cos(winkel#)*a_speed# y#=y#+Sin(winkel#)*a_speed# If KeyDown(2) If energy >= 10 And schutzschild =< 95 Then If MilliSecs() - schutzschild_auflad_ms > schutzschild_auflad_zeit Then schutzschild = schutzschild + 5 energy = energy - 10 schutzschild_auflad_ms = MilliSecs() EndIf EndIf EndIf If MouseDown(1) And energy > 1 Then If (MilliSecs() - schuss_ms) > schuss_period schuss_ms = MilliSecs() s.schuss = New schuss s\x# = x#+Cos(stmw#+90)*10 s\y# = y#+Sin(stmw#+90)*10 s\winkel# = stmw# s\speed# = a_speed# * 1.3 s.schuss = New schuss s\x# = x#+Cos(stmw#-90)*10 s\y# = y#+Sin(stmw#-90)*10 s\winkel# = stmw# s\speed# = a_speed# * 1.3 as = as + 2 energy = energy - 2 EndIf EndIf If winkel# < 0 Then winkel# = 360 If winkel# > 360 Then winkel# = 0 If x# < 0 Then x# = 800 If x# > 800 Then x# = 0 If y# < 0 Then y# = 600 If y# > 600 Then y# = 0 End Function Function US() Color 200,200,200 For s.schuss = Each schuss s\x# = s\x# + Cos(s\winkel#)*s\speed# s\y# = s\y# + Sin(s\winkel#)*s\speed# Oval s\x#-3,s\y#-3,6,6,1 If (s\x# < 0 Or s\x# > 800) Or ( s\y# < 0 Or s\y# > 600) Then Delete s.schuss as = as - 1 Goto endschuss EndIf s_x# = s\x# s_y# = s\y# For r.rock = Each rock If abstand(r\x#,s_x#,r\y#,s_y#,r\u,3) Then score = score + 1 Delete r.rock Delete s.schuss as = as - 1 : ar = ar - 1 new_r() EndIf Next .endschuss Next If MilliSecs()-nextenergy > nextenergy_period nextenergy = MilliSecs() If energy < 100 energy = energy + 1 EndIf EndIf End Function Function UR() Color 100,100,100 For r.rock = Each rock r\x# = r\x# + Cos(r\winkel#)*r\speed r\y# = r\y# + Sin(r\winkel#)*r\speed winkela#(r\x#,r\y#,x#,y#,r\winkel#) If r\x# < 0 Then r\x# = 800 ElseIf r\x# > 800 Then r\x# = 0 ElseIf r\y# < 0 Then r\y# = 600 ElseIf r\y# > 600 Then r\y# = 0 EndIf Oval r\x# - r\u,r\y#-r\u,r\u*2,r\u*2,1 If abstand(r\x#,x#,r\y#,y#,r\u,15) Then Delete r.rock ar = ar - 1 If schutzschild > 10 schutzschild = schutzschild - 10 Else huelle = huelle - 10 If huelle = 0 Then Cls:Text 10,10,"Verloren" EndIf new_r() EndIf Next End Function Function new_r() If ar < 10 And MilliSecs() - lastf > 1000 lastf = MilliSecs() ar = ar + 1 speed_u = Rnd(7,30) u_wird = Rnd(5,speed_u-1) If x# < 400 Then ty = Rnd(100,500) r.rock = New rock r\y# = ty r\x# = 1 ww = (360 + Rnd(-45,45)) Mod 360 r\winkel# = ww r\speed = speed_u - u_wird r\u = u_wird ElseIf x# > 400 r.rock = New rock ty = Rnd(100,500) r\y# = ty r\x# = 799 ww = (180 + Rnd(-45,45)) Mod 360 r\winkel# = ww r\speed = speed_u - u_wird r\u = u_wird EndIf EndIf End Function Function winkela#(x1#,y1#,x2#,y2#,rockw#) ywert# = y2#-y1# xwert# = x2#-x1# w# = (ATan2(ywert#,xwert#)) + 360 Mod 360 wminus# = w#-rockw# If wminus# < 0 Then rockw# = wockw# - 1 If wminus# > 0 Then rockw# = wockw# + 1 End Function Function UI() Color 0,255,255 Rect 10,540,350,50,0 Rect 440,540,350,50,0 huelle_breite =(huelle*3.5)-1 Color 255,0,0 Rect 11,541,huelle_breite,49,1 schield_breite = (schutzschild*3.5)-1 Rect 441,541,schield_breite,49,1 Color 0,255,0 Text 150,550,"Hülle "+huelle+"%" Text 550,550,"Schutzschild "+schutzschild+"%" Color 0,255,255 Rect 740,100,50,400,0 energy_hoehe = (energy*4) - 2 Color 0,200,200 Rect 741,101,50,energy_hoehe,1 Color 0,255,0 Text 743,300,"E "+energy+"%" End Function Function abstand#(x1#,x2#,y1#,y2#,r1,r2) Abstand_e=Sqr((X1-X2)^2+(Y1-Y2)^2) radius_e = r1+r2 If abstand_e - radius_e =< 0 Then Return True End Function Function ship_to_mouse_w#(x1#,x2#,y1#,y2#) ywert# = y2#-y1# xwert# = x2#-x1# w# = (ATan2(ywert#,xwert#)) + 360 Mod 360 Return w# End Function Function a_s_f() If KeyHit(3) Then DebugLog "antialias geändert" antialiasing_w = 1 - antialiasing_w AntiAlias antialiasing_w EndIf If huelle =< 0 Then End mx# = MouseX() : my = MouseY() stmw# = ship_to_mouse_w#(x#,mx#,y#,my#) End Function End Fehlerhafter Code: Code: [AUSKLAPPEN] Graphics3D 800,600,16,2 SetBuffer BackBuffer() Global x#=400:Global y#=300:Global winkel#=180:Global a_speed#: Global a# = 0.1 Global as = 0: Global ar = 0 Global lastf = MilliSecs():Global ttnr= 1000 Global huelle = 100: Global energy = 100:Global schutzschild = 100 Global schutzschild_auflad_zeit = 7000: schutzschild_auflad_ms = MilliSecs() Global nextenergy= MilliSecs():Global nextenergy_period = 500 Global schuss_period = 200:Global schuss_ms = MilliSecs() Global score = 0 Global mx# = MouseX() : Global my# = MouseY() : Global stmw# Global antialiasing_w = 1 ;Global timer = CreateTimer(60) Type schuss Field x# Field y# Field winkel# Field speed# End Type Type rock Field x# Field y# Field winkel# Field speed Field u ;radius Field stuecke End Type While Not KeyHit(1) Cls move() US() UR() new_r() UI() a_s_f() Color 255,255,255 ;das schiff Oval x#-10,y#-10,20,20,1 Line x#+Cos(winkel#+90)*10,y#+Sin(winkel#+90)*10,x#+Cos(winkel#)*30,y#+Sin(winkel#)*30 Line x#+Cos(winkel#-90)*10,y#+Sin(winkel#-90)*10,x#+Cos(winkel#)*30,y#+Sin(winkel#)*30 Line x#-Cos(winkel#+90)*10,y#-Sin(winkel#+90)*10,x#-Cos(winkel#)*30,y#-Sin(winkel#)*30 Line x#-Cos(winkel#-90)*10,y#-Sin(winkel#-90)*10,x#-Cos(winkel#)*30,y#-Sin(winkel#)*30 ;die kanonen Line x#+Cos(stmw#+90)*10,y#+Sin(stmw#+90)*10,x#+Cos(stmw#+20)*30,y#+Sin(stmw#+20)*30 Line x#+Cos(stmw#-90)*10,y#+Sin(stmw#-90)*10,x#+Cos(stmw#-20)*30,y#+Sin(stmw#-20)*30 ;das rote zeugs hinten If schutzschild >= 10 Color 0,255,0 Oval x#-15,y#-15,30,30,0 EndIf Color 255,255,255 Text 10,10,"x: "+x#+" y: "+y#+ " winkel: "+winkel# Text 10,30,"aktive Schüsse: "+as+" aktive felsbrocken: "+ar ms=MilliSecs():Text 10,50,"fps: "+fps If ms>mt mt=ms+502:fps=frame:frame=0 Else frame=frame+2 Text 10,70,"score :"+score Text 400,10,"Geschwindigkeit: "+a_speed# Text 400,30,"Antialiasing (0=Aus | 1=An) :"+antialiasing_w Text 400,50,"Schiff-Maus-Winkel = "+stmw# Flip WaitTimer(timer) Wend Function move() If KeyDown(17) a_speed# = a_speed# + a# If a_speed# > 8 Then a_speed# = 8 ;x#=x#+Cos(winkel#)*a_speed# ;y#=y#+Sin(winkel#)*a_speed# EndIf If KeyDown(31) a_speed# = a_speed# - a# If a_speed# < -6 Then a_speed# = -6 ;x#=x#-Cos(winkel#)*a_speed# ;y#=y#-Sin(winkel#)*a_speed# EndIf If KeyDown(30) winkel# = winkel# - 5 EndIf If KeyDown(32) winkel# = winkel# + 5 EndIf x#=x#+Cos(winkel#)*a_speed# y#=y#+Sin(winkel#)*a_speed# If KeyDown(2) If energy >= 10 And schutzschild =< 95 Then If MilliSecs() - schutzschild_auflad_ms > schutzschild_auflad_zeit Then schutzschild = schutzschild + 5 energy = energy - 10 schutzschild_auflad_ms = MilliSecs() EndIf EndIf EndIf If MouseDown(1) And energy > 1 Then If (MilliSecs() - schuss_ms) > schuss_period schuss_ms = MilliSecs() s.schuss = New schuss s\x# = x#+Cos(stmw#+90)*10 s\y# = y#+Sin(stmw#+90)*10 s\winkel# = stmw# s\speed# = a_speed# * 1.3 s.schuss = New schuss s\x# = x#+Cos(stmw#-90)*10 s\y# = y#+Sin(stmw#-90)*10 s\winkel# = stmw# s\speed# = a_speed# * 1.3 as = as + 2 energy = energy - 2 EndIf EndIf If winkel# < 0 Then winkel# = 360 If winkel# > 360 Then winkel# = 0 If x# < 0 Then x# = 800 If x# > 800 Then x# = 0 If y# < 0 Then y# = 600 If y# > 600 Then y# = 0 End Function Function US() Color 200,200,200 For s.schuss = Each schuss s\x# = s\x# + Cos(s\winkel#)*s\speed# s\y# = s\y# + Sin(s\winkel#)*s\speed# Oval s\x#-3,s\y#-3,6,6,1 If (s\x# < 0 Or s\x# > 800) Or ( s\y# < 0 Or s\y# > 600) Then Delete s.schuss as = as - 1 Goto endschuss EndIf ;s_x# = s\x# ;s_y# = s\y# For r.rock = Each rock If abstand(r\x#,s\x#,r\y#,s\y#,r\u,3) Then score = score + 1 Delete r.rock Delete s.schuss as = as - 1 : ar = ar - 1 new_r() EndIf Next .endschuss Next If MilliSecs()-nextenergy > nextenergy_period nextenergy = MilliSecs() If energy < 100 energy = energy + 1 EndIf EndIf End Function Function UR() Color 100,100,100 For r.rock = Each rock r\x# = r\x# + Cos(r\winkel#)*r\speed r\y# = r\y# + Sin(r\winkel#)*r\speed winkela#(r\x#,r\y#,x#,y#,r\winkel#) If r\x# < 0 Then r\x# = 800 ElseIf r\x# > 800 Then r\x# = 0 ElseIf r\y# < 0 Then r\y# = 600 ElseIf r\y# > 600 Then r\y# = 0 EndIf Oval r\x# - r\u,r\y#-r\u,r\u*2,r\u*2,1 If abstand(r\x#,x#,r\y#,y#,r\u,15) Then Delete r.rock ar = ar - 1 If schutzschild > 10 schutzschild = schutzschild - 10 Else huelle = huelle - 10 If huelle = 0 Then Cls:Text 10,10,"Verloren" EndIf new_r() EndIf Next End Function Function new_r() If ar < 10 And MilliSecs() - lastf > 1000 lastf = MilliSecs() ar = ar + 1 speed_u = Rnd(7,30) u_wird = Rnd(5,speed_u-1) If x# < 400 Then ty = Rnd(100,500) r.rock = New rock r\y# = ty r\x# = 1 ww = (360 + Rnd(-45,45)) Mod 360 r\winkel# = ww r\speed = speed_u - u_wird r\u = u_wird ElseIf x# > 400 r.rock = New rock ty = Rnd(100,500) r\y# = ty r\x# = 799 ww = (180 + Rnd(-45,45)) Mod 360 r\winkel# = ww r\speed = speed_u - u_wird r\u = u_wird EndIf EndIf End Function Function winkela#(x1#,y1#,x2#,y2#,rockw#) ywert# = y2#-y1# xwert# = x2#-x1# w# = (ATan2(ywert#,xwert#)) + 360 Mod 360 wminus# = w#-rockw# If wminus# < 0 Then rockw# = wockw# - 1 If wminus# > 0 Then rockw# = wockw# + 1 End Function Function UI() Color 0,255,255 Rect 10,540,350,50,0 Rect 440,540,350,50,0 huelle_breite =(huelle*3.5)-1 Color 255,0,0 Rect 11,541,huelle_breite,49,1 schield_breite = (schutzschild*3.5)-1 Rect 441,541,schield_breite,49,1 Color 0,255,0 Text 150,550,"Hülle "+huelle+"%" Text 550,550,"Schutzschild "+schutzschild+"%" Color 0,255,255 Rect 740,100,50,400,0 energy_hoehe = (energy*4) - 2 Color 0,200,200 Rect 741,101,50,energy_hoehe,1 Color 0,255,0 Text 743,300,"E "+energy+"%" End Function Function abstand#(x1#,x2#,y1#,y2#,r1,r2) Abstand_e=Sqr((X1-X2)^2+(Y1-Y2)^2) radius_e = r1+r2 If abstand_e - radius_e =< 0 Then Return True End Function Function ship_to_mouse_w#(x1#,x2#,y1#,y2#) ywert# = y2#-y1# xwert# = x2#-x1# w# = (ATan2(ywert#,xwert#)) + 360 Mod 360 Return w# End Function Function a_s_f() If KeyHit(3) Then DebugLog "antialias geändert" antialiasing_w = 1 - antialiasing_w AntiAlias antialiasing_w EndIf If huelle =< 0 Then End mx# = MouseX() : my = MouseY() stmw# = ship_to_mouse_w#(x#,mx#,y#,my#) End Function End Beide versionen für die Faulen ![]() Hoffe ihr könnt mir erläutern, wieso das laut BB nicht richtig ist. Und nun zum 2ten Punkt: Habe einem Freund eine exe( funktionsfähig ) geschickt und er hat Vista. So nun sagt er mir, das die Schüsse immer um 180° gedreht seien, also nicht zur Maus fliegen sondern genau in die entgegengesetzte richtung ... Wollte mal fragen, ob das bei euch auch so ist, für die Leute die Vista oder was anderes haben. Ich selbst habe XP und bei mir funktioniert es tadellos. Habe Graphics3D eingesetzt um mit Antialiasing rumzuspielen zur Steuerung: wasd links/rechts schneller/langsamer Linke Maustaste zum schießen und die Maus zum steuern, der kanonen. Entschuldigt bitte meine rechtschreibfehler Ich hoffe ihr könnt mir bei dem einem oder anderem Problem helfen mfg MM |
||
![]() |
aMulSieger des Minimalist Compo 01/13 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Zu 1.
An die Werte der Variablen solltest du ohne Probleme auch in der X-ten Schleife kommen. Was mir allerdings auffällt ist, dass du, wenn ein Schuss getroffen hast, diesen löscht allerdings trotzdem weiter die Steine durch gehst und auf Kollision prüfst. Da du den Schuss aber gelöscht hast versucht Blitz auf einen nicht existierenden Type-Eintrag zuzugreifen, was normalerweise in einem Absturz des Programmes enden sollte. Um das zu fixen musst du einfach nach dem Aufruf von "new_r()" die Schleife mit "Exit" verlassen. Vielleicht läuft das Programm nach dieser Änderung ja wie gewünscht. Falls nicht, dann sag nochmal Bescheid. Vielleicht findet ja auch noch wer einen anderen Fehler. Zu 2. Keine Ahnung ![]() |
||
Panic Pong - ultimate action mashup of Pong and Breakout <= aktives Spiele-Projekt, Downloads mit vielen bunten Farben!
advASCIIdraw - the advanced ASCII art program <= aktives nicht-Spiele-Projekt, must-have für ASCII/roguelike/dungeon-crawler fans! Alter BB-Kram: ThroughTheAsteroidBelt - mit Quelltext! | RGB-Palette in 32²-Textur / Farbige Beleuchtung mit Dot3 | Stereoskopie in Blitz3D | Teleport-Animation Screensaver |
MadMental |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
@aMul, das programm läuft ja wie gewünscht, nur wollte ich wissen, wieso ich die variablen hier in der 2ten for-next schleife nicht einsetzten kann, ohne die variablen der ersten for-next schleife neu zu deklarieren.
Habe ausversehen den Befehl "Exit" vergessen und dafür "Goto" hergenommen *schäm* MM |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group