red = Color.new(139, 12, 5)
green = Color.new(0, 255, 0)
yellow = Color.new(240, 192, 0)
black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
orange = Color.new(255, 146, 5)
green2 = Color.new(62, 197, 21)
oldpad = Controls.read()
gamestate = "Intro"
LUA = Image.load("Pics/LuaLogo.png")
KORInc = Image.load("Pics/KORInc.png")
MBK = Image.load("Pics/MBkGnd.png")
SBK = Image.load("Pics/SBkGnd.png")
SlecBK = Image.load("Pics/SlecBkGnd.png")
TBKGND = Image.load("Pics/temple.png")
HB = Image.load("Player/HB.png")
HBT = Image.load("Player/HBT.png")
PAUSE = Image.load("Pics/Pause.png")
Lose = Image.load("Pics/loser.png")
Win = Image.load("Pics/Winner.png")
Draw = Image.load("Pics/Draw.png")
WIcon = Image.load("Pics/RoundI.png")
GBKGND = Image.load("Pics/Gbak.png")
LGBKGND = Image.load("Pics/Gbak1.png")
RGBKGND = Image.load("Pics/Gbak2.png")
HighSc = Image.load("Pics/HighSc.png")
No3 = Image.load("Pics/No3.png")
No2 = Image.load("Pics/No2.png")
No1 = Image.load("Pics/No1.png")
fight = Image.load("Pics/fight.png")
round1 = Image.load("Pics/Round1.png")
round2 = Image.load("Pics/Round2.png")
Fround = Image.load("Pics/FRound.png")
Bolt = Image.load("Pics/Bolt.png")
punch = Sound.load("Sounds/punch.wav",false)
punch2 = Sound.load("Sounds/punch2.wav",false)
Bbreak = Sound.load("Sounds/boards.wav",false)
bang = Sound.load("Sounds/bang.wav",false)
bird = Sound.load("Sounds/bird.wav",false)
Bruce = Sound.load("Sounds/brucehit.wav",false)
laugh = Sound.load("Sounds/muhahaha.wav",false)

animation = {}
animation[1] = Image.load("Player/Bruce/animation1.png")
animation[2] = Image.load("Player/Bruce/animation2.png")
animation[3] = Image.load("Player/Bruce/animation3.png")
animation[4] = Image.load("Player/Bruce/animation4.png")
animation[5] = Image.load("Player/Bruce/animation5.png")
animation[6] = Image.load("Player/Bruce/animation6.png")
animation[7] = Image.load("Player/Bruce/animation7.png")
animation[8] = Image.load("Player/Bruce/animation8.png")
animation[9] = Image.load("Player/Bruce/animation9.png")
animation[10] = Image.load("Player/Bruce/animation10.png")
animation[11] = Image.load("Player/Bruce/animation11.png")
animation[12] = Image.load("Player/Bruce/animation12.png")
animation[13] = Image.load("Player/Bruce/animation13.png")
animation[14] = Image.load("Player/Bruce/animation14.png")
animation[15] = Image.load("Player/Bruce/animation15.png")
animation[16] = Image.load("Player/Bruce/animation16.png")
animation[17] = Image.load("Player/Bruce/animation17.png")
animation[18] = Image.load("Player/Bruce/animation18.png")
animation[19] = Image.load("Player/Bruce/animation19.png")
animation[20] = Image.load("Player/Bruce/animation20.png")
animation[21] = Image.load("Player/Bruce/animation21.png")
animation[22] = Image.load("Player/Bruce/animation22.png")
animation[23] = Image.load("Player/Bruce/animation23.png")
animation[24] = Image.load("Player/Bruce/animation24.png")
animation[25] = Image.load("Player/Bruce/animation25.png")
animation[26] = Image.load("Player/Bruce/animation26.png")
animation[27] = Image.load("Player/Bruce/animation27.png")
animation[28] = Image.load("Player/Bruce/animation28.png")
animation[29] = Image.load("Player/Bruce/animation29.png")
animation[30] = Image.load("Player/Bruce/animation30.png")
animation[31] = Image.load("Player/Bruce/animation31.png")
animation[32] = Image.load("Player/Bruce/animation32.png")
Ranimation = {}
Ranimation[1] = Image.load("Player/Bruce/animation1R.png")
Ranimation[2] = Image.load("Player/Bruce/animation2R.png")
Ranimation[3] = Image.load("Player/Bruce/animation3R.png")
Ranimation[4] = Image.load("Player/Bruce/animation4R.png")
Ranimation[5] = Image.load("Player/Bruce/animation5R.png")
Ranimation[6] = Image.load("Player/Bruce/animation6R.png")
Ranimation[7] = Image.load("Player/Bruce/animation7R.png")
Ranimation[8] = Image.load("Player/Bruce/animation8R.png")
Ranimation[9] = Image.load("Player/Bruce/animation9R.png")
Ranimation[10] = Image.load("Player/Bruce/animation10R.png")
Ranimation[11] = Image.load("Player/Bruce/animation11R.png")
Ranimation[12] = Image.load("Player/Bruce/animation12R.png")
Ranimation[13] = Image.load("Player/Bruce/animation13R.png")
Ranimation[14] = Image.load("Player/Bruce/animation14R.png")
Ranimation[15] = Image.load("Player/Bruce/animation15R.png")
Ranimation[16] = Image.load("Player/Bruce/animation16R.png")
Ranimation[17] = Image.load("Player/Bruce/animation17R.png")
Ranimation[18] = Image.load("Player/Bruce/animation18R.png")
Ranimation[19] = Image.load("Player/Bruce/animation19R.png")
Ranimation[20] = Image.load("Player/Bruce/animation20R.png")
Ranimation[21] = Image.load("Player/Bruce/animation21R.png")
Ranimation[22] = Image.load("Player/Bruce/animation22R.png")
Ranimation[23] = Image.load("Player/Bruce/animation23R.png")
Ranimation[24] = Image.load("Player/Bruce/animation24R.png")
Ranimation[25] = Image.load("Player/Bruce/animation25R.png")
Ranimation[26] = Image.load("Player/Bruce/animation26R.png")
Ranimation[27] = Image.load("Player/Bruce/animation27R.png")
Ranimation[28] = Image.load("Player/Bruce/animation28R.png")
Ranimation[29] = Image.load("Player/Bruce/animation29R.png")
Ranimation[30] = Image.load("Player/Bruce/animation30R.png")
Ranimation[31] = Image.load("Player/Bruce/animation31R.png")
Ranimation[32] = Image.load("Player/Bruce/animation32R.png")

Eanimation = {}
Eanimation[1] = Image.load("Player/Ryu/animation1.png")
Eanimation[2] = Image.load("Player/Ryu/animation2.png")
Eanimation[3] = Image.load("Player/Ryu/animation3.png")
Eanimation[4] = Image.load("Player/Ryu/animation4.png")
Eanimation[5] = Image.load("Player/Ryu/animation5.png")
Eanimation[6] = Image.load("Player/Ryu/animation6.png")
Eanimation[7] = Image.load("Player/Ryu/animation7.png")
Eanimation[8] = Image.load("Player/Ryu/animation8.png")
Eanimation[9] = Image.load("Player/Ryu/animation9.png")
Eanimation[10] = Image.load("Player/Ryu/animation10.png")
Eanimation[11] = Image.load("Player/Ryu/animation11.png")
Eanimation[12] = Image.load("Player/Ryu/animation12.png")
Eanimation[13] = Image.load("Player/Ryu/animation13.png")
Eanimation[14] = Image.load("Player/Ryu/animation14.png")
Eanimation[15] = Image.load("Player/Ryu/animation15.png")
Eanimation[16] = Image.load("Player/Ryu/animation16.png")
Eanimation[17] = Image.load("Player/Ryu/animation17.png")
REanimation = {}
REanimation[1] = Image.load("Player/Ryu/animation1R.png")
REanimation[2] = Image.load("Player/Ryu/animation2R.png")
REanimation[3] = Image.load("Player/Ryu/animation3R.png")
REanimation[4] = Image.load("Player/Ryu/animation4R.png")
REanimation[5] = Image.load("Player/Ryu/animation5R.png")
REanimation[6] = Image.load("Player/Ryu/animation6R.png")
REanimation[7] = Image.load("Player/Ryu/animation7R.png")
REanimation[8] = Image.load("Player/Ryu/animation8R.png")
REanimation[9] = Image.load("Player/Ryu/animation9R.png")
REanimation[10] = Image.load("Player/Ryu/animation10R.png")
REanimation[11] = Image.load("Player/Ryu/animation11R.png")
REanimation[12] = Image.load("Player/Ryu/animation12R.png")
REanimation[13] = Image.load("Player/Ryu/animation13R.png")
REanimation[14] = Image.load("Player/Ryu/animation14R.png")
REanimation[15] = Image.load("Player/Ryu/animation15R.png")
REanimation[16] = Image.load("Player/Ryu/animation16R.png")
REanimation[17] = Image.load("Player/Ryu/animation17R.png")

Banimation = {}
Banimation[1] = Image.load("Player/board.png")
Banimation[2] = Image.load("Player/board2.png")
Banimation[3] = Image.load("Player/board3.png")
Banimation[4] = Image.load("Player/board4.png")
Banimation[5] = Image.load("Player/board5.png")
Banimation[6] = Image.load("Player/board6.png")

Round = 1

player = {}
player.gravity = 145
player.x = 70
player.y = 145
player.jumpspeed = 10
player.jumpstate = "ground"
player.health = 165
player.walk = "no"
player.style = "JKD"
player.strike = "no"
player.win = 0
player.dir = "right"

StopP1 = "no"

player2 = {}
player2.gravity = 140
player2.x = 400
player2.y = 135
player2.jumpspeed = 10
player2.jumpstate = "ground"
player2.health = 165
player2.walk = "no"
player2.win = 0

healthbar = {}
healthbar.y = 13
healthx = 53
healthcolor = green2
healthcolor2 = green2

currentEnemy = 1

Enemy = {}
Enemy[1] = { health = 80 }
Enemy[2] = { health = 80 }
Enemy[3] = { health = 80 }
MesTim = 0
MesShow = "yes"

