KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Gorilla.bas

 
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting
View previous topic :: View next topic  
Author Message
Bryce
KiXforms Supporter
KiXforms Supporter


Joined: 26 Mar 2003
Posts: 69

PostPosted: Thu Sep 14, 2006 9:49 pm    Post subject: Gorilla.bas Reply with quote

got the math part down.....

Code:

break on
$math = CreateObject("Kixtart.System").math

;the angle of launch
$angle = 45.0

$angle = $angle/180 * $math.pi
;how stong of a throw
$power = 10.0

;direction of the wind -# is right to left +# is left to right
$wind = 10.0

;gravity setting
$gravity = 9.8

;starting X and Y position
$X = 0.0
$y = 0.0

$iXVel = $math.cos($angle)*$power
$iYVel = $math.sin($angle)*$power

while $yy <= 0
   $xx = ($IXVel * $t) + (0.5 * ($Wind / 5) * $math.pow($t,2))
   $yy = ((-1.0 * ($IYVel * $t)) + (0.5 * $gravity * $math.pow($t,2)))
   
   ? $X + $xx "     " $y+$yy*-1+$starty
   $t = $t+0.01
loop


slow day at the office...
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Fri Sep 15, 2006 12:16 am    Post subject: Reply with quote

yo dude - whats with the math kick all of a sudden ? ;0)
Back to top
View user's profile Send private message
Bryce
KiXforms Supporter
KiXforms Supporter


Joined: 26 Mar 2003
Posts: 69

PostPosted: Fri Sep 15, 2006 8:52 pm    Post subject: Reply with quote

just playing arround....

Code:

Break On
$System = CreateObject("Kixtart.System")

;KD START

;************* Form **************
$Form = $System.Form()
$form.ClientSize = 800,600
$form.center
;**************************************

MakeScreen

;KD END

$math = CreateObject("Kixtart.System").math

;the angle of launch
$angle.text = 75

;how stong of a throw
$power.text = 100

;direction of the wind -# is right to left +# is left to right
$wind.text = 0

;gravity setting
$gravity.text = 9.8

;starting X and Y position
$X.text = 100.0
$y.text = 0.0


$Form.Show
While $Form.Visible
 $=Execute($System.Application.DoEvents)
Loop

quit 0

Function ClearScreen
   $screen.BackColor = 14215660   
endfunction


Function launchit()
   dim $1,$2,$3,$4,$5,$6,$point

   $1 = 0.0+cdbl($x.text)
   $2 = 0.0+cdbl($y.text)
   $3 = 0.0+cdbl($angle.text)/180 * $math.pi
   $4 = 0.0+cdbl($power.text)
   $5 = 0.0+cdbl($wind.text)
   $6 = 0.0+cdbl($gravity.text)


   $screen.circle($1,$screen.height-$2,10)
   for each $Point in Plotshot($1,$2,$3,$4,$5,$6)
      $point = split($point,',')
      if ubound($point) = 1
            $screen.circle($point[0],$screen.height - val($point[1]),1)
         ;? $point[0]","$point[1]
      endif
   next
   /*
   ? "x       " $1
   ? "y       " $2
   ? "angle   " $3
   ? "power   " $4
   ? "wind    " $5
   ? "Gravity " $6
   */
endfunction



Function Plotshot($x, $y, $angle, $power, $wind, $gravity)

   Dim $t, $xvel, $yvel, $i, $yy, $xx
   dim $array[0]
   $XVel = $math.cos($angle)*$power
   $YVel = $math.sin($angle)*$power
   
   while $yy <= $y
      $xx = round(($XVel * $t) + (0.5 * ($Wind / 5) * $math.pow($t,2)),2)
      $yy = round(((-1.0 * ($YVel * $t)) + (0.5 * $gravity * $math.pow($t,2))),2)
     
      $array[$i] = "" + ($X + $xx) + ',' + ($y+$yy*-1)
      $i = $i + 1 redim preserve $array[$i]
      $t = $t+0.01
   loop
   if not $i
      $array = 0
   endif
   $Plotshot = $array
endfunction

