Dim Map und Kollision?
Übersicht

![]() |
Schranz0rBetreff: Dim Map und Kollision? |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi leute,
Wie bekommt man das hin, das ein Rect mit einer Map Kollidiert ? Hier mein Code alles ohne Pix wie man sieht ![]() Code: [AUSKLAPPEN] AppTitle "Sokoban" Graphics 400, 600, 0, 0 SetBuffer BackBuffer() Global P_1 = 20 Global P_X = 20 Global P_Y = 20 frametimer = CreateTimer (30) Const Weg = 20, rauf = 200, runter = 208, links = 203, rechts = 205 Dim map (20,15) Restore mapdata For y=0 To 14 For x=0 To 19 Read map(x,y) Next Next Function DrawMap() For y = 0 To 14 For x = 0 To 19 If map(x,y) = 1 Then Color 255, 0, 0 Rect x*20, y*20, 20, 20 EndIf Next Next End Function Function Player() Color 0, 255, 0 Rect P_X, P_Y, P_1, P_1 End Function While Not KeyHit(1) Cls WaitTimer (frametimer) DrawMap() If KeyHit(rauf) Then P_Y = P_Y - Weg If KeyHit(runter) Then P_Y = P_Y + Weg If KeyHit(links) Then P_X = P_X - Weg If KeyHit(rechts) Then P_X = P_X + Weg Player() Flip Wend End .mapdata Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 Schon mal danke für die hilfe ![]() |
||
![]() |
Schranz0r |
![]() Antworten mit Zitat ![]() |
---|---|---|
So habs selber geschaft, wenn es interessiert:
Code: [AUSKLAPPEN] While Not KeyHit(1) Cls WaitTimer (frametimer) Anzeigen() DrawMap() If KeyHit(rauf) Then If map(P_X /20, (P_Y -20) /20) = 0 Then P_Y = P_Y - Weg EndIf EndIf If KeyHit(runter) Then If map(P_X /20, (P_Y +20) /20) = 0 Then P_Y = P_Y + Weg EndIf EndIf If KeyHit(links) Then If map((P_X -20) /20, P_Y /20) = 0 Then P_X = P_X - Weg EndIf EndIf If KeyHit(rechts) Then If map((P_X +20) /20, P_Y /20) = 0 Then P_X = P_X + Weg EndIf EndIf Player() Flip Wend Für meinen Fall jetzt, man kann es ja vielleicht nachvollziehen ![]() Naja wenn ich ehrlich bin, hab ich ein wenig rum probiert, bis es gepast hast, evtl kanns ja einer genau erklären ?!?!? |
||
![]() |
Dreiser |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi Schranz0r,
Die If-Befehle in der Hauptschleife gehen auch einfacher. Code: [AUSKLAPPEN] While Not KeyHit(1) Cls WaitTimer (frametimer) DrawMap() If KeyHit(rauf) And map( P_X/20 , P_Y/20 -1 )= 0 Then P_Y = P_Y - Weg If KeyHit(runter) And map( P_X/20 , P_Y/20 +1 ) = 0 Then P_Y = P_Y + Weg If KeyHit(links) And map( P_X/20 -1 , P_Y/20 ) = 0 Then P_X = P_X - Weg If KeyHit(rechts) And map( P_X/20 +1 , P_Y/20 ) = 0 Then P_X = P_X + Weg Player() Flip Wend Ausserdem habe ich noch folgendes geändert: Code: [AUSKLAPPEN] Graphics 400, 300, 0, 2 Gruss Dreiser |
||
![]() |
Schranz0r |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi Dreiser
Ja danke, schaut natürlich schöner aus ^^ Noch folgendes Problem hab ich, wenn ich einen 2 level laden will, wie geht das ohne jedes mal wieder eine Dim map und Function zu schreiben , bzw. geht das überhaupt ohne nochmal zu schreiben? Also da die .Lev2 Code: [AUSKLAPPEN] AppTitle "Sokoban 1.0 BETA ..::By Schranz0r::.." Graphics 400, 320, 0, 0 SetBuffer BackBuffer() Global P_1 = 20 Global P_X = 20 Global P_Y = 40 Global Punkte frametimer = CreateTimer (20) Const Weg = 20, rauf = 200, runter = 208, links = 203, rechts = 205 Dim map (20,15) Restore Lev1 For y=0 To 14 For x=0 To 19 Read map(x,y) Next Next Function DrawMap() For y = 0 To 14 For x = 0 To 19 If map(x,y) = 1 Then Color 255, 0, 0 Rect x*20, y*20, 20, 20 EndIf Next Next End Function Function Player() Color 100, 100, 255 Rect P_X, P_Y, P_1, P_1 End Function Function Anzeigen() Locate 0, 300 Print "Punkte: " + Punkte Locate 100, 300 Print "Level: " + Level End Function While Not KeyHit(1) Cls WaitTimer (frametimer) Anzeigen() DrawMap() If KeyHit(rauf) And map( P_X/20 , P_Y/20 -1 )= 0 Then P_Y = P_Y - Weg If KeyHit(runter) And map( P_X/20 , P_Y/20 +1 ) = 0 Then P_Y = P_Y + Weg If KeyHit(links) And map( P_X/20 -1 , P_Y/20 ) = 0 Then P_X = P_X - Weg If KeyHit(rechts) And map( P_X/20 +1 , P_Y/20 ) = 0 Then P_X = P_X + Weg Player() Flip Wend End .Lev1 Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 Data 1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1 Data 1,0,1,1,1,0,0,0,1,1,0,1,1,1,1,1,1,1,1,1 Data 1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1,1,1,1,1 Data 1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1 Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 |
||
![]() |
x-pressive |
![]() Antworten mit Zitat ![]() |
---|---|---|
Vergiss DATA und lagere die Mapdaten in eine (oder einzelne) Dateien aus. Vorteile:
![]() ![]() ![]() ![]() ![]() |
||
• BLITZ SHOWCASE:
PARTICLE CANDY • PARTICLE CANDY FOR iPHONE • SPRITE CANDY • DON'T GET ANGRY! 2-3 • CLICK CLACK XL |
![]() |
Schranz0r |
![]() Antworten mit Zitat ![]() |
---|---|---|
hmmm guter Einwand
Soll aber ein kleiner versuch sein das Spiel^^ Also nur für mich sein, ausarbeiten will ich das dann später evtl ![]() |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group