Hilfe bei Vereinfachung einer Funktion...

Übersicht BlitzBasic Beginners-Corner

Neue Antwort erstellen

SenSix

Betreff: Hilfe bei Vereinfachung einer Funktion...

BeitragSo, Nov 12, 2006 1:58
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo ^^

Also, ich hab mal wieder, nach einem Jahr Pause, mit Blitz Basic 2D angefangen und mir folgende Funktion zusammen geschraeubselt:

Code: [AUSKLAPPEN]
Function dot_show()

If dot_stat(1,1) = 0 Then dot_1 = gfx_dot_0
If dot_stat(1,1) = 1 Then dot_1 = gfx_dot_1
If dot_stat(1,1) = 2 Then dot_1 = gfx_dot_2
If dot_stat(1,1) = 3 Then dot_1 = gfx_dot_3
If dot_stat(1,1) = 4 Then dot_1 = gfx_dot_4
If dot_stat(1,1) = 5 Then dot_1 = gfx_dot_5
If dot_stat(1,1) = 6 Then dot_1 = gfx_dot_6
DrawBlock dot_1, 28, 28

If dot_stat(2,1) = 0 Then dot_2 = gfx_dot_0
If dot_stat(2,1) = 1 Then dot_2 = gfx_dot_1
If dot_stat(2,1) = 2 Then dot_2 = gfx_dot_2
If dot_stat(2,1) = 3 Then dot_2 = gfx_dot_3
If dot_stat(2,1) = 4 Then dot_2 = gfx_dot_4
If dot_stat(2,1) = 5 Then dot_2 = gfx_dot_5
If dot_stat(2,1) = 6 Then dot_2 = gfx_dot_6
DrawBlock dot_2, 63, 28

If dot_stat(3,1) = 0 Then dot_3 = gfx_dot_0
If dot_stat(3,1) = 1 Then dot_3 = gfx_dot_1
If dot_stat(3,1) = 2 Then dot_3 = gfx_dot_2
If dot_stat(3,1) = 3 Then dot_3 = gfx_dot_3
If dot_stat(3,1) = 4 Then dot_3 = gfx_dot_4
If dot_stat(3,1) = 5 Then dot_3 = gfx_dot_5
If dot_stat(3,1) = 6 Then dot_3 = gfx_dot_6
DrawBlock dot_3, 98, 28

If dot_stat(4,1) = 0 Then dot_4 = gfx_dot_0
If dot_stat(4,1) = 1 Then dot_4 = gfx_dot_1
If dot_stat(4,1) = 2 Then dot_4 = gfx_dot_2
If dot_stat(4,1) = 3 Then dot_4 = gfx_dot_3
If dot_stat(4,1) = 4 Then dot_4 = gfx_dot_4
If dot_stat(4,1) = 5 Then dot_4 = gfx_dot_5
If dot_stat(4,1) = 6 Then dot_4 = gfx_dot_6
DrawBlock dot_4, 133, 28

If dot_stat(5,1) = 0 Then dot_5 = gfx_dot_0
If dot_stat(5,1) = 1 Then dot_5 = gfx_dot_1
If dot_stat(5,1) = 2 Then dot_5 = gfx_dot_2
If dot_stat(5,1) = 3 Then dot_5 = gfx_dot_3
If dot_stat(5,1) = 4 Then dot_5 = gfx_dot_4
If dot_stat(5,1) = 5 Then dot_5 = gfx_dot_5
If dot_stat(5,1) = 6 Then dot_5 = gfx_dot_6
DrawBlock dot_5, 168, 28

If dot_stat(6,1) = 0 Then dot_6 = gfx_dot_0
If dot_stat(6,1) = 1 Then dot_6 = gfx_dot_1
If dot_stat(6,1) = 2 Then dot_6 = gfx_dot_2
If dot_stat(6,1) = 3 Then dot_6 = gfx_dot_3
If dot_stat(6,1) = 4 Then dot_6 = gfx_dot_4
If dot_stat(6,1) = 5 Then dot_6 = gfx_dot_5
If dot_stat(6,1) = 6 Then dot_6 = gfx_dot_6
DrawBlock dot_6, 203, 28

