Glitch or Coding Error
Posted: Fri Jun 06, 2014 11:38 pm
here is my code
http://tinypic.com/player.php?v=1zc1n4g ... 5JQOPldXiV
is this a error in my code or a glitch all help will be much appreciated THANK YOU!
Code: Select all
function love.load()
love.graphics.setBackgroundColor( 255, 255, 255 )
xPlayer1 = 0
yPlayer1 = 0
xPlayer2 = 800
yPlayer2 = 600
imageStartMenuBG = love.graphics.newImage( "textures/StartMenuBG.png" )
imageButton1 = love.graphics.newImage( "textures/Button1.png" )
imageBackground1 = love.graphics.newImage( "textures/Background1.png" )
imagePlayerR = love.graphics.newImage( "textures/Player.png" )
imagePlayerL = love.graphics.newImage( "textures/PlayerL.png" )
imagePlayer2R = love.graphics.newImage( "textures/Player1.png" )
imagePlayer2L = love.graphics.newImage( "textures/Player1L.png" )
x = x
y = y
life1 = 10
life2 = 10
player = imagePlayerR
player2 = imagePlayer2R
gamestate = "startmenu"
end
function love.draw()
if gamestate == "startmenu" then
love.graphics.draw( imageStartMenuBG, 0, 0, 0, 1.25, 1.5, 0, 0 )
love.graphics.draw( imageButton1, 50, 50, 0, 1, 1, 0, 0 )
elseif gamestate == "playing" then
local x = love.mouse.getX( )
local y = love.mouse.getY( )
love.graphics.setColor( 255, 255, 255, 255 )
love.graphics.draw( imageBackground1, 0, 0, 0, 1, 2, 0, 0 )
love.graphics.setColor( 255, 255, 255, 255 )
love.graphics.draw( player, xPlayer1 - 8, yPlayer1 - 8, 0, 1, 1, 0, 0 )
love.graphics.draw( player2, xPlayer2 - 8, yPlayer2 - 8, 0, 1, 1, 0, 0 )
end
end
function love.update(dt)
if xPlayer1 < 0 then
xPlayer1 = 0
end
if yPlayer1 < 0 then
yPlayer1 = 0
end
if xPlayer1 > 800 - 85 then
xPlayer2 = 800 - 85
end
if yPlayer1 > 600 - 113 then
yPlayer2 = 600 - 113
end
if xPlayer2 < 0 then
xPlayer2 = 0
end
if yPlayer2 < 0 then
yPlayer2 = 0
end
if xPlayer2 > 800 - 85 then
xPlayer2 = 800 - 86
end
if yPlayer2 > 600 - 113 then
yPlayer2 = 600 - 114
end
if up then
yPlayer1 = yPlayer1 - 32*dt
else
yPlayer1 = yPlayer1
end
if down then
yPlayer1 = yPlayer1 + 32*dt
else
yPlayer1 = yPlayer1
end
if right then
player = imagePlayerR
xPlayer1 = xPlayer1 + 32*dt
else
xPlayer1 = xPlayer1
end
if left then
player = imagePlayerL
xPlayer1 = xPlayer1 - 32*dt
else
xPlayer1 = xPlayer1
end
if up2 then
yPlayer2 = yPlayer2 - 32*dt
else
yPlayer2 = yPlayer2
end
if down2 then
yPlayer2 = yPlayer2 + 32*dt
else
yPlayer2 = yPlayer2
end
if right2 then
player2 = imagePlayer2R
xPlayer2 = xPlayer2 + 32*dt
else
xPlayer2 = xPlayer2
end
if left2 then
player2 = imagePlayer2L
xPlayer2 = xPlayer2 - 32*dt
else
xPlayer2 = xPlayer2
end
if xPlayer2 > xPlayer1 - 30 and xPlayer2 < xPlayer1 + 30 and yPlayer2 < yPlayer1 + 30 and yPlayer2 > yPlayer1 - 30 and hit2 then
life1 = life1 - 1
hit2 = false
else
hit2 = false
end
if xPlayer1 > xPlayer2 - 30 and xPlayer1 < xPlayer2 + 30 and yPlayer1 < yPlayer2 + 30 and yPlayer1 > yPlayer2 - 30 and hit1 then
print("NO")
life2 = life2 - 1
hit1 = false
else
hit1 = false
end
if life1 < 1 then
xPlayer1 = 10000
yPlayer1 = -10000
end
if life2 < 1 then
xPlayer2 = -10000
yPlayer2 = 10000
end
end
function love.focus(bool)
end
function love.keypressed( key, y, x, unicode )
if love.keyboard.isDown("d") then
right = true
end
if love.keyboard.isDown("a") then
left = true
end
if love.keyboard.isDown("w") then
up = true
end
if love.keyboard.isDown("s") then
down = true
end
if love.keyboard.isDown("/") then
hit1 = true
end
if love.keyboard.isDown("right") then
right2 = true
end
if love.keyboard.isDown("left") then
left2 = true
end
if love.keyboard.isDown("up") then
up2 = true
end
if love.keyboard.isDown("down") then
down2 = true
end
if love.keyboard.isDown("rshift") then
hit2 = true
end
end
function love.keyreleased( key, unicode )
local keyup = key
print( keyup )
if keyup == "d" then
right = false
end
if keyup == "a" then
left = false
end
if keyup == "w" then
up = false
end
if keyup == "s" then
down = false
end
if keyup == "/" then
hit1 = false
end
if keyup == "right" then
right2 = false
end
if keyup == "left" then
left2 = false
end
if keyup == "up" then
up2 = false
end
if keyup == "down" then
down2 = false
end
if keyup == "rshift" then
hit2 = false
end
end
function love.mousepressed( x, y, button )
if x > 50 and x < 250 and y > 50 and y < 150 then
gamestate = "playing"
end
print( x, y )
end
function love.mousereleased( x, y, button )
end
function love.quit()
end
is this a error in my code or a glitch all help will be much appreciated THANK YOU!