When I make and position a box in my game, the box does not show the top face. The odd thing about this is that the box on the right shows perfectly and it has almost the same code! The box is not intersecting with the camera in any way.
Here is the code of the section with the problem. The object before is called oldnum, and we want to read data from that object to span the distance between the wall and the side.
check_1:
if combined = 1
if object angle y(oldnumu) = 0
test = 0
for o = 6 to lv+6
if object position z(o) > object position z(oldnumu)-object size z(oldnumu)/2 and object position z(o) < object position z(oldnumu)+object size z(oldnumu)/2
if object position x(o) > object position x(oldnumu) then test = test +1
if object position x(o) < object position x(oldnumu) then test = test -1
endif
next o
if test = 2
px = object position x(oldnumu)
pz = object position z(oldnumu)
sz = object size z(oldnumu)
make object box num2,100+pz,50,px
set object num2,1,1,1
texture object num2,2
position object num2,pz- object size x(num2)/2,1,pz
num2 = num2+1
delete object oldnumu
oldnumu = 0
endif
if test = -2
px = object position x(oldnumu)
pz = object position z(oldnumu)
sz = object size z(oldnumu)
make object box num2,100-pz,50,px
texture object num2,2
set object num2,1,1,1
position object num2,pz+object size x(num2)/2,1,pz
num2 = num2+1
delete object oldnumu
oldnumu = 0
endif
endif
endif
return
Here is the code for the full game. WARNING: Many media references!
`TO DO:
`fix check_vertical
`make it only check for things on that x/z
`allow 90 degree angles
`put in correct scoring
`allow saving high scores
`instructions for playing
`input "enter level>",lv
#include "title.dba"
lv = 1
sync on
sync rate 30
hide mouse
autocam off
dim xs#(106)
dim zs#(106)
load music "media/music.mid",1
loop music 1
begin:
for a = 1 to 65000
if object exist(a) then delete object a
next a
cs = 0
cs2 = 0
pexpandd = 0
pexpandu = 0
`SOUND LOADING
load sound "media/bounce.wav",1
load sound "media/explode.wav",2
menu2:
`MENU FUNCTION
option = menu()
`check for exiting
if option = 4 then end
if option = 3 then instructions()
if option = 3 then goto menu2
backdrop on
ink rgb(255,0,0),0
score = 0
start:
life = lv + 1
num2 = 35000
xpos# = 0
zpos# = 0
randomize timer()
for a = 6 to 106
xs#(a) = rnd(1)
if xs#(a) = 0 then xs#(a) = -1
zs#(a) = rnd(1)
if zs#(a) = 0 then zs#(a) = -1
next a
num = 1000
gosub setup
gosub createballs
set global collision on
make object box 300,5,5,40
pos = 1
set object 300,0,0,0
color object 300,rgb(0,0,255)
cs = 0
cs2 = 0
load image "media/jezz.bmp",1
load image "media/moss.bmp",2
texture object 1,1
texture object 2,2
texture object 3,2
texture object 4,2
texture object 5,2
onumu = 12345
onumd = 12346
oldnumu = 0
`*****************************************************************************************************
`**********************************MAIN LOOP BEGINS***************************************************
`*****************************************************************************************************
do
if mouseclick()=2
if object angle y(300) = 0 then mp = 1
if object angle y(300) = 90 then mp = 2
endif
if mp = 1 and mouseclick() = 0
yrotate object 300,90
mp = 0
endif
if mp = 2 and mouseclick()=0
yrotate object 300,0
mp = 0
endif
if mouseclick()=1 then mp2 = 1
gosub pexpandu
gosub pexpandd
out:
if mouseclick()=0 and mp2 = 1
pexnumu2 = pexnumu + 2000
pexnumd2 = pexnumu + 3000
pexnumu = num
pexnumd = num + 1000
num = num + 1
cnumu = pexnumu
cnumd = pexnumd
onumu = pexnumu
onumd = pexnumd
sposx = object position x(300)
sposz = object position z(300)
pexpandu = 1
pexpandd = 1
direction = object angle y(300)
mp2 = 0
endif
gosub ballcollision
if pexpandu = 0 and pexpandd = 0 then gosub combine
if oldnumu > 0 then gosub check_1
position object 300,0+((mousex()-320)*1.000),6,0-((mousey()-240)*1.000)
ink rgb(255,255,255),0
text 100,0,"Lives: " + str$(life)
center text 320,0,"Score: " + str$(score)
if life < 1
while spacekey() = 0
set text size 72
set text font "Courier New"
center text 320,200,"GAME OVER"
set text size 24
center text 320,300,"Press Space Key to Continue"
sync
endwhile
goto begin
endif
gosub ballcheck
set cursor 0,0
sync
loop
`*******************SUB ROUTINES****************
check_1:
if combined = 1
if object angle y(oldnumu) = 0
test = 0
for o = 6 to lv+6
if object position z(o) > object position z(oldnumu)-object size z(oldnumu)/2 and object position z(o) < object position z(oldnumu)+object size z(oldnumu)/2
if object position x(o) > object position x(oldnumu) then test = test +1
if object position x(o) < object position x(oldnumu) then test = test -1
endif
next o
if test = 2
px = object position x(oldnumu)
pz = object position z(oldnumu)
sz = object size z(oldnumu)
make object box num2,100+pz,50,px
set object num2,1,1,1
texture object num2,2
position object num2,pz- object size x(num2)/2,1,pz
num2 = num2+1
delete object oldnumu
oldnumu = 0
endif
if test = -2
px = object position x(oldnumu)
pz = object position z(oldnumu)
sz = object size z(oldnumu)
make object box num2,100-pz,50,px
texture object num2,2
set object num2,1,1,1
position object num2,pz+object size x(num2)/2,1,pz
num2 = num2+1
delete object oldnumu
oldnumu = 0
endif
endif
endif
return
`*************C**O**M**B**I**N**E**************
combine:
if object exist(onumu) = 1 and object exist(onumd) = 1
if direction = 90 or direction = 270
wu = object size z(onumu)
wd = object size z(onumd)
bottom = object position x(onumd) - wd/2
oz = object position z(onumu)
oxs = wu+wd
opx = bottom + oxs/2
delete object onumu
delete object onumd
make object box onumu,5,10,oxs
position object onumu,opx,0,oz
yrotate object onumu,direction
color object onumu,rgb(255,0,0)
else
wu = object size z(onumu)
wd = object size z(onumd)
bottom = object position z(onumd) - wd/2
ox = object position x(onumu)
ozs = wu+wd
opz = bottom + ozs/2
delete object onumu
delete object onumd
make object box onumu,5,10,ozs
position object onumu,ox,0,opz
yrotate object onumu,direction
color object onumu,rgb(255,0,0)
endif
oldnumu = onumu
onumu = 12345
onumd = 12346
endif
combined = 1
return
`BALL COLLISION*********************************
ballcollision:
for a = 6 to lv+6
yrotate object a,0
move object a,zs#(a)
yrotate object a,90
move object a,xs#(a)
position object a+10000,object position x(a)-odis,2,object position z(a)
position object a+20000,object position x(a)+odis,2,object position z(a)
position object a+30000,object position x(a),2,object position z(a)-odis
position object a+40000,object position x(a),2,object position z(a)+odis
if object collision(a+10000,0) > 0 and object collision(a+10000,0) <> 300
if object collision(a+10000,0) = pexnumd
pexpandd = 0
cs2 = 0
delete object pexnumd
life = life - 1
pexnumd = 0
if sound playing(2) = 0 then play sound 2
endif
if object collision(a+10000,0) = pexnumu
pexpandu = 0
cs = 0
delete object pexnumu
life = life - 1
pexnumu = 0
if sound playing(2) = 0 then play sound 2
endif
xs#(a) = rnd(3)
if sound playing(1) = 0 and sound playing(2) = 0 then play sound 1
endif
if object collision(a+20000,0) > 0 and object collision(a+20000,0) <> 300
if object collision(a+20000,0) = pexnumd
pexpandd = 0
cs2 = 0
life = life - 1
delete object pexnumd
pexnumd = 0
if sound playing(2) = 0 then play sound 2
endif
if object collision(a+20000,0) = pexnumu
pexpandu = 0
cs = 0
life = life - 1
delete object pexnumu
pexnumu = 0
if sound playing(2) = 0 then play sound 2
endif
xs#(a) = 0 - rnd(3)
if sound playing(1) = 0 and sound playing(2) = 0 then play sound 1
endif
if object collision(a+30000,0) > 0 and object collision(a+30000,0) <> 300
if object collision(a+30000,0) = pexnumd
pexpandd = 0
cs2 = 0
delete object pexnumd
life = life - 1
pexnumd = 0
if sound playing(2) = 0 then play sound 2
endif
if object collision(a+30000,0) = pexnumu
pexpandu = 0
cs = 0
delete object pexnumu
life = life - 1
pexnumu = 0
if sound playing(2) = 0 then play sound 2
endif
zs#(a) = rnd(3)
if sound playing(1) = 0 and sound playing(2) = 0 then play sound 1
endif
if object collision(a+40000,0) > 0 and object collision(a+40000,0) <> 300
if object collision(a+40000,0) = pexnumd
pexpandd = 0
cs2 = 0
delete object pexnumd
life = life - 1
pexnumd = 0
if sound playing(2) = 0 then play sound 2
endif
if object collision(a+40000,0) = pexnumu
pexpandu = 0
cs = 0
delete object pexnumu
life = life - 1
pexnumu = 0
if sound playing(2) = 0 then play sound 2
endif
zs#(a) = 0 - rnd(3)
if sound playing(1) = 0 and sound playing(2) = 0 then play sound 1
endif
next a
return
`CREATE BALLS*******************************
createballs:
for a = 6 to lv+6
load object "media/sphere.x",a
size2 = rnd(1000)+1000
scale object a,size2,size2,size2
xpos = rnd(400) - 200
zpos = rnd(400) - 200
odis = 8 + 2
position object a,rnd(300)-150,0,rnd(300)-150
make object cube a+10000,2
hide object a+10000
position object a+10000,xpos-odis,2,zpos
make object cube a+20000,2
hide object a+20000
position object a+20000,xpos-odis,2,zpos
make object cube a+30000,2
hide object a+30000
position object a+30000,xpos,2,zpos-odis
make object cube a+40000,2
hide object a+40000
position object a+40000,xpos,2,zpos+odis
next a
return
`SETUP**********************************
setup:
make object plain 1,400,400
xrotate object 1,90
position object 1,0,0,0
color object 1,rgb(150,130,150)
make object box 2,400,300,10
position object 2,0,-100,200
make object box 3,400,300,10
position object 3,0,-100,-200
make object box 4,400,300,10
position object 4,200,-100,0
yrotate object 4,90
make object box 5,400,300,10
position object 5,-200,-100,0
yrotate object 5,90
position camera 0,400,0
xrotate camera 90
color backdrop rgb(44,172,209)
return
`CHECK FOR OUTSIDE
ballcheck:
for a = 6 to lv+6
if object position x(a) < -200 and object position x(a) > 200
x = rnd(400)-200
else
x = object position x(a)
endif
if object position z(a) < -200 and object position x(a) > 200
z = rnd(400)-200
else
z = object position z(a)
endif
position object a,x,0,z
next a
return
`pexpand*up******************************************************************
pexpandu:
if pexpandu = 1
if direction = 0 or direction = 180
if object exist(pexnumu) = 1 then delete object pexnumu
make object box pexnumu,5,10,15+cs
position object pexnumu,sposx,0,sposz + (10+cs)/2
yrotate object pexnumu,direction
else
if object exist(pexnumu) = 1 then delete object pexnumu
make object box pexnumu,5,10,15+cs
position object pexnumu,sposx + (10+cs)/2,0,sposz
yrotate object pexnumu,direction
endif
mp2 = 0
cs = cs + 2
color object pexnumu,rgb(255,0,0)
for a = 2 to 5
if object collision(pexnumu,a) = 1
pexpandu = 0
cs = 0
pexnumu = 0
goto out
endif
next a
for a = 1000 to num
if object exist(a)
if object collision(pexnumu,a) = 1 and a <> cnumd and a <> cnumu
pexpandu = 0
cs = 0
pexnumu = 0
goto out
endif
endif
next a
for a = 2000 to num+1000
if object exist(a)
if object collision(pexnumu,a) =1 and a <> cnumd and a <> cnumu
pexpandu = 0
cs = 0
pexnumu = 0
goto out
endif
endif
next a
for a = 35000 to num2
if object exist(a)
if object collision(pexnumu,a) =1
pexpandu = 0
cs = 0
pexnumu = 0
goto out
endif
endif
next a
endif
return
`pexpand*down************************************
pexpandd:
if pexpandd = 1
if direction = 0 or direction = 180
if object exist(pexnumd) = 1 then delete object pexnumd
make object box pexnumd,5,10,15+cs2
position object pexnumd,sposx,0,sposz - (10+cs2)/2
yrotate object pexnumd,direction
else
if object exist(pexnumd) = 1 then delete object pexnumd
make object box pexnumd,5,10,15+cs2
position object pexnumd,sposx - (10+cs2)/2,0,sposz
yrotate object pexnumd,direction
endif
mp2 = 0
cs2 = cs2 + 2
color object pexnumd,rgb(0,0,255)
for a = 2 to 5
if object collision(pexnumd,a) = 1
pexpandd = 0
cs2 = 0
pexnumd = 0
goto out
endif
next a
for a = 1000 to num
if object exist(a)
if object collision(pexnumd,a) = 1 and a <> cnumd and a <> cnumu
pexpandd = 0
cs2 = 0
pexnumd = 0
goto out
endif
endif
next a
for a = 2000 to num+1000
if object exist(a)
if object collision(pexnumd,a) =1 and a <> cnumd and a <> cnumu
pexpandd = 0
cs2 = 0
pexnumd = 0
goto out
endif
endif
next a
for a = 35000 to num2
if object exist(a)
if object collision(pexnumd,a) =1
pexpandd = 0
cs2 = 0
pexnumd = 0
goto out
endif
endif
next a
endif
return
function instructions()
backdrop off
ink rgb(255,255,255),0
cls : cls
do
center text 320,50,"Jezzball XP Instructions"
center text 320,80,"Use the mouse to move your pointer."
center text 320,110,"Click to begin the wallmaker."
center text 320,150,"The object of this game is to get"
center text 320,180,"75% of the area filled."
center text 320,210,"To do this you must build walls to"
center text 320,240,"section off areas and trap balls."
center text 320,310,"Press the space key to return to the menu"
if spacekey()=1 then exitfunction ; backdrop on
sync
loop
cls
endloop:
endfunction
"Computers in the future may weigh no more then
1.5 tons. - Popular Mechanics, 1949