PulsarLua 3d Game Board

    This is part of my efforts to make 3d objects on a 2d system.


      
win = openwindow ("Start",0,0,1200,700)
scnt = 100 ; num = 100 ; v1 = 11
setactivewindow (win)
  -- declare array
YSlope = {}
XSlope = {}
reverse = {}
var = {}
   for count =1,9000 do  -- This code dimensions an array to 9000 variables
       XSlope[count] = 1
       YSlope[count] = 1
       reverse[count] = 1
   end
   for count = 1,900  do
      var[count] = 1
   end
backcolor (20,60,80,255)
cls()

 
function SetConversion( )
       local cnt = 0
       local x1 = 1 ; y1 = 1
        for cnt = 0, 7000 do
             XSlope[cnt] = x1
             YSlope[cnt] = y1
             x1 = x1 * .9997
             y1 = y1 * .9997
             reverse[cnt] = 660 - cnt -- Reverse Z coordinates and add offset
            
        end    
 
end

function Zline(x1,z1,x2,z2)
       z1 = z1 * YSlope[z1]
       z2 = z2 * YSlope[z2] 
      y1 =  reverse[round(z1)]  -- 1 = bottom  higher numbers of z get closer to horizon
      y2 =  reverse[round(z2)]   -- converts z to screen 2d y coordinates.
   
       x1 = 600 - (600 * XSlope[round(z1)]) + x1 * XSlope[round(z1)]
       x2 = 600 - (600 * XSlope[round(z2)]) + x2 * XSlope[round(z2)]

      line (x1,y1,x2,y2)
end

function Zboard()
   local x1 = 201 ; x2 = 300 ; x3 = 300 ; x4 = 201 ; z1 = 1 ; z2 = 1 ; z3 = 100 ; z4 = 100 ; clr = 2
     for row = 1,8 do
         clr = clr + 1
         if(clr==3) then clr = 1 ; end
         for column = 1,8 do
            if(clr == 1) then
               color (0,230,230,255) ; clr = 2
               else
               color (200,255,255,255) ; clr = 1
            end
             Squad(x1,z1,x2,z2,x3,z3,x4,z4)
             color (0,0,0,255)
             Zquad(x1,z1,x2,z2,x3,z3,x4,z4)
             x1 = x1 + 100 ; x2 = x2 + 100 ; x3 = x3 + 100 ; x4 = x4 + 100
         end
         var[row] = z1
         x1 = 201 ; x2 = 300 ; x3 = 300 ; x4 = 201
         z1 = z1 + 100 ; z2 = z2 + 100 ; z3 = z3 + 100 ; z4 = z4 + 100
        
      end
     
end

function Zquad(x1,z1,x2,z2,x3,z3,x4,z4)

         Zline(x1,z1,x2,z2)  -- x1 = bottom left   x2 = bottom right   x3 = top right   x4 = top left
         Zline(x2,z2,x3,z3)
         Zline(x3,z3,x4,z4)
         Zline(x1,z1,x4,z4)
end
 
function Squad(x1,z1,x2,z2,x3,z3,x4,z4)
      while z1<z4 do
         Zline(x1,z1,x2,z2)
         z1=z1+1
         z2=z2+1
      end  
end

function Zprint()
   for count = 1,20  do
       drawtext ( var[count],1100,count * 20 )
   end
end
function Vprint()
   local c1 = 1
   for count = 1,20  do
       drawtext ( YSlope[c1],1100,count * 20 )
       drawtext (v1,900,count * 20)
       c1 = c1 + 50
      
   end
  
end
function Start()
   -- This is a marker to the start of the main loop.
end       
SetConversion()
color (255,255,255,255)
repeat
        cls()
          Zboard()
          Zprint()
        color (255,255,255,255)
        drawtext ("Press Escape Key to exit ..",0,0)
        drawtext ( mousex(),20,40)
        drawtext ( mousey(),20,60)
        --Vprint()
        m1 = mousey()
        if (m1<1) then
            m1 = 1
        end
        drawtext (  reverse[m1],20,80)
        sync()
        wait(50)

until getkey() == 41

closewindow(win)
closeapplication()

 

Make a free website with Yola