OK!
I scrapped this floor renderer and are working on an new one
But i post a snippet of how i did the old one that is broken!
But maybe someone else find it usefull and can fix it for them self?
I simply found that i must start drawing the floors from an point that i get with the wall renderer?
At least i belive so?
I seam to have messed the snippet up when i wrote it?
Its a bit distorted?
You nead an texture that is 64x64 in size!
With the name bricks64.png
Rem Project: 1 fake matrix
Rem Created: Sunday, May 17, 2011
Rem ***** Main Source File *****
sync on : sync rate 0
SET DISPLAY MODE 800,600,32
load image "bricks64.png",1
``-----------------------------Engine types-------------------------------
type Intersection_t Intersect as integer ,X as float ,Y as float endtype
global Intersection as Intersection_t
``------------------
type Timed_t a as integer ,b as integer ,c as integer ,d as integer ,e as integer ,init as integer ,spd as float endtype
global Timed as Timed_t
``------------------
type Player_t
X as float
Y as float
OldX as float
OldY as float
Radius as float
Angle as float
Move as float
Turn as float
IsMoving as integer
Direction as float
endtype
global Player as Player_t
``---- Setup some player data ---
Player.X = 270.0
Player.Y = 270.0
Player.Radius=8.0
Player.Move = 160.0
Player.Turn = 160.0
Player.Angle = 0.0
Player.Direction = Wrapvalue(Player.Angle-90)
#constant Tusen 1000.0
#constant Renderer_Column 200
type Ray_t
X as float
Y as float
Hit as integer
Speed as float
Angle as float
endtype
global Ray as Ray_t
``This is only used to set the starting angle for the first ray and is always -30 from the players angle
#constant RayStart 30.0
type Grid_t
X1 as integer
Y1 as integer
X2 as integer
Y2 as integer
X3 as integer
Y3 as integer
endtype
global Grid as Grid_t
#constant Tile_size 64
``----------End types----------------------------------------
node=1
sprite node,0,0,1
hide sprite node
create animated sprite 2,"bricks64.png",64,64,1100
sprite 2,Renderer_X+value,Renderer_Y,4
size sprite 2,4,4
offset sprite 2,0,0
hide sprite 2
dim texture1(64*64)
for t=0 to 64*64
set sprite frame 2,t
paste sprite 2,0,0
Ink_col=POINT(0,0)
texture1(t)=Ink_col
NEXT t
do
Timed(timer())
cls
if upkey()=1
Player.X = Player.X + (cos(wrapvalue(Player.Angle-90))*Player.Move*Timed.spd)
Player.Y = Player.Y + (sin(wrapvalue(Player.Angle-90))*Player.Move*Timed.spd)
endif
if downkey()=1
Player.X = Player.X + (cos(wrapvalue(Player.Angle+90))*Player.Move*Timed.spd)
Player.Y = Player.Y + (sin(wrapvalue(Player.Angle+90))*Player.Move*Timed.spd)
endif
if leftkey()=1 then Player.Angle=wrapvalue(Player.Angle-(Player.Turn*Timed.spd)):Player.Direction = Wrapvalue(Player.Angle-90)
if rightkey()=1 then Player.Angle=wrapvalue(Player.Angle+(Player.Turn*Timed.spd)):Player.Direction = Wrapvalue(Player.Angle-90)
gosub Floor_renderer
set cursor 0,0
print " FPS = ";screen fps ()
sync
loop
function Timed(a#)
` Timed.e is how often to change speed (in milliseconds)/only used when the loop starts
if Timed.init=0 then Timed.a = a# : Timed.e = Tusen:Timed.init=1
` don't change any of this!
Timed.b = a# : inc Timed.c : temp = Timed.b - Timed.a
if temp >= Timed.e then Timed.spd = ((temp)/Tusen)/Timed.c : Timed.a=Timed.b : Timed.c=0 : Timed.d=1 : exit
if Timed.d = 0 then Timed.spd = ((temp)/Tusen)/Timed.c : exit
endfunction Timed.spd
``working on--------------------------------------------
floor_renderer:
_y_Floor=screen height ()-4
for f=1 to 60
Default_x=0
``setup the line in front of the player that we will raycast to get the floor pixel
sprite node,Player.X,Player.Y,4
rotate sprite node,Player.angle
move sprite node, 30+f
rotate sprite node,wrapvalue(Player.Angle-90)
move sprite node, 200
fx1# = sprite x(node)
fy1# = sprite y(node)
move sprite node, -400
fx2# = sprite x(node)
fy2# = sprite y(node)
``time to cast some rays to get the pixel cordinates
Ray.Speed = 0.0
for t=1 to Renderer_Column
A2#=wrapvalue(Player.Direction - RayStart)
Ray.Angle = wrapvalue( A2# + Ray.Speed)
Ray.X = Player.X + ( cos( Ray.Angle ) * 1000)
Ray.Y = Player.Y + ( sin( Ray.Angle ) * 1000)
Ray.Hit=RayCheck2( Player.X , Player.Y , Ray.X , Ray.Y ,fx1#,fy1#,fx2#,fy2# )
if Intersection.X>0 and Intersection.Y>0
x=Intersection.X
y=Intersection.Y
``converts it to an grid grid nr
Grid.X1=x/Tile_size
Grid.Y1=y/Tile_size
``converts it to an world position
Grid.X2=(Grid.X1*Tile_size)-Tile_size
Grid.Y2=(Grid.Y1*Tile_size)-Tile_size
``here do we get an pixel cord inside that tile
Grid.X3=((x-Grid.X2)-Tile_size)``+1
Grid.Y3=((y-Grid.Y2)-Tile_size)``+1
ink texture1(Grid.X3+(Grid.Y3*Tile_size)),0
BOX default_x,_y_Floor,default_x+4,_y_Floor+4
endif
Ray.Speed = Ray.Speed+0.3
inc default_x,4
next t
dec _y_Floor,4
next f
ink RGB(255,255,255),RGB(0,0,0)
return
function RayCheck2(Ax#,Ay#,Bx#,By#,Cx#,Cy#,Dx#,Dy#)
``Intersection.Intersect = 0
Intersection.X = 0.0
Intersection.Y = 0.0
`
Rem Early calculations
BxAx# = Bx#-Ax#
ByAy# = By#-Ay#
DxCx# = Dx#-Cx#
DyCy# = Dy#-Cy#
d# = ((BxAx#)*(DyCy#))-((ByAy#)*(DxCx#))
if d# = 0.0 then exitfunction 0
d#=1/d#
AyCy# = Ay#-Cy#
AxCx# = Ax#-Cx#
n# = ((AyCy#)*(DxCx#))-((AxCx#)*(DyCy#))
r# = n# * d#
s# = ( ((AyCy#)*(BxAx#))-((AxCx#)*(ByAy#)) ) * d#
``if r# <= 0.0 or r# >= 1.0 or s# <= 0.0 or s# >= 1.0 then exitfunction 0
if r# <= 0.0 then exitfunction 0
if r# >= 1.0 then exitfunction 0
if s# <= 0.0 then exitfunction 0
if s# >= 1.0 then exitfunction 0
Intersection.X = Ax# + (r# * (BxAx#) )
Intersection.Y = Ay# + (r# * (ByAy#) )
``Intersection.Intersect = 1
endfunction 1