Function MakeScreen
   ;************* drawing screen **************
   $Screen = $Form.Controls.PictureBox
   $screen.BorderStyle=1
   $screen.clientsize = 800,600
   ;**************************************

   ;************* LaunchControl **************
   $LaunchControl = $screen.Controls.GroupBox()
   $LaunchControl.Height = 122
   $LaunchControl.Left = 15
   $LaunchControl.Text = "Launch Control"
   $LaunchControl.Top = 10
   $LaunchControl.Width = 195
   ;**************************************
   
   ;************* LaunchButton **************
   $LaunchButton = $LaunchControl.Controls.Button()
   $LaunchButton.Anchor = 2
   $LaunchButton.Height = 23
   $LaunchButton.Left = 94
   $LaunchButton.Text = "Launch"
   $LaunchButton.Top = 89
   $LaunchButton.Width = 75
   $launchbutton.onclick = 'launchit'
   ;**************************************

   ;************* ClearButton **************
   $ClearButton = $LaunchControl.Controls.Button()
   $ClearButton.Anchor = 2
   $ClearButton.Height = 23
   $ClearButton.Left = 14
   $ClearButton.Text = "Clear"
   $ClearButton.Top = 89
   $ClearButton.Width = 75
   $ClearButton.onclick = 'ClearScreen'
   ;**************************************
      
   ;************* Angle **************
   $Angle = $LaunchControl.Controls.TextBox()
   $Angle.Height = 20
   $Angle.Left = 10
   $Angle.Text = ""
   $Angle.Top = 20
   $Angle.Width = 29
   ;**************************************
   
   ;************* Label1 **************
   $Label1 = $LaunchControl.Controls.Label()
   $Label1.Height = 17
   $Label1.Left = 40
   $Label1.Text = "Angle"
   $Label1.Top = 20
   $Label1.Width = 36
   ;**************************************
   
   ;************* power **************
   $power = $LaunchControl.Controls.TextBox()
   $power.Height = 20
   $power.Left = 10
   $power.Text = ""
   $power.Top = 40
   $power.Width = 30
   ;**************************************

   ;************* Label2 **************
   $Label2 = $LaunchControl.Controls.Label()
   $Label2.Height = 16
   $Label2.Left = 40
   $Label2.Text = "Power"
   $Label2.Top = 40
   $Label2.Width = 37
   ;**************************************
   
   ;************* Wind **************
   $Wind = $LaunchControl.Controls.TextBox()
   $Wind.Height = 20
   $Wind.Left = 10
   $Wind.Text = ""
   $Wind.Top = 60
   $Wind.Width = 30
   ;**************************************
   
   ;************* Label3 **************
   $Label3 = $LaunchControl.Controls.Label()
   $Label3.Height = 18
   $Label3.Left = 40
   $Label3.Text = "Wind"
   $Label3.Top = 60
   $Label3.Width = 32
   ;**************************************
   
   ;************* X **************
   $X = $LaunchControl.Controls.TextBox()
   $X.Height = 20
   $X.Left = 110
   $X.Text = ""
   $X.Top = 20
   $X.Width = 29
   ;**************************************
   
   ;************* Label4 **************
   $Label4 = $LaunchControl.Controls.Label()
   $Label4.Height = 21
   $Label4.Left = 140
   $Label4.Text = "Start X"
   $Label4.Top = 20
   $Label4.Width = 41
   ;**************************************
   
   ;************* Y **************
   $Y = $LaunchControl.Controls.TextBox()
   $Y.Height = 20
   $Y.Left = 110
   $Y.Text = ""
   $Y.Top = 40
   $Y.Width = 29
   ;**************************************
   
   ;************* Label5 **************
   $Label5 = $LaunchControl.Controls.Label()
   $Label5.Height = 21
   $Label5.Left = 140
   $Label5.Text = "Start Y"
   $Label5.Top = 40
   $Label5.Width = 41
   ;**************************************
   
   ;************* Gravity **************
   $Gravity = $LaunchControl.Controls.TextBox()
   $Gravity.Height = 20
   $Gravity.Left = 110
   $Gravity.Text = ""
   $Gravity.Top = 60
   $Gravity.Width = 29
   ;**************************************
   
   ;************* Label6 **************
   $Label6 = $LaunchControl.Controls.Label()
   $Label6.Height = 19
   $Label6.Left = 140
   $Label6.Text = "Gravity"
   $Label6.Top = 60
   $Label6.Width = 41
   ;**************************************
endfunction
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Fri Sep 15, 2006 10:13 pm    Post subject: Reply with quote

Now if only understood half of the math that you did.

But I did break it (or send it into an endless loop of some sort)

Angle 45
Power 100
Wind 0

Start X 100
Start Y 0
Gravity 0

_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
Bryce
KiXforms Supporter
KiXforms Supporter


Joined: 26 Mar 2003
Posts: 69

PostPosted: Fri Sep 15, 2006 10:19 pm    Post subject: Reply with quote

the math function is set to plot the corse of object until it comes back to the ground, or x = 0... with no gravity.... it jsut keeps going and going and going.... Shocked
Back to top
View user's profile Send private message
Bryce
KiXforms Supporter
KiXforms Supporter


