Alright thank you!
Right now I'm trying to get the show object part to work the way i want. It hides itself right. But, now i want each part of the tail to only show once its in the cube field again. Since its supposed to look like the snake came from another face the tail can't show on the opposite side once its done rotating. So any ideas for that would be helpful. I'll let you know if I figure anything out.
Edit:
Figured it out. Here's what I did. I added the following code to show the object when needed.
For T = 4 to TailLength
Position Object T,8,CubeSize#/2+SphereSize#/2,SpherePosZ#
Next T
Show Object SnakeHead
For S = 4 to TailLength
If Object Position X(S) < 9 then Show Object S
Next S
I added that to each of the four rotating sub routines editing them as needed for each.
I've added collision checking for the tail and it does what it supposed to for the most part. If I have the check just print out you loose it does that. But, I'm trying to make it go to a function gameover() and clear the screen and print out Sorry You loose then wait and end the program. But it's not printing what I want it to. Please help with that.
Here's what I have so far.
Set Display Mode 800,600,32
Sync On: Sync Rate 10: CLS
AutoCam Off
BackDrop On: Color BackDrop RGB(12,12,12)
`Define Variables
Setup:
CubeSize# = 18
CubeSideRight# = CubeSize#/2
CubeSideLeft# = 0-CubeSize#/2
CubeSideTop# = CubeSize#/2
CubeSideBottom# = 0-CubeSize#/2
SphereSize# = 1
SpherePosX# = 0.0
SpherePosY# = (CubeSize#/2.0)+(SphereSize#/2.0)
SpherePosZ# = 0.0
KeyValue = 1
Score = 0
SnakeHead = 3
TailLength = 7
PO = -1
Dim X(100)
Dim Z(100)
`Create Objects
LimbCube(1,CubeSize#)
`Color The Six Sides
Color Limb 1,1,RGB(0,0,255)
Color Limb 1,2,RGB(255,0,0)
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)
Make Object Sphere 2,.5
For make = 3 to TailLength
Make Object Sphere make,SphereSize#
Next make
`Color Items
Color Object 2,RGB(100,0,0)
For c = 3 to Object Count()
Color Object c,RGB(0,200,0)
Next c
`Set Camera and Object Position
Position Camera 0,25,-25 : Point Camera 0,9,-8
Position Object 1,0,0,0
Position Object 2,RND(8)-8,CubeSize#/2+.25,RND(8)-8
Position Object SnakeHead,0,CubeSize#/2+SphereSize#/2,0
For PT = SnakeHead+1 to TailLength
Position Object PT,0,CubeSize#/2+SphereSize#/2,PO
Dec PO
Next PT
`Main Loop
Start:
Do
`Get Positions for Tail
For get = 3 to TailLength
x(get) = Object Position X(get)
z(get) = Object Position Z(get)
Next get
`Allow For Constant Movement
If Upkey()=1 and KeyValue <> 2 then KeyValue = 1
If Downkey()=1 and KeyValue <> 1 then KeyValue = 2
If Rightkey()=1 and KeyValue <> 4 then KeyValue = 3
If Leftkey()=1 and KeyValue <> 3 then KeyValue = 4
If KeyValue = 1 then Move Object SnakeHead,1
If KeyValue = 2 then Move Object SnakeHead,-1
If KeyValue = 3 then Move Object Right SnakeHead,1
If KeyValue = 4 then Move Object Left SnakeHead,1
For tail = SnakeHead+1 to TailLength
Position Object tail,x(tail-1),CubeSize#/2+SphereSize#/2,z(tail-1)
Next tail
`Update Sphere Position To Variables
SpherePosX# = Object Position X(SnakeHead)
SpherePosZ# = Object Position Z(SnakeHead)
`ROTATE CUBE
If SpherePosZ# > 8 then Gosub CubeRotateTop
If SpherePosZ# < -8 then Gosub CubeRotateBottom
If SpherePosX# > 8 then Gosub CubeRotateRight
If SpherePosX# < -8 then Gosub CubeRotateLeft
For SCT = Snakehead+1 to TailLength
If Object Collision (SnakeHead,SCT) > 0
gameover()
Endif
Next SCT
If Object Collision (SnakeHead,2) > 0
Position Object 2, RND(8)-8,CubeSize#/2+.25,RND(8)-8
Inc TailLength
Make Object Sphere TailLength,SphereSize#
Color Object TailLength,RGB(0,200,0)
Score = Score + 5
Endif
FPS# = Screen FPS()
Set Cursor 0,0
Print "Position X =" ;SpherePosX#
Print "Position Z =" ;SpherePosZ#
Print Score
Print FPS#
Sync
Loop
CubeRotateTop:
For H = SnakeHead to TailLength
Hide Object H
Next H
For N=1 To 10
Rotate_GX(1,-9)
Sync
Next N
SpherePosZ# = -7
Position Object SnakeHead,SpherePosX#,SpherePosY#,SpherePosZ#
For T = 4 to TailLength
Position Object T,SpherePosX#,CubeSize#/2+SphereSize#/2,-8
Next T
Show Object SnakeHead
For S = 4 to TailLength
If Object Position Z(S) > -9 then Show Object S
Next S
Return
CubeRotateBottom:
For H = SnakeHead to TailLength
Hide Object H
Next H
For N=1 To 10
Rotate_GX(1,9)
Sync
Next N
SpherePosZ# = 7
Position Object SnakeHead,SpherePosX#,SpherePosY#,SpherePosZ#
For T = 4 to TailLength
Position Object T,SpherePosX#,CubeSize#/2+SphereSize#/2,8
Next T
Show Object SnakeHead
For S = 4 to TailLength
If Object Position Z(S) < 9 then Show Object S
Next S
Return
CubeRotateRight:
For H = SnakeHead to TailLength
Hide Object H
Next H
For N=1 To 10
Rotate_GZ(1,9)
Sync
Next N
SpherePosX# = -7
Position Object SnakeHead,SpherePosX#,SpherePosY#,SpherePosZ#
For T = 4 to TailLength
Position Object T,-8,CubeSize#/2+SphereSize#/2,SpherePosZ#
Next T
Show Object SnakeHead
For S = 4 to TailLength
If Object Position X(S) > -9 then Show Object S
Next S
Return
CubeRotateLeft:
For H = SnakeHead to TailLength
Hide Object H
Next H
For N=1 To 10
Rotate_GZ(1,-9)
Sync
Next N
SpherePosX# = 7
Position Object SnakeHead,SpherePosX#,SpherePosY#,SpherePosZ#
For T = 4 to TailLength
Position Object T,8,CubeSize#/2+SphereSize#/2,SpherePosZ#
Next T
Show Object SnakeHead
For S = 4 to TailLength
If Object Position X(S) < 9 then Show Object S
Next S
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
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
remstart Rotate_GZ
This function rotates the given object around the global (world) z axis by
the given amount.
Param obj The object to rotate
Param amount# The angle to rotate the object by
remend
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
function gameover()
ObjectCount = 0
For OC = 1 to 103
If Object Exist(OC)
Inc ObjectCount
EndiF
Next OC
For D = 1 to ObjectCount
Delete Object D
Next D
CLS
Sync
Text 200,200,"Sorry, You Loose!!!"
wait key
Gosub Setup
endfunction
I've tried using both the text command and Print.
Edit2:
Man I should really try things thoroughly first before I start asking on the forum. I figured out the game over problem and printing You loose and such.
I simply made these changes to the gameover() function.
function gameover()
CLS
Print "Sorry, You Loose!!!"
Print "Your Score Was "+str$(Score)
Sync
Wait Key
ObjectCount = 0
For OC = 1 to 103
If Object Exist(OC)
Inc ObjectCount
EndiF
Next OC
For D = 1 to ObjectCount
Delete Object D
Next D
Gosub Setup
endfunction
Turns out the sync goes after your print your text...should have known.
Anyways from now on I'm going to try to fix a problem as much as I possibly can before I as for help. It probably gets annoying to others.
On to making the movement smoother...
I was therefore I can be.