this is the code and you can use any heightmap and jpg to texture it, it wont give you more than 8 fps
whats wrong with this one?
rem Initial settings
sync on : sync rate 100
backdrop on : hide mouse : color backdrop 0
fog on : fog distance 1000
rem Load all media for game
gosub _load_game
rem Setup all objects for game
gosub _setup_game
rem Game loop
do
rem Control game elements
gosub _control_player
gosub _control_weather
gosub _control_enemies
rem Update screen
sync
rem End loop
loop
rem gosublar
_control_player:
rem Mouseclicks control speed
if mouseclick()=1 then thrust#=thrust#+thruststep#
if mouseclick()=2 then thrust#=thrust#-thruststep#
rem Now the joystick button controls speed
`if joystick fire a()=1 then thrust#=thrust#+thruststep#
if keystate(17)=1 then yaxisstrafe#=yaxisstrafe#-thruststep#
if keystate(30)=1 then xaxisstrafe#=xaxisstrafe#-thruststep#
if keystate(31)=1 then yaxisstrafe#=yaxisstrafe#+thruststep#
if keystate(32)=1 then xaxisstrafe#=xaxisstrafe#+thruststep#
rem Shooting
rem Putting in a firing delay
if mouseclick()=4 and shotrecently#=0
shotrecently#=4
for i=0 to 9
rem If the bullet is 'dead' then create a new one
if shot#(i,0)=0
rem Alive
shot#(i,0)=1
rem Current position
shot#(i,1)=x#
shot#(i,2)=y#
shot#(i,3)=z#
rem Current velocities plus velocities provided by the gun
shot#(i,4)=xvel#+(sin(theta#)*cos(phi#)*20)
shot#(i,5)=yvel#-(sin(phi#)*20)
shot#(i,6)=zvel#+(cos(theta#)*cos(phi#)*20)
rem Angle
shot#(i,7)=theta#
shot#(i,8)=phi#
rem Life
shot#(i,9)=30
show object i+1
exit
endif
next i
endif
if shotrecently#>0 then shotrecently#=shotrecently#-1
rem Update the bullets
for i=0 to 9
rem If the bullet is 'alive' then move it by it's velocity
if shot#(i,0)=1
shot#(i,1)=shot#(i,1)+shot#(i,4)
shot#(i,2)=shot#(i,2)+shot#(i,5)
shot#(i,3)=shot#(i,3)+shot#(i,6)
position object i+1,shot#(i,1),shot#(i,2),shot#(i,3)
shot#(i,9)=shot#(i,9)-1
rem If it's just run out of 'life' then 'kill' it and make
rem it available for use again
if shot#(i,9)=0
hide object i+1
shot#(i,0)=0
endif
endif
next i
rem Mouse movements control angles
`theta#=curveangle(theta#+mousemovex(),theta#,7)
`phi#=curveangle(phi#+mousemovey(),phi#,7)
theta#=wrapvalue(theta#+mousemovex())
phi#=wrapvalue(phi#+mousemovey())
rem Joystick controls angles
`theta#=wrapvalue(theta#+(joystick x()*0.005))
`phi#=wrapvalue(phi#-(joystick y()*0.005))
rem Decay the thrust so you don't go really fast
thrust#=thrust#*0.9
xaxisstrafe#=xaxisstrafe#*0.9
yaxisstrafe#=yaxisstrafe#*0.9
rem Accelerate the velocities (this took ages to work out)
xvel#=xvel#+(sin(theta#)*cos(phi#)*thrust#)
yvel#=yvel#-(sin(phi#)*thrust#)
zvel#=zvel#+(cos(theta#)*cos(phi#)*thrust#)
xvel#=xvel#+(sin(theta#+90)*xaxisstrafe#)
zvel#=zvel#+(cos(theta#+90)*xaxisstrafe#)
xvel#=xvel#+(sin(theta#)*cos(phi#+90)*yaxisstrafe#)
yvel#=yvel#-(sin(phi#+90)*yaxisstrafe#)
zvel#=zvel#+(cos(theta#)*cos(phi#+90)*yaxisstrafe#)
rem Some friction to stop you going too fast
xvel#=xvel#*0.99
yvel#=yvel#*0.99
zvel#=zvel#*0.99
rem Simple velocity
x#=x#+xvel#
y#=y#+yvel#
z#=z#+zvel#
rem Screen display
set cursor 10,10
print screen fps()
text#=matrix tile count(1)
set cursor 10,20
print text#
rem Rotate and position the camera
position camera x#,y#,z#
yrotate camera theta#
xrotate camera phi#
sync
return
_control_weather:
return
_control_enemies:
return
_control_stats:
return
_setup_game:
Open To Read 1,"matrix/binalar2.bmp"
Read Byte 1,Char1
Read Byte 1,Char2
REM Make Certain it is a bitmap
If Upper$(Chr$(Char1) + Chr$(Char2)) = "BM"
REM Begin collecting bitmap data from file header
Read Long 1, VOID :`- Dont need
Read Long 1, VOID :` these bytes
Read Long 1, OFFSET :`- Offset to bitmap data
Read Long 1, VOID :`- Don't need this
Read Long 1, WIDTH :`- Width
Read Long 1, HEIGHT :`- Height
Read Word 1, VOID :`- Don't need these 2 bytes
Read Word 1, BITSPERPIXEL :`- Use this to make sure we are loading in a 24bit bmp
Read Long 1, COMPRESSION :`- Compression type, we are only handling non compressed bmps
REM Check that we are working with a 24bit bmp with no compression, if so, begin reading the
REM Data into an array
If BITSPERPIXEL = 24 And COMPRESSION = 0
REM We've already read in the first 36 bytes. Calculate the remaining bytes left to
REM reach the byte data and move to the correct position in the file
For I = 1 to (OFFSET - 34)
Read Byte 1,VOID
Next I
REM Create an array to hold the bitmap data
Dim Bitmap(WIDTH, HEIGHT)
REM Begin reading in the bitmap data
REM First byte represents the lower left hand corner of the image
REM Last byte represents the upper right
For Y = 1 To HEIGHT
For X = 1 To WIDTH
Read Byte 1, Bitmap(X, HEIGHT-Y)
Read Byte 1, Void : Read Byte 1, Void
Next X
Next Y
REM Now we are ready to create our terrain. First we define some variable for our matrix
MATWIDTH# = 2000.0
MATLENGTH# = 2000.0
XSEG = 70
ZSEG = 70
MAXHEIGHT# = 600
REM Create Our Terrain
Make Matrix 1, MATWIDTH#, MATLENGTH#, XSEG, ZSEG
REM Now we are going to use the pixel data to generate our terrain.
REM Note: Pixels coordinates range from 0 to Width-1 and 0 to Height-1 so the bottom
REM right pixel coordinate of a 256x256 bitmap would be at (255,255)
For Z = 0 To ZSeg
For X = 0 To XSeg
PX = ((WIDTH-1.0) / XSEG) * X
PY = ((HEIGHT-1.0) / ZSEG) * Z
Set Matrix Height 1, X, Z, (MAXHEIGHT# / 255) * Bitmap(PX,PY)
set matrix normal 1,x,z,30,30,30
REM Set up the coordinates of our light source
BX# = 3000.0
BY# = 300.0
BZ# = 3000.0
REM Calculate the actual world position of the vertex at matrix segment 5,2
AX# = TILE_WIDTH# * 5
AZ# = TILE_LENGTH# * 2
AY# = Get Ground Height(1, AX#, AZ#)
rem vektör posizyonu
VX# = BX# - AX#
VY# = BY# - AY#
VZ# = BZ# - AZ#
REM Set up a flag to record whether or not the line was blocked
BLOCKED = 0
REM Calculate the number of intervals required by dividing the length
REM of the line by a single tile/width (which ever is larger).
REM First, determine which tile size to divide by
If TILE_WIDTH# > TILE_LENGTH#
DIV# = TILE_WIDTH#
Else
DIV# = TILE_LENGTH#
EndIf
REM Now calculate how many intervals we need
INTERVALS = Sqrt(VX#^2 + VY#^2 + VZ#^2) / DIV#
REM Avoid divide by zero error when calculating K#
If INTERVALS = 0 Then INTERVALS = 1
REM Time to cast our ray!
REM We now user linear interpolation to calculate the coordinates of the points
REM at each interval and then test to see wether this point is above the matrix
REM or not. If it is not, then an intersection has occured
For I = 1 To INTERVALS
K# = (1.0 / INTERVALS) * I
REM Calculate 3D coordinates at the current line interval
REM this is where linear interpolation comes into play. Note that we have split the equation up somewhat
REM along the way. The calculation could also be written as: CX# = AX# + ((BX#-AX#) * ((1.0 / INTERVALS)*I))
REM which is in the same form as our original equation C = A + ((B-A)*K)
CX# = AX# + (VX# * K#)
CY# = AY# + (VY# * K#)
CZ# = AZ# + (VZ# * K#)
REM Check height of matrix at the current interval.
REM If it is higher than the current point, an intersection has occured.
REM in which case, we set the BLOCKED flag to 1 and exit the loop
If Get Ground Height(1,CX#,CZ#) + Matrix Position Y(1) > CY# Then BLOCKED = 1 : Exit
Next I
REM If an intersection occured, adjust the normal to a value which results in a dark patch on the matrix
If BLOCKED = 1
Set Matrix Normal 1,X,Z, 0.4, 0.4, 0.4
REM if all is fine, leave it at its default value
Else
Set Matrix Normal 1,X,Z, 0.0, 1.0, 0.0
EndIf
Next X
Next Z
REM Update the matrix so we can see the changes
Update Matrix 1
EndIf
EndIf
Close File 1
rem matrix texture
prepare matrix texture 1,1,2,1
for x=1 to 58
for y=1 to 58
cimen=get matrix height(1,x,y)
cimen2=get matrix height(1,x+1,y+1)
cimen3=get matrix height(1,x-1,y-1)
if cimen>1 and cimen2>1 and cimen3>1
set matrix tile 1,x,y,1
endif
if cimen<1 and cimen2<1 and cimen3<1
set matrix tile 1,x,y,2
endif
next x
next y
update matrix 1
rem mermiler ve degiskenler
rem Set up initial positions and angles
x#=20
y#=10
z#=20
theta#=0
phi#=0
thruststep#=0.01
rem Set up bullets
dim shot#(10,10)
for i=0 to 9
make object sphere i+1,5
next i
sync
return
_load_game:
load image "matrix/tile.jpg",1
return