Page 2 of 2

Re: Unnamed Pathman ( A Pac Man Clone )

Posted: Sat Oct 06, 2012 10:21 pm
by Nixola
That's a normal way to use dt, it's to repeat an action every second

Re: Unnamed Pathman ( A Pac Man Clone )

Posted: Sat Oct 06, 2012 10:40 pm
by Zer0
Nsmurf wrote:
Zer0 wrote: I doubt it have such a big effect on Fps it goes something lik

Code: Select all

moving = moving + dt
if moving > 1 then
        moving = moving - 1
        --turning code here
end
the player has 4 variables for movement
x
y
direction ( 1 to 4 where 1 = left, 2 = up, 3 = right and 4 = down )
movement ( 0 and up is increased by Delta Time, it defines how long it's left until it goes with x and y to the next position )
the same goes for the ghost's so the code runs 4 times ( at average ) per frame
I'm not sure if it will, i was just saying that that might be why Larsii30 was having problems.
Also, that is a fairly strange way to use dt (at least, to me it is.) i use it like this:

Code: Select all

--in love.update
if love.keyboard.isDown('up') then
        playery = playery - 20*dt
end
and the player would move at a rate of 20 pixels per second. (correct me if i'm wrong, but i think that's how it works)

Code: Select all

function love.load()
  player = {
    x = 8,
    y = 6,
    direction = 1, -- 0 left, 1 up, 2 right and 3 down idid it wrong last time
    walking = 0,
  }
  map = {}
  for i = 1, 16 do -- x side
    map[i] = {}
    for j = 1, 16 do -- y side
      map[i][j] = math.random()
    end
  end
  screen = {
    width = 800,
    height = 600,
  }
  scale = {
    x = screen.width / table.getn(map),
    y = screen.height / table.getn(map[1]),
  }
end

function love.update(dt)
  -- already posted this example.
end

function love.draw()
  for i = 1, table.getn(map) do
    for j = 1, table.getn(map[i]) do
      -- grid drawing here
    end
  end
  love.graphocs.circle("fill",player.x * scale.x,player.y * scale.y,0.8 *math.min(scale.x,scale.y),32)
  -- that was the player
end
thats how i do grid based rendering

Re: Unnamed Pathman ( A Pac Man Clone ) ( UPDATED! 1)

Posted: Sun Oct 07, 2012 6:41 pm
by Nsmurf
Nice speed slider!

But 2 as a speed setting, lol. :awesome:

Anyways, thatnks for putting in the speed slider :)

Re: Unnamed Pathman ( A Pac Man Clone ) ( UPDATED! 1)

Posted: Sun Oct 07, 2012 7:53 pm
by Zer0
Nsmurf wrote:Nice speed slider!
Thanks it's 2 lines and a circle if you want i can post the code to it.
Nsmurf wrote:But 2 as a speed setting, lol. :awesome:
It's so you really have to think about where you go.
Nsmurf wrote:Anyways, thatnks for putting in the speed slider :)
No problem

EDIT: here's the code

Code: Select all

function love.load()
  slider = {
    x = 100,
    y = 100,
    width = 600,
    lowvalue = 0.5,
    highvalue = 2.0,
    value = 1.0,
    move = function(t)
      slider.value = math.min(slider.highvalue,math.max(slider.lowvalue,math.lerp(slider.lowvalue,slider.highvalue,t)))
    end,
    held = false,
    offset = 0,
  }
end

function math.lerp(a,b,t)
  return a + (b - a) * t
end

function math.delerp(a,b,g)
  return (g - a) / (b - a)
end

function love.update(dt)
  mouse_x,mouse_y = love.mouse.getPos()
  if slider.held == true then
    slider.move(math.delerp(slider.x,slider.x + slider.width,mouse_x + slider.offset))
  end
end

function love.mousereleased()
  slider.held = false
end

function love.mousepressed(x,y,b)
  if math.distance(math.lerp(slider.x,slider.x + slider.width,math.delerp(slider.lowvalue,slider.highvalue,slider.value)),slider.y,mouse_x,mouse_y) < 16 then
    slider.held = true
    slider.offset = mouse_x - math.lerp(slider.x,slider.x + slider.width,math.delerp(slider.lowvalue,slider.highvalue,slider.value))
  end
end

function math.distance(x1,y1,x2,y2)
  return math.sqrt((x1 - x2)^2 + (y1 - y2)^2)
end

function love.draw()
  local lrpd = math.lerp(slider.x,slider.x + slider.width,math.delerp(slider.lowvalue,slider.highvalue,slider.value))
  love.graphics.line(math.min(slider.x,lrpd - 16),slider.y,lrpd - 16,slider.y)
  love.graphics.line(lrpd + 16,slider.y,math.max(slider.x + slider.width,lrpd + 16),slider.y)
  love.graphics.circle("line",lrpd,slider.y,16,32)
end