Sync on:Sync Rate 60:Autocam Off
 
autocam off
Type Coordinates
   x as float
   y as float
   z as float
endtype
 
Type Direction
   Up as Boolean
   Down as Boolean
   Left as Boolean
   Right as Boolean
Endtype
 
Type pacstuff
   pos as coordinates
   facing as coordinates
   mouth_ang as float
   mouth_dir as float
Endtype
 
Type Colors
   Red as DWord
   Green as DWord
   Blue as DWord
   Yellow as DWord
   Pink as DWord
Endtype
 
Global Color as Colors
Color.red=rgb(255,0,0)
Color.green=Rgb(0,255,0)
Color.blue=rgb(0,0,255)
Color.yellow=rgb(255,255,0)
Color.pink=rgb(255,128,255)
 
Global IPacMan as pacstuff
Global Object as Coordinates
Global Target as Coordinates
Global AID as Coordinates
Global Camera As Coordinates
Global Limb As Coordinates
Global Clear as Direction
Global Score as Integer
Global Glow as Integer
Global GlowDir as Integer
#Constant AI=6
#Constant PacMan=1000
 
 
IPacMan.mouth_ang=0
IPacMan.mouth_dir=3
 
Make_PacMan():Scale Object PacMan,80,80,80;Set Object Collision To Boxes PacMan
Position Object PacMan,80,5,20
Make Object Cube PacMan+1,7.5:Set Object Collision To Boxes PacMan+1:Hide Object PacMan+1
 
Make_Ghost(1010)
Scale Object 1010,80,80,80
Color Object 1010,Color.red:Color Limb 1010,2,Rgb(200,200,255):Color Limb 1010,3,Rgb(200,200,255)
Position Object 1010,80,7.5,80
 
Clean_AI()
 
 
Make Object Sphere 1,1,8,8
Make Object Sphere 2,2,8,8
Color Object 2,RGB(255,255,0)
Set Object Emissive 2,Rgb(150,150,0)
Make Object Box 3,10,8,10
Color Object 3,Rgb(0,0,255)
Set Object Emissive 3,Rgb(0,0,50)
Make Object Box 4,10,8,5
Color Object 4,Rgb(200,100,0)
Ghost Object On 4
 
Create Bitmap 1,256,256
Ink RGB(100,100,100),0
Box 0,0,255,255
Ink RGB(255,255,255),0
Get Image 1,0,0,255,255
Set Current Bitmap 0
Delete Bitmap 1
 
Make Matrix 1,150,150,15,15
Prepare Matrix Texture 1,1,1,1
Fill Matrix 1,0,1
Position Matrix 1,5,0,5
 
Restore Maze
Obj=1
For y=1 to 15
   For x=1 to 15
      Read obj_type
      If Object Exist(obj_type)
         new=Obj+(obj_type)*2000
         Clone Object new,obj_type
         Position Object new,x*10,5,y*10
         Set Object Collision To Boxes new
         obj=obj+1
      Endif
   Next x
Next y
For i = 1 to 4
   Delete Object i
Next i
 
Score=0
Do
   Glow_Dots()
   Move_PacMan()
   Move_Camera()
   Set Cursor 0,0:Print Score
   Sync
Loop
 
Function Move_Camera()
   Set_AI(PacMan)
   Rotate Object AI,0,0,0
   Move Object AI,-30
   Move Object Up AI,70
   Return_AI()
   Set Camera to Follow AID.x,AID.y,AID.z,0,5,0,5,0
   Point Camera Object.x,Object.y,Object.z
Endfunction
 
Function Move_PacMan()
   Dot_Collision(0)
   Check_Direction()
   If Upkey() And Clear.up
      Rotate Object PacMan,0,0,0
      Clip_Position_X()
   Endif
   If Downkey() And Clear.down
      Rotate Object PacMan,0,180,0
      Clip_Position_X()
   Endif
   If Leftkey() And Clear.left
      Rotate Object PacMan,0,270,0
      Clip_Position_Z()
   Endif
   If RightKey() And Clear.right
      Rotate Object PacMan,0,90,0
      Clip_Position_Z()
   Endif
   Dot_Collision(1)
   Move Object PacMan,.5
   col_obj=Object Collision (PacMan,0)
   If col_obj>2000 And col_obj<3000
      Delete Object col_obj
      Score=Score+1
   Endif
   If col_obj>4000 And col_obj<5000
      Delete Object col_obj
      Score=Score+10
   Endif
   If col_obj>6000 And col_obj<9000 then Move Object PacMan,-.5
   Return_Object(PacMan)
   If Object.x>150 Then Position Object PacMan,5,Object.y,Object.z
   If Object.x<5 Then Position Object PacMan,150,Object.y,Object.z
   Loop_PacMan()
Endfunction
 
Function Dot_Collision(on as boolean)
   For i = 2000 to 2300
      If Object Exist(i)
         If on
            Set Object Collision On i
         Else
            Set Object Collision off i
         Endif
      Endif
      j=i+2000
      If Object Exist(j)
         If on
            Set Object Collision On j
         Else
            Set Object Collision off j
         Endif
      Endif
   Next i
