Problem mit einfachem Programm
Übersicht

![]() |
sbrogBetreff: Problem mit einfachem Programm |
![]() Antworten mit Zitat ![]() |
---|---|---|
Dieses Programm soll ein Rechteck schräg in eine richtung laufen und von der Wand abprallen lassen, sobald es jedoch an der oberen Wand ankommt, läuft es nicht mehr so wie es sollte ?
Wo ist der Fehler ? Code: [AUSKLAPPEN] ; richtung 1 : oben links ; richtung 2 : oben rechts ; richtung 3 : unten rechts ;richtung 4 : unten links Graphics 1024,768 Global y = Rand(50,718) Global Direct = 3 Repeat ClsColor 255,0,50 Cls ;.............................................................................................. If direct =1 Then x = x-2 y = y-2 EndIf If direct = 2 Then x = x+2 y = y-2 EndIf If Direct = 3 Then x = x +2 y = y +2 EndIf If direct = 4 Then x = x-2 y = y+2 EndIf ;---------------------------------------------------------------------------------------------------- If x>1024 If direct = 3 direct = 4 EndIf EndIf If x>1024 If direct = 2 direct = 1 EndIf EndIf If y> 768 If direct = 3 Direct = 2 EndIf EndIf If y>768 If direct = 4 Direct = 1 EndIf EndIf If x<0 If direct = 1 Direct = 2 EndIf EndIf If x<0 If direct = 4 Direct = 3 EndIf EndIf If y<0 If direct = 1 direct = 4 EndIf EndIf If y<0 If direct = 2 direct = 3 EndIf EndIf ;--------------------------------------------------------------------------------------------------- Rect x,y,50,50,2 Print direct Flip Until KeyHit(1) Danke im Vorraus für die Mühe ![]() |
||
- Zuletzt bearbeitet von sbrog am Di, Apr 06, 2004 15:17, insgesamt einmal bearbeitet
AvaGast |
![]() Antworten mit Zitat |
|
---|---|---|
Versucht doch bitte, mal ein bischen übersichtlicher und optimaler zu programmieren (vorallem bei so simplen Programmen).
Code: [AUSKLAPPEN] Graphics 800, 600, 16, 2
Global player_x# = 100 Global player_last_x# = 100 Global player_y# = 300 Global player_vel# = 0 Global wall_x = 600 Global wall_y = 150 SetBuffer BackBuffer() Repeat Cls ; Steuerung player_last_x = player_x If KeyDown(203) Then player_vel# = player_vel# - 1.0 If KeyDown(205) Then player_vel# = player_vel# + 1.0 player_vel# = player_vel# * 0.9 player_x = player_x + player_vel ; Kollision If RectsOverlap(player_x, player_y, 25, 50, wall_x, wall_y, 100, 300) Then player_vel# = -player_vel# : player_x = player_last_x ; Player/Wall zeichnen Rect player_x, player_y, 25, 50 Rect wall_x, wall_y, 100, 300 Flip Until KeyHit(1) : End |
||
![]() |
sbrog |
![]() Antworten mit Zitat ![]() |
---|---|---|
Was hat das jetzt hiermit zu tun ![]() |
||
AvaGast |
![]() Antworten mit Zitat |
|
---|---|---|
Sieh es Dir an. Da läuft ein Rechteck gegen eine Wand und prallt ab! Vielleicht kannste daraus was lernen?! | ||
AvaGast |
![]() Antworten mit Zitat |
|
---|---|---|
Okay, hab mir jetzt dochmal Deinen Code angeschaut.
Bei Dir fehlt der Befehl SetBuffer BackBuffer(), ist es das was Du meinst? - ausserdem ist der Print Befehl dafür verantwortlich, dass es flimmert! Benutze Text! Code: [AUSKLAPPEN] ; richtung 1 : oben links ; richtung 2 : oben rechts ; richtung 3 : unten rechts ;richtung 4 : unten links Graphics 1024,768 Global y = Rand(50,718) Global Direct = 3 SetBuffer BackBuffer() Repeat ClsColor 255,0,50 Cls ;.............................................................................................. If direct =1 Then x = x-2 y = y-2 EndIf If direct = 2 Then x = x+2 y = y-2 EndIf If Direct = 3 Then x = x +2 y = y +2 EndIf If direct = 4 Then x = x-2 y = y+2 EndIf ;---------------------------------------------------------------------------------------------------- If x>1024 If direct = 3 direct = 4 EndIf EndIf If x>1024 If direct = 2 direct = 1 EndIf EndIf If y> 768 If direct = 3 Direct = 2 EndIf EndIf If y>768 If direct = 4 Direct = 1 EndIf EndIf If x<0 If direct = 1 Direct = 2 EndIf EndIf If x<0 If direct = 4 Direct = 3 EndIf EndIf If y<0 If direct = 1 direct = 4 EndIf EndIf If y<0 If direct = 2 direct = 3 EndIf EndIf ;--------------------------------------------------------------------------------------------------- Rect x,y,50,50,2 Text 20, 20, direct Flip Until KeyHit(1) |
||
- Zuletzt bearbeitet von Ava am Di, Apr 06, 2004 15:25, insgesamt einmal bearbeitet
![]() |
sbrog |
![]() Antworten mit Zitat ![]() |
---|---|---|
Zitat: Versucht doch bitte, mal ein bischen übersichtlicher und optimaler zu programmieren (vorallem bei so simplen Programmen).
ich hab das gemeint. Im übrigen finde ich den Umgangston hier im Forum für den A**** Trotzdem Danke *gruml* |
||
![]() |
Hubsi |
![]() Antworten mit Zitat ![]() |
---|---|---|
ClsColor bitte nicht in einer Schleife anwenden. Und der ganze Block unter dem Until ist für die Katz. Was mir auch aufgefallen ist:
Rect x,y,50,50,2 ![]() ![]() |
||
Den ganzen Doag im Bett umanandflagga und iaz daherkema und meine Hendl`n fressn... |
- Zuletzt bearbeitet von Hubsi am Di, Apr 06, 2004 15:29, insgesamt einmal bearbeitet
AvaGast |
![]() Antworten mit Zitat |
|
---|---|---|
Achso okay, das meinst Du. Was es damit zu tun hat? - Naja, das ist eigentlich ganz einfach: es ist super anstrengenden solche Codes durchzusehen und dort etwas nachzuvollziehen. Es war ja nur ein gut gemeinter Rat, sonst nix....
mfG + die blöde Ava + |
||
![]() |
sbrog |
![]() Antworten mit Zitat ![]() |
---|---|---|
Danke für die Hilfe
nene,So blöd bist du auch nicht ![]() |
||
![]() |
WEBLink |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hier hast du mal ein kleines Beispiel wie man so eine abprallphystik machen kann. Als ball image kannst du jedes mögliche Bild nehmen.
Code: [AUSKLAPPEN] Graphics 800,600,0,2
ball = LoadImage("ball.bmp") MaskImage ball ,0,255,0 ymax = 200 SetBuffer BackBuffer() Repeat If x = 0 Then rechts = 1 If x = 794 Then rechts = 2 If ywert>ymax Then hoch = 1 ; Lass springen den ball... If ywert<ymin Then hoch = 0 If rechts = 1 Then x = x + 2 If rechts = 2 Then x = x - 2 If hoch = 0 Then ywert = ywert + 2 If hoch = 1 Then ywert = ywert - 2 DrawImage ball, x, ywert Flip Cls Until KeyHit(1) |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group