Joined: 26 Mar 2003
Posts: 69

PostPosted: Sat Sep 16, 2006 9:12 pm    Post subject: Reply with quote

* Fixed that endless loop by putting a boundry in
* added player 1 and 2 controls
* got a ball now in place of a line, and with adjusted timing.

Code:

Break On
$System = CreateObject("Kixtart.System")

;KD START

;************* Form **************
$Form = $System.Form()
$form.ClientSize = 1024,768
$form.center
;**************************************

MakeScreen

;KD END

$math = CreateObject("Kixtart.System").math

;the angle of launch
$p1angle.text = 66
$p2angle.text = 66

;how stong of a throw
$p1power.text = 100
$p2power.text = 100

;direction of the wind -# is right to left +# is left to right
$p1wind.text = 0
$p2wind.text = 0

;gravity setting
$p1gravity.text = 9.8
$p2gravity.text = 9.8

;starting X and Y position
$p1X.text = 100.0
$p1y.text = 0.0
$p2X.text = 924.0
$p2y.text = 0.0


$Form.Show
While $Form.Visible
 $=Execute($System.Application.DoEvents)
Loop

quit 0

Function ClearScreen
   $screen.BackColor = 14215660   
endfunction


Function launchit($1,$2,$3,$4,$5,$6)
   dim $point

   /*
   $1 = cdbl($x.text)
   $2 = cdbl($y.text)
   $3 = cdbl($angle.text)/180 * $math.pi
   $4 = cdbl($power.text)
   $5 = cdbl($wind.text)
   $6 = cdbl($gravity.text)
   */

   
   /*
   ? "x       " $1
   ? "y       " $2
   ? "angle   " $3
   ? "power   " $4
   ? "wind    " $5
   ? "Gravity " $6
   */


   $screen.circle($1,$screen.height-$2,10)
   for each $Point in Plotshot($1,$2,$3,$4,$5,$6)
      $point = split($point,',')
      if ubound($point) = 1
         $screen.fillstyle = 1
         $screen.circle($point[0],$screen.height - val($point[1]),2)
         $screen.fillstyle = 0
         $screen.circle($point[0],$screen.height - val($point[1]),4)
         sleep 0.005
         $screen.forecolor = $screen.backcolor
         $screen.fillcolor = $screen.backcolor
         $screen.fillstyle = 1
         $screen.circle($point[0],$screen.height - val($point[1]),4)
         $screen.forecolor = 0
         $screen.fillcolor = 0

         
         ;? $point[0]","$point[1]
      endif
   next
endfunction



Function Plotshot($x, $y, $angle, $power, $wind, $gravity)

   Dim $t, $xvel, $yvel, $i, $yy, $xx, $inbound
   dim $array[0]
   $XVel = $math.cos($angle)*$power
   $YVel = $math.sin($angle)*$power
   
   $inbound = 1

   while $inbound
      $xx = round(($XVel * $t) + (0.5 * ($Wind / 5) * $math.pow($t,2)),1)
      $yy = round(((-1.0 * ($YVel * $t)) + (0.5 * $gravity * $math.pow($t,2))),1)
     
      $array[$i] = "" + ($X + $xx) + ',' + ($y+$yy*-1)
      $i = $i + 1 redim preserve $array[$i]
      $t = $t+0.05
   
   select
      case $yy*-1 < 0-$y or $yy*-1 > ($screen.height - $y)*2
         $inbound = 0
      case $xx < 0-$x or $xx > $screen.width-$x
         $inbound = 0
   endselect



   loop
   if not $i
      $array = 0
   endif
   $Plotshot = $array
endfunction

Function MakeScreen
   ;************* drawing screen **************
   $Screen = $Form.Controls.PictureBox
   $screen.BorderStyle=1
   $screen.clientsize = 1024,768
   ;**************************************
   Playerone
   playertwo
endfunction