If dot_stat(7,1) = 0 Then dot_7 = gfx_dot_0
If dot_stat(7,1) = 1 Then dot_7 = gfx_dot_1
If dot_stat(7,1) = 2 Then dot_7 = gfx_dot_2
If dot_stat(7,1) = 3 Then dot_7 = gfx_dot_3
If dot_stat(7,1) = 4 Then dot_7 = gfx_dot_4
If dot_stat(7,1) = 5 Then dot_7 = gfx_dot_5
If dot_stat(7,1) = 6 Then dot_7 = gfx_dot_6
DrawBlock dot_7, 238, 28

If dot_stat(8,1) = 0 Then dot_8 = gfx_dot_0
If dot_stat(8,1) = 1 Then dot_8 = gfx_dot_1
If dot_stat(8,1) = 2 Then dot_8 = gfx_dot_2
If dot_stat(8,1) = 3 Then dot_8 = gfx_dot_3
If dot_stat(8,1) = 4 Then dot_8 = gfx_dot_4
If dot_stat(8,1) = 5 Then dot_8 = gfx_dot_5
If dot_stat(8,1) = 6 Then dot_8 = gfx_dot_6
DrawBlock dot_8, 273, 28

If dot_stat(9,1) = 0 Then dot_9 = gfx_dot_0
If dot_stat(9,1) = 1 Then dot_9 = gfx_dot_1
If dot_stat(9,1) = 2 Then dot_9 = gfx_dot_2
If dot_stat(9,1) = 3 Then dot_9 = gfx_dot_3
If dot_stat(9,1) = 4 Then dot_9 = gfx_dot_4
If dot_stat(9,1) = 5 Then dot_9 = gfx_dot_5
If dot_stat(9,1) = 6 Then dot_9 = gfx_dot_6
DrawBlock dot_9, 308, 28

If dot_stat(10,1) = 0 Then dot_10 = gfx_dot_0
If dot_stat(10,1) = 1 Then dot_10 = gfx_dot_1
If dot_stat(10,1) = 2 Then dot_10 = gfx_dot_2
If dot_stat(10,1) = 3 Then dot_10 = gfx_dot_3
If dot_stat(10,1) = 4 Then dot_10 = gfx_dot_4
If dot_stat(10,1) = 5 Then dot_10 = gfx_dot_5
If dot_stat(10,1) = 6 Then dot_10 = gfx_dot_6
DrawBlock dot_10, 343, 28

If dot_stat(1,2) = 0 Then dot_11 = gfx_dot_0
If dot_stat(1,2) = 1 Then dot_11 = gfx_dot_1
If dot_stat(1,2) = 2 Then dot_11 = gfx_dot_2
If dot_stat(1,2) = 3 Then dot_11 = gfx_dot_3
If dot_stat(1,2) = 4 Then dot_11 = gfx_dot_4
If dot_stat(1,2) = 5 Then dot_11 = gfx_dot_5
If dot_stat(1,2) = 6 Then dot_11 = gfx_dot_6
DrawBlock dot_11, 28, 63

; ....ETC ETC....

End Function


Zur Info: dot_stat(10,10). Ich habe hundert Felder und 7 "Moeglichkeiten"
pro Feld (0, 1, 2, 3, 4, 5, 6) Je nach Status soll ein anderes Bild angzeigt werden.

