love2d엔진 쓰는데요
dw = love.graphics.getWidth()
dh = love.graphics.getHeight()
function love.load()
music = love.audio.newSource(\"HorrorPB[1].mp3\")
love.audio.play(music)
music:setLooping(true)
world = love.physics.newWorld(-650, -500, 650, 500)
world:setGravity(0, 50)
imgg = love.graphics.newImage(\"background.png\")
imgp = love.graphics.newImage(\"cha.png\")
gw, gh, gx, gy = dw, 40, 0, dh-40
objects = {}
objects.ground={}
objects.ground.body=love.physics.newBody(world, 650/2, 475, 0, 0)
objects.ground.shape=love.physics.newRectangleShape(objects.ground.body, 0, 0, 650, 100, 0)
objects.ground.shape:setData(\"ground\")
objects.groundd={}
objects.groundd.body=love.physics.newBody(world, 650/2, -30, 0, 0)
objects.groundd.shape=love.physics.newRectangleShape(objects.groundd.body, 0, 0, 650, 10, 0)
objects.groundd.shape:setData(\"ground\")
pw = imgp:getWidth()
ph = imgp:getHeight()
px = 500
py = dh - ph*2+20
player = {}
player.b = love.physics.newBody(world, px, py, 10, 0)
player.s = love.physics.newRectangleShape(player.b, 0, 0, pw, ph, 0)
love.graphics.setMode(650,500,false,true,0)
end
function love.update(dt)
world:update(dt)
if love.keyboard.isDown(\"escape\") then
love.event.push(\'q\')
end
if love.keyboard.isDown(\"right\") then
px = math.min(px + (200*dt),dw-imgp:getWidth())
end
if love.keyboard.isDown(\"left\") then
px = math.max(px - (200*dt),0)
end
if love.keyboard.isDown(\" \")then
player.b:applyForce(0,-100)
end
player.b:setX(px)
end
function love.draw()
love.graphics.draw(imgg, 0,0)
love.graphics.draw(imgp,player.b:getX(), player.b:getY())
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle(\"fill\", objects.ground.body:getX(),objects.ground.body:getY(),650,100)
love.graphics.setColor(255, 255, 255)
love.graphics.polygon(\"fill\", objects.groundd.shape:getPoints())
end
update에서 점프 하고 싶은데 그냥 부스터 단듯이 하늘을 날아요
점프하는데 이차함수 써야한다는데 어떻게 써요?;;
점프를 구현하는데 탄도학공식을 이용하거나 중력방정식만 이용하기도 하지.. 게임 관련 물리를 검색해봐