verschieden instanzen eines type abfragen
Übersicht

tutschBetreff: verschieden instanzen eines type abfragen |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
hallo,
ich baue grade ein sokoban das meine tochter darstellt die ihr zimmer aufreumt. nu bin ich auf ein problem gestossen. es liegen statt kisten in dem labyrinth spielzeuge. diese spielzeuge mochte ich nun nicht alle einzelnd auf cordinaten abfragen sondern wenn ich an ein feld komme wo eines liegt sollte dieses wenn keine mauer im weg ist verschoben werden koennen. da ich nicht weiss ob ich ueberhaupt auf dem richtigen weg bin, und ich mir viele sachen von ueberall zusammen geklaut habe poste ich meinen code einfach mal. Code: [AUSKLAPPEN] Strict Local screen_w = 640 Local screen_h = 480 Graphics(screen_w,screen_h,16,60) 'Hintergrundbild Laden Local room_back:TImage = LoadImage("olivias_room.jpg") Local player_ou:TImage = LoadImage("ou.png") Local player_od:TImage = LoadImage("od.png") Local player_ol:TImage = LoadImage("ol.png") Local player_or:TImage = LoadImage("or.png") Global y Global x Global move = 1 Global schieben = 1 'Player initalisieren Local player:TImage = player_ou Local px = 14 Local py = 12 'Spielzeug init Type TSpielzeug Field sx, sy Global bild:TImage = LoadImage("auto.png") EndType 'Local test:String[]=["a","b","c","d","e","f"] 'Local test:TSpielzeug=New TSpielzeug Local a:TSpielzeug=New TSpielzeug a.sx = 10 a.sy = 11 Local tileset:TImage = LoadAnimImage("TileSet.png",25,25,0,4) Global map[30+1,30+1] 'Level1 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,1,1,1,1,1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,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 'Level einlesen For y = 0 To 30 For x = 0 To 30 ReadData map[x,y] Next Next 'Spielschleife While KeyHit(KEY_ESCAPE)=0 Cls DrawImage room_back, 0, 0 'Level auslesen For y = 0 To 30 For x = 0 To 30 DrawImage tileset,x*25,y*25,map[x,y] Next Next 'PLayer bewegen If KeyHit(KEY_LEFT) Then player = player_ol If map[px-1,py] > 1 Then If px-1 = a.sx And py = a.sy And map[px-2, py] > 1 Then a.sx = a.sx - 1 px = px - 1 move = 1 ElseIf px-1 = a.sx And py = a.sy And map[px-2, py] < 2 Then px = px move = 1 Else px = px -1 move = 1 EndIf End If EndIf If KeyHit(KEY_RIGHT) Then player = player_or If map[px+1,py] > 1 Then If px+1 = a.sx And py = a.sy And map[px+2, py] > 1 Then a.sx = a.sx + 1 px = px + 1 move = 1 ElseIf px+1 = a.sx And py = a.sy And map[px+2, py] < 2 Then px = px move = 1 Else px = px + 1 move = 1 EndIf End If EndIf If KeyHit(KEY_UP) Then player = player_ou If map[px,py-1] > 1 Then If px = a.sx And py-1 = a.sy And map[px, py-2] > 1 Then a.sy = a.sy - 1 py = py - 1 move = 1 ElseIf px = a.sx And py-1 = a.sy And map[px, py-2] < 2 Then py = py move = 1 Else py = py - 1 move = 1 EndIf End If EndIf If KeyHit(KEY_DOWN) Then player = player_od If map[px,py+1] > 1 Then If px = a.sx And py+1 = a.sy And map[px, py+2] > 1 Then a.sy = a.sy + 1 py = py + 1 move = 1 ElseIf px = a.sx And py+1 = a.sy And map[px, py+2] < 2 Then py = py move = 1 Else py = py + 1 move = 1 EndIf End If EndIf If move = 1 Then x = px * 25; y = py * 25;DrawImage player, x, y If schieben = 1 Then x = a.sx * 25; y = a.sy * 25;DrawImage a.bild, x, y 'Flip Screen Flip Wend 'Aufräumen Function CleanUp() GCCollect() End Function |
||
- Zuletzt bearbeitet von tutsch am Di, Jun 10, 2008 0:58, insgesamt 5-mal bearbeitet
tutschBetreff: projekt link |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
http://www.antibothis.com/test/olivia_tidies.tgz
und screenshot... ![]() |
||
tutschBetreff: variablename in variable speichern |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
ich wollte das ganze nun so anfangen, dass ich das a von "Local a:TSpielzeug=New TSpielzeug" durch ein array ersetze.
also: Local arr:String=["a", "b", "n"] und ich dachte ich koennte dann einfach so For nr = 1 to 3 Local arr[nr]:TSpielzeug=New TSpielzeug next den typ deklarieren und spaeter auch wieder so auf ihn zugreifen. FUNKTIONIERT ABER NICHT traurig koenntet ihr mich auf einen anderen weg setzen? danke tutsch |
||
![]() |
hamZtaAdministrator |
![]() Antworten mit Zitat ![]() |
---|---|---|
Doppelposts sind hier verboten, Tripleposts erst recht. Bitte merk dir das für die Zukunft, ansonsten müssen wir dich verwarnen.
hamZta edit: Es heißt natürlich "Triple", nicht "Dripple". Danke, shure_kyu ![]() |
||
Blog. |
- Zuletzt bearbeitet von hamZta am Fr, Jun 06, 2008 2:52, insgesamt einmal bearbeitet
tutschBetreff: ich bitte um entschuldigung |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
es ist das erste mal, dass ich in einem forum poste.
mir fiel jedes mal wieder auf, dass ich was vergessen habe . bitte noch mals um entschuldigung. tutsch ps: jetzt habe ich auch den EDIT button gefunden. |
||
AvaGast |
![]() Antworten mit Zitat |
|
---|---|---|
Hallo tutsch,
vorweg mag ich Dir erstmal Deinen Versuch korrigieren: Code: [AUSKLAPPEN] Global spielzeug_array:TSPielzeug[]
' neues hinzufügen local index:int = spielzeug_array.length spielzeug_array = new TSpielzeug[..index + 1] spielzeug_array[index]:TSpielzeug=New TSpielzeug ' zugriff (möglichkeit 1) for local index:int = 0 to spielzeug_array.length - 1 ' mach-was-mit-spielzeug_array[index] ^^ next ' zugriff (möglichkeit 2) for local spielzeug:TSpielzeug = eachin spielzeug_array ' mach-was-mit-spielzeug ^^ next eine etwas unkompliziertere Alternative wäre: Code: [AUSKLAPPEN] Global spielzeug_liste:TList = createList()
'neues hinzufügen ListAddLast(spielzeug_liste, new TSpielzeug) 'zugriff for local spielzeug:TSpielzeug = eachin spielzeug_liste 'mach-was-mit-spielzeug ^^ next Ich hoffe, ich habe Dein Problem richtig verstanden und Dir etwas helfen können. ^^ Gruss, Ava |
||
tutschBetreff: Problem geloest |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Vielen Dank fuer deine Hilfe.
Ich habe gestern Nacht das Problem noch auf deine Weise geloest. (weniger elegant als du aber auch mit List) Doch ich bin dann gleich auf das naechste Problem gestossen. Also habe ich alles noch mal umgekraempelt un nach einem anderen Weg gesucht. Den ich dann auch gefunden habe. Ich habe nun alles in die Haende der Karte (DefData) gelegt. Funktioniert auch super. Nun habe ich das Problem, dass ich gerne die Level (DefData) in eine externe Datei auslagern moechte. Include ist denke ich der falsche Ansatz da die Daten dann mit kompiliert werden. Ich werde aber schon einen Weg finden. Fuer meinen dritten Tag Blitzmax bin ich denke ich schon weit gekommen. (klopf auf die Schulter) Ich habe ja noch 27 Tage Demo gut. tutsch Code: [AUSKLAPPEN] Strict Local screen_w = 640 Local screen_h = 480 Graphics(screen_w,screen_h,16,60) 'Hintergrundbild Laden Local room_back:TImage = LoadImage("images\olivias_room.jpg") Local player_ou:TImage = LoadImage("images\ou.png") Local player_od:TImage = LoadImage("images\od.png") Local player_ol:TImage = LoadImage("images\ol.png") Local player_or:TImage = LoadImage("images\or.png") Local walk:TSound = LoadSound("sound\walk.wav") Local push:TSound = LoadSound("sound\push.wav") Local tileset:TImage = LoadAnimImage("images\TileSet.png",25,25,0,5) Global y Global x Global move = 1 'Level INITALISIEREN 'Player initalisieren Local gewonnen = 0 Local player:TImage = player_ou Global map[30+1,30+1] '#### AUSZULAGERNDER TEIL ########################################## 'Legende: ' 0 = empty ' 1 = wall ' 2 = floor ' 3 = target 'Level 'Level1 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,1,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 DefData 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Local px = 14 Local py = 12 '#### ENDE AUSZULAGERNDER TEIL ###################################### 'Level einlesen For y = 0 To 30 For x = 0 To 30 ReadData map[x,y] Next Next 'target_backup Global backup[30+1,30+1] For y = 0 To 30 For x = 0 To 30 backup[x,y] = map[x,y] Next Next 'Spielschleife While KeyHit(KEY_ESCAPE)=0 Cls DrawImage room_back, 0, 0 'Level auslesen For y = 0 To 30 For x = 0 To 30 DrawImage tileset,x*25,y*25,map[x,y] Next Next 'PLayer bewegen If KeyHit(KEY_LEFT) Then player = player_ol If map[px-1,py] > 1 Then If map[px-1, py] = 4 And map[px-2, py] > 1 And map[px-2, py] < 4 Then If backup[px-1, py] = 3 Then map[px-1, py] = backup[px-1, py] Else map[px-1, py] = 2 EndIf PlaySound push map[px-2, py] = 4 px = px -1 move = 1 ElseIf map[px-1, py] < 4 PlaySound walk px = px -1 move = 1 EndIf End If EndIf If KeyHit(KEY_RIGHT) Then player = player_or If map[px+1,py] > 1 Then If map[px+1, py] = 4 And map[px+2, py] > 1 And map[px+2, py] < 4 Then If backup[px+1, py] = 3 Then map[px+1, py] = backup[px+1, py] Else map[px+1, py] = 2 EndIf PlaySound push map[px+2, py] = 4 px = px +1 move = 1 ElseIf map[px+1, py] < 4 PlaySound walk px = px +1 move = 1 EndIf End If EndIf If KeyHit(KEY_UP) Then player = player_ou If map[px,py-1] > 1 Then If map[px,py-1] > 1 Then If map[px, py-1] = 4 And map[px, py-2] > 1 And map[px, py-2] < 4 Then If backup[px, py-1] = 3 Then map[px, py-1] = backup[px, py-1] Else map[px, py-1] = 2 EndIf PlaySound push map[px, py-2] = 4 py = py -1 move = 1 ElseIf map[px, py-1] < 4 PlaySound walk py = py -1 move = 1 EndIf EndIf End If EndIf If KeyHit(KEY_DOWN) Then player = player_od If map[px,py+1] > 1 Then If map[px,py+1] > 1 Then If map[px, py+1] = 4 And map[px, py+2] > 1 And map[px, py+2] < 4 Then If backup[px, py+1] = 3 Then map[px, py+1] = backup[px, py+1] Else map[px, py+1] = 2 EndIf PlaySound push map[px, py+2] = 4 py = py +1 move = 1 ElseIf map[px, py+1] < 4 PlaySound walk py = py +1 move = 1 EndIf EndIf End If EndIf If move = 1 Then x = px * 25; y = py * 25;DrawImage player, x, y gewonnen = 1 'Ziel abfragen For y = 0 To 30 For x = 0 To 30 If map[x,y] = 3 Then gewonnen = 0 EndIf Next Next If gewonnen = 1 Then DrawText "Gewonnen!",50,50 EndIf 'Flip Screen Flip Wend 'Aufräumen Function CleanUp() GCCollect() End Function |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group