make object plain 2,200,200
rotate object 2,90,0,0
position object 2,0,0,0
global totalobjects as integer
global objecttype as integer
type object
x as float
y as float
z as float
selected as boolean
endtype
position camera 0,10,0
dim object(0) as object
totalobjects=0
objecttype=1
cube=1
cone=2
cylinder=3
sphere=4
do
control camera using arrowkeys 0,1,1
if keystate(30)=1
if press=0
inc objecttype
press=1
endif
endif
if keystate(30)=1
press=0
endif
if keystate(32)=1
if press2=0
dec objecttype
press2=1
endif
endif
if keystate(32)=0
press2=0
endif
if objecttype<1
objecttype=4
endif
if objecttype>4
objecttype=1
endif
if spacekey()=1
if press3=0
press3=1
array insert at bottom object
if objecttype=cube
make object cube totalobjects+1,5
endif
if objecttype=cone
make object cone totalobjects+1,5
endif
if objecttype=cylinder
make object cylinder totalobjects+1,5
endif
if objecttype=sphere
make object sphere totalobjects+1,5
endif
inc totalobjects
object(totalobjects).selected=1
endif
endif
if spacekey()=0
press3=0
endif
if mouseclick()=1
for b=1 to totalobjects
if object(b).selected=1
object(b).selected=0
endif
next b
a=pick object(mousex(),mousey(),1,1000)
object(a).selected=1
endif
for b=1 to totalobjects
if object(b).selected=1
circle object screen x(b), object screen y(b),4
if upkey()=1
inc object position z(b), 0.5
endif
if downkey()=1
dec object position z(b), 0.5
endif
if rightkey()=1
inc object position x(b), 0.5
endif
if leftkey()=1
dec object position x(b), 0.5
endif
if keystate(17)=1
inc object position y(b),0.5
endif
if keystate(31)=1
dec object position y(b),0.5
endif
endif
next b
loop
It should work.... but when you press the spacebar to make a new object, it just crashes. But - lemme explain all the commands used. i'll cover arrays first.
DIM arrayname(number of rows)
This command creates an array. DIM abcd(3) would create a table 1 row wide, and 3 rows down, with 3 points of data
0
0
0
DIM abcd(3,3) would create a table 3 rows wide, and 3 rows down, with 3*3, or 9 points of data
0 0 0
0 0 0
0 0 0
DIM abcd(3,3,3) would create a table 3 rows wide, three rows down, and 3 rows deep. You can't show it, because it's three dimensional. But this would create 27, or 3^3 (three to the power of 3, the number of dimensions) points of data.
DIM abcd(3,3,3,3) would create an array 81, (three to the power of four) points of data, and
DIM abcd(3,3,3,3,3) would create an array with 243, or 3 to the power of 5 points of data.
I've only ever used a one dimensional array, but you can have up to five dimensions, no more.
Types:
Types are incredibly useful. From my point of view, they add more dimensions.
type
health as integer
dead as boolean
damage as integer
endtype
DIM player(3)
player(1).health=100
player(1).dead=0
player(1).damage=20
player(2).health=9
player(2).dead=1
player(2).damage=25
player(3).health=100
player(3).dead=1
player(3).damage=200
Player one has 100 health, isn't dead, and has a damage of 20
player two has a health of nine, is dead, and a damage of 25
player three has 100 health, is dead, and a damage of 200
Types store different values for each point on the table.
Now, this table of 1 wide, and three deep, has three variables stored for each of the points on the table. In essence, it is an easier to use, easier to read, two dimensional table of 3,3.
You can also have types within types
type vector
x as float
y as float
z as float
endtype
type object
color as dword
size as integer
name as string
position as vector
endtype
DIM potato(2)
potato(1)color=rgb(13,123,4)
potato(1).size=3
potato(1).name="'Tater"
potato(1).position.x=2
potato(1).position.y=5
potato(1).position.z=3
potato(2)color=rgb(133,13,45)
potato(2).size=4
potato(2).name="Hash"
potato(2).position.x=4
potato(2).position.y=2
potato(2).position.z=1
aaand types within types within types if you want but... i don't wanna go there.
array insert at bottom object
array insert at bottom is the command, object is the name of the array. It creates another point of data at the bottom... i'm not quite sure where it inserts the new number on 2d+ arrays, but
dim yahoo(3)
array insert at bottom yahoo
yahoo(4)=2
print str$(yahoo)
`str$ turns numbers into strings, optionally, str$(variable, decimal places)
Speaking of which, integer types, im sure you know about most of them, but why did i put color as a double word variable? (DWORD)
a word variable has 16 bits, which is how much is needed to store a color for a 16 pit, 32,000 color screen. A 32 bit screen, what most people have, has around 16,000,000 colors. If a word is 16 bits.... then what's a double word?
RGB returns the value of the color in it's 32 digit 1010010101010... (machine code) form, based on it's red,green, and blue components...
AAAnnyways, the command
GLOBAL abcdsljf
creates a variable that will be accessable anywhere in the program. I put
as integer
after them, because, even though im pretty sure variables always start out as integers, its just a habit.
Keystate is an annoying but necessary command. Instead of typing in
if A key()=1
you have to type in
if keystate(30)=1
Basically, from top left starting at squiggly, to bottom right ending at CTRL, you count. the one key is two, three is four, w is seventeen, zkey is 43.... etc... etc...
parrot