Function Playerone
   ;************* Player1 **************
   $Player1 = $screen.Controls.GroupBox()
   $Player1.Height = 122
   $Player1.Left = 15
   $Player1.Text = "Player 1"
   $Player1.Top = 10
   $Player1.Width = 195
   ;**************************************
   
   ;************* LaunchButton **************
   $P1LaunchButton = $Player1.Controls.Button()
   $P1LaunchButton.Anchor = 2
   $P1LaunchButton.Height = 23
   $P1LaunchButton.Left = 94
   $P1LaunchButton.Text = "Fire!"
   $P1LaunchButton.Top = 89
   $P1LaunchButton.Width = 75
   $P1launchbutton.onclick = 'launchit(cdbl($p1x.text), cdbl($p1y.text), cdbl($p1angle.text)/180 * $math.pi, cdbl($p1Power.text),cdbl($p1wind.text),cdbl($p1gravity.text))'
   ;**************************************

   ;************* ClearButton **************
   $P1ClearButton = $Player1.Controls.Button()
   $P1ClearButton.Anchor = 2
   $P1ClearButton.Height = 23
   $P1ClearButton.Left = 14
   $P1ClearButton.Text = "Clear"
   $P1ClearButton.Top = 89
   $P1ClearButton.Width = 75
   $P1ClearButton.onclick = 'ClearScreen'
   ;**************************************
     
   ;************* Angle **************
   $P1Angle = $Player1.Controls.TextBox()
   $P1Angle.Height = 20
   $P1Angle.Left = 10
   $P1Angle.Text = ""
   $P1Angle.Top = 20
   $P1Angle.Width = 29
   ;**************************************
   
   ;************* Label1 **************
   $P1Label1 = $Player1.Controls.Label()
   $P1Label1.Height = 17
   $P1Label1.Left = 40
   $P1Label1.Text = "Angle"
   $P1Label1.Top = 20
   $P1Label1.Width = 36
   ;**************************************
   
   ;************* power **************
   $P1power = $Player1.Controls.TextBox()
   $P1power.Height = 20
   $P1power.Left = 10
   $P1power.Text = ""
   $P1power.Top = 40
   $P1power.Width = 30
   ;**************************************

   ;************* Label2 **************
   $P1Label2 = $Player1.Controls.Label()
   $P1Label2.Height = 16
   $P1Label2.Left = 40
   $P1Label2.Text = "Power"
   $P1Label2.Top = 40
   $P1Label2.Width = 37
   ;**************************************
   
   ;************* Wind **************
   $P1Wind = $Player1.Controls.TextBox()
   $P1Wind.Height = 20
   $P1Wind.Left = 10
   $P1Wind.Text = ""
   $P1Wind.Top = 60
   $P1Wind.Width = 30
   ;**************************************
   
   ;************* Label3 **************
   $P1Label3 = $Player1.Controls.Label()
   $P1Label3.Height = 18
   $P1Label3.Left = 40
   $P1Label3.Text = "Wind"
   $P1Label3.Top = 60
   $P1Label3.Width = 32
   ;**************************************
   
   ;************* X **************
   $P1X = $Player1.Controls.TextBox()
   $P1X.Height = 20
   $P1X.Left = 110
   $P1X.Text = ""
   $P1X.Top = 20
   $P1X.Width = 29
   ;**************************************
   
   ;************* Label4 **************
   $P1Label4 = $Player1.Controls.Label()
   $P1Label4.Height = 21
   $P1Label4.Left = 140
   $P1Label4.Text = "Start X"
   $P1Label4.Top = 20
   $P1Label4.Width = 41
   ;**************************************
   
   ;************* Y **************
   $P1Y = $Player1.Controls.TextBox()
   $P1Y.Height = 20
   $P1Y.Left = 110
   $P1Y.Text = ""
   $P1Y.Top = 40
   $P1Y.Width = 29
   ;**************************************
   
   ;************* Label5 **************
   $P1Label5 = $Player1.Controls.Label()
   $P1Label5.Height = 21
   $P1Label5.Left = 140
   $P1Label5.Text = "Start Y"
   $P1Label5.Top = 40
   $P1Label5.Width = 41
   ;**************************************
   
   ;************* Gravity **************
   $P1Gravity = $Player1.Controls.TextBox()
   $P1Gravity.Height = 20
   $P1Gravity.Left = 110
   $P1Gravity.Text = ""
   $P1Gravity.Top = 60
   $P1Gravity.Width = 29
   ;**************************************
   
   ;************* Label6 **************
   $P1Label6 = $Player1.Controls.Label()
   $P1Label6.Height = 19
   $P1Label6.Left = 140
   $P1Label6.Text = "Gravity"
   $P1Label6.Top = 60
   $P1Label6.Width = 41
   ;**************************************
endfunction