FirstPoints = 0
RanNumber = 0
RanNumber2 = 0
anim = animation[1]
Eanim = Eanimation[1]
board = Banimation[1] 
board2 = Banimation[5]
board3 = Banimation[3]
bakg = 0
bakg2 = 480
bakg3 = -479
bakmov = "no"
lowhealth = 130

IntroTimer = 0
Timer = 99
deadCount = 0
fightCount = 0
Wasteloop = 0
Blockloop = 0
Walkloop = 0
FWalk = 0
AllowRan = "yes"

loopCount = 0
loopCount1 = 0
loopCount2 = 0
loopCount3 = 0
loopCount4 = 0
loopCount5 = 0
loopCount6 = 0
loopCount7 = 0
loopCount8 = 0
loopCount9 = 0
loopCount10 = 0
loopCount11 = 0
loopCount12 = 0
loopCount13 = 0
loopCount14 = 0
loopCount15 = 0
loopCount16 = 0
loopCount17 = 0
loopCount18 = 0
loopCount19 = 0
loopCount20 = 0
loopCount21 = 0
loopCount22 = 0
loopCount24 = 0
loopCount25 = 0
loopCount26 = 0

selector = { image = Image.createEmpty(10,2), x = 178,y = 218 }
selector.image:clear(red)
selector1 = { image = Image.createEmpty(10,2), x = 297,y = 218 }
selector1.image:clear(red)

Box = { image = Image.createEmpty(140,10), x = 48,y = 9 }
Box.image:clear(green)
Box2 = { image = Image.createEmpty(187,10), x = 250,y = 35 }
Box2.image:clear(green)
Box3 = { image = Image.createEmpty(245,64), x = 122,y = 50 }
Box3.image:clear(black)

----------------highscore varia------------

currentletter = 1
name = ""
letter = { }
letter[1] = { type = "A"}
letter[2] = { type = "B"}
letter[3] = { type = "C"}
letter[4] = { type = "D"}
letter[5] = { type = "E"}
letter[6] = { type = "F"}
letter[7] = { type = "G"}
letter[8] = { type = "H"}
letter[9] = { type = "I"}
letter[10] = { type = "J"}
letter[11] = { type = "K"}
letter[12] = { type = "L"}
letter[13] = { type = "M"}
letter[14] = { type = "N"}
letter[15] = { type = "O"}
letter[16] = { type = "P"}
letter[17] = { type = "Q"}
letter[18] = { type = "R"}
letter[19] = { type = "S"}
letter[20] = { type = "T"}
letter[21] = { type = "U"}
letter[22] = { type = "V"}
letter[23] = { type = "W"}
letter[24] = { type = "X"}
letter[25] = { type = "Y"}
letter[26] = { type = "Z"}

t = 0
spin = 200
pi = math.atan(1) * 4
SideBK1 = -71
SideBK2 = 480
SlecY = 272

function drawIntro()
screen:clear()
if IntroTimer == 0.1 then
Music.playFile("Sounds/dragon.it", true)
end
IntroTimer = IntroTimer + 0.1
if IntroTimer < 10 then
screen:blit(0,0,LUA)
end
if IntroTimer >= 10 and IntroTimer < 30 then
if spin > 0 then
spin = spin - 1.5 end
x = math.cos(pi / 16 * t) * spin
y = math.sin(pi / 16 * t) * spin
t = t + 1
if t == 63 then
t = 0
end
screen:blit(0,0,KORInc)
screen:blit(170 + x, 10 + y, Bolt)
end
if IntroTimer >= 30 then
screen:blit(0,0,MBK)
screen:blit(SideBK1,0,SBK)
screen:blit(SideBK2,0,SBK)
screen:blit(168,SlecY,SlecBK)
if SideBK1 < 0 then
SideBK1 = SideBK1 + 1
SideBK2 = SideBK2 - 1
end
if SlecY > 207 then
SlecY = SlecY - 1
end
end

if IntroTimer >= 43 then
gamestate = "menu"
end
end

function drawMenu()
screen:clear()
if Music.playing() == false then
Music.playFile("Sounds/dragon.it", true)
end
pad = Controls.read()
screen:blit(0,0,MBK)
screen:blit(409,0,SBK)
screen:blit(0,0,SBK)
screen:blit(168,207,SlecBK)
screen:blit(selector.x,selector.y,selector.image)
screen:blit(selector1.x,selector1.y,selector1.image)

if pad:up() and oldpad:up() ~= pad:up() and selector.y > 218 then
selector.y = selector.y - 20
selector1.y = selector1.y - 20
end

if pad:down() and oldpad:down() ~= pad:down() and selector.y < 249 then
selector.y = selector.y + 20
selector1.y = selector1.y + 20
end

if pad:cross() and selector.y == 238 then
gamestate = "train"
Music.pause()
end
if pad:cross() and selector.y == 218 then
gamestate = "count"
Music.pause()
Music.playFile("Sounds/InGame.it", true)
end
if pad:cross() and selector.y == 258 then
os.exit()
end
end

function drawCount()
screen:clear()
screen:blit(bakg,0,GBKGND)
screen:blit(bakg2,0,RGBKGND)
screen:blit(bakg3,0,LGBKGND)
player2BlitX = player2.x - Eanim:width()
screen:blit(player2BlitX,player2.y,Eanim)
screen:blit(player.x,player.y,anim)
screen:blit(50,9,HB)
screen:fillRect(264,17,player2.health,healthbar.y,healthcolor2)
screen:fillRect(healthx,17,player.health,healthbar.y,healthcolor)
screen:print(63,20,"Bruce Lee",black)
screen:print(395,20,"Ryu",black)
screen:print(234,20,Timer,black)
if player.win == 1 then
screen:blit(55,35,WIcon)
end
if player2.win == 1 then
screen:blit(410,35,WIcon)
end

if Round == 1 then
screen:blit(157,66,round1)
end
if Round == 2 then
screen:blit(157,66,round2)
end
if Round == 3 then
screen:blit(127,66,Fround)
end

if gamestate == "count" then
if loopCount15 >= 0 and loopCount15 < 6 then Eanim = Eanimation[1]
elseif loopCount15 >= 6 and loopCount15 < 12 then Eanim = Eanimation[2] end
if loopCount15 + 0.5 >= 12 then loopCount15 = 0 else loopCount15 = loopCount15 + 0.5 end
end
if gamestate == "count" then
if loopCount >= 0 and loopCount < 6 then anim = animation[1]
elseif loopCount >= 6 and loopCount < 12 then anim = animation[2]
elseif loopCount >= 12 and loopCount < 18 then anim = animation[3]
elseif loopCount >= 18 and loopCount < 24 then anim = animation[4]
elseif loopCount >= 24 and loopCount < 30 then anim = animation[3]
elseif loopCount >= 30 and loopCount < 36 then anim = animation[2] end
if loopCount + 1 >= 36 then loopCount = 0 else loopCount = loopCount + 1 end
end

if gamestate == "count" then
fightCount = fightCount + 1
end
if fightCount >= 0 and fightCount < 50 then
screen:blit(207,110,No3)
end
if fightCount >= 50 and fightCount < 100 then
screen:blit(207,110,No2)
end
if fightCount >= 100 and fightCount < 150 then
screen:blit(207,110,No1)
end
if fightCount >= 150 and fightCount < 200 then
screen:blit(156,110,fight)
end
if fightCount == 200 then
gamestate = "game"
end
end

function playgame()
pad = Controls.read()
screen:clear()
screen:blit(bakg,0,GBKGND)
screen:blit(bakg2,0,RGBKGND)
screen:blit(bakg3,0,LGBKGND)
if player.dir == "right" then
playerBlitX = player.x
player2BlitX = player2.x - Eanim:width()
end
if player.dir == "left" then
playerBlitX = (player.x - anim:width()) + 110
player2BlitX = player2.x - 75
end
screen:blit(player2BlitX,player2.y,Eanim)
screen:blit(playerBlitX,player.y,anim)
screen:blit(50,9,HB)
screen:fillRect(264,17,player2.health,healthbar.y,healthcolor2)
screen:fillRect(healthx,17,player.health,healthbar.y,healthcolor)
screen:print(63,20,"Bruce Lee",black)
screen:print(395,20,"Ryu",black)
screen:print(234,20,Timer,black)
if player.win == 1 then
screen:blit(55,35,WIcon)
end
if player2.win == 1 then
screen:blit(410,35,WIcon)
end

-----------------scrolling screen----------------

if player.x >= 225 and pad:right() and bakg2 >= 0 then
bakg = bakg - 2
bakg2 = bakg2 - 2
bakg3 = bakg3 - 2
end
if player.x <= 100 and pad:left() and bakg3 <= 0 then
bakg = bakg + 2
bakg2 = bakg2 + 2
bakg3 = bakg3 + 2
bakmov = "yesb"
else bakmov = "no"
end
if player.x >= 0 and player2.x + 135 >= 475 and bakg2 >= 0 then
bakg = bakg - 2
bakg2 = bakg2 - 2
bakg3 = bakg3 - 2
bakmov = "yesb"
player.x = player.x -2
StopP1 = "yes"
else StopP1 = "no"
end
if StopP1 == "yes" and pad:right() then
StopP1 = "no"
player.x = player.x -2
player.walk = "yes"
end

------------------Timer-------------------

if gamestate == "game" then
loopCount21 = loopCount21 + 0.5
end
if loopCount21 == 20 then
Timer = Timer - 1
loopCount21 = 0
end

-----------------player direction-----------

if player.x > player2.x - 50 and player.jumpstate == "ground" and player.dir == "right" then
player.dir = "left"
end
if player.x < player2.x - 50 and player.jumpstate == "ground" and player.dir == "left" then
player.dir = "right"
end

-----------------(player2)------------------
-----------------standing------------------

if player2.jumpstate == "ground" then
if loopCount15 >= 0 and loopCount15 < 6 and player.dir == "right" then Eanim = Eanimation[1]
elseif loopCount15 >= 0 and loopCount15 < 6 and player.dir == "left" then Eanim = REanimation[1]
elseif loopCount15 >= 6 and loopCount15 < 12 and player.dir == "right" then Eanim = Eanimation[2]
elseif loopCount15 >= 6 and loopCount15 < 12 and player.dir == "left" then Eanim = REanimation[2] end
if loopCount15 + 0.5 >= 12 then loopCount15 = 0 else loopCount15 = loopCount15 + 0.5 end
end

----------------walking-------------------

