Then, instead of using the function on.arrowKey(arrow), create one where you calculate the move, e.g:
function AI()
--place your Artificial Intelligence code here
--if direction==1 then
--dx=dx-1
--dy=dy-1
--else
--dx=dx+1
--dy=dy+1
--end
--if dx==0 then
--direction=1
--end
--if dy==240 then
--direction=0
--end
end
BTW, I see that you use an image from the NES & since the resolution is smaller, it will look awkward, so I would suggest to draw the rest of the background, this code would do:
function on.resize(width, height)
ww = width
wh = height
end
function on.paint(gc)
-- Paint background (sky)
gc:setColorRGB(96, 176, 248)
gc:fillRect(0, 0, ww, wh)
-- Paint floor (dirt)
gc:setColorRGB(104, 104, 0)
gc:fillRect(0, 175, ww, wh-175)
gc:drawImage(background,0,0)
gc:drawImage(duck,dx,dy)
AI()
end
Maybe you'll want to place drawing the duck image inside the AI() function, because if you're going to move the image a lot, it will look like it warps. So, you'll need to add the parameter "gc"
function on.paint(gc)
...
AI(gc)
end
function AI(gc)
gc:drawImage(duck,dx,dy)
end