Tile Map Scrolling Problem (PEBKC Error!)

Just starting out? Need help? Post your questions and find answers here.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Tile Map Scrolling Problem (PEBKC Error!)

Post by Rook Zimbabwe »

I am using a version of the Scrolling Tilemap program that Kaeru Gaman provided. But there is a large problem.

It reads the map files correctly. The map file DATA is in the right place.

But the bottom line of the map is displayed above map 0,0!

And it does not go down to the bottom of the map.

Worse than that it seems to shift the bottom of the map over 1 tile so what is being placed at 0,0 would actually be on the OPPOSITE BOTTOM CORNER of the map.

Code: Select all

; from an example provided by Kaeru Gaman in the PB Forums
; file load is all Rook ZImbabwe
InitSprite()
InitKeyboard()
InitMouse()
OpenScreen(1024,768,16,"Tiledemo 1")

; ************************************ Change the following to change maps!
filename$ = "MAP-9.rwd" ; "MAP-001.rwd"
GFile$ = "MAP-9.bmp" ; "MAP-001.bmp"

OpenPreferences(filename$)   ; if the file could be read, we continue...

PreferenceGroup("DATA")
MaxWide = ReadPreferenceLong("X2",0)
MaxHigh = ReadPreferenceLong("X3",0)
SPX = ReadPreferenceLong("X4",32)
SPY = ReadPreferenceLong("X5",32)
PreferenceGroup("LAYER")
LVL$ = ReadPreferenceString("X2","")
PreferenceGroup("MAPDATA")
GFile$ = ReadPreferenceString("X1", "MAP-0.bmp")
IntBase = ReadPreferenceLong("X2",4)
SpriteCount = ReadPreferenceLong("X3",4)
ClosePreferences()               ; close the previously opened file

result = LoadSprite(999, GFile$)

Debug "Sprite to clip load is = "+Str(result) ; indicate success of failure
UseBuffer(999) ; change grab buffer to sprite just created

Imagesize = IntBase * SPX - 1

For y = 0 To Imagesize  ; <== for images arranged in column order the loops should be reversed (making x the outside loop)
    For x = 0 To Imagesize
        GrabSprite(Spritenumber,x,y,SPX,SPY)
        Spritenumber = Spritenumber + 1
        If Spritenumber >= SpriteCount
            Break 2
        EndIf
        x + SPX - 1  ; <=='variable' step
    Next
    y + SPY - 1 ; <=='variable' step
Next
UseBuffer(#PB_Default)

Dim LAYER(MaxWide,MaxHigh)

op = 0

For x = 0 To MaxWide
    For y = 0 To MaxHigh
        LAYER(x,y) = Asc(Mid(LVL$,op,1)) - 35
        op = op + 1
    Next
Next

MouseLocate(512,381)

FineStep = 4 ; 4

Repeat
    
    ExamineKeyboard()
    ExamineMouse()
    MauX = MouseX() : MauY = MouseY()
    ClearScreen(0)
    
    If KeyboardPushed(#PB_Key_Left) Or MauX < 8
        FineX - FineStep
        If FineX < 0
            FineX = SPX - FineStep
            MapX-1
            If MapX < 0
                MapX = 0
                FineX = 0
            EndIf
        EndIf
    EndIf
    If KeyboardPushed(#PB_Key_Right) Or MauX > 1016
        FineX + FineStep
        If FineX > SPX - FineStep
            FineX = 0
            MapX+1
            If MapX > MaxWide - 16
                MapX = MaxWide - 16
                FineX = SPX - FineStep
            EndIf
        EndIf
    EndIf
    If KeyboardPushed(#PB_Key_Up) Or MauY < 8
        FineY - FineStep
        If FineY < 0
            FineY = SPY - FineStep
            MapY-1
            If MapY < 0
                MapY = 0
                FineY = 0
            EndIf
        EndIf
    EndIf
    If KeyboardPushed(#PB_Key_Down) Or MauY > 760
        FineY + FineStep
        If FineY > SPY - FineStep
            FineY = 0
            MapY+1
            If MapY > MaxHigh - 12
                MapY = MaxHigh - 12
                FineY = SPY - FineStep
            EndIf
        EndIf
    EndIf
    
; ***** PLACE TO CUT AND INSERT NEW CODE

    ; THIS IS THE MOUSE DISPLAY ***********************************
    ActTileX = (MauX+FineX) / SPX + MapX
    ActTileY = (MauY+FineY) / SPY + MapY
    
    ;   Buff = LAYER(ActTileX,ActTileY)
    ;   LAYER(ActTileX,ActTileY) = 28
    ;***********************************
    ;*** Tile Engine
    
    For SY=0 To 12
        For SX = 0 To 16
            DisplaySprite(LAYER(MapX+SX,MapY+SY), SPX * SX - FineX , SPY * SY - FineY )
        Next
    Next
    ;***********************************
    ; LAYER(ActTileX,ActTileY) = Buff   ; den alten Wert wiederherstellen.
    
    FlipBuffers()
    
Until KeyboardPushed(#PB_Key_Escape)

Files are here:

http://www.bluemesapc.com/Downloads/MAP-001.zip
Last edited by Rook Zimbabwe on Thu Aug 14, 2008 9:32 pm, edited 2 times in total.
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
y3an
User
User
Posts: 56
Joined: Sun Mar 09, 2008 6:06 am

Post by y3an »

It looks working with

op = 1 instead of 0

I hope I dont' make false hope ;}
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

I changed the end code to this:

Code: Select all

    ;*** PLACE TO CUT AND INSERT NEW CODE

    For SY=0 To 12
        For SX = 0 To 16
            DisplaySprite(LAYER(MapX+SX,MapY+SY), SPX * SX - FineX , SPY * SY - FineY )
        Next
    Next
    ;***********************************
     
    If MouseButton(1)
    ActTileX = (MauX+FineX) / SPX + MapX
    ActTileY = (MauY+FineY) / SPY + MapY 
        Text$ = "TILE IS: "+Str(LAYER(ActTileX,ActTileY) )
            StartDrawing(ScreenOutput())
                DrawText(10, 0, Text$ ,RGB(255,255,255),RGB(0,0,0))
                DrawText(10,20,"LAYER( "+Str(ActTileX)+" , "+Str(ActTileY))
            StopDrawing()
     EndIf

    DisplaySprite(28,MouseX(),MouseY())
 
     
    FlipBuffers()
    
Until KeyboardPushed(#PB_Key_Escape)
According to this the TOP ROW showing does not actually exist!

I states that the ROW is equal to the second row down... Tilenumber is equal and location in array is equal...

You are going to need to load a sprite # 28 for a cursor (48 - 64 square is reccomended)

EDIT:: Y3an!!! You are a genius!

Now why? Why does that do that?
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
y3an
User
User
Posts: 56
Joined: Sun Mar 09, 2008 6:06 am

Post by y3an »

LoL

I'm not able to say why it does that.. :lol:

I have just past a lot of time on maps on each prog i have started.. The only thing that i can say is... in my codes, I have ever littles problems like that..

I have just put some "Layer(0,0) = truc", "Layer(max_x , max_y) = machin" here and there to see what happen..

And.. old memories of issues with incrementation's variable in a loop.. came back..

So.. I have try to move op.. Before the loop where you read Asc() values of the file.


I have just made tests, because it would take me a relative time x) to really "read neer" to the code.
And fortunatly the solution came fast..


So no, no, sorry... nothing genius here, and especially any claim of it in my approach of the prog :roll: lol
Post Reply