--COLOURS--

red = Color.new(200,0,0)
blue = Color.new(0,0,200)
black = Color.new(0,0,0)

--IMAGES--

track = Image.load("IMAGES/dragracetrack1.png")
player1won = Image.load("IMAGES/player1won.png")
player2won = Image.load("IMAGES/player2won.png")
playersdraw = Image.load("IMAGES/playersdraw.png")

--PLAYER 1 IMAGES--

dragster1 = Image.load("IMAGES/dragster1.png")

--PLAYER 2 IMAGES--

dragster2 = Image.load("IMAGES/dragster2.png")

--PLAYERS--

player1 = {}
player1.img = dragster1
player1.x = 50
player1.y = 80

player2 = {}
player2.img = dragster2
player2.x = 50
player2.y = 170

--FINISH LINE--

finishline = {}
finishline.img = Image.createEmpty(1,1)
finishline.x = 372
finishline.y = 0

--FONTS--

font1 = Font.load("FONTS/font1.ttf")
font1:setPixelSizes(25,30)

--SOUNDS--

--Wav.load("SOUNDS/carengine.wav",0)

--local volume = 1.0
--local speed = 1.0


--COUNT DOWN UNTILL RACE STARTS--
screen:clear()
screen:blit(0,0,track)
screen:blit(player1.x, player1.y, player1.img)
screen:blit(player2.x, player2.y, player2.img)

screen:fontPrint(font1,230,140,"3",black)
screen:flip()
screen.waitVblankStart(70)

screen:blit(0,0,track)
screen:blit(player1.x, player1.y, player1.img)
screen:blit(player2.x, player2.y, player2.img)

screen:fontPrint(font1,230,140,"2",black)
screen:flip()
screen.waitVblankStart(70)

screen:blit(0,0,track)
screen:blit(player1.x, player1.y, player1.img)
screen:blit(player2.x, player2.y, player2.img)

screen:fontPrint(font1,230,140,"1",black)
screen:flip()
screen.waitVblankStart(70)

screen:blit(0,0,track)
screen:blit(player1.x, player1.y, player1.img)
screen:blit(player2.x, player2.y, player2.img)

screen:fontPrint(font1,225,140,"GO!",black)
screen:flip()
screen.waitVblankStart(70)



while true do
oldpad = pad
pad = Controls.read()
screen:clear()

screen:blit(0,0,track,false)
screen:blit(player1.x, player1.y, player1.img)
screen:blit(player2.x, player2.y, player2.img)



--CONTROLS--

if pad:start() then
screen:fontPrint(font1,180,140,"Exiting...",black)
screen:flip()
dofile("FILES/MULTIPLAYER/multiplayermenu.lua")
end


if pad:select() then
screen:fontPrint(font1,170,140,"Restarting...",black)
screen:flip()
dofile("FILES/MULTIPLAYER/dragrace1.lua")
end


--PLAYER 1 CONTROLS--

if pad:right() and oldpad:right() ~= pad:right() and player1.x < 423 then
player1.x = player1.x + 4
end


--PLAYER 2 CONTROLS--

if pad:circle() and oldpad:circle() ~= pad:circle() and player2.x < 423 then
player2.x = player2.x + 4
end


--PLAYER 1 COLLISION/WIN--

if (pad:right() and player1.x > finishline.x and player1.x < (finishline.x + 30)) and (player1.y > finishline.y and player1.y < (finishline.y + 272)) then
screen:clear()
screen:blit(0,0,player1won)
screen:flip()
screen.waitVblankStart(250)
dofile("FILES/MULTIPLAYER/multiplayermenu.lua")
end


--PLAYER 2 COLLISION/WIN--

if (pad:circle() and player2.x > finishline.x and player2.x < (finishline.x + 30)) and (player2.y > finishline.y and player2.y < (finishline.y + 272)) then
screen:clear()
screen:blit(0,0,player2won)
screen:flip()
screen.waitVblankStart(250)
dofile("FILES/MULTIPLAYER/multiplayermenu.lua")
end


--PLAYERS DRAW--

if p2laps == 6 and p1laps == 6 then
screen:clear()
screen:blit(0,0,playersdraw)
screen:flip()
screen.waitVblankStart(250)
dofile("FILES/MULTIPLAYER/championshiprace2menu.lua")
end



collectgarbage()
screen.waitVblankStart()
screen.flip()
end







































