blue = Color.new(0,0,255)
green = Color.new(0,255,0)
white = Color.new(255,255,255)
red = Color.new(255,0,0)
bull = Image.load("bull.png")
s = Image.load("s.png")
g = Image.load("go.png")

f = Image.load("f.png")
counter = Timer.new()
counter:start()

wallpaper = Image.load("bg.png")

math.randomseed(os.time()) 

player = Image.createEmpty(32,32)
Player = { width=player:width(), height=player:height(), image = player }
Player.x = 300
Player.y = 240

Player.image:clear(blue) 


enemy = Image.createEmpty(32,32)
Enemy = {width=enemy:width(), height=enemy:height(), (bull)} 
Enemy.x = 50
Enemy.y = 50

score = Image.createEmpty(480,31)
score = {width=score:width(), height=score:height(), (s)}
score.x = 0
score.y = 0


function movePlayer() 
pad = Controls.read()
if pad:left() then
Player.x = Player.x - 1
end
if pad:right() then
Player.x = Player.x + 1
end
if pad:up() then
Player.y = Player.y  - 1
end
if pad:down() then
Player.y = Player.y + 1
end
end

function chasePlayer() 
stallchase = math.random(2)
if stallchase == 1 then
if Enemy.x > Player.x then
Enemy.x = Enemy.x - 5
elseif Enemy.x < Player.x then
Enemy.x = Enemy.x + 5
end
end
stallchase = math.random(2)
if stallchase == 1 then 
if Enemy.y > Player.y then
Enemy.y = Enemy.y - 5
elseif Enemy.y < Player.y then
Enemy.y = Enemy.y + 5
end
end
end

function collisionCheck(object, object2)
if (object2.x + object2.width > object.x) and (object2.x < object.x + object.width) and (object2.y + object2.height > object.y) and (object2.y < object.y + object.height) then
return 1
end
end			


while true do
screen:clear()
currentTime = counter:time()

if paused == true and currentTime > 2000 and currentTime < 2500 then
screen:blit(200,100, g)
end
screen.waitVblankStart()
pad = Controls.read()

if currentTime < 2000 or
collisionCheck(Player, Enemy) or
collisionCheck(Player, Enemy) or
collisionCheck(Player, Enemy) then
paused = true
elseif currentTime > 2500 then
paused = false
movePlayer() 

chasePlayer() 
end



screen:clear()


screen:blit(0, 0, wallpaper, false)
screen:blit(Player.x,Player.y,Player.image)
screen:blit(Enemy.x,Enemy.y,bull)
screen:blit(score.x,score.y,s)


if collisionCheck(Player, Enemy) or
collisionCheck(Player, Enemy) or
collisionCheck(Player, Enemy) then
screen:blit(0,0,f)
end
if collisionCheck(Player, score) and currentTime > 2500 or
collisionCheck(Player, score) and currentTime > 2500 or
collisionCheck(Player, score) and currentTime > 2500 then
dofile("./index.lua")
end
if pad:l() then
screen:clear()
dofile("./easy1.lua")
end
if pad:r() then
screen:clear()
dofile("./index.lua")
end






screen.waitVblankStart()
screen.flip()
end