Author Topic: Colliding  (Read 18 times)

0 Members and 1 Guest are viewing this topic.

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 319
  • Karma: 25
  • Hard players don't go home.
    • View Profile
Colliding
« on: May 12, 2026 »
Object ball bouncing off static squares.

Depending on the end result (sel=1,2,3 or 4),

The squares will randomly pop up somewhere else,

or not.

Code: [Select]
blox=40
dim x(blox)
dim y(blox)

for a=1 to blox
x(a)=int(ran(30))*20+20
y(a)=int(ran(23))*20+20
next a
b=5

xb=320
yb=256
r=5

xm=1
ym=1

sel=1

open window 640,512
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window

for a=1 to blox
rectangle x(a)-b,y(a)-b to x(a)+b,y(a)+b
next a

circle xb,yb,r
xb=xb+xm
yb=yb+ym
if xb<0+r or xb>640-r xm=-xm
if yb<0+r or yb>512-r ym=-ym

for a=1 to blox

if xb+r>x(a)-b and xb-r<x(a)+b and yb>y(a)-b and yb<y(a)+b then
xm=-xm

if sel=1 then
x(a)=int(ran(30))*20+20
y(a)=int(ran(23))*20+20
endif

if sel=2 then
x(a)=a*10+120
y(a)=256
endif

if sel=3 then
row=row+1
if row>8 then
row=1
col=col+1
endif
x(a)=row*10+240
y(a)=col*10+200
endif

if sel=4 then
x(a)=cos((a)*(360/blox)*(pi/180))*240+320
y(a)=sin((a)*(360/blox)*(pi/180))*150+256
endif

endif

if yb+r>y(a)-b and yb-r<y(a)+b and xb>x(a)-b and xb<x(a)+b then
ym=-ym

if sel=1 then
x(a)=int(ran(30))*20+20
y(a)=int(ran(23))*20+20
endif

if sel=2 then
x(a)=a*10+120
y(a)=256
endif

if sel=3 then
row=row+1
if row>8 then
row=1
col=col+1
endif
x(a)=row*10+240
y(a)=col*10+200
endif

if sel=4 then
x(a)=cos((a)*(360/blox)*(pi/180))*240+320
y(a)=sin((a)*(360/blox)*(pi/180))*150+256
endif

endif

next a

until (1=0)

Have a Yahappy day.
I don't know what is wrong with the world - but I know how to fix it.