-- inizializzo le variabili
--colori
CODICE
green = Color.new(0, 255, 0)
red= Color.new(255,0, 0)
white = Color.new(255,255,255)
--variabili scritte
CODICE
tempo_scritta=0
--varibili di moto
CODICE
xspeed=4
yspeed=4
x=10
y=10
--punteggio
CODICE
punteggio = 0
--posizione nemico
CODICE
ex=math.random(470)
ey=math.random(260)
---funzioni
CODICE
function collide()
if (x>=ex-5 and x<=ex+5 and y>=ey-5 and y<=ey+5) then
tempo_scritta=30
return true
end
end
CODICE
function limiti_bordi()
if x>=470 then
x=470
end
if x<=0 then
x=0
end
if y>=260 then
y=260
end
if y<=0 then
y=0
end
end
CODICE
function disegna()
--disegna il cursore
screen:print(x, y,"X", white)
--disegna l'obiettivo
screen:print(ex, ey,"O", red)
--disegna il punteggio
screen:print(3, 3, punteggio, green)
end
CODICE
function informazioni()
--se la collisione avviene o è appena avvenuta
CODICE
if (collide() or tempo_scritta>0) then
screen:print(3, 15,"Preso!", red)
punteggio=punteggio+1
screen:print(3, 3, punteggio, green)
tempo_scritta=tempo_scritta-1
ex=math.random(470)
ey=math.random(260)
end
end
-- ciclo principale
CODICE
while true do
screen:clear()
disegna()
informazioni()
pad = Controls.read()
if pad:start() then
break
end
if pad:left() then
x=x-xspeed
end
if pad:right() then
x=x+xspeed
end
if pad:up() then
y=y-yspeed
end
if pad:down() then
y=y+yspeed
end
CODICE
limiti_bordi()
screen.waitVblankStart()
screen.flip()
end