Here's something I was working on an hour ago lol. It includes 2 examples. just run the code and see the "Matrix With Gravity" example. Then, in the source code just look for that example. Shouldn't be too hard to find. Anyway, here are the 2 examples: you'll see why it's so long when you run it
And don't worry, it's also the REMS that make it long. Hope it's not too complex for you... If you want I can make an easier one.
rem Setup for ALL examples.
set display mode 800,600,32
sync on
sync rate 60
set text font "verdana"
disable escapekey
color backdrop 0
MAIN_MENU:
x#=0
y#=0
z#=0
Grav#=0.0
Weight#=0.0
OnFloor=0
Choose=0
for o = 1 to 1000
if object exist(o) then delete object o
next o
for i = 1 to 1000
if image exist(i) then delete image i
next i
for m =1 to 1000
if matrix exist(m) then delete matrix m
next m
fog off
fog color 0
fog distance 0
rem THE MAIN MENU
NumberOfExamples=2
inc NumberOfExamples,1
Dim Menu$(NumberOfExamples,3)
Menu$(1,1)="Matrix With Gravity"
Menu$(1,2)="Shows how to have gravity on a matrix."
Menu$(1,3)="Sixty Squares"
Menu$(2,1)="Bouncy Ball On A Matrix"
Menu$(2,2)="Adds bouncing up and down to the gravity example."
Menu$(2,3)="Sixty Squares"
Menu$(NumberOfExamples,1)="EXIT PROGRAM"
Menu$(NumberOfExamples,2)="Will exit this program."
mmr=100+rnd(100)
mmg=100+rnd(100)
mmb=100+rnd(100)
repeat
cls
set text size 18
ink rgb(0,255,0),0
Center Text Screen widtH()/2,0,"SELECT AN EXAMPLE."
CHOSEN=0
for i = 1 to NumberOfExamples
ink rgb(255,255,255),0
if mousex()>0 and Mousex()<Text width(Menu$(i,1)) and Mousey()>i*20-MYOFF and Mousey()<i*20+Text Height(Menu$(i,1))-MYOFF
ink rgb(mmr,mmg,mmb),0
CHOSEN=i
endif
Text 0,i*20-MYOFF,Menu$(i,1)
next i
ink rgb(mmr,mmg,mmb),0
box 0,screen height()-80,screen width(),screen height()
ink rgb(255,255,255),0
if Chosen>0
Text 0,Screen height()-50,Menu$(chosen,2)
set text size 16
ink rgb(mmr+55,mmg+55,mmb+55),0
if Menu$(Chosen,3)>"" then Text 0,Screen height()-25,"Author: "+Menu$(chosen,3)
endif
`MYOFF=MYOFF+5*downkey()-5*upkey()
if MyOFF<0 then MYOFF=0
if MYOFF>NumberOfExamples*20 then MYOFF=NumberOfExamples*20
sync
until mouseclick()=1 and chosen>0
cls
if Chosen=1 then gosub Matrix_With_Gravity
if Chosen=2 then gosub Bounce
if Chosen=NumberOfExamples then end
rem ******************************************************************
rem MATRIX WITH GAVITY EXAMPLE
rem ******************************************************************
rem THIS IS NOT RELATED TO THIS EXAMPLE
Matrix_With_Gravity:
rem Allow the camera to see far away... 10000 units to be exact.
set camera range 1,10000
rem Create an image to put on the matrix.
create bitmap 1,10,10
ink rgb(0,155,0),0
box 0,0,10,10
ink rgb(0,255,0),0
for d = 1 to 30
dot rnd(10),rnd(10)
next d
get image 1,0,0,10,10
delete bitmap 1
rem Make an image to put on the UGLY sky
create bitmap 1,10,10
ink rgb(0,0,155),0
box 0,0,10,10
ink rgb(0,0,255),0
for d = 1 to 30
dot rnd(10),rnd(10)
next d
get image 2,0,0,10,10
delete bitmap 1
rem Create the player
make object sphere 1,10
rem Make a giant cube to be our ugly sky
make object cube 2,-8000
texture object 2,2
rem Make the object insensetive to light. I just specefied random things for everything leading up to light.
set object 2,1,0,1,1,0,1
rem Create the matrix.
Make matrix 1,1000,1000,20,20
rem Make the matrix into small random heights.
randomize matrix 1,5
rem Texture our matrix
prepare matrix texture 1,1,1,1
rem Create our little hill so you can test the gavity. This is not very important.
for h = 4 to 10
set matrix height 1,5,h,h*10
set matrix height 1,5,h+1,h*10
set matrix height 1,6,h+1,h*10
set matrix height 1,6,h,h*10
if h>7
set matrix height 1,5,h,-1*h*10
set matrix height 1,5,h+1,-1*h*10
set matrix height 1,6,h+1,-1*h*10
set matrix height 1,6,h,-1*h*10
endif
next h
rem Finally, update our changes to the matrix.
update matrix 1
rem Make the size of the text 32 and the color yellow.
set text size 32
ink rgb(255,255,0),0
rem Start the loop
do
rem Make the variable "OnFloor" into 0 to say that the player is not on the floor. If the player is on the floor then it will be changed to 1 later.
OnFloor=0
rem rotate our sky quickly for no reason.
rotate object 2,wrapvalue(object angle x(2)+5),wrapvalue(object angle y(2)+5),wrapvalue(object angle z(2)+5)
rem Print the text.
center text screen width()/2,0,"MATRIX AND GRAVITY DEMO"
rem Define the player's X,Y and Z positions and store them in variables.
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
rem Make the pull of gravity get stronger and stronger downwards.
Grav#=Grav#-0.05
rem Add the pull of gravity to where you are on the Y axis (up and down)
Y#=Y#+Grav#
rem If where you are on the Y axis goes under the terrain, then make it on top of the terrain and make the pull of gravity nothing.
rem Also, make it so that you are on the floor when this happens by changing the Variable "OnFloor" to 1. Furthermore, stop making the
rem gravity pull you down or up by setting it to 0.
if Y#<Get Ground Height(1,x#,z#)+5 then y#=Get Ground height(1,x#,z#)+5 : Grav#=0.0 : OnFloor=1
rem Alright, you don't want to be able to go off of the terrain, do you? So, to fix that we will add some bounds to the matrix. The matrix is 1000x1000.
rem So, if the player goes past that 1000 mark then he can just go back in it. We need to do this for the X and Z axis.
rem Let's handle the X axis:
if x#>1000 then x#=1000
if x#<0 then x#=0
rem Now, let's handle the Z axis!
if z#>1000 then z#=1000
if z#<0 then z#=0
rem Finally, place the player where it should be.
position object 1,x#,y#,z#
rem Put the camera behind the player.
position camera newxvalue(x#,object angle y(1),-40),y#+20,newzvalue(z#,object angle y(1),-40)
rem Make it look at the player.
point camera x#,y#,z#
rem If the camera goes under the terrain, then put it on top.
if camera position y()<get ground height(1,Camera position x(),Camera position z())+4
position camera Camera position x(),get ground height(1,Camera position x(),Camera position z())+4,camera position z()
endif
rem Control the player using the arrow keys.
if upkey() then move object 1,2
if downkey() then move object 1,-2
if leftkey() then yrotate object 1,wrapvalue(Object angle y(1)-1)
if rightkey() then yrotate object 1,wrapvalue(Object angle y(1)+1)
rem When you press space, the pull of gravity goes upwards, pulling you up too. In other words, you are jumping :)
if spacekey() and OnFloor=1 then Grav#=2.0
rem When you hit escape, then you return the the main menu. (NOT RELATED TO THIS EXAMPLE)
if escapekey() then goto Main_Menu
rem Refresh the screen
sync
rem Let's do it again!
loop
Goto Main_Menu
rem *******************************************************************
rem BOUNCY BALL ON MATRIX EXAMPLE
rem *******************************************************************
Bounce:
rem Allow the camera to see far away... 10000 units to be exact.
set camera range 1,10000
rem Create an image to put on the matrix.
create bitmap 1,10,10
ink rgb(155,0,0),0
box 0,0,10,10
ink rgb(255,0,0),0
for d = 1 to 30
dot rnd(10),rnd(10)
next d
get image 1,0,0,10,10
delete bitmap 1
rem Make an image to put on the UGLY sky
create bitmap 1,10,10
ink rgb(0,0,155),0
box 0,0,10,10
ink rgb(0,0,255),0
for d = 1 to 30
dot rnd(10),rnd(10)
next d
get image 2,0,0,10,10
delete bitmap 1
rem Create the player
make object sphere 1,10
rem Make a giant cube to be our ugly sky
make object cube 2,-8000
texture object 2,2
rem Make the object insensetive to light. I just specefied random things for everything leading up to light.
set object 2,1,0,1,1,0,1
rem Create the matrix.
Make matrix 1,1000,1000,20,20
rem Make the matrix into small random heights.
randomize matrix 1,5
rem Texture our matrix
prepare matrix texture 1,1,1,1
rem Create our little hill so you can test the gavity. This is not very important.
for h = 4 to 10
set matrix height 1,5,h,h*20
set matrix height 1,5,h+1,h*20
set matrix height 1,6,h+1,h*20
set matrix height 1,6,h,h*20
if h>7
set matrix height 1,5,h,-1*h*20
set matrix height 1,5,h+1,-1*h*20
set matrix height 1,6,h+1,-1*h*20
set matrix height 1,6,h,-1*h*20
endif
next h
rem Finally, update our changes to the matrix.
update matrix 1
rem Make the size of the text 32 and the color yellow.
set text size 32
ink rgb(255,255,0),0
rem Set the weight of the ball to 1 unit. Try changing this and see what effect it has on the ball.
Weight#=1.0
rem Start the loop
do
rem Make the variable "OnFloor" into 0 to say that the player is not on the floor. If the player is on the floor then it will be changed to 1 later.
OnFloor=0
rem rotate our sky quickly for no reason.
rotate object 2,wrapvalue(object angle x(2)+5),wrapvalue(object angle y(2)+5),wrapvalue(object angle z(2)+5)
rem Print the text.
center text screen width()/2,0,"MATRIX AND BOUNCE DEMO"
rem Define the player's X,Y and Z positions and store them in variables.
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
rem Make the pull of gravity get stronger and stronger downwards.
Grav#=Grav#-0.05
rem Add the pull of gravity to where you are on the Y axis (up and down)
Y#=Y#+Grav#
rem If where you are on the Y axis goes under the terrain, then make it on top of the terrain and make the pull of gravity nothing.
rem Also, make it so that you are on the floor when this happens by changing the Variable "OnFloor" to 1.
rem Make the gravity push you upwards by 75% of the push before, no matter what by finding the absolute balue of the number (Absolute value basically makes a number positive)
rem The ABS(Value) command is used for this. This 75% will change based on the weight of the ball.
if Y#<Get Ground Height(1,x#,z#)+5 then y#=Get Ground height(1,x#,z#)+5 : Grav#=abs(Grav#*(0.75/Weight#)) : OnFloor=1
rem If the push gets this low, then just stop bouncing.
if Grav#>0 and Grav#<0.5 then Grav#=0.0
rem Alright, you don't want to be able to go off of the terrain, do you? So, to fix that we will add some bounds to the matrix. The matrix is 1000x1000.
rem So, if the player goes past that 1000 mark then he can just go back in it. We need to do this for the X and Z axis.
rem Let's handle the X axis:
if x#>1000 then x#=1000
if x#<0 then x#=0
rem Now, let's handle the Z axis!
if z#>1000 then z#=1000
if z#<0 then z#=0
rem Finally, place the player where it should be.
position object 1,x#,y#,z#
rem Put the camera behind the player.
position camera newxvalue(x#,object angle y(1),-40),y#+20,newzvalue(z#,object angle y(1),-40)
rem Make it look at the player.
point camera x#,y#,z#
rem If the camera goes under the terrain, then put it on top.
if camera position y()<get ground height(1,Camera position x(),Camera position z())+4
position camera Camera position x(),get ground height(1,Camera position x(),Camera position z())+4,camera position z()
endif
rem Control the player using the arrow keys.
if upkey() then move object 1,2
if downkey() then move object 1,-2
if leftkey() then yrotate object 1,wrapvalue(Object angle y(1)-1)
if rightkey() then yrotate object 1,wrapvalue(Object angle y(1)+1)
rem When you press space, the pull of gravity goes upwards, pulling you up too. In other words, you are jumping :)
if spacekey() and OnFloor=1 then Grav#=2.0
rem When you hit escape, then you return the the main menu. (NOT RELATED TO THIS EXAMPLE)
if escapekey() then goto Main_Menu
rem Refresh the screen
sync
rem Let's do it again!
loop
goto Main_MEnu
And here is the source code that you want alone. LOTS easier to read:
rem ******************************************************************
rem MATRIX WITH GAVITY EXAMPLE
rem ******************************************************************
sync on
sync rate 60
set text font "verdana"
color backdrop 0
rem Allow the camera to see far away... 10000 units to be exact.
set camera range 1,10000
rem Create an image to put on the matrix.
create bitmap 1,10,10
ink rgb(0,155,0),0
box 0,0,10,10
ink rgb(0,255,0),0
for d = 1 to 30
dot rnd(10),rnd(10)
next d
get image 1,0,0,10,10
delete bitmap 1
rem Make an image to put on the UGLY sky
create bitmap 1,10,10
ink rgb(0,0,155),0
box 0,0,10,10
ink rgb(0,0,255),0
for d = 1 to 30
dot rnd(10),rnd(10)
next d
get image 2,0,0,10,10
delete bitmap 1
rem Create the player
make object sphere 1,10
rem Make a giant cube to be our ugly sky
make object cube 2,-8000
texture object 2,2
rem Make the object insensetive to light. I just specefied random things for everything leading up to light.
set object 2,1,0,1,1,0,1
rem Create the matrix.
Make matrix 1,1000,1000,20,20
rem Make the matrix into small random heights.
randomize matrix 1,5
rem Texture our matrix
prepare matrix texture 1,1,1,1
rem Create our little hill so you can test the gavity. This is not very important.
for h = 4 to 10
set matrix height 1,5,h,h*10
set matrix height 1,5,h+1,h*10
set matrix height 1,6,h+1,h*10
set matrix height 1,6,h,h*10
if h>7
set matrix height 1,5,h,-1*h*10
set matrix height 1,5,h+1,-1*h*10
set matrix height 1,6,h+1,-1*h*10
set matrix height 1,6,h,-1*h*10
endif
next h
rem Finally, update our changes to the matrix.
update matrix 1
rem Make the size of the text 32 and the color yellow.
set text size 32
ink rgb(255,255,0),0
rem Start the loop
do
rem Make the variable "OnFloor" into 0 to say that the player is not on the floor. If the player is on the floor then it will be changed to 1 later.
OnFloor=0
rem rotate our sky quickly for no reason.
rotate object 2,wrapvalue(object angle x(2)+5),wrapvalue(object angle y(2)+5),wrapvalue(object angle z(2)+5)
rem Print the text.
center text screen width()/2,0,"MATRIX AND GRAVITY DEMO"
rem Define the player's X,Y and Z positions and store them in variables.
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
rem Make the pull of gravity get stronger and stronger downwards.
Grav#=Grav#-0.05
rem Add the pull of gravity to where you are on the Y axis (up and down)
Y#=Y#+Grav#
rem If where you are on the Y axis goes under the terrain, then make it on top of the terrain and make the pull of gravity nothing.
rem Also, make it so that you are on the floor when this happens by changing the Variable "OnFloor" to 1. Furthermore, stop making the
rem gravity pull you down or up by setting it to 0.
if Y#<Get Ground Height(1,x#,z#)+5 then y#=Get Ground height(1,x#,z#)+5 : Grav#=0.0 : OnFloor=1
rem Alright, you don't want to be able to go off of the terrain, do you? So, to fix that we will add some bounds to the matrix. The matrix is 1000x1000.
rem So, if the player goes past that 1000 mark then he can just go back in it. We need to do this for the X and Z axis.
rem Let's handle the X axis:
if x#>1000 then x#=1000
if x#<0 then x#=0
rem Now, let's handle the Z axis!
if z#>1000 then z#=1000
if z#<0 then z#=0
rem Finally, place the player where it should be.
position object 1,x#,y#,z#
rem Put the camera behind the player.
position camera newxvalue(x#,object angle y(1),-40),y#+20,newzvalue(z#,object angle y(1),-40)
rem Make it look at the player.
point camera x#,y#,z#
rem If the camera goes under the terrain, then put it on top.
if camera position y()<get ground height(1,Camera position x(),Camera position z())+4
position camera Camera position x(),get ground height(1,Camera position x(),Camera position z())+4,camera position z()
endif
rem Control the player using the arrow keys.
if upkey() then move object 1,2
if downkey() then move object 1,-2
if leftkey() then yrotate object 1,wrapvalue(Object angle y(1)-1)
if rightkey() then yrotate object 1,wrapvalue(Object angle y(1)+1)
rem When you press space, the pull of gravity goes upwards, pulling you up too. In other words, you are jumping :)
if spacekey() and OnFloor=1 then Grav#=2.0
rem Refresh the screen
sync
rem Let's do it again!
loop