if player2.health <= 50 and player2.health > 0 then
lowhealth = 90
else lowhealth = 140
end
if RanNumber2 == 5 and FWalk == 0 then
FWalk = FWalk + 1
end
if FWalk >= 1 and Wasteloop == 0 then
if playerBlitX + lowhealth <= player2BlitX and player2.health >= 0 and player.dir == "right" then
player2.walk = "yes"
FWalk = FWalk + 1
RanNumber2 = 0
else player2.walk = "no"
end
end
if FWalk >= 50 then
FWalk = 0
end
if playerBlitX - lowhealth >= player2BlitX - 45 and player2.health >= 0 and player.dir == "left" then
player2.walk = "yes"
elseif player.dir == "left" then player2.walk = "no"
end
if loopCount19 == 0 and player2.walk == "yes" and bakmov == "no" and Walkloop == 0 and AllowRan == "yes" and player.dir == "right" then
player2.x = player2.x - 2
end
if loopCount19 == 0 and player2.walk == "yes" and bakmov == "no" and Walkloop == 0 and AllowRan == "yes" and player.dir == "left" then
player2.x = player2.x + 2
end
if player2.walk == "yes" or bakmov == "yesb" then
if loopCount18 >= 0 and loopCount18 < 6 and player.dir == "right" then Eanim = Eanimation[11]
elseif loopCount18 >= 0 and loopCount18 < 6 and player.dir == "left" then Eanim = REanimation[11]
elseif loopCount18 >= 6 and loopCount18 < 12 and player.dir == "right" then Eanim = Eanimation[10]
elseif loopCount18 >= 6 and loopCount18 < 12 and player.dir == "left" then Eanim = REanimation[10]
elseif loopCount18 >= 12 and loopCount18 < 18 and player.dir == "right" then Eanim = Eanimation[9]
elseif loopCount18 >= 12 and loopCount18 < 18 and player.dir == "left" then Eanim = REanimation[9]
elseif loopCount18 >= 18 and loopCount18 < 24 and player.dir == "right" then Eanim = Eanimation[11]
elseif loopCount18 >= 18 and loopCount18 < 24 and player.dir == "left" then Eanim = REanimation[11] end
if loopCount18 + 1 >= 24 then loopCount18 = 0 else loopCount18 = loopCount18 + 1 end
end

----------------movement------------------

if RanNumber2 == 2 and player2BlitX < playerBlitX + 20 and player2.x < 350 and player2.jumpstate == "ground" and AllowRan == "yes" and loopCount19 == 0 and player.dir == "right" then
player2.x = player2.x + 2
player2.walk = "yes"
end

--------------offensive decision-------------

if AllowRan == "yes" and Blockloop == 0 and Wasteloop == 0 and playerBlitX + 140 >= player2BlitX and playerBlitX + 10 <= player2BlitX and player2.jumpstate == "ground" and player.dir == "right" then
RanNumber = math.random(1,10)
else RanNumber = 10
end
if AllowRan == "yes" and Blockloop == 0 and Wasteloop == 0 and playerBlitX - 140 <= player2BlitX and playerBlitX - 10 >= player2BlitX and player2.jumpstate == "ground" and player.dir == "left" then
RanNumber = math.random(1,10)
elseif player.dir == "left" then RanNumber = 10
end

if loopCount19 == 0 and FWalk == 0 and playerBlitX + 140 <= player2BlitX and player2.jumpstate == "ground" and player.dir == "right" and Wasteloop == 0 then
RanNumber2 = math.random(1,10)
end
if loopCount19 == 0 and playerBlitX - 200 <= player2BlitX and playerBlitX - 260 >= player2BlitX and player2.jumpstate == "ground" and player.dir == "left" and Wasteloop == 0 then
RanNumber2 = math.random(1,10)
end

if RanNumber == 6 or RanNumber2 == 6 then
Wasteloop = Wasteloop + 1
end
if Wasteloop >= 1 then
Wasteloop = Wasteloop + 1
RanNumber = 0
RanNumber2 = 0
end
if Wasteloop > 40 then
Wasteloop = 0
end

if Eanim == Eanimation[8] then
loopCount16 = 0
loopCount17 = 0
end

------------------Block----------------

if RanNumber == 8 then
Blockloop = Blockloop + 1
end
if Blockloop >= 1 and Blockloop < 50 and Walkloop == 0 then
Blockloop = Blockloop + 1
if player.dir == "right" then
Eanim = Eanimation[17]
end
if player.dir == "left" then
Eanim = REanimation[17]
end
else Blockloop = 0
end

------------------Walk Away----------------

if RanNumber == 7 then
Walkloop = Walkloop + 1
end
if Walkloop >= 1 and Walkloop < 50 and Blockloop == 0 and AllowRan == "yes" and player2.x < 480 and player.dir == "right" then
Walkloop = Walkloop + 1
player2.x = player2.x + 2
player2.walk = "yes"
elseif player.dir ~= "left" then Walkloop = 0
end
if Walkloop >= 1 and Walkloop < 50 and Blockloop == 0 and AllowRan == "yes" and player2BlitX > 0 and player.dir == "left" then
Walkloop = Walkloop + 1
player2.x = player2.x - 2
player2.walk = "yes"
elseif player.dir ~= "right" then Walkloop = 0
end

------------------punch---------------

if RanNumber == 4 or RanNumber == 3 then
loopCount16 = loopCount16 + 1
end
if loopCount16 >= 1 and loopCount16 < 6 and player.dir == "right" then Eanim = Eanimation[3]
elseif loopCount16 >= 1 and loopCount16 < 6 and player.dir == "left" then Eanim = REanimation[3]
elseif loopCount16 >= 6 and loopCount16 < 13 and player.dir == "right" then Eanim = Eanimation[4]
elseif loopCount16 >= 6 and loopCount16 < 13 and player.dir == "left" then Eanim = REanimation[4]
elseif loopCount16 >= 13 and loopCount16 < 19 and player.dir == "right" then Eanim = Eanimation[3]
elseif loopCount16 >= 13 and loopCount16 < 19 and player.dir == "left" then Eanim = REanimation[3] end
if loopCount16 >= 1 and loopCount16 < 19 and loopCount17 == 0 and loopCount19 == 0 then
loopCount16 = loopCount16 + 1
else loopCount16 = 0
end

------------------kick---------------

if RanNumber == 2 or RanNumber == 1 then
loopCount17 = loopCount17 + 1
end
if loopCount17 >= 1 and loopCount17 < 6 and player.dir == "right" then Eanim = Eanimation[7]
elseif loopCount17 >= 1 and loopCount17 < 6 and player.dir == "left" then Eanim = REanimation[7]
elseif loopCount17 >= 6 and loopCount17 < 13 and player.dir == "right" then Eanim = Eanimation[6]
elseif loopCount17 >= 6 and loopCount17 < 13 and player.dir == "left" then Eanim = REanimation[6]
elseif loopCount17 >= 13 and loopCount17 < 19 and player.dir == "right" then Eanim = Eanimation[5]
elseif loopCount17 >= 13 and loopCount17 < 19 and player.dir == "left" then Eanim = REanimation[5]
elseif loopCount17 >= 19 and loopCount17 < 25 and player.dir == "right" then Eanim = Eanimation[1]
elseif loopCount17 >= 19 and loopCount17 < 25 and player.dir == "left" then Eanim = REanimation[1] end
if loopCount17 >= 1 and loopCount17 < 25 and loopCount16 == 0 and loopCount19 == 0 then
loopCount17 = loopCount17 + 0.8
else loopCount17 = 0
end

----------------Prevent RanNum------------

if loopCount16 == 0 and loopCount17 == 0 and loopCount19 == 0 and Blockloop == 0 then
AllowRan = "yes"
else AllowRan = "no"
end

------------------jumping-------------------

if player2.jumpstate == "ground" and RanNumber == 5 then player2.jumpstate = "jumping" end
if player2.jumpstate == "ground" and RanNumber2 == 1 then player2.jumpstate = "jumping" end
if player2.jumpstate == "jumping" then 
player2.jumpspeed = player2.jumpspeed - 0.8
player2.gravity = player2.gravity - player2.jumpspeed 
end
if player2.gravity < 0 then 
player2.jumpstate = "falling"
end
if player2.gravity < 140 and player2.jumpstate == "falling" then 
player2.gravity = player2.gravity + (player2.jumpspeed + 3) 
end
if player2.gravity == 140 then 
player2.jumpspeed = 14
player2.jumpstate = "ground"
end
if player2.gravity > 140 then
player2.gravity = 140
end
player2.y = player2.gravity
if player2.y == 140 then
player2.jumpstate = "ground"
end

if player2.jumpstate > "ground" and Eanim ~= Eanimation[16] then
if player.dir == "right" then
Eanim = Eanimation[15]
end
if player.dir == "left" then
Eanim = REanimation[15]
end
end

if RanNumber == 5 and player2.jumpstate == "jumping" then
player2.x = player2.x + 3
RanNumber2 = 2
end
 
------------------kick in air-----------------

if anim ~= animation[28] and RanNumber2 == 1 and player2.jumpstate == "jumping" then
RanNumber = 10
if player.dir == "right" then
Eanim = Eanimation[16]
player2.x = player2.x - 4
end
if player.dir == "left" then
Eanim = REanimation[16]
player2.x = player2.x + 4
end
end

-----------------(player2 end)------------------


---------------standing movement--------------

if player.jumpstate == "ground" and player.style == "JKD" then
if loopCount >= 0 and loopCount < 6 and player.dir == "right" then anim = animation[1]
elseif loopCount >= 0 and loopCount < 6 and player.dir == "left" then anim = Ranimation[1]
elseif loopCount >= 6 and loopCount < 12 and player.dir == "right" then anim = animation[2]
elseif loopCount >= 6 and loopCount < 12 and player.dir == "left" then anim = Ranimation[2]
elseif loopCount >= 12 and loopCount < 18 and player.dir == "right" then anim = animation[3]
elseif loopCount >= 12 and loopCount < 18 and player.dir == "left" then anim = Ranimation[3]
elseif loopCount >= 18 and loopCount < 24 and player.dir == "right" then anim = animation[4]
elseif loopCount >= 18 and loopCount < 24 and player.dir == "left" then anim = Ranimation[4]
elseif loopCount >= 24 and loopCount < 30 and player.dir == "right" then anim = animation[3]
elseif loopCount >= 24 and loopCount < 30 and player.dir == "left" then anim = Ranimation[3]
elseif loopCount >= 30 and loopCount < 36 and player.dir == "right" then anim = animation[2]
elseif loopCount >= 30 and loopCount < 36 and player.dir == "left" then anim = Ranimation[2] end
if loopCount + 1 >= 36 then loopCount = 0 else loopCount = loopCount + 1 end
end

