Files
ascii/demos/breakout.lua

95 lines
2.3 KiB
Lua

function init()
mode(1)
reset()
end
function reset()
bx,by=20,28
dx,dy=-1+rnd(1)*2,-1
px=18
wait=1
speed=6
bricks = {}
for i=0,35 do bricks[i]=COLOR_RED end
for i=36,71 do bricks[i]=COLOR_BROWN end
for i=72,107 do bricks[i]=COLOR_GREEN end
for i=108,143 do bricks[i]=COLOR_YELLOW end
end
function update()
-- move ball
wait=wait-1
if wait==0 then
wait=speed
bx=bx+dx
by=by+dy
if speed<6 then
if bx==2 or bx==37 then dx=-dx play("o3l0c") end
if by<9 then
local index=flr(bx/2)-1+(by-1)*18
if bricks[index]~=COLOR_BLACK then
play("o5l0c")
bricks[index]=COLOR_BLACK
dy=-dy
else
if by==1 then dy=-dy play("o3l0c") end
end
end
if by==28 and bx>=px and bx<=px+4 then
play("o4l0c")
dy=-dy
end
if by==29 then
play("l0o3bagfedc")
reset()
end
else
if bx==2 or bx==37 then dx=-dx end
if by==9 or by==29 then dy=-dy end
end
end
-- move paddle
if btn(KEY_LEFT) and px>2 then px=px-1 end
if btn(KEY_RIGHT) and px<34 then px=px+1 end
-- clear screen
paper(COLOR_BLACK)
cls()
-- draw white border
ink(COLOR_WHITE)
print("\150\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\154\156",1,0)
for i=1,29 do
print("\149",1,i)
print("\149",38,i)
end
-- draw bricks
for i=0,143 do
color(0,bricks[i])
print("\095\003",2+2*(i%18),1+flr(i/18))
end
--draw ball
color(COLOR_WHITE,COLOR_BLACK)
print("\233",bx,by)
-- draw paddle
ink(COLOR_LIGHT_BLUE)
for i=0,3 do print("\131",px+i,29) end
if speed==6 then
ink(rnd(16))
print("BREAKOUT",16,13)
ink(COLOR_WHITE)
print("Press '1' to play EASY",9,18)
print("Press '2' to play NORMAL",8,20)
print("Press '3' to play HARD",9,22)
if btn(KEY_1) then reset() speed=4 end
if btn(KEY_2) then reset() speed=3 end
if btn(KEY_3) then reset() speed=2 end
end
end