UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: Deano on June 19, 2009, 08:48:57 PM

Title: Simple Rope demo
Post by: Deano on June 19, 2009, 08:48:57 PM
[pbcode]
; PROJECT : 40rope
; AUTHOR  : Deano
; CREATED : 6/14/2009
; EDITED  : 6/19/2009
screenw=800
screenh=600
OpenScreen screenw,screenh,32,2
setfps 60
FmX#=GetScreenWidth()/2
FmY#=GetScreenHeight()/4
SetMouse FmX#,FmY#


Seg_Length#=5
Air_Resistance#=0.1
Damping#=1
speed#=0.51   
      
Type tObject
   Rx#
   Ry#
EndType

Dim ROPE(40) As tObject
   
FOR i=1 to 32
 ROPE(i).Rx#=FmX#
 ROPE(i).Ry#=FmY#+i*10
next i   
   RenderToScreen
 


   Do

      cls rgb(183,183,183)
   ROPE(1).Rx#=MOUSEx()
   ROPE(1).Ry#=MOUSEy()
    for i=2 to 32
    VX1#=ROPE(i-1).Rx#-ROPE(i).Rx#
    VY1#=ROPE(i-1).Ry#-ROPE(i).Ry#
    VM1#=Sqrt( VX1#^2 + VY1#^2 )
    VE1#=VM1#-Seg_Length#
    
    VX2#=ROPE(i+1).Rx#-ROPE(i).Rx#
    VY2#=ROPE(i+1).Ry#-ROPE(i).Ry#
    VM2#=Sqrt( VX2#^2 + VY2#^2 )
    VE2#=VM2#-Seg_Length#
 
  VX#=(VX1#/VM1#*VE1#)+(VX2#/VM2#*VE2)
  VY#=(VY1#/VM1#*VE1#)+(VY2#/VM2#*VE2)+9.8-Air_Resistance#
    ROPE(i).Rx# = ROPE(i).Rx#  + (VX# * speed#)
    ROPE(i).Ry# = ROPE(i).Ry#  + (VY# * speed#)
    
    
    NEXT i
 
      
      for i= 1 to 32
      If SpaceKey()=True Then  Circle ROPE(i).Rx#,ROPE(i).Ry#,3,0
      if i<32    then   Line ROPE(i).Rx#,ROPE(i).Ry#,ROPE(i+1).Rx#,ROPE(i+1).Ry#
      next i
         
   
      CenterText GetScreenWidth()/2,20,"Hit SpaceBar"
      
      Sync
   Loop


End
[/pbcode]


Related Articles

     * Limb Chain (http://www.underwaredesign.com/forums/index.php?topic=4011.0)