GAME HORRIBLE RACING
Source Code :
% This program is created by Ivan Genov Genov
% from University of Sofia
*Kodingan pembuatan tampilan game dan pendeklarasian timer :
?-
G_Lifes:=3,
G_Counter:=0,
G_Times:=5,
G_Score:=0,
G_Depth:=10,
G_Crashed:=0,
G_Col1:=0, G_Col2:=0, G_Col3:=0,
G_Pos:=2,
G_OldPos:=GPos,
G_Pen0:= pen(1, rgb(155, 155, 255)),
G_Pen1:= pen(1, rgb(0, 0, 255)),
G_Brush0:= brush(rgb(155, 155, 255)),
G_Brush1:= brush(rgb(255, 255, 0)),
G_Brush2:= brush(rgb(255, 0, 0)),
window(G_Wnd, _, win_func(_), "Horrible Racing", 100, 0, 212, 580).
win_func(init):-
G_Timer:=set_timer(G_Wnd, 0.15, time_func).
win_func(key_down(37, _)) :-
(G_Pos > 1 -> G_OldPos:=G_Pos, G_Pos:=G_Pos - 1), draw_car.
win_func(mouse_click(_, _)) :-
(G_Pos > 1 -> G_OldPos:=G_Pos, G_Pos:=G_Pos - 1), draw_car.
win_func(key_down(39, _)) :-
(G_Pos < 3 -> G_OldPos:=G_Pos, G_Pos:=G_Pos + 1), draw_car.
win_func(r_mouse_click(_, _)) :-
(G_Pos < 3 -> G_OldPos:=G_Pos, G_Pos:=G_Pos + 1), draw_car.
*Kodingan untuk pembuatan objek player pada game :
win_func(paint):- draw.
draw_car:-
pen(G_Pen0), brush(G_Brush0),
rect(0, 420, 212, 460),
Pos:=G_Pos*60- 40,
pen(G_Pen1), brush(G_Brush1),
ellipse(Pos, 420, Pos+40, 460),
Pos:=G_OldPos*60- 40,
brush(G_Brush2),
ellipse(Pos+7- G_Crashed, 428- G_Crashed, Pos+15+G_Crashed, 439+G_Crashed),
ellipse(Pos+25- G_Crashed, 428- G_Crashed, Pos+33+G_Crashed, 439+G_Crashed),
ellipse(Pos+13- G_Crashed, 447- G_Crashed, Pos+27+G_Crashed, 453+G_Crashed).
draw:-
pen(G_Pen0), brush(G_Brush0),
rect(0, 0, 300, 600),
color_text_back(G_Wnd, rgb(155, 155, 255)),
color_text(G_Wnd, rgb(255, 255, 0)),
text_out(10, 512, "Score : "+print(G_Score)),
text_out(10, 530, "Lifes : "+print(G_Lifes)),
Pos:=G_Pos*60- 40,
pen(G_Pen1), brush(G_Brush1),
ellipse(Pos, 420, Pos+40, 460),
brush(G_Brush2),
ellipse(Pos+7- G_Crashed, 428- G_Crashed, Pos+15+G_Crashed, 439+G_Crashed),
ellipse(Pos+25- G_Crashed, 428- G_Crashed, Pos+33+G_Crashed, 439+G_Crashed),
ellipse(Pos+13- G_Crashed, 447- G_Crashed, Pos+27+G_Crashed, 453+G_Crashed),
Mask:= 1 << (G_Depth- 1),
for(I, 1, G_Depth),
(
(G_Col1 /\ Mask > 0 -> round_rect(20, I*40- 20, 60, I*40, 10, 10)),
(G_Col2 /\ Mask > 0 -> round_rect(80, I*40- 20, 120, I*40, 10, 10)),
(G_Col3 /\ Mask > 0 -> round_rect(140, I*40- 20, 180, I*40, 10, 10)),
Mask:= Mask >> 1, fail
).
*Kodingan untuk pengaturan fungsi timer game dan nyawa pada player game :
time_func(end):-
G_Counter:=G_Counter+1,
(G_Counter >= G_Times ->
G_Score:=G_Score+1,
G_Crashed:=0,
Pos:=random(300) // 100 + 1, put_trap(Pos),
once(crash(Z)),
(Z =:= G_Pos -> beep, G_Lifes:= G_Lifes- 1, G_Crashed:=3),
(G_Lifes =< 0 -> kill_timer(G_Wnd, G_Timer)),
G_Col1:=G_Col1>>1, G_Col2:=G_Col2>>1, G_Col3:=G_Col3>>1,
G_Counter:=0,
G_Times:= (200- G_Score) // 40,
draw
).
put_trap(1):- G_Col1:= G_Col1 \/ (1 << G_Depth).
put_trap(2):- G_Col2:= G_Col2 \/ (1 << G_Depth).
put_trap(3):- G_Col3:= G_Col3 \/ (1 << G_Depth).
crash(1):- G_Col1 /\ 1 > 0, G_Pos =:= 1.
crash(2):- G_Col2 /\ 1 > 0, G_Pos =:= 2.
crash(3):- G_Col3 /\ 1 > 0, G_Pos =:= 3.
crash(4).