EndFunction
 
Function Glow_Dots()
   Glow=Glow+GlowDir
   For i = 4000 to 5000
      If Object Exist(i)
         Set Object Emissive i,rgb(Glow,Glow,0)
      Endif
   Next i
   If Glow>200 Then GlowDir=-10:Glow=200
   If Glow<10 Then GlowDir=10:Glow=10
Endfunction
 
 
Function Clip_Position_X()
   Return_Object(PacMan)
   new_pos=Int(Object.x/10.0+0.5)*10
   Position Object PacMan,new_pos,Object.y,Object.z
EndFunction
 
Function Clip_Position_Z()
   Return_Object(PacMan)
   new_pos=Int(Object.z/10.0+0.5)*10
   Position Object PacMan,Object.x,Object.y,new_pos
EndFunction
 
Function Loop_PacMan()
   IPacMan.mouth_ang=IPacMan.mouth_ang+IPacMan.mouth_dir
   If IPacMan.mouth_ang>60.0 Then IPacMan.mouth_dir=-3
   If IPacMan.mouth_ang<1.0 Then IPacMan.mouth_dir=3
   Rotate Limb PacMan,0,IPacMan.mouth_ang,0,0
   Rotate Limb PacMan,1,180-IPacMan.mouth_ang,0,0
Endfunction
 
Function Check_Direction()
   Clear.up=1:Clear.down=1:Clear.left=1:Clear.right=1
   Return_Object(PacMan)
   test=PacMan+1
   Set Object Collision On test
   Position Object test,Object.x,Object.y,Object.z
   Rotate Object test,0,0,0
   Move Object test,10
   obj_col=Object Collision(test,0)
   If obj_col>6000 and obj_col<9000
      Clear.up=0
   Endif
   Position Object test,Object.x,Object.y,Object.z
   Rotate Object test,0,180,0
   Move Object test,10
   obj_col=Object Collision(test,0)
   If obj_col>6000 and obj_col<9000
      Clear.down=0
   Endif
   Position Object test,Object.x,Object.y,Object.z
   Rotate Object test,0,270,0
   Move Object test,10
   obj_col=Object Collision(test,0)
   If obj_col>6000 and obj_col<9000
      Clear.left=0
   Endif
   Position Object test,Object.x,Object.y,Object.z
   Rotate Object test,0,90,0
   Move Object test,10
   obj_col=Object Collision(test,0)
   If obj_col>6000 and obj_col<9000
      Clear.right=0
   Endif
   Set Object Collision Off test
Endfunction
 
Function Make_PacMan()
   Make_HemiSphere(PacMan,10)
   Set Object Cull PacMan,0
   Position object PacMan,0,-5,50
   Make Mesh From Object PacMan,PacMan
   Add Limb PacMan,1,PacMan
   Rotate Limb PacMan,1,180,0,0
   Make Object Sphere PacMan+1,1
   Make Mesh From Object PacMan+1,PacMan+1
   Delete Object PacMan+1
   Add limb PacMan,2,PacMan+1
   Add Limb PacMan,3,PacMan+1
   Offset Limb PacMan,2,3.2,3.3,-1.3
   Offset Limb PacMan,3,-3.2,3.3,-1.3
   Color Object PacMan,RGB(255,255,0)
   Set Object Emissive PacMan,RGB(80,80,0)
   Color Limb PacMan,2,0
   Color Limb PacMan,3,0
   Turn Object Right PacMan,180
   Fix Object Pivot PacMan
   Position Object PacMan,0,0,0
Endfunction
 
Function Make_Ghost(ObjectID)
   Make Object Cylinder ObjectID,10
   Make Mesh From Object ObjectID,1010
   Delete Object ObjectID
   Make Object Sphere ObjectID,10
   Add Limb ObjectID,1,ObjectID
   OffSet Limb ObjectID,1,0,-5,0
   Make Object Sphere ObjectID+1,2
   Make Mesh from Object ObjectID+1,ObjectID+1
   Delete Object ObjectID+1
   Add limb ObjectID,2,ObjectID+1
   Add Limb ObjectID,3,ObjectID+1
   Offset Limb ObjectID,2,2.2,.5,-4.2
   Offset Limb ObjectID,3,-2.2,.5,-4.2
EndFunction
 
 
 
Function Make_HemiSphere(ObjectID,Size as Float)
Make Object Sphere ObjectID,Size
verts=vertices(ObjectID)
sy#=Object Size Y(ObjectID)
for vertex=1 to verts
   vx#=vertexx(ObjectID,vertex)
   vy#=vertexy(ObjectID,vertex)
   vz#=vertexz(ObjectID,vertex)
   If vy#<-sy#/10.0 Then Position_Vertex(ObjectID,vertex,0,0,0)
next vertex
EndFunction
 
 
Function Vertices(ObjNo)
`Returns number of Vertices
`Vars
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make your meshes and memblocks
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
`Tidy
delete memblock 1
`delete mesh meshno
endfunction NoVerts
 
 
 
Function VertexX(ObjNo,VertexNo)
`Returns X position of specified vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo<NoVerts
`Get values of vertex cords
ValueX#=memblock float(1,12+((VertexNo*32)-32))
endif
`Tidy Up
delete memblock 1
`delete mesh meshno
endfunction ValueX#
 
 
 
