http://www.bluemesapc.com/Downloads/soko0.zip
with the following code:
Code: Select all
; move example
#WIDE = 1024
#HIGH = 768
#MOUSE = 1030
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "DirectX 7+ Fail!", 0)
End
EndIf
Global Dim LAYER(2,2)
Global Dim PLAYER(16,12) ; holds array info about player available moves / things to encounter or pickup etc.
Global SPX
Global SPY
Global SX
Global SY
Global MaxWide
Global MaxHigh
Global Xwide
Global YHigh
OpenScreen(1024,768,16,"Tiledemo 1")
Procedure OpenMap(filename$)
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-9.bmp")
IntBase = ReadPreferenceLong("X2",4)
SpriteCount = ReadPreferenceLong("X3",4)
ClosePreferences() ; close the previously opened file
result = LoadSprite(999, GFile$)
UseBuffer(999) ; change grab buffer to sprite just created
Imagesize = IntBase * SPX - 1
Spritenumber = 0
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)
Debug "CREATED SPRITE = "+Str(Spritenumber)
Spritenumber = Spritenumber + 1
If Spritenumber >= SpriteCount ; ********************************* with cursor
Break 2
EndIf
x + SPX - 1 ; <=='variable' step
Next
y + SPY - 1 ; <=='variable' step
Next
UseBuffer(#PB_Default)
Dim LAYER(MaxWide,MaxHigh)
Dim PLAYER(MaxWide,MaxHigh)
#DUDE = 7 ; number in graphic
#TARGET = 8 ; likewise
op = 1
For x = 0 To MaxWide
For y = 0 To MaxHigh
LAYER(x,y) = Asc(Mid(LVL$,op,1)) - 35
PLAYER(x,y) = 0
op = op + 1
Next
Next
Debug "***** MAXWide = "+Str(MaXWide)
Debug "***** MaxHigh = "+Str(MaxHigh)
EndProcedure
Procedure LayTargets(dudex,dudey)
For X = 0 To MaxWide
For Y = 0 To MaxHigh
PLAYER(X,Y) = 0
Next
Next
PLAYER(dudex,dudey) = #DUDE ; reset the DUDE
; check S
If LAYER(dudex,dudey+1) < 3
PLAYER(dudex,dudey+1) = #TARGET
EndIf
; check N
If LAYER(dudex+1, dudey) < 3
PLAYER(dudex+1, dudey) = #TARGET
EndIf
; check
If LAYER(dudex+1, dudey+1) < 3
PLAYER(dudex+1, dudey+1) = #TARGET
EndIf
; check W
If LAYER(dudex-1, dudey) < 3
PLAYER(dudex-1, dudey) = #TARGET
EndIf
; check
If LAYER(dudex-1, dudey-1) < 3
PLAYER(dudex-1, dudey-1) = #TARGET
EndIf
; check
If LAYER(dudex, dudey-1) < 3
PLAYER(dudex, dudey-1) = #TARGET
EndIf
; check
If LAYER(dudex-1, dudey+1) < 3
PLAYER(dudex-1, dudey+1) = #TARGET
EndIf
; check
If LAYER(dudex+1, dudey-1) < 3
PLAYER(dudex+1, dudey-1) = #TARGET
EndIf
EndProcedure
Procedure CheckMove(dudex,dudey)
If dudex > 14 ; boundaries are -1 because of 1 tile border
dudex = 14
EndIf
If dudex < 1
dudex = 1
EndIf
If dudey > 10
dudey = 10
EndIf
If dudey < 1
dudey = 1
EndIf
destination = PLAYER(dudex,dudey) ; see we are only supposed to be able to move onto the O ot #TARGET
Debug "DEST: "+Str(destination) ; I use [[ALT]} + {{TAB}} to view this after placing on a square
If destination = #TARGET
PLAYER(dudex,dudey) = #DUDE ; BUT it still places it even when destination = 0
EndIf
Laytargets(dudex,dudey)
EndProcedure
; ************************************ Change the following to change maps!
filename$ = "SOKO0.rwd"
OpenMap(filename$)
LoadSprite(#MOUSE, "Cursor1.bmp")
MouseLocate(512,381)
PLAYER(7,1) = #DUDE
LayTargets(7,1)
dudex = 7 ; start values
dudey = 1
FineStep = 4 ; 4
Repeat
ExamineKeyboard()
ExamineMouse()
MauX = MouseX() : MauY = MouseY()
ClearScreen(0)
If KeyboardPushed(#PB_Key_Left)
dudex = dudex - 1
CheckMove(dudex,dudey)
EndIf
If KeyboardPushed(#PB_Key_Right)
dudex = dudex + 1
CheckMove(dudex,dudey)
EndIf
If KeyboardPushed(#PB_Key_Up)
dudey = dudey - 1
CheckMove(dudex,dudey)
EndIf
If KeyboardPushed(#PB_Key_Down)
dudey = dudey + 1
CheckMove(dudex,dudey)
EndIf
;*** Tile Engine
For SY=0 To MaxHigh
For SX = 0 To MaxWide
DisplaySprite(LAYER(MapX+SX,MapY+SY), SPX * SX , SPY * SY)
DisplayTransparentSprite(PLAYER(MapX+SX,MapY+SY), SPX * SX - FineX , SPY * SY - FineY ) ; i was trying to use this to show movement
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
DisplayTransparentSprite(#MOUSE,MouseX(),MouseY())
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
What am I not doing?

