TGC Codebase Backup



A Line moving left and right in a visible area by Alduce

15th Feb 2009 11:38
Summary

A line showed in a visible area. When a portion pass the edge area so this portion result invisible



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    SET DISPLAY MODE 1152, 864, 16
set window off
sync on
sync rate 100
backdrop off

rem MAIN LINE COORDS
mul as float
mul2 as float
start_x as float
start_x = 130
start_y as float
start_y = 400
end_x as float
end_x = 420
end_y as float
end_y = 600

barrier_x = 100
barrier_x2 = 500
`----------------------------------------------------------------------------
`----------------------------------MAIN LOOP---------------------------
`----------------------------------------------------------------------------
do
  cls
  gosub DrawBar2
  gosub testi
  sync
loop
`----------------------------------------------------------------------------
`--------------------------------MAIN LOOP END------------------------
`----------------------------------------------------------------------------

DrawBar2:

   line 100,307,500,307
   line 100,684,500,684
   line 100,307,100,684 rem left barrier
   line 500,307,500,684 rem right barrier

   if rightkey()=1
       start_x = start_x - 2
       end_x = end_x - 2
   endif
   if leftkey()=1
       start_x = start_x + 2
       end_x = end_x + 2
   endif


   rem LEFT BARRIER
   if start_x > barrier_x and end_x < barrier_x2
     line start_x,start_y,end_x,end_y
   endif
   if start_x <= barrier_x
     if end_x > barrier_x
       mul =(end_x-barrier_x)/(end_x-start_x)
       new_start_y = end_y - ( (end_y-start_y) * mul )
       line barrier_x,new_start_y,end_x,end_y
     endif
   endif

   rem RIGHT BARRIER
   if end_x < barrier_x2 and  start_x > barrier_x
     line start_x,start_y,end_x,end_y
   endif
   if end_x > barrier_x2
     if start_x < barrier_x2
       mul2 =(start_x-barrier_x2)/(start_x-end_x)
       new_end_y = start_y - ( (start_y-end_y) * mul2 )
       line start_x,start_y,barrier_x2,new_end_y
     endif
   endif


return





rem *************************** TEXT*********************************
testi:
   ink rgb(255,255,255),0
 set cursor 10,10
 print "start_x = ";start_x
 set cursor 10,20
 print "start_y = ";start_y
 set cursor 10,40
 print "end_x = ";end_x
 set cursor 10,50
 print "end_y = ";end_y
 set cursor 10,80
 print "NEW_START_Y = ";new_start_y
 set cursor 10,100
 print "MUL = ";mul
 set cursor 10,110
 print "MUL2 = ";mul2

set cursor 300,10
print "MOUSE X = ";mousex()

set cursor 300,20
print "MOUSE Y = ";mousey()

return
rem *************************** FINE TEXT ****************************