Page 1 of 1

I'm make game like mario and my code not working why i cant jump ;(

Posted: Sun Jul 31, 2022 9:32 am
by TERIU
function love.load()

window = love.window.setMode(800, 600, {resizable=false}) -- auto settings
wf = require "libraries/windfield"

world = wf.newWorld(0, 500)
world:addCollisionClass('solid')

ground = world:newRectangleCollider(0, 550, 800, 50)
ground:setCollisionClass('solid')

leftWall = world:newRectangleCollider(0, 0, 50, 600)
leftWall:setCollisionClass('solid')

rightWall = world:newRectangleCollider(750, 0, 50, 600)
rightWall:setCollisionClass('solid')

up = world:newRectangleCollider(0, 0, 800, 50)
up:setCollisionClass('solid')

rightWall:setType('static')
leftWall:setType('static')
ground:setType('static')
up:setType('static')
aopdoap = 1
playerS = {}
playerS.x = 250
playerS.y = 10
playerS.h = 100
playerS.w = 100
playerS.xV = 0
playerS.yV = 0
player = world:newRectangleCollider(playerS.x, playerS.y, playerS.w, playerS.h)
end

function love.update(dt)
world:update(dt)

if player:enter('solid') and love.keyboard.isDown('w') then
player:applyLinearImpulse(0, 4000)
end
end

function love.draw() --draw graphics
love.graphics.setColor(0/255, 255/255, 173/255)
world:draw()
end

function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
return x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1
end

Re: I'm make game like mario and my code not working why i cant jump ;(

Posted: Sun Jul 31, 2022 9:38 pm
by togFox
If you wrap the code with code tags on this forum then the formatting is better for us.

I suspect this bit of code is never true, or not true when you think it is.

Code: Select all

if player:enter('solid')

Re: I'm make game like mario and my code not working why i cant jump ;(

Posted: Mon Aug 01, 2022 12:58 pm
by Gunroar:Cannon()
TERIU wrote: Sun Jul 31, 2022 9:32 am
if player:enter('solid') and love.keyboard.isDown('w') then
player:applyLinearImpulse(0, 4000)
end
end
I think it may be that you're using 4000 instead of -4000. In love2d y coordinate 0 is the top of the screen not the bottom. Though also check what togFox said to be sure.

Re: I'm make game like mario and my code not working why i cant jump ;(

Posted: Mon Aug 01, 2022 9:43 pm
by togFox
Yeah. True. 4000 is a vector straight down.

Re: I'm make game like mario and my code not working why i cant jump ;(

Posted: Thu Aug 11, 2022 3:31 pm
by TERIU
thx for help