accuracy = 100
b = 1
y = 1
hitchance = 0
if h == 0 then
hitchance = math.random(100)
h = 1
end
counter = 0
while b == 1 do
counter = counter +1
pad = Controls.read()
screen:blit(0,0,battlescreen)
screen:blit(88, 100, pokemon[1].picB)
screen:blit(311, 28, enemy[1].pic)
screen:print(33,11,enemy[1].name, blue)
screen:print(15,20,enemy[1].C_HP.."/"..enemy[1].MAX_HP, blue)
screen:print(393, 125, pokemon[1].name, blue)
screen:print(385, 140, pokemon[1].C_HP.."/"..pokemon[1].MAX_HP, blue)
screen:print(55, 190, "Enemy "..enemy[1].name.." used quick-attack.", blue)

if pad:r() and oldpad:r() ~= pad:r() and counter >= 25 and hitchance <= accuracy then
if enemy[1].C_HP >0 then	
	damage = (40 + enemy[1].STR) / pokemon[1].DEF
	pokemon[1].C_HP = pokemon[1].C_HP - damage
	if pokemon[1].C_HP %1 ~= 0 and y == 1 then
		pokemon[1].C_HP = pokemon[1].C_HP - (pokemon[1].C_HP%1)
		y = 0
	end
	b = 0
	a = 0
	turn = 0


end
end
if pad:r() and oldpad:r() ~= pad:r() and hitchance > accuracy and counter >= 15 then		
	if h == 1 then
	screen:blit(0,171,textbox)
	screen:print(55,190, "Enemy "..enemy[1].name.." has missed", blue)
	if pad:r() and oldpad:r() ~= pad:r() and counter >= 45 then	
		turn = 0
		b = 0
		h = 0
		a = 0
		hitchance = 0
	end


end
end
if pokemon[1].C_HP < 0 then
pokemon[1].C_HP = 0
randombattle = 1
end
if enemy[1].C_HP < 0 then
enemy[1].C_HP = 0
randombattle = 2
end
 
screen.waitVblankStart()
screen.flip()
oldpad = pad
end