Dim Map und Kollision?

Übersicht BlitzBasic Beginners-Corner

Neue Antwort erstellen

Schranz0r

Betreff: Dim Map und Kollision?

BeitragDi, Mai 16, 2006 22:14
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi leute,

Wie bekommt man das hin, das ein Rect mit einer Map Kollidiert ?

Hier mein Code alles ohne Pix wie man sieht Wink

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 Very Happy

Schranz0r

BeitragDi, Mai 16, 2006 23:05
Antworten mit Zitat
Benutzer-Profile anzeigen
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 Very Happy
Naja wenn ich ehrlich bin, hab ich ein wenig rum probiert, bis es gepast hast, evtl kanns ja einer genau erklären ?!?!?

Dreiser

BeitragDi, Mai 16, 2006 23:22
Antworten mit Zitat
Benutzer-Profile anzeigen
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

BeitragDi, Mai 16, 2006 23:48
Antworten mit Zitat
Benutzer-Profile anzeigen
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)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data 1,0,1,1,1,0,0,0,1,1,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,0,1,1,1,0,0,0,1,1,0,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,0,0,0,1,1,1,0,1,1,1,1,1,1,1,1,1
Data 1,0,1,1,0,0,0,1,1,1,0,1,1,1,1,1,1,1,1,1
Data 1,0,1,1,1,1,1,1,1,1,0,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

x-pressive

BeitragDo, Mai 18, 2006 6:46
Antworten mit Zitat
Benutzer-Profile anzeigen
Vergiss DATA und lagere die Mapdaten in eine (oder einzelne) Dateien aus. Vorteile:

Arrow Sorgt für Ordnung in deinem Programm (vor allem, wenn es immer mehr Levels werden).
Arrow Du kannst deinen Spielern jederzeit neue Levels nachreichen, ohne das sie extra das ganze Programm noch mal downloaden müssen.
Arrow Du musst nicht jedesmal das ganze Programm neu kompilieren, wenn du etwas an den Levels änderst.
Arrow Du kannst einen Mapeditor programmieren, der die erstellten Levels abspeichern kann.
Arrow Du musst dich nicht mit Restore und Data rumärgern.
• BLITZ SHOWCASE:
PARTICLE CANDY • PARTICLE CANDY FOR iPHONE • SPRITE CANDY • DON'T GET ANGRY! 2-3 • CLICK CLACK XL

Schranz0r

BeitragDo, Mai 18, 2006 17:05
Antworten mit Zitat
Benutzer-Profile anzeigen
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 Very Happy

Neue Antwort erstellen


Übersicht BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group