Wie man sieht, koennte man das auch mit einer For Next Schleife einfacher loesen, aber ich habs bereits versucht (mit einem 2. Array das die Variablen "dot_X" ersetzt... Ging aber irgendwie nicht, weil ich diesen Variablen keine Bilder uebergeben kann (per dot_11 = gfx_dot_1).

Hat da jemand ne Idee, wie ich das auf ne lustigere Art und Weise loesen koennte?

Vielen Dank im Voraus.
 

Dreamora

BeitragSo, Nov 12, 2006 2:38
Antworten mit Zitat
Benutzer-Profile anzeigen
ja mit einem dot Array für die bilder, der ebenfalls 2 dimensional ist oder indem du in den Array den du schon nutzt direkt die Bilder speicherst, abhängig von einer Variable beim einlesen.
Ihr findet die aktuellen Projekte unter Gayasoft und könnt mich unter @gayasoft auf Twitter erreichen.

SenSix

BeitragSo, Nov 12, 2006 3:51
Antworten mit Zitat
Benutzer-Profile anzeigen
Erstmal danke fuer deine Antwort.

Ich hab's mal so versucht:

Code: [AUSKLAPPEN]
Function dot_show()

dot_show_file = 0
dot_x = 0
dot_y = 1

For dot_show_file = 1 To 100 Step 1

dot_x = dot_x + 1

If dot_x = 10 Then
   dot_x = 1
   dot_y = dot_y + 1
EndIf

If dot_stat(dot_x,dot_y) = 0 Then dot_gfx(dot_x,dot_y) = gfx_dot_0
If dot_stat(dot_x,dot_y) = 1 Then dot_gfx(dot_x,dot_y) = gfx_dot_1
If dot_stat(dot_x,dot_y) = 2 Then dot_gfx(dot_x,dot_y) = gfx_dot_2
If dot_stat(dot_x,dot_y) = 3 Then dot_gfx(dot_x,dot_y) = gfx_dot_3
If dot_stat(dot_x,dot_y) = 4 Then dot_gfx(dot_x,dot_y) = gfx_dot_4
If dot_stat(dot_x,dot_y) = 5 Then dot_gfx(dot_x,dot_y) = gfx_dot_5
If dot_stat(dot_x,dot_y) = 6 Then dot_gfx(dot_x,dot_y) = gfx_dot_6

Next


End Function


Aber dann bekomm ich folgende Meldung:

"Array index out of bounds"

Damit kann ich leider nix anfangen.

Abrexxes

BeitragSo, Nov 12, 2006 4:55
Antworten mit Zitat
Benutzer-Profile anzeigen
Code: [AUSKLAPPEN]

For counterx = 1 to 10
stax:+1
     For countery = 1 to 10
      stay:+1     
            For counter = 1 to 6
            If dot_stat(stax,stay) = value Then draw(actueldot)
            actueldot:+1
            value:+1
            next
     next
next

Function draw()
     Select actualdot
     Case 0 draw dies und  das auf Postion x,y
     Case 1 draw blub und bla auf x,y
     else fehler
     x:+28
     y:+28
EndFunktion


Das funzt jetzt so nicht, aber sollte das sein was du willst. (Ist mir grad zu früh das auszubasteln). Ich muss jetzt boxen gucken. Wink

cu

Rone

BeitragSo, Nov 12, 2006 15:33
Antworten mit Zitat
Benutzer-Profile anzeigen
Code: [AUSKLAPPEN]
Dim dot_stat(11,11)
Dim gfx_dot(7)


Function dot_show()
   For iy = 1 To 10
      For ix = 1 To 10
         If dot_stat(ix,iy)>=0 And dot_stat(ix,iy)<7 Then
            DrawImage gfx_dot( dot_stat(ix,iy) ),28+35*(ix-1),28+35*(iy-1)
         EndIf
      Next
   Next
End Function


...müsste eigendlich funktionieren.

mfg
Rone

SenSix

BeitragSo, Nov 12, 2006 16:34
Antworten mit Zitat
Benutzer-Profile anzeigen
Habs so aehnlich hinbekommen, danke sehr (:

Neue Antwort erstellen


Übersicht BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group