Function Playertwo
   ;************* player2 **************
   $player2 = $screen.Controls.GroupBox()
   $player2.Height = 122
   $player2.Left = 207+10
   $player2.Text = "Player 2"
   $player2.Top = 10
   $player2.Width = 195
   ;**************************************
   
   ;************* LaunchButton **************
   $p2LaunchButton = $player2.Controls.Button()
   $p2LaunchButton.Anchor = 2
   $p2LaunchButton.Height = 23
   $p2LaunchButton.Left = 94
   $p2LaunchButton.Text = "Fire!"
   $p2LaunchButton.Top = 89
   $p2LaunchButton.Width = 75
   $p2launchbutton.onclick = 'launchit(cdbl($p2x.text), cdbl($p2y.text), (180.0-cdbl($p2angle.text))/180 * $math.pi, cdbl($p2Power.text),cdbl($p2wind.text),cdbl($p2gravity.text))'
   ;**************************************

   ;************* ClearButton **************
   $p2ClearButton = $player2.Controls.Button()
   $p2ClearButton.Anchor = 2
   $p2ClearButton.Height = 23
   $p2ClearButton.Left = 14
   $p2ClearButton.Text = "Clear"
   $p2ClearButton.Top = 89
   $p2ClearButton.Width = 75
   $p2ClearButton.onclick = 'ClearScreen'
   ;**************************************
     
   ;************* Angle **************
   $p2Angle = $player2.Controls.TextBox()
   $p2Angle.Height = 20
   $p2Angle.Left = 10
   $p2Angle.Text = ""
   $p2Angle.Top = 20
   $p2Angle.Width = 29
   ;**************************************
   
   ;************* Label1 **************
   $p2Label1 = $player2.Controls.Label()
   $p2Label1.Height = 17
   $p2Label1.Left = 40
   $p2Label1.Text = "Angle"
   $p2Label1.Top = 20
   $p2Label1.Width = 36
   ;**************************************
   
   ;************* power **************
   $p2power = $player2.Controls.TextBox()
   $p2power.Height = 20
   $p2power.Left = 10
   $p2power.Text = ""
   $p2power.Top = 40
   $p2power.Width = 30
   ;**************************************

   ;************* Label2 **************
   $p2Label2 = $player2.Controls.Label()
   $p2Label2.Height = 16
   $p2Label2.Left = 40
   $p2Label2.Text = "Power"
   $p2Label2.Top = 40
   $p2Label2.Width = 37
   ;**************************************
   
   ;************* Wind **************
   $p2Wind = $player2.Controls.TextBox()
   $p2Wind.Height = 20
   $p2Wind.Left = 10
   $p2Wind.Text = ""
   $p2Wind.Top = 60
   $p2Wind.Width = 30
   ;**************************************
   
   ;************* Label3 **************
   $p2Label3 = $player2.Controls.Label()
   $p2Label3.Height = 18
   $p2Label3.Left = 40
   $p2Label3.Text = "Wind"
   $p2Label3.Top = 60
   $p2Label3.Width = 32
   ;**************************************
   
   ;************* X **************
   $p2X = $player2.Controls.TextBox()
   $p2X.Height = 20
   $p2X.Left = 110
   $p2X.Text = ""
   $p2X.Top = 20
   $p2X.Width = 29
   ;**************************************
   
   ;************* Label4 **************
   $p2Label4 = $player2.Controls.Label()
   $p2Label4.Height = 21
   $p2Label4.Left = 140
   $p2Label4.Text = "Start X"
   $p2Label4.Top = 20
   $p2Label4.Width = 41
   ;**************************************
   
   ;************* Y **************
   $p2Y = $player2.Controls.TextBox()
   $p2Y.Height = 20
   $p2Y.Left = 110
   $p2Y.Text = ""
   $p2Y.Top = 40
   $p2Y.Width = 29
   ;**************************************
   
   ;************* Label5 **************
   $p2Label5 = $player2.Controls.Label()
   $p2Label5.Height = 21
   $p2Label5.Left = 140
   $p2Label5.Text = "Start Y"
   $p2Label5.Top = 40
   $p2Label5.Width = 41
   ;**************************************
   
   ;************* Gravity **************
   $p2Gravity = $player2.Controls.TextBox()
   $p2Gravity.Height = 20
   $p2Gravity.Left = 110
   $p2Gravity.Text = ""
   $p2Gravity.Top = 60
   $p2Gravity.Width = 29
   ;**************************************
   
   ;************* Label6 **************
   $p2Label6 = $player2.Controls.Label()
   $p2Label6.Height = 19
   $p2Label6.Left = 140
   $p2Label6.Text = "Gravity"
   $p2Label6.Top = 60
   $p2Label6.Width = 41
   ;**************************************
endfunction
Back to top
View user's profile Send private message
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Mon Sep 18, 2006 7:33 am    Post subject: Reply with quote

Now we're playing! Nod

Welcome (back) Bryce in the fraction of Kixtart gamers Mr. Green

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group