2020-11-21 17:03:57 +00:00
|
|
|
%import textio
|
2022-10-22 14:35:57 +00:00
|
|
|
%import math
|
2020-11-21 17:03:57 +00:00
|
|
|
%zeropage basicsafe
|
|
|
|
|
|
|
|
; Note: this program is compatible with C64 and CX16.
|
|
|
|
|
|
|
|
main {
|
|
|
|
|
|
|
|
sub start() {
|
|
|
|
str input = ".........."
|
|
|
|
ubyte ballCount
|
|
|
|
ubyte[255] BX
|
|
|
|
ubyte[255] BY
|
|
|
|
ubyte[255] BC
|
2022-07-08 19:50:32 +00:00
|
|
|
bool[255] DX
|
|
|
|
bool[255] DY
|
2020-11-21 17:03:57 +00:00
|
|
|
|
|
|
|
txt.print("number of balls (1-255)? ")
|
|
|
|
void txt.input_chars(input)
|
|
|
|
ballCount = conv.str2ubyte(input)
|
|
|
|
txt.fill_screen(81, 0)
|
|
|
|
|
|
|
|
; Setup Starting Ball Positions
|
|
|
|
ubyte lp
|
|
|
|
for lp in 0 to ballCount-1 {
|
2022-10-22 14:35:57 +00:00
|
|
|
BX[lp] = math.rnd() % txt.DEFAULT_WIDTH
|
|
|
|
BY[lp] = math.rnd() % txt.DEFAULT_HEIGHT
|
|
|
|
BC[lp] = math.rnd() & 15
|
|
|
|
DX[lp] = math.rnd() & 1
|
|
|
|
DY[lp] = math.rnd() & 1
|
2020-11-21 17:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
; display balls
|
2021-11-29 22:13:04 +00:00
|
|
|
repeat {
|
2020-11-21 17:03:57 +00:00
|
|
|
; Loop though all balls clearing current spot and setting new spot
|
|
|
|
for lp in 0 to ballCount-1 {
|
|
|
|
|
|
|
|
; Clear existing Location the ball is at
|
|
|
|
txt.setclr(BX[lp], BY[lp], 0)
|
|
|
|
|
2022-07-08 19:50:32 +00:00
|
|
|
if not DX[lp] {
|
2020-11-21 17:03:57 +00:00
|
|
|
if (BX[lp] == 0)
|
2022-07-08 19:50:32 +00:00
|
|
|
DX[lp] = true
|
2021-11-29 00:25:21 +00:00
|
|
|
else
|
2020-11-21 17:03:57 +00:00
|
|
|
BX[lp]=BX[lp]-1
|
2022-07-08 19:50:32 +00:00
|
|
|
} else if DX[lp] {
|
2021-11-29 00:25:21 +00:00
|
|
|
if (BX[lp] == txt.DEFAULT_WIDTH-1) {
|
2020-11-21 17:03:57 +00:00
|
|
|
BX[lp] = txt.DEFAULT_WIDTH-2
|
2022-07-08 19:50:32 +00:00
|
|
|
DX[lp] = false
|
2020-11-21 17:03:57 +00:00
|
|
|
} else {
|
|
|
|
BX[lp]=BX[lp]+1
|
|
|
|
}
|
|
|
|
}
|
2022-07-08 19:50:32 +00:00
|
|
|
if not DY[lp] {
|
2020-11-21 17:03:57 +00:00
|
|
|
if (BY[lp] == 0)
|
2022-07-08 19:50:32 +00:00
|
|
|
DY[lp] = true
|
2021-11-29 00:25:21 +00:00
|
|
|
else
|
2020-11-21 17:03:57 +00:00
|
|
|
BY[lp]=BY[lp]-1
|
|
|
|
} else if DY[lp] == 1 {
|
2021-11-29 00:25:21 +00:00
|
|
|
if (BY[lp] == txt.DEFAULT_HEIGHT-1) {
|
2020-11-21 17:03:57 +00:00
|
|
|
BY[lp] = txt.DEFAULT_HEIGHT-2
|
2022-07-08 19:50:32 +00:00
|
|
|
DY[lp] = false
|
2020-11-21 17:03:57 +00:00
|
|
|
} else {
|
|
|
|
BY[lp]=BY[lp]+1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
; Put the new ball possition
|
|
|
|
txt.setclr(BX[lp], BY[lp], BC[lp])
|
|
|
|
}
|
|
|
|
|
2021-11-29 00:25:21 +00:00
|
|
|
sys.waitvsync()
|
2020-11-21 17:03:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|