-------------------hit, loop reset------------

if anim == animation[28] then
loopCount2 = 0
loopCount3 = 0
loopCount4 = 0
loopCount5 = 0
loopCount11 = 0
loopCount12 = 0
loopCount26 = 0
end
--------------------punch--------------------

if anim ~= animation[28] and pad:triangle() and oldpad:triangle() ~= pad:triangle() and player.jumpstate == "ground" and player.style == "JKD" then
loopCount2 = loopCount2 + 1
end
if loopCount2 >= 1 and loopCount2 < 6 and player.dir == "right" then anim = animation[11]
elseif loopCount2 >= 1 and loopCount2 < 6 and player.dir == "left" then anim = Ranimation[11]
elseif loopCount2 >= 6 and loopCount2 < 13 and player.dir == "right" then anim = animation[12]
elseif loopCount2 >= 6 and loopCount2 < 13 and player.dir == "left" then anim = Ranimation[12]
elseif loopCount2 >= 13 and loopCount2 < 19 and player.dir == "right" then anim = animation[11]
elseif loopCount2 >= 13 and loopCount2 < 19 and player.dir == "left" then anim = Ranimation[11] end

if loopCount2 >= 1 and loopCount2 < 19 and loopCount20 == 0 then
loopCount2 = loopCount2 + 1
else loopCount2 = 0
end

-------------------double punch-------------------

if anim ~= animation[28] and pad:triangle() and oldpad:triangle() ~= pad:triangle() and loopCount2 >= 10 and (anim == animation[12] or anim == Ranimation[12]) then
loopCount11 = loopCount11 + 1
end
if loopCount11 >= 1 and loopCount11 < 5 and player.dir == "right" then anim = animation[11]
elseif loopCount11 >= 1 and loopCount11 < 5 and player.dir == "left" then anim = Ranimation[11]
elseif loopCount11 >= 5 and loopCount11 < 11 and player.dir == "right" then anim = animation[23]
elseif loopCount11 >= 5 and loopCount11 < 11 and player.dir == "left" then anim = Ranimation[23]
elseif loopCount11 >= 11 and loopCount11 < 15 and player.dir == "right" then anim = animation[11]
elseif loopCount11 >= 11 and loopCount11 < 15 and player.dir == "left" then anim = Ranimation[11] end
if loopCount11 + 1 >= 15 then
loopCount11 = 0
end
if loopCount11 >= 1 then
loopCount11 = loopCount11 + 0.4
end

------------------jumping chop--------------------

if pad:triangle() and oldpad:triangle() ~= pad:triangle() and player.jumpstate > "ground" then
loopCount12 = loopCount12 + 1
end
if loopCount12 >= 1 and loopCount12 < 6 then anim = animation[24]
elseif loopCount12 >= 6 and loopCount12 < 13 then anim = animation[25]
elseif loopCount12 >= 13 and loopCount12 < 17 then anim = animation[24] end
if loopCount12 + 1 >= 17 then
loopCount12 = 0
end
if loopCount12 >= 1 then
loopCount12 = loopCount12 + 1
end

---------------------basic kick-------------------

if anim ~= animation[28] and pad:circle() and oldpad:circle() ~= pad:circle() and player.jumpstate == "ground" and loopCount3 == 0 then
loopCount3 = loopCount3 + 1
end
if loopCount3 >= 1 and loopCount3 < 5 and player.dir == "right" then anim = animation[13]
elseif loopCount3 >= 1 and loopCount3 < 5 and player.dir == "left" then anim = Ranimation[13]
elseif loopCount3 >= 5 and loopCount3 < 13 and player.dir == "right" then anim = animation[14]
elseif loopCount3 >= 5 and loopCount3 < 13 and player.dir == "left" then anim = Ranimation[14]
elseif loopCount3 >= 13 and loopCount3 < 22 and player.dir == "right" then anim = animation[13]
elseif loopCount3 >= 13 and loopCount3 < 22 and player.dir == "left" then anim = Ranimation[13]
end
if loopCount3 + 1 >= 22 then
loopCount3 = 0
end
if loopCount3 >= 1 and loopCount3 < 22 and loopCount20 == 0 then
loopCount3 = loopCount3 + 1
else loopCount3 = 0
end

---------------------double kick--------------------

if anim ~= animation[28] and pad:circle() and oldpad:circle() ~= pad:circle() and (anim == animation[14] or anim == Ranimation[14]) then
loopCount4 = loopCount4 + 1
end
if loopCount4 >= 1 and loopCount4 < 5 and player.dir == "right" then anim = animation[15]
elseif loopCount4 >= 1 and loopCount4 < 5 and player.dir == "left" then anim = Ranimation[15]
elseif loopCount4 >= 5 and loopCount4 < 7 and player.dir == "right" then anim = animation[16]
elseif loopCount4 >= 5 and loopCount4 < 7 and player.dir == "left" then anim = Ranimation[16]
elseif loopCount4 >= 7 and loopCount4 < 15 and player.dir == "right" then anim = animation[17]
elseif loopCount4 >= 7 and loopCount4 < 15 and player.dir == "left" then anim = Ranimation[17] end
if loopCount4 + 1 >= 15 then
loopCount4 = 0
end
if loopCount4 >= 1 then
loopCount4 = loopCount4 + 0.5
end
if anim == animation[16] and player.x < 380 then
player.x = player.x + 3
end

----------------------kick up---------------------

if anim ~= animation[28] and pad:up() and loopCount3 >= 1 then
loopCount3 = 0
loopCount5 = loopCount5 + 1
player.jumpstate = "jumping"
end
if loopCount5 >= 1 and loopCount5 < 4 and player.dir == "right" then anim = animation[18]
elseif loopCount5 >= 1 and loopCount5 < 4 and player.dir == "left" then anim = Ranimation[18]
elseif loopCount5 >= 4 and loopCount5 < 11 and player.dir == "right" then anim = animation[19]
elseif loopCount5 >= 4 and loopCount5 < 11 and player.dir == "left" then anim = Ranimation[19]
elseif loopCount5 >= 11 and loopCount5 < 15 and player.dir == "right" then anim = animation[18]
elseif loopCount5 >= 11 and loopCount5 < 15 and player.dir == "left" then anim = Ranimation[18]
end
if loopCount5 + 1 >= 15 then
loopCount5 = 0
end
if loopCount5 >= 1 then
loopCount5 = loopCount5 + 1
end
if anim == animation[19] and player.x < 380 then
player.x = player.x + 6
end
if anim == Ranimation[19] and player.x > 0 then
player.x = player.x - 6
end

--------------------kick in air----------------

if anim ~= animation[28] and player.jumpstate > "ground" and loopCount5 == 0 and pad:circle() and oldpad:circle() ~= pad:circle() then
if player.dir == "right" then
anim = animation[20]
end
if player.dir == "left" then
anim = Ranimation[20]
end
end
if anim == animation[20] and player.x + 156 < 480 then
player.x = player.x + 10
end
if anim == Ranimation[20] and player.x > 0 then
player.x = player.x - 10
end

----------------------block-------------------

if pad:square() and player.jumpstate == "ground" then
if player.dir == "right" then
anim = animation[29]
end
if player.dir == "left" then
anim = Ranimation[29]
end
end

--------------------crouch---------------

if pad:down() and player.jumpstate == "ground" then
if player.dir == "right" then
anim = animation[6]
end
if player.dir == "left" then
anim = Ranimation[6]
end
end

-------------------Crouch kick-------------

if anim ~= animation[28] and (anim == animation[6] or anim == Ranimation[6]) and pad:circle() and oldpad:circle() ~= pad:circle() and player.jumpstate == "ground" then
loopCount10 = loopCount10 + 1
end
if loopCount10 >= 1 and loopCount10 < 5 and player.dir == "right" then anim = animation[21]
elseif loopCount10 >= 1 and loopCount10 < 5 and player.dir == "left" then anim = Ranimation[21]
elseif loopCount10 >= 5 and loopCount10 < 13 and player.dir == "right" then anim = animation[22]
elseif loopCount10 >= 5 and loopCount10 < 13 and player.dir == "left" then anim = Ranimation[22]
elseif loopCount10 >= 13 and loopCount10 < 19 and player.dir == "right" then anim = animation[21]
elseif loopCount10 >= 13 and loopCount10 < 19 and player.dir == "left" then anim = Ranimation[21] end
if loopCount10 + 1 >= 19 then
loopCount10 = 0
end
if loopCount10 >= 1 then
loopCount10 = loopCount10 + 1
end
if anim == animation[22] and player.x < 380 then
player.x = player.x + 3
end
if anim == Ranimation[22] and player.x > 0 then
player.x = player.x - 3
end

---------------------Crouch punch-------------------

if anim ~= animation[28] and (anim == animation[6] or anim == Ranimation[6]) and pad:triangle() and oldpad:triangle() ~= pad:triangle() and player.jumpstate == "ground" then
loopCount13 = loopCount13 + 1
end
if loopCount13 >= 1 and loopCount13 < 5 and player.dir == "right" then anim = animation[26]
elseif loopCount13 >= 1 and loopCount13 < 5 and player.dir == "left" then anim = Ranimation[26]
elseif loopCount13 >= 5 and loopCount13 < 13 and player.dir == "right" then anim = animation[27]
elseif loopCount13 >= 5 and loopCount13 < 13 and player.dir == "left" then anim = Ranimation[27]
elseif loopCount13 >= 13 and loopCount13 < 19 and player.dir == "right" then anim = animation[26]
elseif loopCount13 >= 13 and loopCount13 < 19 and player.dir == "left" then anim = Ranimation[26] end
if loopCount13 + 1 >= 19 then
loopCount13 = 0
end
if loopCount13 >= 1 then
loopCount13 = loopCount13 + 1
end


------------------moving in air----------------

if pad:right() and player.jumpstate == "jumping" and player.x < 380 then
player.x = player.x + 4.5
end

