Skip to content

Instantly share code, notes, and snippets.

@eterps
Created May 25, 2022
Embed
What would you like to do?
% bouncing balls
-initialization(main).
main :-
poke(0x4c00, [0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c], D1),
set_colors(0x0ce9, 0x01c0, 0x0ce5, D2),
start(D1, D2).
start([], []) :-
set_screen_vector(S),
foreach(ball(S), [[1, 1, 1, 2, 2],
[2, 504, 100, -3, -2],
[3, 1, 312, 3, 3],
[1, 100, 1, -3, 3],
[2, 100, 312, 3, -2]], _).
ball(S, [C, X, Y, Dx, Dy]) :-
move(S, C, X, Y, X, Y, Dx, Dy).
move([_|S], C, X1, Y1, X, Y, Dx, Dy) :-
draw_sprite(X1, Y1, 0x00, 0x4c00, D1),
when(D1, draw_sprite(X, Y, C, 0x4c00, D2)),
X2 is X + Dx,
Y2 is Y + Dy,
when(D2, advance(S, C, X, Y, X2, Y2, Dx, Dy)).
advance(S, C, X1, Y1, X, Y, Dx, Dy) :-
X =< 0 |
Dx2 is -Dx,
advance(S, C, X1, Y1, 1, Y, Dx2, Dy).
advance(S, C, X1, Y1, X, Y, Dx, Dy) :-
Y =< 0 |
Dy2 is -Dy,
advance(S, C, X1, Y1, X, 1, Dx, Dy2).
advance(S, C, X1, Y1, X, Y, Dx, Dy) :-
X > 504 |
Dx2 is -Dx,
advance(S, C, X1, Y1, 504, Y, Dx2, Dy).
advance(S, C, X1, Y1, X, Y, Dx, Dy) :-
Y > 312 |
Dy2 is -Dy,
advance(S, C, X1, Y1, X, 312, Dx, Dy2).
advance(S, C, X1, Y1, X, Y, Dx, Dy) :-
otherwise |
move(S, C, X1, Y1, X, Y, Dx, Dy).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment