Author Topic: Collisions  (Read 1358 times)

0 Members and 1 Guest are viewing this topic.

Offline bikemadness

  • Amiga 1200
  • ****
  • Posts: 312
  • Karma: 25
  • Hard players don't go home.
    • View Profile
Collisions
« on: October 26, 2021 »
Some colliding fun.

Code: [Select]
open window 640,512
s=40
xp=300
yp=240
mp=0
ang=pi/180
hit=0
hit1=0
b=15
dim x(b),y(b),mx(b),my(b),m(b)
for a=1 to b
x(a)=int(ran(100)+20)*5
y(a)=int(ran(70)+15)*5
m(a)=ran(5)+1
mx(a)=m(a)
my(a)=m(a)
next a
repeat
setdrawbuf vm
vm=1-vm
setdispbuf vm
clear window
setrgb 1,200,150,0
fill rectangle 0,0 to 640,512
mp=mp-0.1
if mp<0 mp=0
if xp>640-s dir=2
if xp<0 dir=0
if yp>510-s dir=3
if yp<0 dir=1
xp=xp+cos(90*dir*ang)*mp
yp=yp+sin(90*dir*ang)*mp
setrgb 1,0,0,0
rectangle xp,yp to xp+s,yp+s
for a=1 to b
x(a)=x(a)+mx(a)
y(a)=y(a)+my(a)
rectangle x(a),y(a) to x(a)+s,y(a)+s
if x(a)<0 or x(a)>640-s mx(a)=-mx(a)
if y(a)<0 or y(a)>510-s my(a)=-my(a)
if x(a)+s>xp and x(a)<xp+s and y(a)+s>yp and y(a)+s<yp+5 then
dir=1
mp=m(a)
my(a)=-my(a)
hit=hit+1
endif
if x(a)+s>xp and x(a)<xp+s and y(a)<yp+s and y(a)>yp+s-5 then
dir=3
mp=m(a)
my(a)=-my(a)
hit=hit+1
endif
if y(a)+s>yp and y(a)<yp+s and x(a)+s>xp and x(a)+s<xp+5 then
dir=0
mp=m(a)
mx(a)=-mx(a)
hit=hit+1
endif
if y(a)+s>yp and y(a)<yp+s and x(a)<xp+s and x(a)>xp+s-5 then
dir=2
mp=m(a)
mx(a)=-mx(a)
hit=hit+1
endif
next a
if hit<10 text xp+5,yp+35,"00"+str$(hit)
if hit>9 and hit<100 text xp+5,yp+35,"0"+str$(hit)
if hit>99 and hit<1000 text xp+5,yp+35,str$(hit)
if hit>999 then
hit=0
hit1=hit1+1
endif
text xp+5,yp+15,str$(hit1)
until (1=0)

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