if pad:left() and player.jumpstate == "jumping" and player.x > 0 then
player.x = player.x - 3.5
end

--------------------walk(forward)-----------------

if anim ~= animation[28] and pad:right() and player.dir == "right" then
player.walk = "yes"
end
if anim ~= animation[28] and pad:left() and player.dir == "left" then
player.walk = "yes"
end
if player.walk == "yes" and playerBlitX < 380 and playerBlitX + 35 <= player2BlitX and player.jumpstate == "ground" and StopP1 == "no" and player.dir == "right" then
player.x = player.x + 5
end
if player.walk == "yes" and playerBlitX > 0 and playerBlitX >= player2BlitX + 80 and player.jumpstate == "ground" and StopP1 == "no" and player.dir == "left" then
player.x = player.x - 5
end
if player.walk == "yes" and player.style == "JKD" then
if loopCount1 >= 0 and loopCount1 < 6 and player.dir == "right" then anim = animation[4]
elseif loopCount1 >= 0 and loopCount1 < 6 and player.dir == "left" then anim = Ranimation[4]
elseif loopCount1 >= 6 and loopCount1 < 12 and player.dir == "right" then anim = animation[7]
elseif loopCount1 >= 6 and loopCount1 < 12 and player.dir == "left" then anim = Ranimation[7]
elseif loopCount1 >= 12 and loopCount1 < 18 and player.dir == "right" then anim = animation[8]
elseif loopCount1 >= 12 and loopCount1 < 18 and player.dir == "left" then anim = Ranimation[8]
elseif loopCount1 >= 18 and loopCount1 < 24 and player.dir == "right" then anim = animation[9]
elseif loopCount1 >= 18 and loopCount1 < 24 and player.dir == "left" then anim = Ranimation[9]
elseif loopCount1 >= 24 and loopCount1 < 30 and player.dir == "right" then anim = animation[10]
elseif loopCount1 >= 24 and loopCount1 < 30 and player.dir == "left" then anim = Ranimation[10] end
if loopCount1 + 1 >= 30 then loopCount1 = 0 else loopCount1 = loopCount1 + 1 end
end

--------------------walk(back)-----------------

if anim ~= animation[28] and pad:left() and player.dir == "right" then
player.walk = "yesb"
else player.walk = "no"
end
if anim ~= animation[28] and pad:right() and player.dir == "left" then
player.walk = "yesb"
elseif player.dir ~= "right" then player.walk = "no"
end
if player.walk == "yesb" and bakmov == "no" and player.x >= 0 and player.jumpstate == "ground" and player.dir == "right" then
player.x = player.x - 3.5
end
if player.walk == "yesb" and bakmov == "no" and player.x <= 400 and player.jumpstate == "ground" and player.dir == "left" then
player.x = player.x + 3.5
end
if player.walk == "yesb" and player.style == "JKD" then
if loopCount1 >= 0 and loopCount1 < 6 and player.dir == "right" then anim = animation[10]
elseif loopCount1 >= 0 and loopCount1 < 6 and player.dir == "left" then anim = Ranimation[10]
elseif loopCount1 >= 6 and loopCount1 < 12 and player.dir == "right" then anim = animation[9]
elseif loopCount1 >= 6 and loopCount1 < 12 and player.dir == "left" then anim = Ranimation[9]
elseif loopCount1 >= 12 and loopCount1 < 18 and player.dir == "right" then anim = animation[8]
elseif loopCount1 >= 12 and loopCount1 < 18 and player.dir == "left" then anim = Ranimation[8]
elseif loopCount1 >= 18 and loopCount1 < 24 and player.dir == "right" then anim = animation[7]
elseif loopCount1 >= 18 and loopCount1 < 24 and player.dir == "left" then anim = Ranimation[7]
elseif loopCount1 >= 24 and loopCount1 < 30 and player.dir == "right" then anim = animation[4]
elseif loopCount1 >= 24 and loopCount1 < 30 and player.dir == "left" then anim = Ranimation[4] end
if loopCount1 + 1 >= 30 then loopCount1 = 0 else loopCount1 = loopCount1 + 0.8 end
end

------------------jumping-------------------

if anim == animation[28] and player.jumpstate > "ground" then
loopCount24 = loopCount24 + 1
end
if player.jumpstate > "ground" and anim ~= animation[18] and anim ~= Ranimation[18] and anim ~= animation[19] and anim ~= Ranimation[19] and anim ~= animation[20] and anim ~= Ranimation[20] and anim ~= animation[24] and anim ~= animation[24] and anim ~= animation[25] and anim ~= Ranimation[25] then
if player.dir == "right" then
anim = animation[5]
end
if player.dir == "left" then
anim = Ranimation[5]
end
end

if pad:cross() and player.jumpstate == "ground" then player.jumpstate = "jumping" end 
if player.jumpstate == "jumping" then 
player.jumpspeed = player.jumpspeed - 0.8
player.gravity = player.gravity - player.jumpspeed 
end
if player.gravity < 0 then 
player.jumpstate = "falling"
end
if player.gravity < 145 and player.jumpstate == "falling" then 
player.gravity = player.gravity + (player.jumpspeed + 3) 
end
if player.gravity == 145 then 
player.jumpspeed = 14
player.jumpstate = "ground"
end

if player.gravity > 145 then player.gravity = 145
end
player.y = player.gravity
if player.y == 145 and anim ~= animation[32] then
player.jumpstate = "ground"
end

----------------hitting(P2)------------------

if Eanim ~= Eanimation[17] and anim == animation[14] and loopCount3 <= 6 and player.x + anim:width() >= player2BlitX then
player2.health = player2.health  - 3
local sound = punch
voice = sound:play()
Eanim = Eanimation[8]
end
if Eanim ~= REanimation[17] and anim == Ranimation[14] and loopCount3 <= 7 and playerBlitX <= player2.x then
player2.health = player2.health  - 3
local sound = punch
voice = sound:play()
Eanim = REanimation[8]
end

if Eanim ~= Eanimation[17] and anim == animation[17] and loopCount4 <= 8 and player.x + anim:width() >= player2BlitX and player.x + anim:width() <= player2.x then
player2.health = player2.health - 5
local sound = punch
voice = sound:play()
Eanim = Eanimation[8]
end
if Eanim ~= REanimation[17] and anim == Ranimation[17] and loopCount4 <= 8 and playerBlitX <= player2.x then
player2.health = player2.health - 5
local sound = punch
voice = sound:play()
Eanim = REanimation[8]
end

if Eanim ~= Eanimation[17] and anim == animation[12] and loopCount2 <= 7 and player.x + anim:width() >= player2BlitX and player.x + anim:width() <= player2.x then
player2.health = player2.health - 3
local sound = punch2
voice = sound:play()
Eanim = Eanimation[8]
end
if Eanim ~= REanimation[17] and anim == Ranimation[12] and loopCount2 <= 7 and playerBlitX <= player2.x then
player2.health = player2.health - 3
local sound = punch2
voice = sound:play()
Eanim = REanimation[8]
end

if Eanim ~= Eanimation[17] and anim == animation[22] and loopCount10 <= 6 and player.x + anim:width() >= player2BlitX and player.x + anim:width() <= player2.x then
player2.health = player2.health - 3
local sound = punch2
voice = sound:play()
Eanim = Eanimation[8]
end
if Eanim ~= REanimation[17] and anim == Ranimation[22] and loopCount10 <= 6 and playerBlitX <= player2.x then
player2.health = player2.health - 3
local sound = punch2
voice = sound:play()
Eanim = REanimation[8]
end

if Eanim ~= Eanimation[17] and anim == animation[19] and loopCount5 <= 5 and player.x + anim:width() >= player2BlitX and player.x + anim:width() <= player2.x then
player2.health = player2.health - 3
local sound = punch2
voice = sound:play()
Eanim = Eanimation[8]
end
if Eanim ~= REanimation[17] and anim == Ranimation[19] and loopCount5 <= 5 and playerBlitX <= player2.x then
player2.health = player2.health - 3
local sound = punch2
voice = sound:play()
Eanim = REanimation[8]
end

if Eanim ~= Eanimation[17] and anim == animation[23] and loopCount11 <= 6 and player.x + anim:width() >= player2BlitX and player.x + anim:width() <= player2.x then
player2.health = player2.health - 7
local sound = punch
voice = sound:play()
Eanim = Eanimation[8]
end
if Eanim ~= REanimation[17] and anim == Ranimation[23] and loopCount11 <= 6 and playerBlitX <= player2.x then
player2.health = player2.health - 7
local sound = punch
voice = sound:play()
Eanim = REanimation[8]
end

if Eanim ~= Eanimation[17] and anim == animation[25] and loopCount12 <= 7 and player.x + anim:width() >= player2BlitX and player.x + anim:width() <= player2.x then
player2.health = player2.health - 5
local sound = punch
voice = sound:play()
Eanim = Eanimation[8]
end
if Eanim ~= REanimation[17] and anim == Ranimation[25] and loopCount12 <= 7 and playerBlitX <= player2.x then
player2.health = player2.health - 5
local sound = punch
voice = sound:play()
Eanim = REanimation[8]
end

if Eanim ~= Eanimation[17] and anim == animation[27] and loopCount13 <= 6 and player.x + anim:width() >= player2BlitX and player.x + anim:width() <= player2.x then
player2.health = player2.health - 3
local sound = punch
voice = sound:play()
Eanim = Eanimation[8]
end
if Eanim ~= REanimation[17] and anim == Ranimation[27] and loopCount13 <= 6 and playerBlitX <= player2.x then
player2.health = player2.health - 3
local sound = punch
voice = sound:play()
Eanim = REanimation[8]
end

if Eanim ~= Eanimation[17] and anim == animation[20] and playerBlitX + anim:width() >= player2BlitX and playerBlitX + anim:width() <= (player2BlitX + Eanim:width()) and player.y + anim:height() <= player2.y then
player2.health = player2.health - 4
local sound = punch2
voice = sound:play()
Eanim = Eanimation[8]
end
if (loopCount19 > 0 or loopCount22 > 0) and anim == animation[20] then
anim = animation[5]
end
if Eanim ~= REanimation[17] and anim == Ranimation[20] and playerBlitX <= player2BlitX + Eanim:width() and playerBlitX >= player2BlitX and player.y + anim:height() <= player2.y then
player2.health = player2.health - 4
local sound = punch2
voice = sound:play()
Eanim = REanimation[8]
end
if (loopCount19 > 0 or loopCount22 > 0) and anim == Ranimation[20] then
anim = Ranimation[5]
end

