Freilaufen auf Tiles inkl. Kollisionen :/

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

klin

Betreff: Freilaufen auf Tiles inkl. Kollisionen :/

BeitragMo, Apr 07, 2008 18:12
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo Leute,
ich habe ein Problem, das mich fast schon ein ganzes Jahr verfolgt >.<
Undzwar, will ich ein 2D Game machen, wo man frei rumlaufen kann, doch natürlich mit Mauern (Kollisionen). Von tile zu tile, war kein Problem, doch nun von pixel zu pixel (also freirumlaufen) ist schon ein Problem.

Das war zumindest das letzte was ich gemacht hatt Rolling Eyes

Code: [AUSKLAPPEN]

'Collisions-zwischen-Test

Graphics 640,480

Global map[24,25]
Global spawnpointx:Float[24]
Global spawnpointy:Float[25]

'tilemapdaten 23x24
#map
DefData 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
DefData 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1
DefData 1,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1
DefData 1,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1
DefData 1,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1
DefData 1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1
DefData 1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,1
DefData 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
DefData 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

'Tiles lesen
RestoreData map
For Local j=0 To 23
   For Local i=0 To 22
      ReadData map[i,j]
   Next
Next

For j=0 To 24
   For i=0 To 23
      If map[i,j]=1 Then
      SetColor 255,0,0
      DrawRect 20*i,20*j,20,20
      SetColor 255,255,255
     ElseIf map[i,j]=2 Then
       SetColor 0,0,255
      spawnpointx[1]=i
      spawnpointy[1]=j
       DrawRect 20*i,20*j,20,20
       SetColor 255,255,255
   EndIf
   Next
Next


While Not AppTerminate()
For j=0 To 24
   For i=0 To 23
      If map[i,j]=1 Then
      SetColor 255,0,0
      DrawRect 20*i,20*j,20,20
      SetColor 255,255,255
   Rem
     ElseIf map[i,j]=2 Then
       SetColor 0,0,255
      spawnpointx[1]=i
      spawnpointy[1]=j
       DrawRect 20*i,20*j,20,20
       SetColor 255,255,255
   EndRem
   EndIf
   Next
Next

If KeyDown(KEY_UP) Then
If map[spawnpointx[1],spawnpointy[1]]<>1 Then
spawnpointy[1]=spawnpointy[1]-0.1
EndIf
EndIf
If KeyDown(KEY_DOWN) Then
If map[spawnpointx[1],spawnpointy[1]+1]<>1 Then
spawnpointy[1]=spawnpointy[1]+0.1
EndIf
EndIf
If KeyDown(KEY_RIGHT) Then
If map[spawnpointx[1]+1,spawnpointy[1]]<>1 Then
spawnpointx[1]=spawnpointx[1]+0.1
EndIf
EndIf
If KeyDown(KEY_LEFT) Then
If map[spawnpointx[1],spawnpointy[1]+1]<>1 Then
spawnpointx[1]=spawnpointx[1]-0.1
EndIf
EndIf

DrawOval 20*spawnpointx[1],20*spawnpointy[1],20,20
DrawText Int(spawnpointx[1])+" | "+Int(spawnpointy[1]),0,0


Flip
Cls
Wend
End


so weit bin ich gekommen... danach verlor ich die Lust und regte mich nurnoch auf, weil die blöden kollisionen nicht funktionieren Evil or Very Mad !
Also seit ihr meine letzte hoffnung!
Ich wäre euch sehr dankbar!

THX
MFG
Klin

Markus2

BeitragDi, Apr 08, 2008 12:11
Antworten mit Zitat
Benutzer-Profile anzeigen
Guck dir mal an:

ImagesCollide
ImagesCollide2
ResetCollisions
CollideImage
CollideRect

ein Beispiel findest du auch dabei
 

battlegorge

BeitragDi, Apr 08, 2008 13:35
Antworten mit Zitat
Benutzer-Profile anzeigen
Sowas hatte ich letztes Jahr mal ins Codearchiv gestellt:
https://www.blitzforum.de/foru...hp?t=25173
Ist aber nicht ganz ausgereift.
Man muss eigentlich nur die 9 Tiles um den Spieler auf Kollisionen überprüfen.
Wenn über dem Spieler eine Kollision ist bewegt er sich nicht hoch usw.

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group