So what i'm trying to do is make a frogger game and make the frog jump 1/11 of the screen. So below I have an example but the jump length is not measured in pixels. If anyone could help me that'd be great me and a friend are making this for a school project, thanks.
player = {x = 1, y = 1, jumpLength = 40000, playerImg = love.graphics.newImage('frog.png')}
player.y = player.y - (player.jumpLength * dt)
How can I make the player move a certain ammount of pixels?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 14
- Joined: Mon Sep 28, 2015 3:28 pm
- CanadianGamer
- Party member
- Posts: 132
- Joined: Tue Jun 30, 2015 1:23 pm
- Location: Canada
- Contact:
Re: How can I make the player move a certain ammount of pixe
Do you need the frog to jump in an arc or can it be a linear movement?
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
Re: How can I make the player move a certain ammount of pixe
What you've got there
Will move the player by jumpLength pixels per second.MichaelShort wrote:player.y = player.y - (player.jumpLength * dt)
-
- Prole
- Posts: 14
- Joined: Mon Sep 28, 2015 3:28 pm
Re: How can I make the player move a certain ammount of pixe
Id like it to be linear movement.CanadianGamer wrote:Do you need the frog to jump in an arc or can it be a linear movement?
-
- Prole
- Posts: 14
- Joined: Mon Sep 28, 2015 3:28 pm
Re: How can I make the player move a certain ammount of pixe
So it will move it 40,000 pixels? When me and my friend do it on are screen it doesn't even go are full height of the screen (1080). Are we missing something here?Ulydev wrote:What you've got there
Will move the player by jumpLength pixels per second.MichaelShort wrote:player.y = player.y - (player.jumpLength * dt)
- CanadianGamer
- Party member
- Posts: 132
- Joined: Tue Jun 30, 2015 1:23 pm
- Location: Canada
- Contact:
Re: How can I make the player move a certain ammount of pixe
It might help if you posted all the code so that we can get a little more context.
My serious itch.io page:
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
https://pentamonium-studios.itch.io/
My less serious itch.io page:
http://canadiangamer.itch.io
-
- Prole
- Posts: 14
- Joined: Mon Sep 28, 2015 3:28 pm
Re: How can I make the player move a certain ammount of pixe
Frog is 64x64 pixels.CanadianGamer wrote:It might help if you posted all the code so that we can get a little more context.
Code: Select all
player = {x = 1, y = 1, jumpLength = 40000, playerImg = love.graphics.newImage('frog.png')}
jump = true
jumpMax = 0.4
jumpTimer = jumpMax
play = false
sound = love.audio.newSource("Frogger - Main.mp3")
--[[
frog width: 64
frog height: 64
screen height: 1031
screen width: 1920
--]]
function love.load()
end
function love.update(dt)
sound:setVolume(0.2)
sound:play()
jumpTimer = jumpTimer - (1 * dt)
if jumpTimer < 0 then
jump = true
end
if love.keyboard.isDown('escape') then
love.event.push('quit')
end
if love.keyboard.isDown('return') then
play = true
end
if love.keyboard.isDown('w') and jump and play then
player.y = player.y - (player.jumpLength * dt)
jump = false
jumpTimer = jumpMax
end
if love.keyboard.isDown('s') and jump and play then
player.y = player.y + (player.jumpLength * dt)
jump = false
jumpTimer = jumpMax
end
if love.keyboard.isDown('a') and jump and play then
player.x = player.x - (player.jumpLength * dt)
jump = false
jumpTimer = jumpMax
end
if love.keyboard.isDown('d') and jump and play then
player.x = player.x + (player.jumpLength * dt)
jump = false
jumpTimer = jumpMax
end
end
function love.draw()
if play == true then
love.graphics.setColor(0, 255, 0)
love.graphics.draw(player.playerImg, player.x, player.y)
else
if play == false then
love.graphics.setFont(love.graphics.newFont(20))
love.graphics.setColor(0, 191, 255)
love.graphics.print("Press enter/return to start!", love.graphics:getWidth()/2-100, love.graphics:getHeight()/2)
end
end
end
Re: How can I make the player move a certain ammount of pixe
Okay, it looks like you want to create a Frogger clone?
If so you don't have to use love.update to update the movement (if you dont want smooth movement). Instead try to use the keypressed callback. And then to move the frog just update its x / y position by adding a static value (the jumpDistance).
Here is a small example:
Another way would be to create a tile based level or a grid to move the frog from cell to cell.
If so you don't have to use love.update to update the movement (if you dont want smooth movement). Instead try to use the keypressed callback. And then to move the frog just update its x / y position by adding a static value (the jumpDistance).
Here is a small example:
Code: Select all
love.window.setTitle("Frogger")
love.window.setMode(512, 512, {vsync = false})
WIDTH, HEIGHT = love.graphics.getDimensions()
-- Create the Frog --
local frog = {}
frog.w = 64
frog.h = 64
frog.x = 0
frog.y = 192
frog.jumpDistance = 64
function frog.move(dx, dy)
frog.x = frog.x + dx
frog.y = frog.y + dy
end
function frog.draw()
love.graphics.setColor(0, 255, 0)
love.graphics.rectangle("fill", frog.x, frog.y, frog.w, frog.h)
love.graphics.setColor(255, 255, 255)
end
function frog.keypressed(key)
if key == "w" and frog.y > 0 then frog.move(0, -frog.jumpDistance)
elseif key == "s" and frog.y < HEIGHT - frog.h then frog.move(0, frog.jumpDistance) end
if key == "a" and frog.x > 0 then frog.move(-frog.jumpDistance, 0)
elseif key == "d" and frog.x < WIDTH - frog.w then frog.move(frog.jumpDistance, 0) end
end
-- Main callbacks --
function love.draw()
frog.draw()
love.graphics.print("ESC to Quit")
end
function love.keypressed(key)
frog.keypressed(key)
if key == "escape" then love.event.quit() end
end
-
- Prole
- Posts: 14
- Joined: Mon Sep 28, 2015 3:28 pm
Re: How can I make the player move a certain ammount of pixe
Alright thank you. So I think it was not working because we had * dt.MadByte wrote:Okay, it looks like you want to create a Frogger clone?
If so you don't have to use love.update to update the movement (if you dont want smooth movement). Instead try to use the keypressed callback. And then to move the frog just update its x / y position by adding a static value (the jumpDistance).
Here is a small example:Another way would be to create a tile based level or a grid to move the frog from cell to cell.Code: Select all
love.window.setTitle("Frogger") love.window.setMode(512, 512, {vsync = false}) WIDTH, HEIGHT = love.graphics.getDimensions() -- Create the Frog -- local frog = {} frog.w = 64 frog.h = 64 frog.x = 0 frog.y = 192 frog.jumpDistance = 64 function frog.move(dx, dy) frog.x = frog.x + dx frog.y = frog.y + dy end function frog.draw() love.graphics.setColor(0, 255, 0) love.graphics.rectangle("fill", frog.x, frog.y, frog.w, frog.h) love.graphics.setColor(255, 255, 255) end function frog.keypressed(key) if key == "w" and frog.y > 0 then frog.move(0, -frog.jumpDistance) elseif key == "s" and frog.y < HEIGHT - frog.h then frog.move(0, frog.jumpDistance) end if key == "a" and frog.x > 0 then frog.move(-frog.jumpDistance, 0) elseif key == "d" and frog.x < WIDTH - frog.w then frog.move(frog.jumpDistance, 0) end end -- Main callbacks -- function love.draw() frog.draw() love.graphics.print("ESC to Quit") end function love.keypressed(key) frog.keypressed(key) if key == "escape" then love.event.quit() end end
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests