Unnamed Pathman (A Pac Man Clone)(UPDATED! 1)(+Youtube)

Show off your games, demos and other (playable) creations.

How many enemies do you play the game with? pick the 3 you play with most

1. loser lvl
2
17%
2. easy
0
No votes
3. normal
2
17%
4. hard
4
33%
5. harder
1
8%
6. devil number
1
8%
7. lucky number
1
8%
8. infinite on the side
1
8%
 
Total votes: 12

User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Unnamed Pathman ( A Pac Man Clone )

Post by Nixola »

That's a normal way to use dt, it's to repeat an action every second
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Zer0
Citizen
Posts: 59
Joined: Sat Oct 06, 2012 9:55 am
Location: Sweden
Contact:

Re: Unnamed Pathman ( A Pac Man Clone )

Post 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
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
User avatar
Nsmurf
Party member
Posts: 191
Joined: Fri Jul 27, 2012 1:58 am
Location: West coast.

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

Post by Nsmurf »

Nice speed slider!

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

Anyways, thatnks for putting in the speed slider :)
OBEY!!!
My Blog
UE0gbWUgd2l0aCB0aGUgd29yZCAnSE1TRycgYXMgdGhlIHN1YmplY3Q=
User avatar
Zer0
Citizen
Posts: 59
Joined: Sat Oct 06, 2012 9:55 am
Location: Sweden
Contact:

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

Post 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
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 4 guests