Function VertexY(ObjNo,VertexNo)
`Returns Y position of specified vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo<NoVerts
`Get values of vertex cords
ValueY#=memblock float(1,16+((VertexNo*32)-32))
endif
`Tidy Up
delete memblock 1
`delete mesh meshno
endfunction ValueY#
 
 
 
Function VertexZ(ObjNo,VertexNo)
`Returns Z position of specified vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo<NoVerts
`Get values of vertex cords
ValueZ#=memblock float(1,20+((VertexNo*32)-32))
endif
`Tidy Up
delete memblock 1
`delete mesh meshno
endfunction ValueZ#
 
 
Function Position_Vertex(ObjNo,VertexNo,X#,Y#,Z#)
`Moves the Vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo<NoVerts
`Get values of vertex cords
write memblock float 1,12+((VertexNo*32)-32),X#
write memblock float 1,16+((VertexNo*32)-32),Y#
write memblock float 1,20+((VertexNo*32)-32),Z#
`Change the mesh
change mesh from memblock MeshNo,1
endif
`Tidy Up
change mesh ObjNo,0,MeshNo
delete memblock 1
`delete mesh meshno
endfunction
 
` This function shortens the Object Postion X/Y/Z() functions.
Function Return_Object(ObjectID)
   If Object Exist (ObjectID)
      Object.x=Object Position X(ObjectID):Object.y=Object Position Y(ObjectID):Object.z=Object Position Z(ObjectID)
   Endif
Endfunction
 
` This function shortens the Object Postion X/Y/Z() functions.
Function Return_Target(TargetID)
   If Object Exist (TargetID)
      Target.x=Object Position X(TargetID):Target.y=Object Position Y(TargetID):Target.z=Object Position Z(TargetID)
   Endif
EndFunction
 
` This function shortens the Object Postion X/Y/Z() functions for object #2
Function Return_AI()
   If Object Exist (AI)
      AID.x=Object Position X(AI):AID.y=Object Position Y(AI):AID.z=Object Position Z(AI)
   Endif
EndFunction
 
` This function shortens the Camera Postion X/Y/Z() functions.
Function Return_Camera()
Camera.x=Camera Position X():Camera.y=Camera Position Y():Camera.z=Camera Position Z()
EndFunction
 
` This function positions the AI object (#2) at ObjectID's position and set the AI to the ObjectID's orientation
Function Set_AI(ObjectID)
If Object Exist(ObjectID) And Object Exist(AI)
   Return_Object(ObjectID)
   Position Object AI,Object.x,Object.y,Object.z
   Set Object To Object Orientation AI,ObjectID
Endif
EndFunction
 
` This function deletes an old AI object and creates a new "clean" AI object.
Function Clean_AI()
   If Object Exist(AI) Then Delete Object AI
   Make Object Sphere AI,1,6,6
   Hide Object AI
   Set Object Collision To Boxes AI
   Set Object Collision Off AI
EndFunction
 
 
`This function places ObjectID at the AI position. It does not set the ObjectID's orientation
Function Set_Object(ObjectID)
If Object Exist(ObjectID)
   If Object Exist(2)=0 Then Clean_AI()
   Return_AI()
   Position Object ObjectID,AID.x,AID.y,AID.z
Endif
EndFunction
 
`This function places the CameraID at the AI position. It does not orient the camera.
Function Set_Camera()
Return_AI()
Position Camera AID.x,AID.y,AID.z
EndFunction
 
`This function shortens the Limb Position X/Y/Z() functions
Function Return_Limb(ObjectID,LimbID)
If Object Exist(ObjectID)
   If Limb Exist(ObjectID,LimbID)
      Limb.x=Limb Position X(ObjectID,LimbID):Limb.y=Limb Position Y(ObjectID,LimbID):Limb.z=Limb Position Z(ObjectID,LimbID)
   Endif
Endif
EndFunction
 
 
 
Maze:
Data 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
Data 3,2,1,1,1,3,1,1,1,3,1,1,1,2,3
Data 3,1,3,3,1,3,1,3,1,3,1,3,3,1,3
Data 3,1,3,1,1,1,1,1,1,1,1,1,3,1,3
Data 3,1,3,1,3,3,1,3,1,3,3,1,3,1,3
Data 3,1,1,1,3,1,1,1,1,1,3,1,1,1,3
Data 3,3,3,1,3,1,3,4,3,1,3,1,3,3,3
Data 5,5,5,1,1,1,3,5,3,1,1,1,5,5,5
Data 3,3,3,1,3,1,3,3,3,1,3,1,3,3,3
Data 3,1,1,1,3,1,1,1,1,1,3,1,1,1,3
Data 3,1,3,1,3,3,1,3,1,3,3,1,3,1,3
Data 3,1,3,1,1,1,1,1,1,1,1,1,3,1,3
Data 3,1,3,3,1,3,1,3,1,3,1,3,3,1,3
Data 3,2,1,1,1,3,1,1,1,3,1,1,1,2,3
Data 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3