tilemap bearbeiten - problem

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

 

getlose

Betreff: tilemap bearbeiten - problem

BeitragSa, Dez 11, 2004 15:13
Antworten mit Zitat
Benutzer-Profile anzeigen
grüße,

user posted image

Das Bild erklärt ganz gut was gemeint ist und wo
der Fehler ist. Die benachbarten Tiles werden
mit-bearbeitet, und somit werden die Übergange (land->wasser)
automatisch erstellt. Hab jetzt schon locker 3 Stunden
gesucht. Neutral finde den Fehler aber nicht...

BlitzBasic: [AUSKLAPPEN]

Graphics 320,240,16,2

tiles=LoadAnimImage (\"t1.png\",8,8,0,100)

Dim b_map(50,50,7)
Dim g_map(50,50)

For x=0 To 50
For y=0 To 50
For a=0 To 7
b_map(x,y,a)=0
Next
g_map(x,y)=1
Next
Next

Global mw=50,mh=50,mx,my,omx,omy

Type tile_codes
Field frame
Field code$
End Type

g_tc()


SetBuffer BackBuffer()
While Not KeyHit(1)
Cls

mx=MouseX()
my=MouseY()

d_gmap(tiles)
If MouseDown(1) Then e_bmap(1)
If MouseDown(2) Then s_gmap()
debug()

If KeyHit(203) Then u_gmap(x,y,1)

omx=mx
omy=my

Flip
Wend



Function g_tc()

file=ReadFile (\"tile_codes.dat\")
While Not Eof(file)=1
t.tile_codes=New tile_codes
t\frame=a
t\code$=ReadLine (file)
a=a+1
Wend
CloseFile file

End Function



Function d_gmap(tiles)

For x=mpx To mpx+40
For y=mpx To mpx+30
DrawImage tiles,(x-mpx)*8,(y-mpy)*8,g_map(x,y)
Next
Next

End Function



Function e_bmap(tile)

For x=0 To 40
For y=0 To 30
If RectsOverlap (mx,my,1,1,x*8,y*8,8,8) Then

For a=0 To 7
b_map(x+mpx,y+mpy,a)=tile
Next

b_map(x+mpx,y+mpy-1,3)=tile
b_map(x+mpx,y+mpy-1,4)=tile
b_map(x+mpx,y+mpy-1,5)=tile
b_map(x+mpx+1,y+mpy-1,5)=tile

b_map(x+mpx+1,y+mpy,5)=tile
b_map(x+mpx+1,y+mpy,6)=tile
b_map(x+mpx+1,y+mpy,7)=tile
b_map(x+mpx+1,y+mpy+1,7)=tile

b_map(x+mpx,y+mpy+1,7)=tile
b_map(x+mpx,y+mpy+1,0)=tile
b_map(x+mpx,y+mpy+1,1)=tile
b_map(x+mpx-1,y+mpy+1,1)=tile

b_map(x+mpx-1,y+mpy,1)=tile
b_map(x+mpx-1,y+mpy,2)=tile
b_map(x+mpx-1,y+mpy,3)=tile
b_map(x+mpx-1,y+mpy-1,3)=tile

u_gmap(x,y,0)

EndIf
Next
Next

End Function



Function u_gmap(x,y,c)

If c=0 Then

For xx=x-2 To x+2
For yy=y-2 To y+2
For a=0 To 7
tmp$=tmp$+Str(b_map(xx,yy,a))
Next
For t.tile_codes=Each tile_codes
If t\code$=tmp$ Then
g_map(xx,yy)=t\frame
EndIf
Next
tmp$=\"\"
Next
Next

Else

For xx=0 To mw
For yy=0 To mh
For a=0 To 7
tmp$=tmp$+Str(b_map(xx,yy,a))
Next
For t.tile_codes=Each tile_codes
If t\code$=tmp$ Then
g_map(xx,yy)=t\frame
EndIf
Next
tmp$=\"\"
Next
Next

EndIf

End Function



Function s_gmap()

mpx=mpx-(mx-omx)
mpy=mpy-(my-omy)

If mpx<0 Then mpx=0
If mpy<0 Then mpy=0
If mpx>mw-40 Then mpx=mw-40
If mpy>mh-30 Then mpy=mh-30

End Function

Function debug()
For x=0 To 40
For y=0 To 30
If RectsOverlap (mx,my,1,1,x*8,y*8,8,8) Then
Color 0,0,0
For a=0 To 7
Text mx+30,my,b_map(x,y,0)
Text mx+40,my,b_map(x,y,1)
Text mx+40,my+10,b_map(x,y,2)
Text mx+40,my+20,b_map(x,y,3)
Text mx+30,my+20,b_map(x,y,4)
Text mx+20,my+20,b_map(x,y,5)
Text mx+20,my+10,b_map(x,y,6)
Text mx+20,my,b_map(x,y,7)

Rect x*8,y*8,8,8,0
Next
EndIf
Next
Next
End Function


und die Datei tile_codes.dat :
Code: [AUSKLAPPEN]

11111111
00000000
11000001
00011100
01110000
00000111
00000001
01000000
00000100
00100000
00011111
01111100
11000111
11110001
11100000
11011101
11110111
01111111
11111101
11011111
01000111
00010000
01110001
01110100
11000101
11010001
00011101
01011100
01010111
01110101
11010101
01011101
00010001
01000100
00000101
01010000
01000001
00010100
01010101


und das Tileset (Reihenfolge wichtig) :
user posted image

hilfe ! Smile
 

Klaas

BeitragSa, Dez 11, 2004 18:28
Antworten mit Zitat
Benutzer-Profile anzeigen
pjuuh .. habs mir grad angeschaut. Du hast leider keinen einziegen Kommentar im Code! zudem sind die variabeln und funktionsnamen nicht sehr aussagekräftig.
Erklär doch bitte mal was du so ca. machst, dann würde man dir evtl. besser / schneller helfen können
 

konstantin

BeitragSa, Dez 11, 2004 19:58
Antworten mit Zitat
Benutzer-Profile anzeigen
Klaas hat Folgendes geschrieben:
zudem sind die variabeln und funktionsnamen nicht sehr aussagekräftig.


sorry für ot - aber welche variablen und funktionsnamen erkennst du nicht oO?
 

Dreamora

BeitragSa, Dez 11, 2004 20:58
Antworten mit Zitat
Benutzer-Profile anzeigen
sorry die funktionen etc haben wirklich keine akzeptable Namensgebung.

Du hast 256 Zeichen zur verfügung, da sind kryptische 5 Zeichen bezeichnungen definitiv net gebraucht ( und unkommentiert dann schon erst recht nicht )
Ihr findet die aktuellen Projekte unter Gayasoft und könnt mich unter @gayasoft auf Twitter erreichen.
 

getlose

BeitragSo, Dez 12, 2004 1:48
Antworten mit Zitat
Benutzer-Profile anzeigen
hm, ja, stimmt schon :)
hier noch mal, etwas auskommentiert,
funtions-namen ausgeschrieben usw.

BlitzBasic: [AUSKLAPPEN]
Graphics 320,240,16,3

tiles=LoadAnimImage (\"t1.png\",8,8,0,100)

Dim b_map(50,50,7)
Dim gfx_map(50,50)

For x=0 To 50
For y=0 To 50
For a=0 To 7
b_map(x,y,a)=0
Next
gfx_map(x,y)=1
Next
Next

Global mw=50,mh=50,mx,my,omx,omy

Type tile_codes
Field frame
Field code$
End Type

get_tilecodes()


SetBuffer BackBuffer()
While Not KeyHit(1)
Cls

mx=MouseX()
my=MouseY()

draw_gfxmap(tiles)
If MouseDown(1) Then edit_bmap(1)
If MouseDown(2) Then scroll_gfxmap()
debug()

If KeyHit(203) Then update_gfxmap(x,y,1)

omx=mx
omy=my

Flip
Wend


Function get_tilecodes()
;liest die 'codes' ein, beispiel : wir haben ein tile, oben wasser und unten wiese. in der
;b_map würde das wie folgt aussehen 0 0 0 1 1 1 0 0 - 0 steht für wasser und 1 für land, anfangen
;tut das ganze oben in der mitte des tiles.
file=ReadFile (\"tile_codes.dat\")
While Not Eof(file)=1
t.tile_codes=New tile_codes
t\frame=a
t\code$=ReadLine (file)
a=a+1
Wend
CloseFile file
End Function



Function draw_gfxmap(tiles)
;zeichnet die gfx-map
For x=mpx To mpx+40
For y=mpx To mpx+30
DrawImage tiles,(x-mpx)*8,(y-mpy)*8,gfx_map(x,y)
Next
Next
End Function



Function edit_bmap(tile)
;bearbeitet die \"tile-code-map\"
For x=0 To 40
For y=0 To 30
If RectsOverlap (mx,my,1,1,x*8,y*8,8,8) Then
For a=0 To 7
b_map(x+mpx,y+mpy,a)=tile
Next

b_map(x+mpx,y+mpy-1,3)=tile
b_map(x+mpx,y+mpy-1,4)=tile
b_map(x+mpx,y+mpy-1,5)=tile
b_map(x+mpx+1,y+mpy-1,5)=tile

b_map(x+mpx+1,y+mpy,5)=tile
b_map(x+mpx+1,y+mpy,6)=tile
b_map(x+mpx+1,y+mpy,7)=tile
b_map(x+mpx+1,y+mpy+1,7)=tile

b_map(x+mpx,y+mpy+1,7)=tile
b_map(x+mpx,y+mpy+1,0)=tile
b_map(x+mpx,y+mpy+1,1)=tile
b_map(x+mpx-1,y+mpy+1,1)=tile

b_map(x+mpx-1,y+mpy,1)=tile
b_map(x+mpx-1,y+mpy,2)=tile
b_map(x+mpx-1,y+mpy,3)=tile
b_map(x+mpx-1,y+mpy-1,3)=tile

update_gfxmap(x,y,0)
EndIf
Next
Next
End Function

Function update_gfxmap(x,y,c)
;aktualisiert die eigentliche tile-map aus den werten in b_map
For xx=x-2 To x+2
For yy=y-2 To y+2
For a=0 To 7
tmp$=tmp$+Str(b_map(xx,yy,a))
Next
For t.tile_codes=Each tile_codes
If t\code$=tmp$ Then
gfx_map(xx,yy)=t\frame
EndIf
Next
tmp$=\"\"
Next
Next
End Function

Function scroll_gfxmap()
;scrolling, tut aber nix zur sache
mpx=mpx-(mx-omx)
mpy=mpy-(my-omy)
If mpx<0 Then mpx=0
If mpy<0 Then mpy=0
If mpx>mw-40 Then mpx=mw-40
If mpy>mh-30 Then mpy=mh-30
End Function

Function debug()
For x=0 To 40
For y=0 To 30
If RectsOverlap (mx,my,1,1,x*8,y*8,8,8) Then
Color 0,0,0
For a=0 To 7
Text mx+30,my,b_map(x,y,0)
Text mx+40,my,b_map(x,y,1)
Text mx+40,my+10,b_map(x,y,2)
Text mx+40,my+20,b_map(x,y,3)
Text mx+30,my+20,b_map(x,y,4)
Text mx+20,my+20,b_map(x,y,5)
Text mx+20,my+10,b_map(x,y,6)
Text mx+20,my,b_map(x,y,7)
Rect x*8,y*8,8,8,0
Next
EndIf
Next
Next
End Function




also, wir haben ein array 'b_map(x,y,z[7])' , x und y ist die position
auf der map, und z gibt die himmelsrichtung an. 0 ist norden, 1
nord-ost, 2 ost usw. . wenn man nun die map bearbeitet gibt
man dem tile, auf das man mit der maus zeigt für 0-7 den wert 1 (rasen).
den 8 benachbarten tiles werden an den entsprechenden seiten
und ecken der wert 1 zugewiesen. 'update_bmap' prüft nur noch
die werte aus 'b_map', sucht aus dem type (das vorher mit den
werten aus der datei (tile_codes.dat) gefüllt wurde) das richtige tile,
(bzw. frame) und gibt die werte an 'gfx_map(x,y)'. ich hab bestimmt schon
zum zehnten mal die tile_codes.dat neu geschrieben, es ändert sich
auch andauernd wieder was, scheine mich da ständig zu verzetteln. user posted image

das ganze nochmal als rar-file zum download (3kb) mit fast-richtiger tile_codes.dat.


[edit]

lol, hat sich erledigt, hab nur 4 tiles vergessen zu pixeln !

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group