News:

Function Finder  Find all the functions within source code files

Main Menu

Building Ray Casting Map Slow Motion Demo

Started by kevin, January 11, 2025, 11:31:18 AM

Previous topic - Next topic

kevin

Building Ray Casting Map Slow Motion Demo




PlayBASIC Code: [Select]
; PROJECT : Ray Casting Map Slow Motion
; AUTHOR : PlayBASIC TUTOR (https://playbasic.com)
; CREATED : 12/01/2025
; EDITED : 12/01/2025
; ---------------------------------------------------------------------

openscreen 1280,900,32,1

loadfont "courier new",1, 40,0,8
setfont 1

// ---------------------------------------------------------
// -- LOAD MAP DATA INTO MAP
// ---------------------------------------------------------

global Map_Height = 16
global Map_Width = 16



dim Map(Map_Width,Map_Height)

for ylp=0 to Map_Height-1
row$=readdata$()
for xlp=0 to Map_Width-1
ThisBLOCK=mid(row$,1+xlp)-asc("0")
Map(xlp,ylp) = ThisBLOCK
next
next


; Get the Screen size and use it as the world size
WorldWidth =GetScreenWidth()
WorldHeight =GetScreenHeight()

global BlockSizeX#= WorldWidth /float(Map_Width)
global BlockSizeY#= WorldHeight/float(Map_Height)

//
global BlockSizeX_Scaler# = 64/BlockSizeX#
global BlockSizeY_Scaler# = 64/BlockSizeY#


type tMap_Text
Tile
x1#,Y1#
x2#,Y2#
Colour
endtype
dim MapText(Map_Width,Map_Height) as tMap_Text
RenderTextMap(10,115)


Type tLine
TileX,TileY
X1,Y1,X2,Y2,Colour
EndType
Dim Buffer(1000) as tLine

Draw_Collision_Map()

Lines_Used=GetFreeCell(Buffer())

setfps 10


Scale#=0.5

Do
cls

Walls_To_Draw++
x#=Getsurfacewidth()*0.48
y#=Getsurfaceheight()*0.10
Draw_Buffer(x#,Y#,Scale#,Walls_To_Draw)

ink -1
centertext getscreenwidth()*0.25,10,"Tile Map"
centertext getscreenwidth()*0.75,10,"Collision Map"

Sync
loop spacekey()



Function Draw_Buffer(BaseX#,BaseY#,Scale#,Walls_To_Draw)

Walls_To_Draw=cliprange(Walls_To_Draw,0,Getarrayelements(Buffer()) )


lockbuffer
c=rgb(255,255,255)
for lp=1 to Walls_To_Draw
if buffer(lp)=0 then continue

x1=basex#+(buffer(lp).x1*Scale#)
y1=basey#+(buffer(lp).y1*Scale#)
x2=basex#+(buffer(lp).x2*Scale#)
y2=basey#+(buffer(lp).y2*Scale#)
if lp>=(Walls_To_Draw-1) then c=$ff2020
linec x1,y1,x2,y2,c

LastLineX = (X1+X2)*0.5
LastLineY = (Y1+Y2)*0.5
next
unlockbuffer


// Draw the Text Map
Map_Height = getarrayelements(Map(),2)
Map_Width = getarrayelements(Map(),1)

th#=GetTextHeight("|")
th2#=th#/2

Dim Palette(1)

Palette(0)=$445566
Palette(1)=$223322

lockbuffer
// Draw the map edges to collision for ray intersection
For ylp=0 To Map_Height-1

PaletteIndex= ylp and 1
For xlp=0 To Map_Width-1
x1#=Maptext(xlp,ylp).x1#
y1#=Maptext(xlp,ylp).y1#
x2#=Maptext(xlp,ylp).x2#
y2#=Maptext(xlp,ylp).y2#
ThisBlock = Maptext(xlp,ylp).tile
x#=(x2#+x1#)*0.5
y#=(y2#+y1#)*0.5
Colour=Maptext(xlp,ylp).Colour

boxc x1#,y1#,x2#,y2#,true,Palette(PaletteIndex)
PaletteIndex=1-PaletteIndex

ink Colour
centertext X#,Y#-th2#,ThisBlock

Maptext(xlp,ylp).Colour=$ffffff

next
next

unlockbuffer

Login required to view complete source code



  Related Articles:

    -- Wolf 3D