File: ballaccel_2.kbs

package info (click to toggle)
basic256 2.0.99.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,888 kB
  • sloc: cpp: 17,185; yacc: 4,025; lex: 1,466; java: 1,091; sh: 39; xml: 33; makefile: 20
file content (42 lines) | stat: -rw-r--r-- 825 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
print "Using Newton's laws to make the ball bounce realistically"

# updated 2012-10-06 j.m.reneau using loops and subroutines for 0.9.9.x

rem set up initial ball position and speed
x = 20
y = 100
r = 10
yvel = -1.0
xvel = 1.10
yacc = .0098
fastgraphics
 
do
  clg
  rem change the downward velocity according to the acceleration
  yvel = yvel + yacc

  rem calculate new position
  y = y + yvel
  x = x + xvel
  
  rem check for collisions
  if y > 289 then yvel = -0.9 * yvel : y = 289 : xvel = xvel * 0.9
  if x > 285 then xvel = -xvel : x = 285
  if x < 10 then xvel = -xvel : x = 10
  
  rem draw the ball
  call drawBall(x,y,r)
until xvel * xvel < 0.0001
end
 
subroutine drawBall(x,y,r)
  color darkblue
  rect 0,0,300,300
  color darkgray
  circle x, y, r
  color gray
  circle x, y, r - 2
  refresh
end subroutine