WolfNinja2 wrote:You're right, I do want to expand a LOT, but I don't think he's talking about indentation really. I think he means how my coding works. BUT, if he's talking about the indentation I can do that no problem! In fact, I'm going to do it either way now that you mention it xD
-Wolf
Yes, yess I am talking about how it works. While what Robin and kikito, the almighty defenders of all that is this forum (which, when you think about it, is just this forum
), are definitely right in all that, this doesn't make any sense at all.
Code: Select all
if love.keyboard.isDown("up") and
onGround == true or
love.keyboard.isDown("up") and
jumping == true then
Even when you fix this semantically:
Code: Select all
if love.keyboard.isDown("up") and onGround == true or love.keyboard.isDown("up") and jumping == true then
Then that's still ridiculously bizarre. If it runs whether you're jumping or not, then why not run it whenever "up" is held? Or should it not run when you're falling? *sigh*... I'm losing my mind a bit here.
And as far as I can tell, this thing thinks from this:
Code: Select all
function playerupdate(dt)
if maploaded == true then
local dt = math.min(dt,0.1)
timedSpeed = player.speed * dt
timedyvel = player.yvel * dt
player.yvel = player.yvel + player.grav * dt
--Left and Right Collision
if love.keyboard.isDown("left") then
if mapCollide(player.x - timedSpeed, player.y + 1) or mapCollide(player.x - timedSpeed, player.y + player.h - 1) then
player.x = math.floor(player.x / tiledivisor) * tiledivisor
else
player.x = player.x - timedSpeed
end
end
if love.keyboard.isDown("right") then
if mapCollide(player.x + timedSpeed + player.w, player.y + 1) or mapCollide(player.x + timedSpeed + player.w, player.y + player.h - 1) then
player.x = (math.floor((player.x + player.w + timedSpeed) / tiledivisor) * tiledivisor) - player.w
else
player.x = player.x + timedSpeed
end
end
--Up and Down Collision
if math.abs(timedyvel) < tiledivisor then j = math.abs(timedyvel) else j = tiledivisor end
if timedyvel > 0 then negateit = 1 else negateit = -1 end
if mapCollide(player.x + 1, player.y + player.h + j*negateit) or mapCollide(player.x + player.w - 1, player.y + player.h + j*negateit) then
player.y =(math.floor((player.y + player.h + j) / tiledivisor) * tiledivisor) - player.h
player.yvel = 0
onGround = true
storedY = 0
elseif mapCollide(player.x + 1, player.y + j*negateit) or mapCollide(player.x + player.w - 1, player.y + j*negateit) then
player.y = math.floor(player.y / tiledivisor) * tiledivisor
player.yvel = 0
else
player.y = player.y + j*negateit
onGround = false
end
function skin_change(key)
--Skin Change
if love.keyboard.isDown("s") then
if P == love.graphics.newImage("player1.png") then
P = love.graphics.newImage("player2.png")
end
elseif P == love.graphics.newImage("player2.png") then
P = love.graphics.newImage("player1.png")
end
end
end
end
That function skin change is inside playerupdate... That is not what you want. There is also an extra end in that skin function that should be somewhere else. I'd normally not just give it to you, but it's so messed up, I'd be doing you and myself a disservice not to. Basically, you should get rid of that function completely, and move that end.
Code: Select all
function playerupdate(dt)
if maploaded == true then
local dt = math.min(dt,0.1)
timedSpeed = player.speed * dt
timedyvel = player.yvel * dt
player.yvel = player.yvel + player.grav * dt
--Left and Right Collision
if love.keyboard.isDown("left") then
if mapCollide(player.x - timedSpeed, player.y + 1) or mapCollide(player.x - timedSpeed, player.y + player.h - 1) then
player.x = math.floor(player.x / tiledivisor) * tiledivisor
else
player.x = player.x - timedSpeed
end
end
if love.keyboard.isDown("right") then
if mapCollide(player.x + timedSpeed + player.w, player.y + 1) or mapCollide(player.x + timedSpeed + player.w, player.y + player.h - 1) then
player.x = (math.floor((player.x + player.w + timedSpeed) / tiledivisor) * tiledivisor) - player.w
else
player.x = player.x + timedSpeed
end
end
--Up and Down Collision
if math.abs(timedyvel) < tiledivisor then j = math.abs(timedyvel) else j = tiledivisor end
if timedyvel > 0 then negateit = 1 else negateit = -1 end
if mapCollide(player.x + 1, player.y + player.h + j*negateit) or mapCollide(player.x + player.w - 1, player.y + player.h + j*negateit) then
player.y =(math.floor((player.y + player.h + j) / tiledivisor) * tiledivisor) - player.h
player.yvel = 0
onGround = true
storedY = 0
elseif mapCollide(player.x + 1, player.y + j*negateit) or mapCollide(player.x + player.w - 1, player.y + j*negateit) then
player.y = math.floor(player.y / tiledivisor) * tiledivisor
player.yvel = 0
else
player.y = player.y + j*negateit
onGround = false
end
if love.keyboard.isDown("s") then
if P == love.graphics.newImage("player1.png") then
P = love.graphics.newImage("player2.png")
elseif P == love.graphics.newImage("player2.png") then
P = love.graphics.newImage("player1.png")
end
end
end
end
You can tell this works because now pressing 's' produces the error that there's no other skin to change to. Ironic, an error showing it works, eh?