-----------------hitting(P1)-----------------

if Eanim == Eanimation[6] and player2BlitX <= (player.x + anim:width()) and player2BlitX >= player.x and anim ~= animation[29] and loopCount17 <= 8 then
player.health = player.health - 7
healthx = healthx + 7
local sound = punch2
voice = sound:play()
anim = animation[28]
end
if Eanim == REanimation[6] and (player2BlitX + Eanim:width()) >= (playerBlitX + 30) and (player2BlitX + Eanim:width()) <= (playerBlitX + anim:width()) and anim ~= Ranimation[29] and loopCount17 <= 8 then
player.health = player.health - 7
healthx = healthx + 7
local sound = punch2
voice = sound:play()
anim = Ranimation[28]
end

if Eanim == Eanimation[16] and player2BlitX <= player.x + anim:width() and player2BlitX >= player.x and anim ~= animation[29] and player2.y + Eanim:height() >= player.y then
player.health = player.health - 10
healthx = healthx + 10
local sound = punch2
voice = sound:play()
anim = animation[28]
end
if (loopCount20 > 0 or loopCount24 > 0) and Eanim == Eanimation[16] then
Eanim = Eanimation[15]
end

if Eanim == Eanimation[4] and player2BlitX <= (player.x + anim:width()) and player2BlitX >= player.x and anim ~= animation[29] and loopCount16 <= 7 then
player.health = player.health - 5
healthx = healthx + 5
local sound = punch
voice = sound:play()
anim = animation[28]
end
if Eanim == REanimation[4] and (player2BlitX + Eanim:width()) >= (playerBlitX + 30) and (player2BlitX + Eanim:width()) <= (playerBlitX + anim:width()) and anim ~= Ranimation[29] and loopCount16 <= 7 then
player.health = player.health - 5
healthx = healthx + 5
local sound = punch
voice = sound:play()
anim = Ranimation[28]
end

-----------------Hit effect-------------

if (Eanim == Eanimation[8] or Eanim == REanimation[8]) and loopCount19 == 0 then loopCount19 = loopCount19 + 1 end
if loopCount19 >= 1 and player.dir == "right" then Eanim = Eanimation[8] loopCount19 = loopCount19 + 1 end
if loopCount19 >= 1 and player.dir == "left" then Eanim = REanimation[8] loopCount19 = loopCount19 + 1 end
if loopCount19 == 20 then loopCount19 = 0
end
if Eanim == Eanimation[8] and player2BlitX + 129 <= 479 then
player2.x = player2.x + 1
end
if Eanim == REanimation[8] and player2BlitX + 129 <= 479 then
player2.x = player2.x - 1
end

if (anim == animation[28] or anim == Ranimation[28]) and loopCount20 == 0 then loopCount20 = loopCount20 + 1 end
if loopCount20 >= 1 and player.dir == "right" then anim = animation[28] loopCount20 = loopCount20 + 1 end
if loopCount20 >= 1 and player.dir == "left" then anim = Ranimation[28] loopCount20 = loopCount20 + 1 end
if anim == animation[28] and player.x > 0 then
player.x = player.x - 1
end
if anim == Eanimation[28] and player.x < 350 then
player.x = player.x + 1
end
if loopCount20 == 20 then loopCount20 = 0 
end

---------------------falling effect(p1)------------------

if player.health <= 0 and loopCount24 == 0 then
loopCount24 = loopCount24 + 1
end

if (anim == animation[28] or anim == Ranimation[28]) and player.jumpstate > "ground" then
loopCount24 = loopCount24 + 1
end

if loopCount24 >= 1 and loopCount24 < 6 and player.dir == "right" then anim = animation[30]
elseif loopCount24 >= 1 and loopCount24 < 6 and player.dir == "left" then anim = Ranimation[30]
elseif loopCount24 >= 6 and loopCount24 < 11 and player.dir == "right" then anim = animation[31]
elseif loopCount24 >= 6 and loopCount24 < 11 and player.dir == "left" then anim = Ranimation[31]
elseif loopCount24 >= 11 and loopCount24 < 16 and player.dir == "right" then anim = animation[32]
elseif loopCount24 >= 11 and loopCount24 < 16 and player.dir == "left" then anim = Ranimation[32]
end
if loopCount24 >= 1 and loopCount24 <= 16 then
loopCount24 = loopCount24 + 0.5
end

if loopCount24 >= 16 and player.health > 0 then
loopCount24 = 0
end
if loopCount24 >= 16 and player.health <= 0 then
anim = animation[32]
end

---------------------falling effect(p2)------------------

if player2.health <= 0 and loopCount22 == 0 then
loopCount22 = loopCount22 + 1
end

if player2.jumpstate > "ground" and (Eanim == Eanimation[8] or Eanim == REanimation[8]) then
loopCount22 = loopCount22 + 1
end

if loopCount22 >= 1 and loopCount22 < 6 and player.dir == "right" then Eanim = Eanimation[12]
elseif loopCount22 >= 1 and loopCount22 < 6 and player.dir == "left" then Eanim = REanimation[12]
elseif loopCount22 >= 6 and loopCount22 < 12 and player.dir == "right" then Eanim = Eanimation[13]
elseif loopCount22 >= 6 and loopCount22 < 12 and player.dir == "left" then Eanim = REanimation[13]
elseif loopCount22 >= 12 and loopCount22 < 18 and player.dir == "right" then Eanim = Eanimation[14]
elseif loopCount22 >= 12 and loopCount22 < 18 and player.dir == "left" then Eanim = REanimation[14]
end
if loopCount22 >= 1 and loopCount22 <= 18 then
loopCount22 = loopCount22 + 0.5
end
if loopCount22 >= 16 and player2.health > 0 then
loopCount22 = 0
end
if loopCount22 >= 17 and player2.health <= 0 then
Eanim = Eanimation[14]
end

-------------------Sound effects--------------------

if loopCount3 == 6 and (anim == animation[14] or anim == Ranimation[14]) then
local sound = Bruce
voice = sound:play()
end

-----------------health bar change---------------

if player2.health <= 164 and player2.health >= 80 then
healthcolor2 = yellow
end
if player2.health <= 79 and player2.health >= 25 then
healthcolor2 = orange
end
if player2.health <= 24 and player2.health >= 0 then
healthcolor2 = red
end

if player.health <= 164 and player.health >= 80 then
healthcolor = yellow
end
if player.health <= 79 and player.health >= 25 then
healthcolor = orange
end
if player.health <= 24 and player.health >= 0 then
healthcolor = red
end

-----------------dead effects--------------------

if player.health <= 0 and loopCount24 > 15 and player.jumpstate == "ground" then
gamestate = "WinLose"
end
if player2.health <= 0 and loopCount22 > 15 and player2.jumpstate == "ground" then
gamestate = "WinLose"
end
if Timer <= 0 then
gamestate = "WinLose"
end----------------Go to pause--------------

if oldpad:start() and not pad:start() then
gamestate = "Pause"
end
end

function playWinLose()
if player.health < player2.health then
screen:blit(145,110,Lose)
deadCount = deadCount + 1
end
if player2.health < player.health then
screen:blit(145,110,Win)
deadCount = deadCount + 1
end
if player.health == player2.health then
screen:blit(145,110,Draw)
deadCount = deadCount + 1
end

if deadCount == 1 and player.health < player2.health then
player2.win = player2.win + 1
local sound = laugh
voice = sound:play()
end
if deadCount == 1 and player2.health < player.health then
player.win = player.win + 1
end
if deadCount == 1 and player2.health == player.health then
player.win = player.win + 1
player2.win = player2.win + 1
end
if player.win == 1 then
screen:blit(55,35,WIcon)
end
if player2.win == 1 then
screen:blit(410,35,WIcon)
end
if player.win == 2 then
screen:blit(76,35,WIcon)
end
if player2.win == 2 then
screen:blit(389,35,WIcon)
end

if player.win == 2 and deadCount == 199 then
gamestate = "score"
end
if player2.win == 2 and deadCount == 199 then
gamestate = "menu"
Music.stop()
end

if player.win == 1 then
FirstPoints = player.health * 100 + Timer * 100
end

if deadCount == 200 then
Round = Round + 1
anim = animation[1]
Eanim = Eanimation[1]
player.x = 70
player.y = 145
player.health = 165
player.style = "JKD"
player2.x = 400
player2.y = 135
player2.health = 165
healthx = 53
healthcolor = green2
healthcolor2 = green2
loopCount = 0
loopCount1 = 0
loopCount2 = 0
loopCount3 = 0
loopCount4 = 0
loopCount5 = 0
loopCount6 = 0
loopCount7 = 0
loopCount8 = 0
loopCount9 = 0
loopCount10 = 0
loopCount11 = 0
loopCount22 = 0
loopCount24 = 0
Timer = 99
deadCount = 0
fightCount = 0
bakg = 0
bakg2 = 479
bakg3 = -479
gamestate = "count"
end
end

--------------------high score-----------
function playscore()
y = 75
Total = player.health * 100 + Timer * 100 + FirstPoints
pad = Controls.read()
screen:clear()
screen:blit(0,0,HighSc)
screen:print(50,160,"Name:",black)
screen:print(95,160,letter[currentletter].type,black)
screen:print(115,160,name,red)
screen:print(75,138,"Score = " .. Total ,red)
if pad:up() and oldpad:up() ~= pad:up() and letter[currentletter].type <= "Y" then
currentletter = currentletter + 1
end
if pad:down() and oldpad:down() ~= pad:down() and letter[currentletter].type >= "B" then
currentletter = currentletter - 1
end
if pad:right() and oldpad:right() ~= pad:right() then
name = name .. letter[currentletter].type
end
if pad:left() and oldpad:left() ~= pad:left() then
name = string.sub(name, 1, string.len(name) - 1)
end
file = io.open("Score.txt","r")
for line in file:lines() do
y = y + 10
screen:print(330,y,line,red)
end
file:close()
if pad:cross() and oldpad:cross() ~= pad:cross()  then
file = io.open("Score.txt","a")
myText = "\n" .. name .. "-" .. Total
file:write(myText)
file:close()
end
if pad:start() then
gamestate = "menu"
Music.stop()
end
end

