Unnamed Pathman (A Pac Man Clone)(UPDATED! 1)(+Youtube)
Re: Unnamed Pathman ( A Pac Man Clone )
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
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Unnamed Pathman ( A Pac Man Clone )
Nsmurf wrote:I'm not sure if it will, i was just saying that that might be why Larsii30 was having problems.Zer0 wrote: I doubt it have such a big effect on Fps it goes something likthe player has 4 variables for movementCode: Select all
moving = moving + dt if moving > 1 then moving = moving - 1 --turning code here end
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
Also, that is a fairly strange way to use dt (at least, to me it is.) i use it like this: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
--in love.update if love.keyboard.isDown('up') then playery = playery - 20*dt end
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
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
Re: Unnamed Pathman ( A Pac Man Clone ) ( UPDATED! 1)
Nice speed slider!
But 2 as a speed setting, lol.
Anyways, thatnks for putting in the speed slider
But 2 as a speed setting, lol.
Anyways, thatnks for putting in the speed slider
Re: Unnamed Pathman ( A Pac Man Clone ) ( UPDATED! 1)
Thanks it's 2 lines and a circle if you want i can post the code to it.Nsmurf wrote:Nice speed slider!
It's so you really have to think about where you go.Nsmurf wrote:But 2 as a speed setting, lol.
No problemNsmurf wrote:Anyways, thatnks for putting in the speed slider
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. )
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 4 guests