Problem mit Type Dim Feldern
Übersicht

zimtstern#3Betreff: Problem mit Type Dim Feldern |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Ich schreib gerade einen Bomberman Clone für 4 Spieler. Mein Problem ist folgendes:
Code: [AUSKLAPPEN] For i = 1 to 4 If KeyHit (KeyACTION(i)) = True Then ; wenn feuer gedrückt If playerBombCount(i) > 0 Then ;wenn mögl. bomben > 0 playerBombs(i) = New bomb playerBombs(i)\timer = MilliSecs () ... playerBombCount(i) = playerBombCount(i) - 1 ; möglicheBomben = möglicheBomben - 1 DebugLog playerBombCount(i) +" "+ i;DEBUG EndIf EndIf Next bis hier klappt alles ganz gut aber: Code: [AUSKLAPPEN] For i = 1 To 4 For playerBombs(i) = Each bomb If playerBombs(i)\timer <= MilliSecs() - BombDelay Then playerBombCount(i) = playerBombCount(i) + 1 ; wenn bombe eplodiert dann anz der mögl. bomben +1 ... Delete playerBombs.bomb(i) DebugLog playerBombCount(i) + " " + i ;DEBUG EndIf Next Next So wenn ich jetzt auf die Feuertaste von Spieler2 drücke wird die anzahl der mögl Bomben von Spieler2 um eins verringert. Ist der Timer der Bombe abgelaufen wird aber die anzahl der mögl Bomben von Spieler1 um eins erhöht. was hab ich falsch gemacht ? |
||
![]() |
Jolinah |
![]() Antworten mit Zitat ![]() |
---|---|---|
Die For Each Schleife geht immer alle Bomben durch, egal welcher Player.
Das Problem lässt sich wahrscheinlich beheben wenn du noch ein Feld machst wo drin steht für welchen Player die Bombe ist. Code: [AUSKLAPPEN] Type bomb Field timer Field player End Type zum erstellen: Code: [AUSKLAPPEN] For i = 1 to 4 If KeyHit (KeyACTION(i)) = True Then ; wenn feuer gedrückt If playerBombCount(i) > 0 Then ;wenn mögl. bomben > 0 playerBombs(i) = New bomb playerBombs(i)\timer = MilliSecs () playerBombs(i)\player = i ;<<<<------- ... playerBombCount(i) = playerBombCount(i) - 1 ; möglicheBomben = möglicheBomben - 1 DebugLog playerBombCount(i) +" "+ i;DEBUG EndIf EndIf Next und dann abfragen für welchen player: Code: [AUSKLAPPEN] For i = 1 To 4 For playerBombs(i) = Each bomb If playerBombs(i)\player = i ;<--- Wenn die Bombe zum Player gehört If playerBombs(i)\timer <= MilliSecs() - BombDelay Then playerBombCount(i) = playerBombCount(i) + 1 ; wenn bombe eplodiert dann anz der mögl. bomben +1 ... Delete playerBombs.bomb(i) DebugLog playerBombCount(i) + " " + i ;DEBUG EndIf Endif Next Next |
||
zimtstern#3 |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Danke!
Lohnt es sich dann überhaupt den so ein Dimtype als Feld erstellen? |
||
![]() |
Jolinah |
![]() Antworten mit Zitat ![]() |
---|---|---|
Eigentlich nicht.
playerBombs(i) ist nur ein Platzhalter für die aktuelle Bombe. Die Types sind ja auch im Speicher wenn keine Variable darauf verlinkt ist. Code: [AUSKLAPPEN] For i = 1 to 4 If KeyHit(KeyACTION(i)) = True Then If playerBombCount(i) > 0 Then b.bomb = new bomb b\timer = MilliSecs() b\player = i .... .... Endif Endif Next und unten das selbe. Code: [AUSKLAPPEN] For i = 1 to 4 For b.bomb = each bomb if b\player = i if b\timer <= Millisecs() - BombDelay then ..... ..... ..... Endif Endif Next Next |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group