12-11-2024, 08:10 AM
(12-11-2024, 06:52 AM)johnno56 Wrote: Well... Using Linux, the chances of attracting a virus is quite slim, "I" clicked the green download button and I was redirected to versions 7 (current) and 6....
As Maxwell Smart usually says, "Missed it by that much..." It would have been cool to examine the differences... *sigh*
Something strange on my old computer, I still have a small precious treasure....NaaLaa 4 is still there !!!
click the image to zoom in
It's bonker !!! (the primitive version of Pool / Billiard ? )
Code:
rem ==================================================================
rem Bonker.
rem
rem I'm not quite sure what this is supposed to be.
rem ==================================================================
rem Global variables =================================================
visible:
rem Objects.
OBJ_X = 0
OBJ_Y = 1
OBJ_DX = 2
OBJ_DY = 3
vObjCount = 40
vObjects#[vObjCount][4]
vObjCol[vObjCount][vObjCount]
vObjColors[vObjCount][3]
rem Images.
BALL_IMAGE = 0
BALL_SHADOW_IMAGE = 1
hidden:
rem Load =============================================================
load image BALL_IMAGE, "data/ball.bmp", "data/ball_.bmp"
load image BALL_SHADOW_IMAGE, "data/ball_shadow.bmp", "data/ball_shadow_.bmp"
if javac() then load font 0, "data/courier.txt", "data/courier.png"
rem Init =============================================================
set redraw off
randomize time()
proc InitObjects
rem Main loop ========================================================
do
startTime = time()
xMouse = mousex()
yMouse = mousey()
rem Bonk when user clicks.
if mousebutton(0, true)
proc Bonk xMouse, yMouse, 100.0
endif
rem Update objects.
proc UpdateObjects
rem Draw.
set color 64, 64, 92
cls
proc DrawObjects
set caret 320, 8
set color 255, 255, 255
center "Click anywhere to make nearby balls move!"
redraw
proc HoldFrame startTime, 60
until keydown(27) or not running()
end
rem ==================================================================
rem Init objects.
rem ==================================================================
procedure InitObjects()
for i = 0 to vObjCount - 1
vObjects#[i][OBJ_X] = float(16 + rnd(640 - 32))
vObjects#[i][OBJ_Y] = float(16 + rnd(480 - 32))
vObjects#[i][OBJ_DX] = 0.0
vObjects#[i][OBJ_DY] = 0.0
vObjColors[i][0] = 64 + rnd(255 - 64)
vObjColors[i][1] = 64 + rnd(255 - 64)
vObjColors[i][2] = 64 + rnd(255 - 64)
next
endproc
rem ==================================================================
rem Bonk.
rem ==================================================================
procedure Bonk(x, y, strength#)
for i = 0 to vObjCount - 1
dx# = vObjects#[i][OBJ_X] - float(x)
dy# = vObjects#[i][OBJ_Y] - float(y)
d# = sqr(dx#*dx# + dy#*dy#)
if d# < strength#
force# = strength# - d#
k# = 1.0/d#
dx# = dx#*k#*force#*0.1
dy# = dy#*k#*force#*0.1
vObjects#[i][OBJ_DX] = vObjects#[i][OBJ_DX] + dx#
vObjects#[i][OBJ_DY] = vObjects#[i][OBJ_DY] + dy#
endif
next
endproc
rem ==================================================================
rem Update objects.
rem
rem Most of the things in this procedure are very simplified and some
rem times completely wrong.
rem ==================================================================
procedure UpdateObjects()
rem Update positions and speeds.
for i = 0 to vObjCount - 1
vObjects#[i][OBJ_X] = vObjects#[i][OBJ_X] + vObjects#[i][OBJ_DX]
vObjects#[i][OBJ_Y] = vObjects#[i][OBJ_Y] + vObjects#[i][OBJ_DY]
if vObjects#[i][OBJ_X] < 16.0
vObjects#[i][OBJ_X] = 16.0
vObjects#[i][OBJ_DX] = abs#(vObjects#[i][OBJ_DX])*0.8
elseif vObjects#[i][OBJ_X] > 624.0
vObjects#[i][OBJ_X] = 624.0
vObjects#[i][OBJ_DX] = -abs#(vObjects#[i][OBJ_DX])*0.8
endif
if vObjects#[i][OBJ_Y] < 16.0
vObjects#[i][OBJ_Y] = 16.0
vObjects#[i][OBJ_DY] = abs#(vObjects#[i][OBJ_DY])*0.8
elseif vObjects#[i][OBJ_Y] > 464.0
vObjects#[i][OBJ_Y] = 464.0
vObjects#[i][OBJ_DY] = -abs#(vObjects#[i][OBJ_DY])*0.8
endif
vObjects#[i][OBJ_DX] = vObjects#[i][OBJ_DX]*0.99
vObjects#[i][OBJ_DY] = vObjects#[i][OBJ_DY]*0.99
next
rem Deal with collisions.
for i = 0 to vObjCount - 2
for j = i + 1 to vObjCount - 1
dx# = vObjects#[i][OBJ_X] - vObjects#[j][OBJ_X]
dy# = vObjects#[i][OBJ_Y] - vObjects#[j][OBJ_Y]
if abs#(dx#) < 32.0 and abs#(dy#) < 32.0
d# = sqr(dx#*dx# + dy#*dy#)
if d# < 32.0 and d# > 0.0
if vObjCol[i][j] = false
n#[] = vNormalize([dx#, dy#])
vi#[] = reflectedVector(vObjects#[i][OBJ_DX], vObjects#[i][OBJ_DY], n#[0], n#[1], vSize([vObjects#[j][OBJ_DX], vObjects#[j][OBJ_DY]]))
n#[] = vScale(n, -1.0)
vj#[] = reflectedVector(vObjects#[j][OBJ_DX], vObjects#[j][OBJ_DY], n#[0], n#[1], vSize([vObjects#[i][OBJ_DX], vObjects#[i][OBJ_DY]]))
vObjects#[i][OBJ_DX] = vi#[0]
vObjects#[i][OBJ_DY] = vi#[1]
vObjects#[j][OBJ_DX] = vj#[0]
vObjects#[j][OBJ_DY] = vj#[1]
vObjCol[i][j] = true
endif
else
vObjCol[i][j] = false
endif
else
vObjCol[i][j] = false
endif
next
next
endproc
rem ==================================================================
rem Draw objects.
rem ==================================================================
procedure DrawObjects()
set color 255, 255, 255
rem Shadows.
for i = 0 to vObjCount - 1
draw image BALL_SHADOW_IMAGE, int(vObjects#[i][OBJ_X]) - 18, int(vObjects#[i][OBJ_Y]) - 18
next
rem Balls.
for i = 0 to vObjCount - 1
set color vObjColors[i][0], vObjColors[i][1], vObjColors[i][2]
draw image BALL_IMAGE, int(vObjects#[i][OBJ_X]) - 16, int(vObjects#[i][OBJ_Y]) - 16
next
endproc
rem ==================================================================
rem Hold frame to maintain constant fps.
rem ==================================================================
procedure HoldFrame(startTime, fps)
hold = 1000/fps
endTime = time()
deltaTime = endTime - startTime
if deltaTime < hold
wait hold - deltaTime
else
wait 0
endif
endproc
rem ==================================================================
rem Some functions for 2D vectors.
rem ==================================================================
function vAdd#[](a#[], b#[])
return [a#[0] + b#[0], a#[1] + b#[1]]
endfunc
function vSub#[](a#[], b#[])
return [a#[0] - b#[0], a#[1] - b#[1]]
endfunc
function vNormalize#[](a#[])
k# = 1.0/sqr(a#[0]*a#[0] + a#[1]*a#[1])
return [a#[0]*k#, a#[1]*k#]
endfunc
function vDot#(a#[], b#[])
return a#[0]*b#[0] + a#[1]*b#[1]
endfunc
function vScale#[](a#[], k#)
return [a#[0]*k#, a#[1]*k#]
endfunc
function vSize#(a#[])
return sqr(a#[0]*a#[0] + a#[1]*a#[1])
endfunc
function reflectedVector#[](x#, y#, nx#, ny#, force#)
s# = vDot#([x#, y#], [nx#, ny#])
if s# < 0.0
x# = -x#
y# = -y#
s# = vDot#([x#, y#], [nx#, ny#])
endif
p#[] = vScale([nx#, ny#], s#)
b#[] = vSub(p, [x#, y#])
return vAdd(vScale(vAdd(p, b), 0.25), vScale([nx#, ny#], force#*0.75))
endfunc