ok,. so, basically what i have is a cube which rotates when i get to one side of the cube, and i have a little "apple" piece that appears randomly and wen u go over it with your player the piece is deleted and you get a point, the problem I'm having is i want the piece to rotate around the global x and z axis whenever the cube rotates, basically so that if the piece appears randomly on the bottom of the cube i can successfully rotate everything by moving so that the piece is on top and i can "eat" it.
Here's the code I got so far. Basically everything works the way I want except for the rotating of the piece thing.
Set Display Mode 800,600,32
Sync On: Sync Rate 60: CLS 0
AutoCam Off
BackDrop On: Color BackDrop 0
Randomize Timer()
`Define Variables
CubeSize# = 360
CubeSideRight# = CubeSize#/2
CubeSideLeft# = 0-CubeSize#/2
CubeSideTop# = CubeSize#/2
CubeSideBottom# = 0-CubeSize#/2
PlayerSize# = 40
PlayerPosX# = 0.0
PlayerPosY# = (CubeSize#/2.0)+(PlayerSize#/2.0)
PlayerPosZ# = 0.0
PlayerSpeed = 1
KeyValue = 0
Percentage = 60
Score=0
AppleSize#=20
AppleExists=1
ApplePosX=rnd(360)
ApplePosZ=rnd(360)
`Create Objects
LimbCube(1,CubeSize#)
`Color The Six Sides
Color Limb 1,1,rgb(0,0,255)
Color Limb 1,2,rgb(255,255,255)
Color Limb 1,3,rgb(0,255,0)
Color Limb 1,4,rgb(0,255,255)
Color Limb 1,5,rgb(255,0,255)
Color Limb 1,6,rgb(255,255,0)
Position Object 1,0,0,0
Ghost Object On 1
Disable Object Zwrite 1
Make Object Sphere 2,PlayerSize#
Color Object 2, rgb(0,255,0)
Position Object 2,0,CubeSize#/2+PlayerSize#/2,0
`Make Apple
Make Object Sphere 1000,AppleSize#
Color Object 1000,rgb(255,0,0)
Position Object 1000,ApplePosX-180,CubeSize#/2+AppleSize#/2,ApplePosZ-180
`Set Camera
Position Object 2,0,CubeSize#/2+PlayerSize#/2,0
Position Camera 0,600,-400 : Point Camera 0,200,-100
`Main Loop
Do
`Print Score To Screen
Center Text Screen Width()/2,5,"Score:" + str$(Score)
`Allow For Constant Movement
If Upkey()=1 then KeyValue = 1
If Downkey()=1 then KeyValue = 2
If Rightkey()=1 then KeyValue = 3
If Leftkey()=1 then KeyValue = 4
If KeyValue = 1 then Move Object 2,PlayerSpeed
If KeyValue = 2 then Move Object 2,-PlayerSpeed
If KeyValue = 3 then Move Object Right 2,PlayerSpeed
If KeyValue = 4 then Move Object Left 2,PlayerSpeed
`Update Sphere Position To Variables
PlayerPosX# = Object Position X(2)
PlayerPosZ# = Object Position Z(2)
If Intersect Object (2, Object Position X(1000),Object Position Y(1000)-50,Object Position Z(1000),Object Position X(1000),Object Position Y(1000),Object Position Z(1000))>0
Delete Object 1000
AppleExists=0
Score=Score+1
Endif
`Create apple
If AppleExists=0
Make Object Sphere 1000,AppleSize#
Color Object 1000,rgb(255,0,0)
`Randomize Where Apple Is Created
ApplePosX=rnd(360)
ApplePosY=rnd(360)
ApplePosZ=rnd(360)
AppleLocation=1+rnd(5)
If AppleLocation=1
Position Object 1000,ApplePosX-180,CubeSize#/2+AppleSize#/2,ApplePosZ-180
Endif
If AppleLocation=2
Position Object 1000,ApplePosX-180,0-CubeSize#/2+AppleSize#/2,ApplePosZ-180
Endif
If AppleLocation=3
Position Object 1000,0-CubeSize#/2+AppleSize#/2,ApplePosY-180,ApplePosZ-180
Endif
If AppleLocation=4
Position Object 1000,CubeSize#/2+AppleSize#/2,ApplePosY-180,ApplePosZ-180
Endif
If AppleLocation=5
Position Object 1000,ApplePosX-180,ApplePosY-180,0-CubeSize#/2+AppleSize#/2
Endif
If AppleLocation=6
Position Object 1000,ApplePosX-180,ApplePosY-180,CubeSize#/2+AppleSize#/2
Endif
AppleExists=1
Sync
Endif
EZro_Set OBJECT ANGLE X(1000),OBJECT ANGLE Y(1000),OBJECT ANGLE Z(1000)
`Rotate Cube
If PlayerPosZ# > CubeSideTop# then Gosub CubeRotateTop
If PlayerPosZ# < CubeSideBottom# then Gosub CubeRotateBottom
If PlayerPosX# > CubeSideRight# then Gosub CubeRotateRight
If PlayerPosX# < CubeSideLeft# then Gosub CubeRotateLeft
Sync
Loop
CubeRotateTop:
Hide Object 2
For N=1 To 30
Rotate_GX(1,-3)
`Rotate Apple
RotateAroundPoint(100,0,0,0,-3,180)
Sync
Next N
PlayerPosZ# = CubeSideBottom#
Position Object 2,PlayerPosX#,PlayerPosY#,PlayerPosZ#
Show Object 2
Return
CubeRotateBottom:
Hide Object 2
For N=1 To 30
Rotate_GX(1,3)
`Rotate Apple
EZro_GX 3
RotateAroundPoint(100,0,0,0,3,180)
Sync
Next N
PlayerPosZ# = CubeSideTop#
Position Object 2,PlayerPosX#,PlayerPosY#,PlayerPosZ#
Show Object 2
Return
CubeRotateRight:
Hide Object 2
For N=1 To 30
Rotate_GZ(1,3)
`Rotate Apple
EZro_GZ 3
RotateAroundPoint(100,0,0,0,3,180)
Sync
Next N
PlayerPosX# = CubeSideLeft#
Position Object 2,PlayerPosX#,PlayerPosY#,PlayerPosZ#
Show Object 2
Return
CubeRotateLeft:
Hide Object 2
For N=1 To 30
Rotate_GZ(1,-3)
`Rotate Apple
EZro_GZ -3
RotateAroundPoint(100,0,0,0,-3,180)
Sync
Next N
PlayerPosX# = CubeSideRight#
Position Object 2,PlayerPosX#,PlayerPosY#,PlayerPosZ#
Show Object 2
Return
Function LimbCube(CubeNum,Size#)
Offset#=Size#/2 : MeshNum=2000 : PlainNum=2000
Make Object Cube CubeNum,Size#
Make Object Plain PlainNum,Size#,Size#
Make Mesh From Object MeshNum,PlainNum
Add Limb CubeNum, 1, 2000: Offset Limb CubeNum,1,0,0,0-Offset#
Add Limb CubeNum, 2, 2000: Rotate Limb CubeNum,2,0,90,0: Offset Limb CubeNum,2,0-Offset#,0,0
Add Limb CubeNum, 3, 2000: Rotate Limb CubeNum,3,0,180,0: Offset Limb CubeNum,3,0,0,Offset#
Add Limb CubeNum, 4, 2000: Rotate Limb CubeNum,4,0,270,0: Offset Limb CubeNum,4,Offset#,0,0
Add Limb CubeNum, 5, 2000: Rotate Limb CubeNum,5,270,0,0: Offset Limb CubeNum,5,0,0-Offset#,0
Add Limb CubeNum, 6, 2000: Rotate Limb CubeNum,6,90,0,0: Offset Limb CubeNum,6,0,Offset#,0
Set Object Cull CubeNum,0
Delete Mesh MeshNum
Delete Object PlainNum
Hide Limb CubeNum,0
EndFunction
`Rotate Object Around Global Z-axis
function rotate_GZ(obj,amount#)
rem Rotating around the global Z axis is trivial
rem as it is the first rotation anyway in the default ZYX rotation order
rotate object obj,object angle x(obj),object angle y(obj),object angle z(obj)+amount#
endfunction
`Rotate Object Around Global X-axis
function rotate_GX(obj as integer,amount# as float)
rem get normal vectors for X, Y, and Z axes of the object
x#=Object Position X(obj):y#=Object Position Y(obj):z#=Object Position Z(obj)
move object right obj,1
xx#=Object Position X(obj)-x#:xy#=Object Position Y(obj)-y#:xz#=Object Position Z(obj)-z#
move object left obj,1:move object up obj,1
yx#=Object Position X(obj)-x#:yy#=Object Position Y(obj)-y#:yz#=Object Position Z(obj)-z#
move object down obj,1:move object obj,1
zx#=Object Position X(obj)-x#:zy#=Object Position Y(obj)-y#:zz#=Object Position Z(obj)-z#
move object obj,-1
rem rotate the vectors
xx1#=xx#
xy1#=xy#*cos(amount#)-xz#*sin(amount#)
xz1#=xz#*cos(amount#)+xy#*sin(amount#)
zx1#=zx#
zy1#=zy#*cos(amount#)-zz#*sin(amount#)
zz1#=zz#*cos(amount#)+zy#*sin(amount#)
rem calculate angle z
zr#=atanfull(xy1#,xx1#)
rem calculate angle y
xx2#=xx1#*cos(zr#)+xy1#*sin(zr#)
xy2#=xy1#*cos(zr#)-xx1#*sin(zr#)
xz2#=xz1#
zx2#=zx1#*cos(zr#)+zy1#*sin(zr#)
zy2#=zy1#*cos(zr#)-zx1#*sin(zr#)
zz2#=zz1#
yr#=atanfull(xx2#,xz2#)-90
rem calculate angle x
zx3#=zx2#*cos(yr#+90)-zz2#*sin(yr#+90)
zy3#=zy2#
xr#=atanfull(zy3#,zx3#)+180
if xr#+1>xr# and yr#+1>yr# and zr#+1>zr#
rotate object obj,xr#,yr#,zr#
endif
endfunction
`Rotate Apple Around Point
Function RotateAroundPoint(ObNum,x#,y#,z#,angle#,distance#)
NewX#=newxvalue(x#,Angle#,distance#)
NewZ#=newzvalue(z#,Angle#,distance#)
Position object 1000,NewX#,y#,NewZ#
endfunction