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

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
TERIU
Prole
Posts: 2
Joined: Sun Jul 31, 2022 9:28 am

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

Post 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
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

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

Post 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')
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

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

Post 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.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

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

Post by togFox »

Yeah. True. 4000 is a vector straight down.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
TERIU
Prole
Posts: 2
Joined: Sun Jul 31, 2022 9:28 am

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

Post by TERIU »

thx for help
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 49 guests