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: 828
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')
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
User avatar
Gunroar:Cannon()
Party member
Posts: 1141
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: 828
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.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
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: No registered users and 3 guests