[net.micro.amiga] Yo-yo source

cjp@vax135.UUCP (Charles Poirier) (01/27/86)

I just got my Amiga (sans Development kit so far), running V1.1 of
kickstart and of AmigaBasic.  My first AmigaBasic program *almost*
works, but there is something funny going on with the detection of
collisions of a BOB (blitter object) with the window edge.  In the
following program, the BOB bounces off edges normally, *except* when it
hits the *same edge* twice in a row.  The second and all subsequent
times the BOB touches the same edge, no collision is detected.  Having
the BOB bounce off a different edge re-enables bounces on the first
edge but disables them on the most recent edge.  Other anomalous
behavior: When the BOB passes through a window edge due to missing a
collision, it sometimes "bounces" off of the off-screen continuation of
a perpendicular "edge" (this I infer from where the BOB re-enters the
screen).  But sometimes it *doesn't* bounce, but passes through this
second edge as well.  This seems to depend on which edge is missing
collisions, *and* on which perpendicular edge.  I tried adding a
"collision on" in subr "bouncy", but it had no effect at all (as indeed
is implied in the collision documentation) so I removed it.

Please help?  Is this a bug in my program, in AmigaBasic, in the Amiga
kernel, or in the collision detection hardware?  I hope it's just
something I am neglecting to reset, but I can't figure out what from
the AmigaBasic manual.  Note, the example program under object.shape
in the AmigaBasic manual doesn't use acceleration, so it would never
find any bug dealing with hitting the same side twice in a row.

entrypoint:
'yoyo: program to have an object yo-yo around the mouse pointer.
on collision gosub bouncy
collision on
open "i", #1, "extras:basicdemos/qbob"  'output of my objedit run
object.shape 1, input$(lof(1),1)        'defines the object
close 1
foo% = mouse(0)     'sample the mouse position, then give it to object 1
object.x 1, mouse(1): object.y 1, mouse(2)
object.vx 1, 40
ax.kludge! = .033: ay.kludge! = .05
object.on
object.start

while (mouse(0) <> 1)     'sample mouse position, exit on click left
   xdiff& = mouse(1) - object.x(1): ydiff& = mouse(2) - object.y(1)
   xsgn% = sgn(xdiff&): ysgn% = sgn(ydiff&)
   xreal! = csng(xdiff&): yreal! = csng(ydiff&)
   xreal! = abs(xreal! * xreal! * xreal!)
   yreal! = abs(yreal! * yreal! * yreal!)
   'adjust acceleration towards current mouse position as 3/2 power of dist
   object.ax 1, (ax.kludge! * sqr(xreal!) * xsgn%)
   object.ay 1, (ay.kludge! * sqr(yreal!) * ysgn%)
wend
object.close
end

bouncy:                       'collision interrupt subroutine
wall% = collision(1)
if (wall% = -1) or (wall% = -3) then
   object.vy 1, (-object.vy(1) * .5)  'bounce; reverse and halve y-component
elseif (wall% = -2) or (wall% = -4) then
   object.vx 1, (-object.vx(1) * .5)
end if
object.start
return