Tileset Loader Function with drawer-beams

Previous topic - Next topic

D2O

Sorry for my bad English ;)

Download this Graphics:
http://www.deuteriumoxid.com/glbasic/tile.bmp
http://www.deuteriumoxid.com/glbasic/tile2.png

Edit: Oops, i forget this, FILLRECT 0,0,l_tilex,l_tiley,RGB(255,0,128).
Fixit.

Code (glbasic) Select
// --------------------------------- //
// Project: loadimagev6
// Start: Saturday, March 10, 2007
// IDE Version: 4.114

// Code example :

GLOBAL player1 AS Tsprite
GLOBAL player2 AS Tsprite


player1= loadimage("tile.bmp",32,32,18)
player2 = loadimage("tile2.png",128,64,18)
//
GLOBAL a
WHILE TRUE

IF a > 17 THEN a = 0
SPRITE player1.pic[a],0,0
SPRITE player2.pic[a],100,100

SHOWSCREEN

MOUSEWAIT
INC a,1
WEND
/////////// Code example End


//--------------------------------loadimage---------------------------
// file Path, tile wight, tile high, tile pay down

FUNCTION loadimage AS Tsprite:l_path$,l_tilex,l_tiley,l_anzahl
    STATIC s_counter = 1000  //Ab 1000 damit überschneidungen mit loadsprite nicht vorkommen

        //-------------
    LOCAL l_x,l_y  // zum berechnen der Tile anzahl aus der Image grösse
    LOCAL  l_xcount,l_ycount // Counter für die Positions verschiebung
    LOCAL imagetemp // für die aufnahme des Tilsets
    LOCAL image AS Tsprite //für die aufnahme der Tiles
    LOCAL l_showload // Variablen für Ladebalken
    LOCAL l_prozent
    l_showload = 100/l_anzahl

    image.tilex = l_tilex
    image.tiley = l_tiley
    image.frame = l_anzahl -1


    LOCAL l_posx,l_posy     // Variablien für Grundposition auf die sich die Verschiebung berechnet| x = 0 | y = 0
    LOCAL l_i                 // für die for schleife
    LOCAL countertemp


        REDIM image.pic[l_anzahl]

            countertemp = s_counter    //Index Temporär speichen um später den Speicher wieder freizu geben
            LOADSPRITE l_path$,countertemp //image laden
            GETSPRITESIZE countertemp,l_x,l_y    //Image grösse ermitteln

                l_x = INTEGER(l_x/l_tilex)
                l_y = INTEGER(l_y/l_tiley)



                     LOADSPRITE l_path$,countertemp
                         INC s_counter,1  //index um 1 erhöhen


            FOR l_i = 0 TO l_anzahl-1

                    IF l_xcount < l_x
                            l_posx = (-l_tilex*l_xcount)
                            ELSE
                                l_xcount = 0
                                l_posx = (-l_tilex*l_xcount)
                                INC l_ycount,1
                    ENDIF

                    IF l_ycount < l_y
                            l_posy = (-l_tiley*l_ycount)
                            ELSE
                                INC l_ycount,1
                                l_posy = (-l_tiley*l_ycount)
                    ENDIF
                    FILLRECT 0,0,l_tilex,l_tiley,RGB(255,0,128) ///<<<<<<<< FIX :)
                    SPRITE countertemp,l_posx,l_posy
                    GRABSPRITE s_counter,0,0,l_tilex,l_tiley
                    BLACKSCREEN
                   
                    ///Ladebalken---------------
                    INC l_prozent,l_showload
                    PRINT INTEGER(l_prozent)+"% geladen",100+l_prozent,480
                    FILLRECT 100,500,100+l_prozent,500+10,RGB(20,200,20)
                    ///-----------------------------
                    SHOWSCREEN //__________________________________________
                   

                        image.pic[l_i] = s_counter
                    INC l_xcount,1
                    INC s_counter,1
            NEXT

                LOADSPRITE "",countertemp  //Speichfreigenen

                RETURN image

ENDFUNCTION




// Dieser Type wir gebraucht um aus der function loadimage ein array als rückgabe wert zu nutzen
// er könnte auch für die bild positionen usw. erweitert werden
TYPE Tsprite
pic[]
x //positionen
y
tilex // Tilegrösse
tiley
frame //anzahl der frames
ENDTYPE
I7 2600K; 8 GB RAM ; Win10 Pro x64 | NVidia GTX 750 TI 2048MB ; Realtec OnBoard Sound;
Lenovo ThinkPad T400: XP Pro
GLB Premium-immer Aktuell

bigsofty

Very handy little routine to load in sprite maps... thank you for sharing Slayer ;)
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)