Na, wie weit seid ihr mit der Tilemap gekommen?
Das war die Aufgabe
Postet hier eure Ergebnisse, Codes, Gedanken. Lernt von den anderen, seht euch deren Quelltext an und versucht euren eigenen zu verbessern.
Diskussion
Postet zu euren Codes stets eine kurze Erklärung mit euren Gedanken in denen ihr simpel gesagt die Frage "Wieso habe ich XY auf diese Art gelöst?" beantwortet. Beiträge, die nur den Code enthalten werden wir aus dem Thread entfernen.
Nächste Aufgabe
In einer Woche wird die Musterlösung nach editiert und in 2 die nächste Aufgabe eingestellt.
Viel Spaß & viel Erfolg!
Musterlösung:
BlitzMax: [AUSKLAPPEN] [EINKLAPPEN] SuperStrict
Const TileSize:Int = 20 Const MapSize:Int = 8 Const MaxTile:Int = 4
Global gfxSize:Int = TileSize * 10 Graphics(gfxSize, gfxSize) Local FrameTimer:TTimer = TTimer.Create(60)
Global TileSet:TImage = LoadAnimImage("tiles.png", TileSize, TileSize, 0, MaxTile) Global ActivTile:Int Global mh1:Int, mx:Int, my:Int
Global map:Int[MapSize, MapSize] ReadMapData()
Repeat Cls mh1=MouseHit(1) mx=MouseX() my=MouseY() DrawMap() DrawActivTile() DrawTileSet() ChooseActivTile() ChangeMap() If KeyHit(KEY_R) Then ReadMapData() If KeyHit(KEY_S) Then SaveMap() If KeyHit(KEY_L) Then LoadMap() Flip(0) FrameTimer.Wait() Until KeyHit(KEY_ESCAPE) Or AppTerminate() End
Function DrawMap() For Local y:Int = 0 Until MapSize For Local x:Int = 0 Until MapSize DrawImage(TileSet, x * TileSize, y * TileSize, map[x, y]) Next Next End Function
Function DrawActivTile() SetColor(200, 0, 0) DrawRect(gfxSize - TileSize * 1.6, TileSize *.4, TileSize * 1.2, TileSize * 1.2) SetColor(255, 255, 255) DrawImage(TileSet, gfxSize - TileSize * 1.5, TileSize *.5, ActivTile) End Function
Function DrawTileSet() For Local i:Int = 0 Until MaxTile DrawImage(TileSet, TileSize*.5+TileSize*i, gfxSize-TileSize*1.5, i) Next End Function
Function ChooseActivTile() If Not(mh1) Then Return If mx<TileSize*.5 Or mx+1 >TileSize*.5+TileSize*MaxTile Then Return If my<gfxSize-TileSize*1.5 Or my+1 >gfxSize-TileSize*0.5 Then Return ActivTile = (mx-Float(TileSize))/TileSize End Function
Function ChangeMap() If Not(mh1) Then Return If mx+1 > TileSize*(MapSize+1) Then Return If my+1 > TileSize*(MapSize+1) Then Return Local x% = mx/TileSize Local y% = my/TileSize map[x, y] = ActivTile End Function
Function SaveMap() Local file:TStream = WriteFile("this.map") For Local y:Int = 0 Until MapSize For Local x:Int = 0 Until MapSize file.WriteInt(map[x, y]) Next Next file.Close() End Function
Function LoadMap() Local file:TStream = ReadFile("this.map") If file = Null Then Return For Local y:Int = 0 Until MapSize For Local x:Int = 0 Until MapSize map[x, y] = file.ReadInt() Next Next file.Close() End Function
Function ReadMapData() RestoreData MapData For Local y:Int = 0 Until MapSize For Local x:Int = 0 Until MapSize ReadData map[x, y] Next Next End Function
#MapData DefData 0, 0, 0, 0, 0, 0, 0, 0 DefData 0, 1, 1, 1, 1, 1, 0, 0 DefData 0, 2, 2, 1, 2, 2, 0, 0 DefData 0, 0, 2, 1, 2, 0, 0, 0 DefData 0, 0, 2, 3, 2, 0, 0, 0 DefData 0, 0, 2, 3, 2, 0, 0, 0 DefData 0, 0, 3, 3, 3, 0, 0, 0 DefData 0, 0, 0, 0, 0, 0, 0, 0
|