function drawInfo()
MesTim = MesTim + 1
pad = Controls.read()
if board == Banimation[1] then
screen:blit(Box3.x,Box3.y,Box3.image)
screen:print(124,52,"OK, destroy the boards one by",green)
screen:print(124,62,"one, start with standing moves:",green)
screen:print(124,72,"Circle = Kick",green)
screen:print(124,82,"Triangle = Punch",green)
screen:print(124,92,"Double tap to double them up",green)
screen:print(154,102,"Press X to exit menu",red)
end

if board == Banimation[2] and board2 == Banimation[5] then
screen:blit(Box3.x,Box3.y,Box3.image)
screen:print(124,52,"Good, now for crouching moves:",green)
screen:print(124,62,"First crouch by holding down",green)
screen:print(124,72,"then",green)
screen:print(124,82,"Circle = Sliding Kick",green)
screen:print(124,92,"Triangle = Crouching punch",green)
screen:print(154,102,"Press X to exit menu",red)
end

if board == Banimation[2] and board2 == Banimation[6] and board3 == Banimation[3] then
screen:blit(Box3.x,Box3.y,Box3.image)
screen:print(124,52,"Good, now for jumping moves:",green)
screen:print(124,62,"Up tap circle = Jumping kick",green)
screen:print(124,72,"jump by pushing cross",green)
screen:print(124,82,"Circle = Super Kick",green)
screen:print(124,92,"Triangle = Jumping chop",green)
screen:print(154,102,"Press X to exit menu",red)
end

if board == Banimation[2] and board2 == Banimation[6] and board3 == Banimation[4] then
screen:blit(Box3.x,Box3.y,Box3.image)
screen:print(124,52,"Well done you have completed",green)
screen:print(123,62,"training, if you would like to",green)
screen:print(124,72,"play again push start and ",green)
screen:print(124,82,"exit to the menu and go into",green)
screen:print(124,92,"the training option again.",green)
end
if oldpad:cross() and not pad:cross() and MesTim >= 10 then
MesShow = "no"
MesTim = 0
gamestate = "train"
end
if oldpad:start() and not pad:start() then
gamestate = "PauseT"
end
end


function playtrain()
pad = Controls.read()
---------------whats shown on screen(in game)------------
screen:clear()
screen:blit(0,0,TBKGND)
--------------flash the broken boards-------------
if loopCount7 == 0 then
screen:blit(200,145,board)
end
if loopCount7 == 2 then
screen:blit(200,145,board)
end
if loopCount7 == 4 then
screen:blit(200,145,board)
end
if loopCount7 == 6 then
screen:blit(200,145,board)
end
if loopCount7 == 8 then
screen:blit(200,145,board)
MesShow = "yes"
end
if loopCount8 == 0 then
screen:blit(270,145,board2)
end
if loopCount8 == 2 then
screen:blit(270,145,board2)
end
if loopCount8 == 4 then
screen:blit(270,145,board2)
end
if loopCount8 == 6 then
screen:blit(270,145,board2)
end
if loopCount8 == 8 then
screen:blit(270,145,board2)
MesShow = "yes"
end
if loopCount9 == 0 then
screen:blit(320,60,board3)
end
if loopCount9 == 2 then
screen:blit(320,60,board3)
end
if loopCount9 == 4 then
screen:blit(320,60,board3)
end
if loopCount9 == 6 then
screen:blit(320,60,board3)
end
if loopCount9 == 8 then
screen:blit(320,60,board3)
MesShow = "yes"
end
screen:blit(player.x,player.y,anim)
screen:blit(182,15,HBT)
screen:fillRect(185,17,Enemy[currentEnemy].health,healthbar.y,yellow)
screen:print(186,20,"Board No." .. currentEnemy,black)

---------------------bird sounds--------------------

if gamestate == "train" then
loopCount14 = loopCount14 + 0.25
end
if loopCount14 == 10 then
local sound = bird
voice = sound:play()
end
if loopCount14 >= 70.1 then
loopCount14 = 1
end

-----------------------Break board flash--------------------

if board == Banimation[2] and loopCount7 < 10 then
loopCount7 = loopCount7 + 0.5
end

if board2 == Banimation[6] and loopCount8 < 10 then
loopCount8 = loopCount8 + 0.5
end

if board3 == Banimation[4] and loopCount9 < 10 then
loopCount9 = loopCount9 + 0.5
end

-------------------------board hitting(1)---------------------

if anim == animation[12] and loopCount2 <= 7 and player.x + anim:width() >= 200 and board == Banimation[1] then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5
local sound = punch2
voice = sound:play()
end

if anim == animation[23] and loopCount11 <= 6 and player.x + anim:width() >= 200 and board == Banimation[1] then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5
local sound = punch2
voice = sound:play()
end

if anim == animation[14] and loopCount3 <= 6 and player.x + anim:width() >= 200 and board == Banimation[1] then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5
local sound = punch
voice = sound:play()
end

if anim == animation[17] and loopCount4 <= 9 and player.x + anim:width() >= 202 and board == Banimation[1] then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 10
local sound = punch
voice = sound:play()
end

-------------------------board hitting(2)---------------------

if anim == animation[22] and loopCount10 <= 7 and player.x + 173 >= 277 and player.x + 114 <= 305 and board2 == Banimation[5] and board == Banimation[2] then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5
local sound = punch
voice = sound:play()
end

if anim == animation[27] and loopCount13 <= 7 and player.x + 115 >= 277 and player.x + 115 <= 305 and board2 == Banimation[5] and board == Banimation[2] then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5
local sound = punch2
voice = sound:play()
end


-------------------------board hitting(3)---------------------

if anim == animation[20] and player.y > 5 and player.y < 90 and player.x + 156 >= 320 and player.x + 156 <= 348 and board3 == Banimation[3] and board2 == Banimation[6] then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5
local sound = punch
voice = sound:play()
end

if anim == animation[19] and player.y < 90 and player.x + 123 >= 320 and player.x + 123 <= 348 and board3 == Banimation[3] and board2 == Banimation[6] and loopCount5 <= 8 then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5
local sound = punch
voice = sound:play()
end

if anim == animation[25] and player.y < 120 and player.x + 113 >= 320 and player.x + 113 <= 348 and board3 == Banimation[3] and board2 == Banimation[6] and loopCount12 <= 7 then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 10
local sound = punch2
voice = sound:play()
end

---------------switching boards--------------

if Enemy[currentEnemy].health <= 0 and currentEnemy <= 2 then
currentEnemy = currentEnemy + 1
end

if Enemy[1].health <= 0 and currentEnemy <= 4 then
board = Banimation[2]
end

if Enemy[2].health <= 0 and currentEnemy <= 4 then
board2 = Banimation[6]
end

if Enemy[3].health <= 0 and currentEnemy <= 4 then
board3 = Banimation[4]
end

if board == Banimation[2] and loopCount6 == 0 then
local sound = Bbreak
voice = sound:play()
loopCount6 = loopCount6 + 1
end

if board2 == Banimation[6] and loopCount6 == 1 then
local sound = Bbreak
voice = sound:play()
loopCount6 = loopCount6 + 1
end

if board3 == Banimation[4] and loopCount6 == 2 then
local sound = bang
voice = sound:play()
loopCount6 = loopCount6 + 1
end

---------------standing movement--------------

if player.jumpstate == "ground" then
if loopCount >= 0 and loopCount < 6 then anim = animation[1]
elseif loopCount >= 6 and loopCount < 12 then anim = animation[2]
elseif loopCount >= 12 and loopCount < 18 then anim = animation[3]
elseif loopCount >= 18 and loopCount < 24 then anim = animation[4]
elseif loopCount >= 24 and loopCount < 30 then anim = animation[3]
elseif loopCount >= 30 and loopCount < 36 then anim = animation[2] end
if loopCount + 1 >= 36 then loopCount = 0 else loopCount = loopCount + 1 end
end

--------------------punch--------------------

if pad:triangle() and oldpad:triangle() ~= pad:triangle() and player.jumpstate == "ground" then
loopCount2 = loopCount2 + 1
end
if loopCount2 >= 1 and loopCount2 < 6 then anim = animation[11]
elseif loopCount2 >= 6 and loopCount2 < 13 then anim = animation[12]
elseif loopCount2 >= 13 and loopCount2 < 19 then anim = animation[11] end
if loopCount2 + 1 >= 19 then
loopCount2 = 0
end
if loopCount2 >= 1 then
loopCount2 = loopCount2 + 1
end
-------------------double punch-------------------

if pad:triangle() and oldpad:triangle() ~= pad:triangle() and anim == animation[12] and loopCount2 >= 10 then
loopCount11 = loopCount11 + 1
end
if loopCount11 >= 1 and loopCount11 < 5 then anim = animation[11]
elseif loopCount11 >= 5 and loopCount11 < 11 then anim = animation[23]
elseif loopCount11 >= 11 and loopCount11 < 15 then anim = animation[11] end
if loopCount11 + 1 >= 15 then
loopCount11 = 0
end
if loopCount11 >= 1 then
loopCount11 = loopCount11 + 0.4
end

------------------jumping chop--------------------

if pad:triangle() and oldpad:triangle() ~= pad:triangle() and player.jumpstate > "ground" then
loopCount12 = loopCount12 + 1
end
if loopCount12 >= 1 and loopCount12 < 6 then anim = animation[24]
elseif loopCount12 >= 6 and loopCount12 < 13 then anim = animation[25]
elseif loopCount12 >= 13 and loopCount12 < 17 then anim = animation[24] end
if loopCount12 + 1 >= 17 then
loopCount12 = 0
end
if loopCount12 >= 1 then
loopCount12 = loopCount12 + 1
end

---------------------basic kick-------------------

if pad:circle() and oldpad:circle() ~= pad:circle() and player.jumpstate == "ground" then
loopCount3 = loopCount3 + 1
end
if loopCount3 >= 1 and loopCount3 < 5 then anim = animation[13]
elseif loopCount3 >= 5 and loopCount3 < 13 then anim = animation[14]
elseif loopCount3 >= 13 and loopCount3 < 22 then anim = animation[13] end
if loopCount3 + 1 >= 22 then
loopCount3 = 0
end
if loopCount3 >= 1 then
loopCount3 = loopCount3 + 1
end

