-- parametrlər
player = {
x = 64,
y = 64,
s = 2,
sprite = 1 -- bu sprite ID-dir
}
item_sprite = 2 -- item üçün sprite ID
score = 0
max_score = 15
items = {}
-- itemləri yarat
function spawn_items()
for i=1, max_score do
add(items, {
x=flr(rnd(120))+4,
y=flr(rnd(120))+4,
collected=false
})
end
end
function _init()
spawn_items()
end
function _update()
if score >= max_score then
return
end
-- hərəkət
if btn(0) then player.x -= player.s end
if btn(1) then player.x += player.s end
if btn(2) then player.y -= player.s end
if btn(3) then player.y += player.s end
-- sərhədlər
player.x = mid(0, player.x, 120)
player.y = mid(0, player.y, 120)
-- item toplanması
for item in all(items) do
if not item.collected and abs(player.x - item.x) < 5 and abs(player.y - item.y) < 5 then
item.collected = true
score += 1
end
end
end
function _draw()
cls()
-- itemləri çək
for item in all(items) do
if not item.collected then
spr(item_sprite, item.x, item.y)
end
end
-- karakteri çək
spr(player.sprite, player.x, player.y)
-- xal
print("xal: "..score, 1, 1, 7)
-- təbrik mesajı
if score >= max_score then
rectfill(20, 50, 108, 78, 0)
print("UYY ALLAH, QAZANDIN!", 30, 60, 11)
end
end
[Please log in to post a comment]