---------------------double kick--------------------

if pad:circle() and oldpad:circle() ~= pad:circle() and anim == animation[14] then
loopCount4 = loopCount4 + 1
end
if loopCount4 >= 1 and loopCount4 < 5 then anim = animation[15]
elseif loopCount4 >= 5 and loopCount4 < 7 then anim = animation[16]
elseif loopCount4 >= 7 and loopCount4 < 15 then anim = animation[17] end
if loopCount4 + 1 >= 15 then
loopCount4 = 0
end
if loopCount4 >= 1 then
loopCount4 = loopCount4 + 0.5
end
if anim == animation[17] and player.x < 110 and board == Banimation[1] then
player.x = player.x + 2
end
if anim == animation[17] and player.x < 175 and board == Banimation[2] and board2 == Banimation[5] then
player.x = player.x + 2
end
if anim == animation[17] and player.x < 380 and board2 == Banimation[6] then
player.x = player.x + 2
end

----------------------kick up---------------------

if pad:up() and loopCount3 >= 1 then
loopCount3 = 0
loopCount5 = loopCount5 + 1
player.jumpstate = "jumping"
end
if loopCount5 >= 1 and loopCount5 < 4 then anim = animation[18]
elseif loopCount5 >= 4 and loopCount5 < 11 then anim = animation[19]
elseif loopCount5 >= 11 and loopCount5 < 15 then anim = animation[18]
end
if loopCount5 + 1 >= 15 then
loopCount5 = 0
end
if loopCount5 >= 1 then
loopCount5 = loopCount5 + 1
end
if anim == animation[19] and player.x < 110 and board == Banimation[1] then
player.x = player.x + 6
end
if anim == animation[19] and player.x < 175 and board == Banimation[2] and board2 == Banimation[5] then
player.x = player.x + 6
end
if anim == animation[19] and player.x < 380 and board2 == Banimation[6] then
player.x = player.x + 6
end


--------------------kick in air----------------

if player.jumpstate > "ground" and loopCount5 == 0 and player.x + 156 < 480 and pad:circle() then
anim = animation[20]
player.x = player.x + 10
end

--------------------crouch---------------

if pad:down() and player.jumpstate == "ground" then
anim = animation[6]
end

-------------------Crouch kick-------------

if anim == animation[6] and pad:circle() and oldpad:circle() ~= pad:circle() and player.jumpstate == "ground" then
loopCount10 = loopCount10 + 1
end
if loopCount10 >= 1 and loopCount10 < 5 then anim = animation[21]
elseif loopCount10 >= 5 and loopCount10 < 13 then anim = animation[22]
elseif loopCount10 >= 13 and loopCount10 < 19 then anim = animation[21] end
if loopCount10 + 1 >= 19 then
loopCount10 = 0
end
if loopCount10 >= 1 then
loopCount10 = loopCount10 + 1
end
if anim == animation[22] and player.x < 110 and board == Banimation[1] then
player.x = player.x + 3
end
if anim == animation[22] and player.x < 175 and board == Banimation[2] and board2 == Banimation[5] then
player.x = player.x + 3
end
if anim == animation[22] and player.x < 380 and board2 == Banimation[6] then
player.x = player.x + 3
end

---------------------Crouch punch-------------------

if anim == animation[6] and pad:triangle() and oldpad:triangle() ~= pad:triangle() and player.jumpstate == "ground" then
loopCount13 = loopCount13 + 1
end
if loopCount13 >= 1 and loopCount13 < 5 then anim = animation[26]
elseif loopCount13 >= 5 and loopCount13 < 13 then anim = animation[27]
elseif loopCount13 >= 13 and loopCount13 < 19 then anim = animation[26] end
if loopCount13 + 1 >= 19 then
loopCount13 = 0
end
if loopCount13 >= 1 then
loopCount13 = loopCount13 + 1
end

--------------------walk(forward)-----------------

if pad:right() and player.x < 110 and board == Banimation[1] and player.jumpstate == "ground" then
player.x = player.x + 5
if loopCount1 >= 0 and loopCount1 < 6 then anim = animation[4]
elseif loopCount1 >= 6 and loopCount1 < 12 then anim = animation[7]
elseif loopCount1 >= 12 and loopCount1 < 18 then anim = animation[8]
elseif loopCount1 >= 18 and loopCount1 < 24 then anim = animation[9]
elseif loopCount1 >= 24 and loopCount1 < 30 then anim = animation[10] end
if loopCount1 + 1 >= 30 then loopCount1 = 0 else loopCount1 = loopCount1 + 1 end
end

if pad:right() and player.x < 175 and board == Banimation[2] and board2 == Banimation[5] and player.jumpstate == "ground" then
player.x = player.x + 5
if loopCount1 >= 0 and loopCount1 < 6 then anim = animation[4]
elseif loopCount1 >= 6 and loopCount1 < 12 then anim = animation[7]
elseif loopCount1 >= 12 and loopCount1 < 18 then anim = animation[8]
elseif loopCount1 >= 18 and loopCount1 < 24 then anim = animation[9]
elseif loopCount1 >= 24 and loopCount1 < 30 then anim = animation[10] end
if loopCount1 + 1 >= 30 then loopCount1 = 0 else loopCount1 = loopCount1 + 1 end
end

if pad:right() and player.x < 380 and board2 == Banimation[6] and player.jumpstate == "ground" then
player.x = player.x + 5
if loopCount1 >= 0 and loopCount1 < 6 then anim = animation[4]
elseif loopCount1 >= 6 and loopCount1 < 12 then anim = animation[7]
elseif loopCount1 >= 12 and loopCount1 < 18 then anim = animation[8]
elseif loopCount1 >= 18 and loopCount1 < 24 then anim = animation[9]
elseif loopCount1 >= 24 and loopCount1 < 30 then anim = animation[10] end
if loopCount1 + 1 >= 30 then loopCount1 = 0 else loopCount1 = loopCount1 + 1 end
end

if player.x >= 190 and board2 == Banimation[5] then
screen:blit(Box2.x,Box2.y,Box2.image)
screen:print(251,36,"No boards here, go back",black)
end


--------------------walk(back)-----------------

if pad:left() and player.x > 0 and player.jumpstate == "ground" then
player.x = player.x - 3.5
if loopCount1 >= 0 and loopCount1 < 6 then anim = animation[10]
elseif loopCount1 >= 6 and loopCount1 < 12 then anim = animation[9]
elseif loopCount1 >= 12 and loopCount1 < 18 then anim = animation[8]
elseif loopCount1 >= 18 and loopCount1 < 24 then anim = animation[7]
elseif loopCount1 >= 24 and loopCount1 < 30 then anim = animation[4] end
if loopCount1 + 1 >= 30 then loopCount1 = 0 else loopCount1 = loopCount1 + 0.8 end
end

------------------moving in air----------------

if pad:right() and player.jumpstate == "jumping" and player.x < 380 then
player.x = player.x + 4.5
end

if pad:left() and player.jumpstate == "jumping" and player.x > 0 then
player.x = player.x - 3.5
end

------------------jumping-------------------

if pad:cross() and player.jumpstate > "ground" then
anim = animation[5]
end

if pad:cross() and player.jumpstate == "ground" then player.jumpstate = "jumping" end 
if player.jumpstate == "jumping" then 
player.jumpspeed = player.jumpspeed - 0.8
player.gravity = player.gravity - player.jumpspeed 
end
if player.gravity < 0 then 
player.jumpstate = "falling"
end
if player.gravity < 145 and player.jumpstate == "falling" then 
player.gravity = player.gravity + (player.jumpspeed + 3) 
end
if player.gravity == 145 then 
player.jumpspeed = 14
player.jumpstate = "ground"
end

if player.gravity > 145 then player.gravity = 145
end
player.y = player.gravity
if player.y == 145 then
player.jumpstate = "ground"
end

---------------------Goto training messages--------------

if MesShow == "yes" and loopCount14 >= 0.5 then
gamestate = "Info"
end

----------------Go to pause--------------

if oldpad:start() and not pad:start() then
gamestate = "PauseT"
end
end

-----------------PAUSE menu-----------------

function drawPauseT()
pad = Controls.read()
screen:blit(0,0,PAUSE)
if oldpad:cross() and not pad:cross() then
gamestate = "train"
end
if pad:triangle() then
gamestate = "menu"
end
end

function drawPause()
pad = Controls.read()
screen:blit(0,0,PAUSE)
if oldpad:cross() and not pad:cross() then
gamestate = "game"
end
if pad:triangle() then
gamestate = "menu"
Music.stop()
end
end


-------------Main loop--------------
while true do

if gamestate == "Intro" then
drawIntro()
end

if gamestate == "menu" then
drawMenu()
end

if gamestate == "count" then
drawCount()
end

if gamestate == "game" then
playgame()
end

if gamestate == "WinLose" then
playWinLose()
end

if gamestate == "train" then
playtrain()
end

if gamestate == "score" then
playscore()
end

if gamestate == "PauseT" then
drawPauseT()
end
if gamestate == "Pause" then
drawPause()
end

if gamestate == "Info" then
drawInfo()
end

if gamestate == "menu" then
MesShow = "yes"
anim = animation[1]
Eanim = Eanimation[1]
Round = 1
player.x = 70
player.y = 145
player.health = 165
player.style = "JKD"
player.win = 0
player2.x = 400
player2.y = 135
player2.health = 165
player2.win = 0
Enemy[1].health = 80
Enemy[2].health = 80
Enemy[3].health = 80
healthx = 53
healthcolor = green2
healthcolor2 = green2
board = Banimation[1] 
board2 = Banimation[5]
board3 = Banimation[3]
currentEnemy = 1
loopCount = 0
loopCount1 = 0
loopCount2 = 0
loopCount3 = 0
loopCount4 = 0
loopCount5 = 0
loopCount6 = 0
loopCount7 = 0
loopCount8 = 0
loopCount9 = 0
loopCount10 = 0
loopCount11 = 0
loopCount14 = 0
loopCount22 = 0
loopCount24 = 0
Timer = 99
deadCount = 0
fightCount = 0
bakg = 0
bakg2 = 479
bakg3 = -479
end

screen.waitVblankStart()
screen.flip()
oldpad = pad
end 
